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

Side by Side Diff: chrome/browser/ui/browser_browsertest.cc

Issue 2601843002: Convert more test helpers to base::RunLoop, fix page title checks. (Closed)
Patch Set: Remove unneeded call. Created 3 years, 11 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 | « no previous file | content/public/test/browser_test_base.cc » ('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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "chrome/browser/ui/browser.h" 5 #include "chrome/browser/ui/browser.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 2368 matching lines...) Expand 10 before | Expand all | Expand 10 after
2379 } 2379 }
2380 2380
2381 // Returns a url that follows a simple link when clicked, unless affected by 2381 // Returns a url that follows a simple link when clicked, unless affected by
2382 // modifiers. 2382 // modifiers.
2383 GURL GetHrefURL() { 2383 GURL GetHrefURL() {
2384 return ui_test_utils::GetTestUrl( 2384 return ui_test_utils::GetTestUrl(
2385 base::FilePath(kTestDir), 2385 base::FilePath(kTestDir),
2386 base::FilePath(FILE_PATH_LITERAL("href.html"))); 2386 base::FilePath(FILE_PATH_LITERAL("href.html")));
2387 } 2387 }
2388 2388
2389 base::string16 getFirstPageTitle() { 2389 base::string16 GetFirstPageTitle() {
2390 return ASCIIToUTF16(kFirstPageTitle); 2390 return ASCIIToUTF16(kFirstPageTitle);
2391 } 2391 }
2392 2392
2393 base::string16 getSecondPageTitle() { 2393 base::string16 GetSecondPageTitle() {
2394 return ASCIIToUTF16(kSecondPageTitle); 2394 return ASCIIToUTF16(kSecondPageTitle);
2395 } 2395 }
2396 2396
2397 // Loads our test page and simulates a single click using the supplied button 2397 // Loads our test page and simulates a single click using the supplied button
2398 // and modifiers. The click will cause either a navigation or the creation of 2398 // and modifiers. The click will cause either a navigation or the creation of
2399 // a new window or foreground or background tab. We verify that the expected 2399 // a new window or foreground or background tab. We verify that the expected
2400 // disposition occurs. 2400 // disposition occurs.
2401 void RunTest(Browser* browser, 2401 void RunTest(Browser* browser,
2402 const GURL& url, 2402 const GURL& url,
2403 int modifiers, 2403 int modifiers,
2404 blink::WebMouseEvent::Button button, 2404 blink::WebMouseEvent::Button button,
2405 WindowOpenDisposition disposition) { 2405 WindowOpenDisposition disposition) {
2406 ui_test_utils::NavigateToURL(browser, url); 2406 ui_test_utils::NavigateToURL(browser, url);
2407 EXPECT_EQ(1u, chrome::GetBrowserCount(browser->profile())); 2407 EXPECT_EQ(1u, chrome::GetBrowserCount(browser->profile()));
2408 EXPECT_EQ(1, browser->tab_strip_model()->count()); 2408 EXPECT_EQ(1, browser->tab_strip_model()->count());
2409 content::WebContents* web_contents = 2409 content::WebContents* web_contents =
2410 browser->tab_strip_model()->GetActiveWebContents(); 2410 browser->tab_strip_model()->GetActiveWebContents();
2411 EXPECT_EQ(url, web_contents->GetURL()); 2411 EXPECT_EQ(url, web_contents->GetURL());
2412 2412
2413 if (disposition == WindowOpenDisposition::CURRENT_TAB) { 2413 if (disposition == WindowOpenDisposition::CURRENT_TAB) {
2414 content::WebContents* web_contents = 2414 content::WebContents* web_contents =
2415 browser->tab_strip_model()->GetActiveWebContents(); 2415 browser->tab_strip_model()->GetActiveWebContents();
2416 content::TestNavigationObserver same_tab_observer(web_contents); 2416 content::TestNavigationObserver same_tab_observer(web_contents);
2417 SimulateMouseClick(web_contents, modifiers, button); 2417 SimulateMouseClick(web_contents, modifiers, button);
2418 same_tab_observer.Wait(); 2418 same_tab_observer.Wait();
2419 EXPECT_EQ(1u, chrome::GetBrowserCount(browser->profile())); 2419 EXPECT_EQ(1u, chrome::GetBrowserCount(browser->profile()));
2420 EXPECT_EQ(1, browser->tab_strip_model()->count()); 2420 EXPECT_EQ(1, browser->tab_strip_model()->count());
2421 EXPECT_EQ(getSecondPageTitle(), web_contents->GetTitle()); 2421 EXPECT_EQ(GetSecondPageTitle(),
2422 content::TitleWatcher(web_contents).WaitAndGetTitle());
2422 return; 2423 return;
2423 } 2424 }
2424 2425
2425 content::WindowedNotificationObserver observer( 2426 content::WindowedNotificationObserver observer(
2426 chrome::NOTIFICATION_TAB_ADDED, 2427 chrome::NOTIFICATION_TAB_ADDED,
2427 content::NotificationService::AllSources()); 2428 content::NotificationService::AllSources());
2428 SimulateMouseClick(web_contents, modifiers, button); 2429 SimulateMouseClick(web_contents, modifiers, button);
2429 observer.Wait(); 2430 observer.Wait();
2430 2431
2431 if (disposition == WindowOpenDisposition::NEW_WINDOW) { 2432 if (disposition == WindowOpenDisposition::NEW_WINDOW) {
2432 EXPECT_EQ(2u, chrome::GetBrowserCount(browser->profile())); 2433 EXPECT_EQ(2u, chrome::GetBrowserCount(browser->profile()));
2433 return; 2434 return;
2434 } 2435 }
2435 2436
2436 EXPECT_EQ(1u, chrome::GetBrowserCount(browser->profile())); 2437 EXPECT_EQ(1u, chrome::GetBrowserCount(browser->profile()));
2437 EXPECT_EQ(2, browser->tab_strip_model()->count()); 2438 EXPECT_EQ(2, browser->tab_strip_model()->count());
2438 web_contents = browser->tab_strip_model()->GetActiveWebContents(); 2439 web_contents = browser->tab_strip_model()->GetActiveWebContents();
2439 WaitForLoadStop(web_contents); 2440 base::string16 expected_title;
2440 if (disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB) { 2441 if (disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB) {
2441 EXPECT_EQ(getSecondPageTitle(), web_contents->GetTitle()); 2442 expected_title = GetSecondPageTitle();
2442 } else { 2443 } else {
2443 ASSERT_EQ(WindowOpenDisposition::NEW_BACKGROUND_TAB, disposition); 2444 ASSERT_EQ(WindowOpenDisposition::NEW_BACKGROUND_TAB, disposition);
2444 EXPECT_EQ(getFirstPageTitle(), web_contents->GetTitle()); 2445 expected_title = GetFirstPageTitle();
2445 } 2446 }
Peter Kasting 2017/01/12 18:16:17 Nit: The preceding lines could optionally be writt
Alexander Semashko 2017/01/12 20:48:19 To me the current code is much more clear, I'd lea
2447 EXPECT_EQ(expected_title,
2448 content::TitleWatcher(web_contents).WaitAndGetTitle());
2446 } 2449 }
2447 2450
2448 private: 2451 private:
2449 DISALLOW_COPY_AND_ASSIGN(ClickModifierTest); 2452 DISALLOW_COPY_AND_ASSIGN(ClickModifierTest);
2450 }; 2453 };
2451 2454
2452 // Tests for clicking on elements with handlers that run window.open. 2455 // Tests for clicking on elements with handlers that run window.open.
2453 2456
2454 IN_PROC_BROWSER_TEST_F(ClickModifierTest, WindowOpenBasicClickTest) { 2457 IN_PROC_BROWSER_TEST_F(ClickModifierTest, WindowOpenBasicClickTest) {
2455 int modifiers = 0; 2458 int modifiers = 0;
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
2881 Browser* browser = new Browser(params); 2884 Browser* browser = new Browser(params);
2882 gfx::Rect bounds = browser->window()->GetBounds(); 2885 gfx::Rect bounds = browser->window()->GetBounds();
2883 2886
2884 // Should be EXPECT_EQ, but this width is inconsistent across platforms. 2887 // Should be EXPECT_EQ, but this width is inconsistent across platforms.
2885 // See https://crbug.com/567925. 2888 // See https://crbug.com/567925.
2886 EXPECT_GE(bounds.width(), 100); 2889 EXPECT_GE(bounds.width(), 100);
2887 EXPECT_EQ(122, bounds.height()); 2890 EXPECT_EQ(122, bounds.height());
2888 browser->window()->Close(); 2891 browser->window()->Close();
2889 } 2892 }
2890 } 2893 }
OLDNEW
« no previous file with comments | « no previous file | content/public/test/browser_test_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698