| OLD | NEW |
| 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 Loading... |
| 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(), | 2421 EXPECT_EQ(getSecondPageTitle(), web_contents->GetTitle()); |
| 2422 content::TitleWatcher(web_contents).WaitAndGetTitle()); | |
| 2423 return; | 2422 return; |
| 2424 } | 2423 } |
| 2425 | 2424 |
| 2426 content::WindowedNotificationObserver observer( | 2425 content::WindowedNotificationObserver observer( |
| 2427 chrome::NOTIFICATION_TAB_ADDED, | 2426 chrome::NOTIFICATION_TAB_ADDED, |
| 2428 content::NotificationService::AllSources()); | 2427 content::NotificationService::AllSources()); |
| 2429 SimulateMouseClick(web_contents, modifiers, button); | 2428 SimulateMouseClick(web_contents, modifiers, button); |
| 2430 observer.Wait(); | 2429 observer.Wait(); |
| 2431 | 2430 |
| 2432 if (disposition == WindowOpenDisposition::NEW_WINDOW) { | 2431 if (disposition == WindowOpenDisposition::NEW_WINDOW) { |
| 2433 EXPECT_EQ(2u, chrome::GetBrowserCount(browser->profile())); | 2432 EXPECT_EQ(2u, chrome::GetBrowserCount(browser->profile())); |
| 2434 return; | 2433 return; |
| 2435 } | 2434 } |
| 2436 | 2435 |
| 2437 EXPECT_EQ(1u, chrome::GetBrowserCount(browser->profile())); | 2436 EXPECT_EQ(1u, chrome::GetBrowserCount(browser->profile())); |
| 2438 EXPECT_EQ(2, browser->tab_strip_model()->count()); | 2437 EXPECT_EQ(2, browser->tab_strip_model()->count()); |
| 2439 web_contents = browser->tab_strip_model()->GetActiveWebContents(); | 2438 web_contents = browser->tab_strip_model()->GetActiveWebContents(); |
| 2440 base::string16 expected_title; | 2439 WaitForLoadStop(web_contents); |
| 2441 if (disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB) { | 2440 if (disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB) { |
| 2442 expected_title = GetSecondPageTitle(); | 2441 EXPECT_EQ(getSecondPageTitle(), web_contents->GetTitle()); |
| 2443 } else { | 2442 } else { |
| 2444 ASSERT_EQ(WindowOpenDisposition::NEW_BACKGROUND_TAB, disposition); | 2443 ASSERT_EQ(WindowOpenDisposition::NEW_BACKGROUND_TAB, disposition); |
| 2445 expected_title = GetFirstPageTitle(); | 2444 EXPECT_EQ(getFirstPageTitle(), web_contents->GetTitle()); |
| 2446 } | 2445 } |
| 2447 EXPECT_EQ(expected_title, | |
| 2448 content::TitleWatcher(web_contents).WaitAndGetTitle()); | |
| 2449 } | 2446 } |
| 2450 | 2447 |
| 2451 private: | 2448 private: |
| 2452 DISALLOW_COPY_AND_ASSIGN(ClickModifierTest); | 2449 DISALLOW_COPY_AND_ASSIGN(ClickModifierTest); |
| 2453 }; | 2450 }; |
| 2454 | 2451 |
| 2455 // Tests for clicking on elements with handlers that run window.open. | 2452 // Tests for clicking on elements with handlers that run window.open. |
| 2456 | 2453 |
| 2457 IN_PROC_BROWSER_TEST_F(ClickModifierTest, WindowOpenBasicClickTest) { | 2454 IN_PROC_BROWSER_TEST_F(ClickModifierTest, WindowOpenBasicClickTest) { |
| 2458 int modifiers = 0; | 2455 int modifiers = 0; |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2884 Browser* browser = new Browser(params); | 2881 Browser* browser = new Browser(params); |
| 2885 gfx::Rect bounds = browser->window()->GetBounds(); | 2882 gfx::Rect bounds = browser->window()->GetBounds(); |
| 2886 | 2883 |
| 2887 // Should be EXPECT_EQ, but this width is inconsistent across platforms. | 2884 // Should be EXPECT_EQ, but this width is inconsistent across platforms. |
| 2888 // See https://crbug.com/567925. | 2885 // See https://crbug.com/567925. |
| 2889 EXPECT_GE(bounds.width(), 100); | 2886 EXPECT_GE(bounds.width(), 100); |
| 2890 EXPECT_EQ(122, bounds.height()); | 2887 EXPECT_EQ(122, bounds.height()); |
| 2891 browser->window()->Close(); | 2888 browser->window()->Close(); |
| 2892 } | 2889 } |
| 2893 } | 2890 } |
| OLD | NEW |