Skip to content

Commit

Permalink
[LSC] Remove UTF8ToUTF16 from Literals without Escape Sequences
Browse files Browse the repository at this point in the history
This change removes calls to base::UTF8ToUTF16 with a single-line string
literal not containing escape sequences and replaces them with a u"..."
literal instead.

This is a mechanical change:
$ git grep -lw UTF8ToUTF16 | \
      xargs sed -i 's/\(base::\)\?UTF8ToUTF16(\("[^\\"]*"\))/u\2/g'
$ git cl format

AX-Relnotes: n/a.

Bug: 1189439
Change-Id: I6df2e531f62926a12be3f610ce8627d94ec407f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2776021
Commit-Queue: Jan Wilken Dörrie <[email protected]>
Commit-Queue: Daniel Cheng <[email protected]>
Reviewed-by: Daniel Cheng <[email protected]>
Owners-Override: Daniel Cheng <[email protected]>
Cr-Commit-Position: refs/heads/master@{#865390}
  • Loading branch information
jdoerrie authored and Chromium LUCI CQ committed Mar 22, 2021
1 parent d82d122 commit 2c470ea
Show file tree
Hide file tree
Showing 451 changed files with 3,096 additions and 3,772 deletions.
4 changes: 2 additions & 2 deletions android_webview/browser/state_serializer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ std::unique_ptr<content::NavigationEntry> CreateNavigationEntry() {
content::Referrer referrer;
referrer.url = GURL("http://referrer_url");
referrer.policy = network::mojom::ReferrerPolicy::kOrigin;
const std::u16string title(base::UTF8ToUTF16("title"));
const std::u16string title(u"title");
const bool has_post_data = true;
const GURL original_request_url("http://original_request_url");
const GURL base_url_for_data_url("http://base_url");
Expand Down Expand Up @@ -182,7 +182,7 @@ TEST_F(AndroidWebViewStateSerializerTest,
GURL virtual_url("https://example.com/virtual_url");
content::Referrer referrer(GURL("https://example.com/referrer"),
network::mojom::ReferrerPolicy::kDefault);
std::u16string title = base::UTF8ToUTF16("title");
std::u16string title = u"title";
std::string empty_encoded_page_state = "";
bool has_post_data = false;
GURL original_request_url("https://example.com/original");
Expand Down
3 changes: 1 addition & 2 deletions ash/app_list/app_list_controller_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,7 @@ TEST_F(AppListControllerImplTest, MAYBE_CloseNotificationWithAppListShown) {
message_center::MessageCenter::Get()->AddNotification(
std::make_unique<message_center::Notification>(
message_center::NOTIFICATION_TYPE_BASE_FORMAT, notification_id,
base::UTF8ToUTF16(notification_title),
base::UTF8ToUTF16("test message"), gfx::Image(),
base::UTF8ToUTF16(notification_title), u"test message", gfx::Image(),
std::u16string() /* display_source */, GURL(),
message_center::NotifierId(), message_center::RichNotificationData(),
new message_center::NotificationDelegate()));
Expand Down
37 changes: 18 additions & 19 deletions ash/app_list/views/app_list_view_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ class AppListViewFocusTest : public views::ViewsTestBase,
// Arabic word of "test".
? base::UTF8ToUTF16(
"\xd8\xa7\xd8\xae\xd8\xaa\xd8\xa8\xd8\xa7\xd8\xb1")
: base::UTF8ToUTF16("test");
: u"test";
textfield->InsertText(
text,
ui::TextInputClient::InsertTextCursorBehavior::kMoveCursorAfterText);
Expand Down Expand Up @@ -749,7 +749,7 @@ class AppListViewFocusTest : public views::ViewsTestBase,

// Clean up
textfield->RequestFocus();
textfield->SetText(base::UTF8ToUTF16(""));
textfield->SetText(u"");
}

AppListView* app_list_view() { return view_; }
Expand Down Expand Up @@ -1002,7 +1002,7 @@ TEST_P(AppListViewFocusTest, LeftRightFocusTraversalInHalfState) {
// Arabic word of "test".
? base::UTF8ToUTF16(
"\xd8\xa7\xd8\xae\xd8\xaa\xd8\xa8\xd8\xa7\xd8\xb1")
: base::UTF8ToUTF16("test");
: u"test";
search_box_view()->search_box()->InsertText(
text,
ui::TextInputClient::InsertTextCursorBehavior::kMoveCursorAfterText);
Expand Down Expand Up @@ -1323,23 +1323,22 @@ TEST_F(AppListViewFocusTest, RedirectFocusToSearchBox) {
GetAllSuggestions()[0]->RequestFocus();
SimulateKeyPress(ui::VKEY_A, false);
EXPECT_EQ(search_box_view()->search_box(), focused_view());
EXPECT_EQ(search_box_view()->search_box()->GetText(), base::UTF8ToUTF16("a"));
EXPECT_EQ(search_box_view()->search_box()->GetText(), u"a");
EXPECT_FALSE(search_box_view()->search_box()->HasSelection());

// Set focus to close button and type a character.
search_box_view()->close_button()->RequestFocus();
EXPECT_NE(search_box_view()->search_box(), focused_view());
SimulateKeyPress(ui::VKEY_B, false);
EXPECT_EQ(search_box_view()->search_box(), focused_view());
EXPECT_EQ(search_box_view()->search_box()->GetText(),
base::UTF8ToUTF16("ab"));
EXPECT_EQ(search_box_view()->search_box()->GetText(), u"ab");
EXPECT_FALSE(search_box_view()->search_box()->HasSelection());

// Set focus to close button and hitting backspace.
search_box_view()->close_button()->RequestFocus();
SimulateKeyPress(ui::VKEY_BACK, false);
EXPECT_EQ(search_box_view()->search_box(), focused_view());
EXPECT_EQ(search_box_view()->search_box()->GetText(), base::UTF8ToUTF16("a"));
EXPECT_EQ(search_box_view()->search_box()->GetText(), u"a");
EXPECT_FALSE(search_box_view()->search_box()->HasSelection());
}

Expand All @@ -1360,18 +1359,18 @@ TEST_F(AppListViewFocusTest, SearchBoxTextUpdatesOnResultFocus) {
// Change focus to the next result
SimulateKeyPress(ui::VKEY_TAB, false);

EXPECT_EQ(search_box->GetText(), base::UTF8ToUTF16("TestResult2"));
EXPECT_EQ(search_box->GetText(), u"TestResult2");

SimulateKeyPress(ui::VKEY_TAB, true);

EXPECT_EQ(search_box->GetText(), base::UTF8ToUTF16("TestResult1"));
EXPECT_EQ(search_box->GetText(), u"TestResult1");

SimulateKeyPress(ui::VKEY_TAB, false);

// Change focus to the final result
SimulateKeyPress(ui::VKEY_TAB, false);

EXPECT_EQ(search_box->GetText(), base::UTF8ToUTF16("TestResult3"));
EXPECT_EQ(search_box->GetText(), u"TestResult3");
}

// Tests that ctrl-A selects all text in the searchbox when the SearchBoxView is
Expand Down Expand Up @@ -1474,7 +1473,7 @@ TEST_F(AppListViewFocusTest, HittingEnterWhenFocusOnSearchBox) {
// Type something in search box to transition to HALF state and populate
// fake list results. Then hit Enter key.
search_box_view()->search_box()->InsertText(
base::UTF8ToUTF16("test"),
u"test",
ui::TextInputClient::InsertTextCursorBehavior::kMoveCursorAfterText);
const int kListResults = 2;
SetUpSearchResults(0, kListResults);
Expand Down Expand Up @@ -1775,7 +1774,7 @@ TEST_F(AppListViewTest, TypingPeekingToHalf) {
Show();
search_box->SetText(std::u16string());
search_box->InsertText(
base::UTF8ToUTF16("nice"),
u"nice",
ui::TextInputClient::InsertTextCursorBehavior::kMoveCursorAfterText);

ASSERT_EQ(ash::AppListViewState::kHalf, view_->app_list_state());
Expand All @@ -1792,7 +1791,7 @@ TEST_F(AppListViewTest, TypingFullscreenToFullscreenSearch) {

search_box->SetText(std::u16string());
search_box->InsertText(
base::UTF8ToUTF16("https://youtu.be/dQw4w9WgXcQ"),
u"https://youtu.be/dQw4w9WgXcQ",
ui::TextInputClient::InsertTextCursorBehavior::kMoveCursorAfterText);

ASSERT_EQ(ash::AppListViewState::kFullscreenSearch, view_->app_list_state());
Expand All @@ -1807,7 +1806,7 @@ TEST_F(AppListViewTest, TypingTabletModeFullscreenSearch) {
Show();
search_box->SetText(std::u16string());
search_box->InsertText(
base::UTF8ToUTF16("cool!"),
u"cool!",
ui::TextInputClient::InsertTextCursorBehavior::kMoveCursorAfterText);

ASSERT_EQ(ash::AppListViewState::kFullscreenSearch, view_->app_list_state());
Expand Down Expand Up @@ -2220,7 +2219,7 @@ TEST_F(AppListViewTest, DISABLED_SearchResultsTest) {
view_->Layout();
EXPECT_TRUE(IsStateShown(ash::AppListState::kStateApps));

std::u16string search_text = base::UTF8ToUTF16("test");
std::u16string search_text = u"test";
main_view->search_box_view()->search_box()->SetText(std::u16string());
main_view->search_box_view()->search_box()->InsertText(
search_text,
Expand All @@ -2241,7 +2240,7 @@ TEST_F(AppListViewTest, DISABLED_SearchResultsTest) {
EXPECT_TRUE(CheckSearchBoxWidget(
contents_view->GetSearchBoxBounds(ash::AppListState::kStateApps)));

std::u16string new_search_text = base::UTF8ToUTF16("apple");
std::u16string new_search_text = u"apple";
main_view->search_box_view()->search_box()->SetText(std::u16string());
main_view->search_box_view()->search_box()->InsertText(
new_search_text,
Expand Down Expand Up @@ -2296,7 +2295,7 @@ TEST_F(AppListViewTest, DISABLED_BackTest) {
EXPECT_EQ(1, delegate_->dismiss_count());

// Show the search results.
std::u16string new_search_text = base::UTF8ToUTF16("apple");
std::u16string new_search_text = u"apple";
search_box_view->search_box()->SetText(std::u16string());
search_box_view->search_box()->InsertText(
new_search_text,
Expand Down Expand Up @@ -2407,7 +2406,7 @@ TEST_F(AppListViewTest, BackAction) {
// Select the second page and open search results page.
apps_grid_view()->pagination_model()->SelectPage(1, false);
search_box_view()->search_box()->InsertText(
base::UTF8ToUTF16("A"),
u"A",
ui::TextInputClient::InsertTextCursorBehavior::kMoveCursorAfterText);
EXPECT_EQ(ash::AppListViewState::kFullscreenSearch, view_->app_list_state());
EXPECT_EQ(1, apps_grid_view()->pagination_model()->selected_page());
Expand Down Expand Up @@ -2485,7 +2484,7 @@ TEST_F(AppListViewFocusTest, ShowEmbeddedAssistantUI) {
// Type something in search box to transition to HALF state and populate
// fake list results. Then hit Enter key.
search_box_view()->search_box()->InsertText(
base::UTF8ToUTF16("test"),
u"test",
ui::TextInputClient::InsertTextCursorBehavior::kMoveCursorAfterText);
const int kListResults = 2;
const int kIndexOpenAssistantUi = 1;
Expand Down
10 changes: 5 additions & 5 deletions ash/app_list/views/assistant/assistant_page_view_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -837,23 +837,23 @@ TEST_F(AssistantPageViewTest, RememberAndShowHistory) {
EXPECT_TRUE(input_text_field()->GetText().empty());

PressKey(ui::VKEY_UP);
EXPECT_EQ(input_text_field()->GetText(), base::UTF8ToUTF16("query 2"));
EXPECT_EQ(input_text_field()->GetText(), u"query 2");

PressKey(ui::VKEY_UP);
EXPECT_EQ(input_text_field()->GetText(), base::UTF8ToUTF16("query 1"));
EXPECT_EQ(input_text_field()->GetText(), u"query 1");

PressKey(ui::VKEY_UP);
EXPECT_EQ(input_text_field()->GetText(), base::UTF8ToUTF16("query 1"));
EXPECT_EQ(input_text_field()->GetText(), u"query 1");

PressKey(ui::VKEY_DOWN);
EXPECT_EQ(input_text_field()->GetText(), base::UTF8ToUTF16("query 2"));
EXPECT_EQ(input_text_field()->GetText(), u"query 2");

PressKey(ui::VKEY_DOWN);
EXPECT_TRUE(input_text_field()->GetText().empty());
}

TEST_F(AssistantPageViewTest, ShouldNotClearQueryWhenSwitchingToTabletMode) {
const std::u16string query_text = base::UTF8ToUTF16("unsubmitted query");
const std::u16string query_text = u"unsubmitted query";
ShowAssistantUiInTextMode();
input_text_field()->SetText(query_text);

Expand Down
4 changes: 2 additions & 2 deletions ash/app_list/views/search_result_list_view_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class SearchResultListViewTest : public views::test::WidgetTest {
assistant_result->set_result_type(
ash::AppListSearchResultType::kAssistantText);
assistant_result->set_display_type(ash::SearchResultDisplayType::kList);
assistant_result->set_title(base::UTF8ToUTF16("assistant result"));
assistant_result->set_title(u"assistant result");
results->Add(std::move(assistant_result));

RunPendingMessages();
Expand Down Expand Up @@ -189,7 +189,7 @@ TEST_F(SearchResultListViewTest, HidesAssistantResultWhenTilesVisible) {
// Assistant result should be set and visible.
for (const auto* view : GetAssistantResultViews()) {
EXPECT_TRUE(view->GetVisible());
EXPECT_EQ(view->result()->title(), base::UTF8ToUTF16("assistant result"));
EXPECT_EQ(view->result()->title(), u"assistant result");
}

// Add a tile result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,7 @@ TEST_F(AssistantOnboardingViewTest, ShouldHandleSuggestionUpdates) {
// Verify view state is updated to reflect model state.
auto suggestion_views = GetOnboardingSuggestionViews();
ASSERT_EQ(suggestion_views.size(), 1u);
EXPECT_EQ(suggestion_views.at(0)->GetText(),
base::UTF8ToUTF16("Forced suggestion"));
EXPECT_EQ(suggestion_views.at(0)->GetText(), u"Forced suggestion");
}

TEST_F(AssistantOnboardingViewTest, ShouldHandleLocalIcons) {
Expand Down
4 changes: 2 additions & 2 deletions ash/clipboard/clipboard_history_resource_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ std::u16string GetLabelForCustomData(const ui::ClipboardData& data) {

// Strip path information, so all that's left are file names.
for (auto it = source_list.begin(); it != source_list.end(); ++it)
*it = it->substr(it->find_last_of(base::UTF8ToUTF16("/")) + 1);
*it = it->substr(it->find_last_of(u"/") + 1);

// Join file names, unescaping encoded character sequences for display. This
// ensures that "My%20File.txt" will display as "My File.txt".
return base::UTF8ToUTF16(base::UnescapeURLComponent(
base::UTF16ToUTF8(base::JoinString(source_list, base::UTF8ToUTF16(", "))),
base::UTF16ToUTF8(base::JoinString(source_list, u", ")),
base::UnescapeRule::SPACES));
}

Expand Down
Loading

0 comments on commit 2c470ea

Please sign in to comment.