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

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

Issue 2848883005: Test FindBar audible alerts. (Closed)
Patch Set: Address Scott's comment. Created 3 years, 7 months 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
« no previous file with comments | « chrome/browser/ui/find_bar/find_bar.h ('k') | chrome/browser/ui/views/find_bar_host.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 base::string16 GetMatchCountText() { 121 base::string16 GetMatchCountText() {
122 return GetFindBarMatchCountTextForBrowser(browser()); 122 return GetFindBarMatchCountTextForBrowser(browser());
123 } 123 }
124 124
125 int GetFindBarWidthForBrowser(Browser* browser) { 125 int GetFindBarWidthForBrowser(Browser* browser) {
126 FindBarTesting* find_bar = 126 FindBarTesting* find_bar =
127 browser->GetFindBarController()->find_bar()->GetFindBarTesting(); 127 browser->GetFindBarController()->find_bar()->GetFindBarTesting();
128 return find_bar->GetWidth(); 128 return find_bar->GetWidth();
129 } 129 }
130 130
131 size_t GetFindBarAudibleAlertsForBrowser(Browser* browser) {
132 FindBarTesting* find_bar =
133 browser->GetFindBarController()->find_bar()->GetFindBarTesting();
134 return find_bar->GetAudibleAlertCount();
135 }
136
131 void EnsureFindBoxOpenForBrowser(Browser* browser) { 137 void EnsureFindBoxOpenForBrowser(Browser* browser) {
132 chrome::ShowFindBar(browser); 138 chrome::ShowFindBar(browser);
133 gfx::Point position; 139 gfx::Point position;
134 bool fully_visible = false; 140 bool fully_visible = false;
135 EXPECT_TRUE(GetFindBarWindowInfoForBrowser( 141 EXPECT_TRUE(GetFindBarWindowInfoForBrowser(
136 browser, &position, &fully_visible)); 142 browser, &position, &fully_visible));
137 EXPECT_TRUE(fully_visible); 143 EXPECT_TRUE(fully_visible);
138 } 144 }
139 145
140 void EnsureFindBoxOpen() { 146 void EnsureFindBoxOpen() {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 // This test loads a page with frames and starts FindInPage requests. 213 // This test loads a page with frames and starts FindInPage requests.
208 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFrames) { 214 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFrames) {
209 // First we navigate to our frames page. 215 // First we navigate to our frames page.
210 GURL url = GetURL(kFramePage); 216 GURL url = GetURL(kFramePage);
211 ui_test_utils::NavigateToURL(browser(), url); 217 ui_test_utils::NavigateToURL(browser(), url);
212 218
213 // Try incremental search (mimicking user typing in). 219 // Try incremental search (mimicking user typing in).
214 int ordinal = 0; 220 int ordinal = 0;
215 WebContents* web_contents = 221 WebContents* web_contents =
216 browser()->tab_strip_model()->GetActiveWebContents(); 222 browser()->tab_strip_model()->GetActiveWebContents();
223 EXPECT_EQ(0u, GetFindBarAudibleAlertsForBrowser(browser()));
224
217 EXPECT_EQ(18, FindInPageASCII(web_contents, "g", 225 EXPECT_EQ(18, FindInPageASCII(web_contents, "g",
218 kFwd, kIgnoreCase, &ordinal)); 226 kFwd, kIgnoreCase, &ordinal));
219 EXPECT_EQ(1, ordinal); 227 EXPECT_EQ(1, ordinal);
220 EXPECT_EQ(11, FindInPageASCII(web_contents, "go", 228 EXPECT_EQ(11, FindInPageASCII(web_contents, "go",
221 kFwd, kIgnoreCase, &ordinal)); 229 kFwd, kIgnoreCase, &ordinal));
222 EXPECT_EQ(1, ordinal); 230 EXPECT_EQ(1, ordinal);
223 EXPECT_EQ(4, FindInPageASCII(web_contents, "goo", 231 EXPECT_EQ(4, FindInPageASCII(web_contents, "goo",
224 kFwd, kIgnoreCase, &ordinal)); 232 kFwd, kIgnoreCase, &ordinal));
225 EXPECT_EQ(1, ordinal); 233 EXPECT_EQ(1, ordinal);
226 EXPECT_EQ(3, FindInPageASCII(web_contents, "goog", 234 EXPECT_EQ(3, FindInPageASCII(web_contents, "goog",
227 kFwd, kIgnoreCase, &ordinal)); 235 kFwd, kIgnoreCase, &ordinal));
228 EXPECT_EQ(1, ordinal); 236 EXPECT_EQ(1, ordinal);
229 EXPECT_EQ(2, FindInPageASCII(web_contents, "googl", 237 EXPECT_EQ(2, FindInPageASCII(web_contents, "googl",
230 kFwd, kIgnoreCase, &ordinal)); 238 kFwd, kIgnoreCase, &ordinal));
231 EXPECT_EQ(1, ordinal); 239 EXPECT_EQ(1, ordinal);
232 EXPECT_EQ(1, FindInPageASCII(web_contents, "google", 240 EXPECT_EQ(1, FindInPageASCII(web_contents, "google",
233 kFwd, kIgnoreCase, &ordinal)); 241 kFwd, kIgnoreCase, &ordinal));
234 EXPECT_EQ(1, ordinal); 242 EXPECT_EQ(1, ordinal);
243 EXPECT_EQ(0u, GetFindBarAudibleAlertsForBrowser(browser()));
244
245 EXPECT_EQ(
246 0, FindInPageASCII(web_contents, "google!", kFwd, kIgnoreCase, &ordinal));
247 EXPECT_EQ(0, ordinal);
248 EXPECT_EQ(1u, GetFindBarAudibleAlertsForBrowser(browser()));
249
250 // Extend the search string one more.
251 EXPECT_EQ(0, FindInPageASCII(web_contents, "google!!", kFwd, kIgnoreCase,
252 &ordinal));
253 EXPECT_EQ(0, ordinal);
254 EXPECT_EQ(2u, GetFindBarAudibleAlertsForBrowser(browser()));
255
256 // "Backspace" one, make sure there's no audible alert while backspacing.
235 EXPECT_EQ(0, FindInPageASCII(web_contents, "google!", 257 EXPECT_EQ(0, FindInPageASCII(web_contents, "google!",
236 kFwd, kIgnoreCase, &ordinal)); 258 kFwd, kIgnoreCase, &ordinal));
237 EXPECT_EQ(0, ordinal); 259 EXPECT_EQ(0, ordinal);
260 EXPECT_EQ(2u, GetFindBarAudibleAlertsForBrowser(browser()));
238 261
239 // Negative test (no matches should be found). 262 // Negative test (no matches should be found).
240 EXPECT_EQ(0, FindInPageASCII(web_contents, "Non-existing string", 263 EXPECT_EQ(0, FindInPageASCII(web_contents, "Non-existing string",
241 kFwd, kIgnoreCase, &ordinal)); 264 kFwd, kIgnoreCase, &ordinal));
242 EXPECT_EQ(0, ordinal); 265 EXPECT_EQ(0, ordinal);
243 266
244 // 'horse' only exists in the three right frames. 267 // 'horse' only exists in the three right frames.
245 EXPECT_EQ(3, FindInPageASCII(web_contents, "horse", 268 EXPECT_EQ(3, FindInPageASCII(web_contents, "horse",
246 kFwd, kIgnoreCase, &ordinal)); 269 kFwd, kIgnoreCase, &ordinal));
247 EXPECT_EQ(1, ordinal); 270 EXPECT_EQ(1, ordinal);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 317
295 for (size_t i = 0; i < urls.size(); ++i) { 318 for (size_t i = 0; i < urls.size(); ++i) {
296 ui_test_utils::NavigateToURL(browser(), urls[i]); 319 ui_test_utils::NavigateToURL(browser(), urls[i]);
297 EXPECT_EQ(1, FindInPageASCII(web_contents, "cat", 320 EXPECT_EQ(1, FindInPageASCII(web_contents, "cat",
298 kFwd, kIgnoreCase, NULL)); 321 kFwd, kIgnoreCase, NULL));
299 EXPECT_EQ(0, FindInPageASCII(web_contents, "bat", 322 EXPECT_EQ(0, FindInPageASCII(web_contents, "bat",
300 kFwd, kIgnoreCase, NULL)); 323 kFwd, kIgnoreCase, NULL));
301 } 324 }
302 } 325 }
303 326
327 // This test removes a frame after a search comes up empty, then navigates to
328 // a different page and verifies this doesn't cause any extraneous dings.
329 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, NoAudibleAlertOnFrameChange) {
330 // First we navigate to our frames page.
331 GURL url = GetURL(kFramePage);
332 ui_test_utils::NavigateToURL(browser(), url);
333
334 int ordinal = 0;
335 WebContents* web_contents =
336 browser()->tab_strip_model()->GetActiveWebContents();
337 EXPECT_EQ(0u, GetFindBarAudibleAlertsForBrowser(browser()));
338
339 // Search for a non-existant string.
340 EXPECT_EQ(
341 0, FindInPageASCII(web_contents, "google!", kFwd, kIgnoreCase, &ordinal));
342 EXPECT_EQ(0, ordinal);
343 EXPECT_EQ(1u, GetFindBarAudibleAlertsForBrowser(browser()));
344
345 // Remove the first frame of the page.
346 constexpr char kRemoveFrameScript[] =
347 "frame = document.getElementsByTagName(\"FRAME\")[0];\n"
348 "frame.parentElement.removeChild(frame);\n";
349 ASSERT_TRUE(content::ExecuteScript(web_contents, kRemoveFrameScript));
350
351 ui_test_utils::NavigateToURL(browser(), GetURL("specialchar.html"));
352
353 EXPECT_EQ(1u, GetFindBarAudibleAlertsForBrowser(browser()));
354 }
355
304 // Verify search for text within special URLs such as chrome:history, 356 // Verify search for text within special URLs such as chrome:history,
305 // chrome://downloads, data directory 357 // chrome://downloads, data directory
306 #if defined(OS_MACOSX) || defined(OS_WIN) 358 #if defined(OS_MACOSX) || defined(OS_WIN)
307 // Disabled on Mac due to http://crbug.com/419987 359 // Disabled on Mac due to http://crbug.com/419987
308 // Disabled on Win due to http://crbug.com/661013 360 // Disabled on Win due to http://crbug.com/661013
309 #define MAYBE_SearchWithinSpecialURL \ 361 #define MAYBE_SearchWithinSpecialURL \
310 DISABLED_SearchWithinSpecialURL 362 DISABLED_SearchWithinSpecialURL
311 #else 363 #else
312 #define MAYBE_SearchWithinSpecialURL \ 364 #define MAYBE_SearchWithinSpecialURL \
313 SearchWithinSpecialURL 365 SearchWithinSpecialURL
(...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after
1568 1620
1569 EXPECT_TRUE(chrome::ExecuteCommand(browser_incognito, IDC_FIND_NEXT)); 1621 EXPECT_TRUE(chrome::ExecuteCommand(browser_incognito, IDC_FIND_NEXT));
1570 WebContents* web_contents_incognito = 1622 WebContents* web_contents_incognito =
1571 browser_incognito->tab_strip_model()->GetActiveWebContents(); 1623 browser_incognito->tab_strip_model()->GetActiveWebContents();
1572 ui_test_utils::FindInPageNotificationObserver observer( 1624 ui_test_utils::FindInPageNotificationObserver observer(
1573 web_contents_incognito); 1625 web_contents_incognito);
1574 observer.Wait(); 1626 observer.Wait();
1575 EXPECT_EQ(ASCIIToUTF16("bar"), 1627 EXPECT_EQ(ASCIIToUTF16("bar"),
1576 GetFindBarTextForBrowser(browser_incognito)); 1628 GetFindBarTextForBrowser(browser_incognito));
1577 } 1629 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/find_bar/find_bar.h ('k') | chrome/browser/ui/views/find_bar_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698