| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 // then opens the blocked popup. Once the popup stopped loading, verifies | 169 // then opens the blocked popup. Once the popup stopped loading, verifies |
| 170 // that the title of the page is "PASS" if |check_title| is set. | 170 // that the title of the page is "PASS" if |check_title| is set. |
| 171 // | 171 // |
| 172 // If |what_to_expect| is ExpectPopup, the popup is expected to open a new | 172 // If |what_to_expect| is ExpectPopup, the popup is expected to open a new |
| 173 // window, or a background tab if it is false. | 173 // window, or a background tab if it is false. |
| 174 // | 174 // |
| 175 // Returns the WebContents of the launched popup. | 175 // Returns the WebContents of the launched popup. |
| 176 WebContents* RunCheckTest(Browser* browser, | 176 WebContents* RunCheckTest(Browser* browser, |
| 177 const std::string& test_name, | 177 const std::string& test_name, |
| 178 WhatToExpect what_to_expect, | 178 WhatToExpect what_to_expect, |
| 179 ShouldCheckTitle check_title) { | 179 ShouldCheckTitle check_title, |
| 180 const base::string16& expected_title) { |
| 180 GURL url(embedded_test_server()->GetURL(test_name)); | 181 GURL url(embedded_test_server()->GetURL(test_name)); |
| 181 | 182 |
| 182 CountRenderViewHosts counter; | 183 CountRenderViewHosts counter; |
| 183 | 184 |
| 184 ui_test_utils::NavigateToURL(browser, url); | 185 ui_test_utils::NavigateToURL(browser, url); |
| 185 | 186 |
| 186 // Since the popup blocker blocked the window.open, there should be only one | 187 // Since the popup blocker blocked the window.open, there should be only one |
| 187 // tab. | 188 // tab. |
| 188 EXPECT_EQ(1u, chrome::GetBrowserCount(browser->profile())); | 189 EXPECT_EQ(1u, chrome::GetBrowserCount(browser->profile())); |
| 189 EXPECT_EQ(1, browser->tab_strip_model()->count()); | 190 EXPECT_EQ(1, browser->tab_strip_model()->count()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 } else { | 223 } else { |
| 223 new_browser = browser; | 224 new_browser = browser; |
| 224 EXPECT_EQ(2, browser->tab_strip_model()->count()); | 225 EXPECT_EQ(2, browser->tab_strip_model()->count()); |
| 225 // Check that we always create foreground tabs. | 226 // Check that we always create foreground tabs. |
| 226 EXPECT_EQ(1, browser->tab_strip_model()->active_index()); | 227 EXPECT_EQ(1, browser->tab_strip_model()->active_index()); |
| 227 web_contents = browser->tab_strip_model()->GetWebContentsAt(1); | 228 web_contents = browser->tab_strip_model()->GetWebContentsAt(1); |
| 228 } | 229 } |
| 229 | 230 |
| 230 if (check_title == CheckTitle) { | 231 if (check_title == CheckTitle) { |
| 231 // Check that the check passed. | 232 // Check that the check passed. |
| 232 base::string16 expected_title(base::ASCIIToUTF16("PASS")); | |
| 233 content::TitleWatcher title_watcher(web_contents, expected_title); | 233 content::TitleWatcher title_watcher(web_contents, expected_title); |
| 234 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 234 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 235 } | 235 } |
| 236 | 236 |
| 237 return web_contents; | 237 return web_contents; |
| 238 } | 238 } |
| 239 | 239 |
| 240 WebContents* RunCheckTest(Browser* browser, |
| 241 const std::string& test_name, |
| 242 WhatToExpect what_to_expect, |
| 243 ShouldCheckTitle check_title) { |
| 244 return RunCheckTest(browser, test_name, what_to_expect, check_title, |
| 245 base::ASCIIToUTF16("PASS")); |
| 246 } |
| 247 |
| 240 private: | 248 private: |
| 241 DISALLOW_COPY_AND_ASSIGN(PopupBlockerBrowserTest); | 249 DISALLOW_COPY_AND_ASSIGN(PopupBlockerBrowserTest); |
| 242 }; | 250 }; |
| 243 | 251 |
| 244 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, | 252 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, |
| 245 BlockWebContentsCreation) { | 253 BlockWebContentsCreation) { |
| 246 RunCheckTest( | 254 RunCheckTest( |
| 247 browser(), | 255 browser(), |
| 248 "/popup_blocker/popup-blocked-to-post-blank.html", | 256 "/popup_blocker/popup-blocked-to-post-blank.html", |
| 249 ExpectTab, | 257 ExpectTab, |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 369 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 362 WaitForHistoryBackendToRun(browser()->profile()); | 370 WaitForHistoryBackendToRun(browser()->profile()); |
| 363 | 371 |
| 364 std::string search_string = | 372 std::string search_string = |
| 365 "data:text/html,<title>Popup Success!</title>you should not see this " | 373 "data:text/html,<title>Popup Success!</title>you should not see this " |
| 366 "message if popup blocker is enabled"; | 374 "message if popup blocker is enabled"; |
| 367 | 375 |
| 368 ui_test_utils::HistoryEnumerator history(browser()->profile()); | 376 ui_test_utils::HistoryEnumerator history(browser()->profile()); |
| 369 std::vector<GURL>& history_urls = history.urls(); | 377 std::vector<GURL>& history_urls = history.urls(); |
| 370 ASSERT_EQ(2u, history_urls.size()); | 378 ASSERT_EQ(2u, history_urls.size()); |
| 371 ASSERT_EQ(GURL(search_string), history_urls[0]); | 379 ASSERT_EQ(embedded_test_server()->GetURL("/popup_blocker/popup-success.html"), |
| 380 history_urls[0]); |
| 372 ASSERT_EQ(url, history_urls[1]); | 381 ASSERT_EQ(url, history_urls[1]); |
| 373 | 382 |
| 374 TemplateURLService* service = TemplateURLServiceFactory::GetForProfile( | 383 TemplateURLService* service = TemplateURLServiceFactory::GetForProfile( |
| 375 browser()->profile()); | 384 browser()->profile()); |
| 376 search_test_utils::WaitForTemplateURLServiceToLoad(service); | 385 search_test_utils::WaitForTemplateURLServiceToLoad(service); |
| 377 LocationBar* location_bar = browser()->window()->GetLocationBar(); | 386 LocationBar* location_bar = browser()->window()->GetLocationBar(); |
| 378 ui_test_utils::SendToOmniboxAndSubmit(location_bar, search_string); | 387 ui_test_utils::SendToOmniboxAndSubmit(location_bar, search_string); |
| 379 OmniboxEditModel* model = location_bar->GetOmniboxView()->model(); | 388 OmniboxEditModel* model = location_bar->GetOmniboxView()->model(); |
| 380 EXPECT_EQ(GURL(search_string), model->CurrentMatch(NULL).destination_url); | 389 EXPECT_EQ(GURL(search_string), model->CurrentMatch(NULL).destination_url); |
| 381 EXPECT_EQ(base::ASCIIToUTF16(search_string), | 390 EXPECT_EQ(base::ASCIIToUTF16(search_string), |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 } | 472 } |
| 464 | 473 |
| 465 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, OpenerSuppressed) { | 474 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, OpenerSuppressed) { |
| 466 RunCheckTest(browser(), | 475 RunCheckTest(browser(), |
| 467 "/popup_blocker/popup-openersuppressed.html", | 476 "/popup_blocker/popup-openersuppressed.html", |
| 468 ExpectTab, | 477 ExpectTab, |
| 469 CheckTitle); | 478 CheckTitle); |
| 470 } | 479 } |
| 471 | 480 |
| 472 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ShiftClick) { | 481 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ShiftClick) { |
| 473 RunCheckTest( | 482 RunCheckTest(browser(), "/popup_blocker/popup-fake-click-on-anchor3.html", |
| 474 browser(), | 483 ExpectPopup, CheckTitle, base::ASCIIToUTF16("Popup Success!")); |
| 475 "/popup_blocker/popup-fake-click-on-anchor3.html", | |
| 476 ExpectPopup, | |
| 477 CheckTitle); | |
| 478 } | 484 } |
| 479 | 485 |
| 480 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, WebUI) { | 486 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, WebUI) { |
| 481 WebContents* popup = | 487 WebContents* popup = |
| 482 RunCheckTest(browser(), | 488 RunCheckTest(browser(), |
| 483 "/popup_blocker/popup-webui.html", | 489 "/popup_blocker/popup-webui.html", |
| 484 ExpectTab, | 490 ExpectTab, |
| 485 DontCheckTitle); | 491 DontCheckTitle); |
| 486 | 492 |
| 487 // Check that the new popup displays about:blank. | 493 // Check that the new popup displays about:blank. |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 871 | 877 |
| 872 wait_for_new_tab.Wait(); | 878 wait_for_new_tab.Wait(); |
| 873 | 879 |
| 874 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile())); | 880 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile())); |
| 875 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 881 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
| 876 // Check that we create the background tab. | 882 // Check that we create the background tab. |
| 877 ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); | 883 ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); |
| 878 } | 884 } |
| 879 | 885 |
| 880 } // namespace | 886 } // namespace |
| OLD | NEW |