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

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

Issue 2635933003: Convert more test helpers to base::RunLoop, fix page title checks. (Reland) (Closed)
Patch Set: Fix ClickModifierTests. 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 2371 matching lines...) Expand 10 before | Expand all | Expand 10 after
2382 } 2382 }
2383 2383
2384 // Returns a url that follows a simple link when clicked, unless affected by 2384 // Returns a url that follows a simple link when clicked, unless affected by
2385 // modifiers. 2385 // modifiers.
2386 GURL GetHrefURL() { 2386 GURL GetHrefURL() {
2387 return ui_test_utils::GetTestUrl( 2387 return ui_test_utils::GetTestUrl(
2388 base::FilePath(kTestDir), 2388 base::FilePath(kTestDir),
2389 base::FilePath(FILE_PATH_LITERAL("href.html"))); 2389 base::FilePath(FILE_PATH_LITERAL("href.html")));
2390 } 2390 }
2391 2391
2392 base::string16 getFirstPageTitle() { 2392 base::string16 GetFirstPageTitle() {
2393 return ASCIIToUTF16(kFirstPageTitle); 2393 return ASCIIToUTF16(kFirstPageTitle);
2394 } 2394 }
2395 2395
2396 base::string16 getSecondPageTitle() { 2396 base::string16 GetSecondPageTitle() {
2397 return ASCIIToUTF16(kSecondPageTitle); 2397 return ASCIIToUTF16(kSecondPageTitle);
2398 } 2398 }
2399 2399
2400 // Loads our test page and simulates a single click using the supplied button 2400 // Loads our test page and simulates a single click using the supplied button
2401 // and modifiers. The click will cause either a navigation or the creation of 2401 // and modifiers. The click will cause either a navigation or the creation of
2402 // a new window or foreground or background tab. We verify that the expected 2402 // a new window or foreground or background tab. We verify that the expected
2403 // disposition occurs. 2403 // disposition occurs.
2404 void RunTest(Browser* browser, 2404 void RunTest(Browser* browser,
2405 const GURL& url, 2405 const GURL& url,
2406 int modifiers, 2406 int modifiers,
2407 blink::WebMouseEvent::Button button, 2407 blink::WebMouseEvent::Button button,
2408 WindowOpenDisposition disposition) { 2408 WindowOpenDisposition disposition) {
2409 ui_test_utils::NavigateToURL(browser, url); 2409 ui_test_utils::NavigateToURL(browser, url);
2410 EXPECT_EQ(1u, chrome::GetBrowserCount(browser->profile())); 2410 EXPECT_EQ(1u, chrome::GetBrowserCount(browser->profile()));
2411 EXPECT_EQ(1, browser->tab_strip_model()->count()); 2411 EXPECT_EQ(1, browser->tab_strip_model()->count());
2412 content::WebContents* web_contents = 2412 content::WebContents* web_contents =
2413 browser->tab_strip_model()->GetActiveWebContents(); 2413 browser->tab_strip_model()->GetActiveWebContents();
2414 EXPECT_EQ(url, web_contents->GetURL()); 2414 EXPECT_EQ(url, web_contents->GetURL());
2415 2415
2416 if (disposition == WindowOpenDisposition::CURRENT_TAB) { 2416 if (disposition == WindowOpenDisposition::CURRENT_TAB) {
2417 content::WebContents* web_contents = 2417 content::WebContents* web_contents =
2418 browser->tab_strip_model()->GetActiveWebContents(); 2418 browser->tab_strip_model()->GetActiveWebContents();
2419 content::TestNavigationObserver same_tab_observer(web_contents); 2419 content::TestNavigationObserver same_tab_observer(web_contents);
2420 SimulateMouseClick(web_contents, modifiers, button); 2420 SimulateMouseClick(web_contents, modifiers, button);
2421 same_tab_observer.Wait(); 2421 same_tab_observer.Wait();
2422 EXPECT_EQ(1u, chrome::GetBrowserCount(browser->profile())); 2422 EXPECT_EQ(1u, chrome::GetBrowserCount(browser->profile()));
2423 EXPECT_EQ(1, browser->tab_strip_model()->count()); 2423 EXPECT_EQ(1, browser->tab_strip_model()->count());
2424 EXPECT_EQ(getSecondPageTitle(), web_contents->GetTitle()); 2424 EXPECT_EQ(GetSecondPageTitle(), web_contents->GetTitle());
2425 return; 2425 return;
2426 } 2426 }
2427 2427
2428 content::WindowedNotificationObserver observer( 2428 content::TestNavigationObserver new_tab_observer(nullptr);
2429 chrome::NOTIFICATION_TAB_ADDED, 2429 new_tab_observer.StartWatchingNewWebContents();
2430 content::NotificationService::AllSources());
2431 SimulateMouseClick(web_contents, modifiers, button); 2430 SimulateMouseClick(web_contents, modifiers, button);
2432 observer.Wait(); 2431 new_tab_observer.Wait();
2433 2432
2434 if (disposition == WindowOpenDisposition::NEW_WINDOW) { 2433 if (disposition == WindowOpenDisposition::NEW_WINDOW) {
2435 EXPECT_EQ(2u, chrome::GetBrowserCount(browser->profile())); 2434 EXPECT_EQ(2u, chrome::GetBrowserCount(browser->profile()));
2436 return; 2435 return;
2437 } 2436 }
2438 2437
2439 EXPECT_EQ(1u, chrome::GetBrowserCount(browser->profile())); 2438 EXPECT_EQ(1u, chrome::GetBrowserCount(browser->profile()));
2440 EXPECT_EQ(2, browser->tab_strip_model()->count()); 2439 EXPECT_EQ(2, browser->tab_strip_model()->count());
2441 web_contents = browser->tab_strip_model()->GetActiveWebContents(); 2440 web_contents = browser->tab_strip_model()->GetActiveWebContents();
2442 WaitForLoadStop(web_contents);
2443 if (disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB) { 2441 if (disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB) {
2444 EXPECT_EQ(getSecondPageTitle(), web_contents->GetTitle()); 2442 EXPECT_EQ(GetSecondPageTitle(), web_contents->GetTitle());
2445 } else { 2443 } else {
2446 ASSERT_EQ(WindowOpenDisposition::NEW_BACKGROUND_TAB, disposition); 2444 ASSERT_EQ(WindowOpenDisposition::NEW_BACKGROUND_TAB, disposition);
2447 EXPECT_EQ(getFirstPageTitle(), web_contents->GetTitle()); 2445 EXPECT_EQ(GetFirstPageTitle(), web_contents->GetTitle());
2448 } 2446 }
2449 } 2447 }
2450 2448
2451 private: 2449 private:
2452 DISALLOW_COPY_AND_ASSIGN(ClickModifierTest); 2450 DISALLOW_COPY_AND_ASSIGN(ClickModifierTest);
2453 }; 2451 };
2454 2452
2455 // Tests for clicking on elements with handlers that run window.open. 2453 // Tests for clicking on elements with handlers that run window.open.
2456 2454
2457 IN_PROC_BROWSER_TEST_F(ClickModifierTest, WindowOpenBasicClickTest) { 2455 IN_PROC_BROWSER_TEST_F(ClickModifierTest, WindowOpenBasicClickTest) {
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
2892 Browser* browser = new Browser(params); 2890 Browser* browser = new Browser(params);
2893 gfx::Rect bounds = browser->window()->GetBounds(); 2891 gfx::Rect bounds = browser->window()->GetBounds();
2894 2892
2895 // Should be EXPECT_EQ, but this width is inconsistent across platforms. 2893 // Should be EXPECT_EQ, but this width is inconsistent across platforms.
2896 // See https://crbug.com/567925. 2894 // See https://crbug.com/567925.
2897 EXPECT_GE(bounds.width(), 100); 2895 EXPECT_GE(bounds.width(), 100);
2898 EXPECT_EQ(122, bounds.height()); 2896 EXPECT_EQ(122, bounds.height());
2899 browser->window()->Close(); 2897 browser->window()->Close();
2900 } 2898 }
2901 } 2899 }
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