Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: chrome/browser/ui/find_bar/find_bar_host_interactive_uitest.cc

Issue 776903002: Cleanup: Remove some unneeded string allocations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix win Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/strings/utf_string_conversions.h" 5 #include "base/strings/utf_string_conversions.h"
6 #include "chrome/browser/ui/browser_finder.h" 6 #include "chrome/browser/ui/browser_finder.h"
7 #include "chrome/browser/ui/find_bar/find_bar.h" 7 #include "chrome/browser/ui/find_bar/find_bar.h"
8 #include "chrome/browser/ui/find_bar/find_bar_controller.h" 8 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
9 #include "chrome/browser/ui/find_bar/find_tab_helper.h" 9 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" 10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
(...skipping 12 matching lines...) Expand all
23 23
24 const char kEndState[] = "/find_in_page/end_state.html"; 24 const char kEndState[] = "/find_in_page/end_state.html";
25 25
26 class FindInPageInteractiveTest : public InProcessBrowserTest { 26 class FindInPageInteractiveTest : public InProcessBrowserTest {
27 public: 27 public:
28 FindInPageInteractiveTest() { 28 FindInPageInteractiveTest() {
29 } 29 }
30 30
31 // Platform independent FindInPage that takes |const wchar_t*| 31 // Platform independent FindInPage that takes |const wchar_t*|
32 // as an input. 32 // as an input.
33 int FindInPageWchar(WebContents* web_contents, 33 int FindInPageASCII(WebContents* web_contents,
34 const wchar_t* search_str, 34 const base::StringPiece& search_str,
35 bool forward, 35 bool forward,
36 bool case_sensitive, 36 bool case_sensitive,
37 int* ordinal) { 37 int* ordinal) {
38 base::string16 search_str16(WideToUTF16(std::wstring(search_str))); 38 base::string16 search_str16(ASCIIToUTF16(search_str));
39 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 39 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
40 browser->GetFindBarController()->find_bar()->SetFindTextAndSelectedRange( 40 browser->GetFindBarController()->find_bar()->SetFindTextAndSelectedRange(
41 search_str16, gfx::Range()); 41 search_str16, gfx::Range());
42 return ui_test_utils::FindInPage( 42 return ui_test_utils::FindInPage(
43 web_contents, search_str16, forward, case_sensitive, ordinal, NULL); 43 web_contents, search_str16, forward, case_sensitive, ordinal, NULL);
44 } 44 }
45 }; 45 };
46 46
47 } // namespace 47 } // namespace
48 48
(...skipping 28 matching lines...) Expand all
77 FindTabHelper* find_tab_helper = 77 FindTabHelper* find_tab_helper =
78 FindTabHelper::FromWebContents(web_contents); 78 FindTabHelper::FromWebContents(web_contents);
79 79
80 // Verify that nothing has focus. 80 // Verify that nothing has focus.
81 std::string result; 81 std::string result;
82 ASSERT_TRUE(FocusedOnPage(web_contents, &result)); 82 ASSERT_TRUE(FocusedOnPage(web_contents, &result));
83 ASSERT_STREQ("{nothing focused}", result.c_str()); 83 ASSERT_STREQ("{nothing focused}", result.c_str());
84 84
85 // Search for a text that exists within a link on the page. 85 // Search for a text that exists within a link on the page.
86 int ordinal = 0; 86 int ordinal = 0;
87 EXPECT_EQ(1, FindInPageWchar(web_contents, L"nk", 87 EXPECT_EQ(1, FindInPageASCII(web_contents, "nk",
88 true, false, &ordinal)); 88 true, false, &ordinal));
89 EXPECT_EQ(1, ordinal); 89 EXPECT_EQ(1, ordinal);
90 90
91 // End the find session, which should set focus to the link. 91 // End the find session, which should set focus to the link.
92 find_tab_helper->StopFinding(FindBarController::kKeepSelectionOnPage); 92 find_tab_helper->StopFinding(FindBarController::kKeepSelectionOnPage);
93 93
94 // Verify that the link is focused. 94 // Verify that the link is focused.
95 ASSERT_TRUE(FocusedOnPage(web_contents, &result)); 95 ASSERT_TRUE(FocusedOnPage(web_contents, &result));
96 EXPECT_STREQ("link1", result.c_str()); 96 EXPECT_STREQ("link1", result.c_str());
97 97
98 // Search for a text that exists within a link on the page. 98 // Search for a text that exists within a link on the page.
99 EXPECT_EQ(1, FindInPageWchar(web_contents, L"Google", 99 EXPECT_EQ(1, FindInPageASCII(web_contents, "Google",
100 true, false, &ordinal)); 100 true, false, &ordinal));
101 EXPECT_EQ(1, ordinal); 101 EXPECT_EQ(1, ordinal);
102 102
103 // Move the selection to link 1, after searching. 103 // Move the selection to link 1, after searching.
104 ASSERT_TRUE(content::ExecuteScriptAndExtractString( 104 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
105 web_contents, 105 web_contents,
106 "window.domAutomationController.send(selectLink1());", 106 "window.domAutomationController.send(selectLink1());",
107 &result)); 107 &result));
108 108
109 // End the find session. 109 // End the find session.
110 find_tab_helper->StopFinding(FindBarController::kKeepSelectionOnPage); 110 find_tab_helper->StopFinding(FindBarController::kKeepSelectionOnPage);
111 111
112 // Verify that link2 is not focused. 112 // Verify that link2 is not focused.
113 ASSERT_TRUE(FocusedOnPage(web_contents, &result)); 113 ASSERT_TRUE(FocusedOnPage(web_contents, &result));
114 EXPECT_STREQ("", result.c_str()); 114 EXPECT_STREQ("", result.c_str());
115 } 115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698