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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/autocomplete/autocomplete_match.h" | 10 #include "chrome/browser/autocomplete/autocomplete_match.h" |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 | 221 |
222 class BetterPopupBlockerBrowserTest : public PopupBlockerBrowserTest { | 222 class BetterPopupBlockerBrowserTest : public PopupBlockerBrowserTest { |
223 public: | 223 public: |
224 BetterPopupBlockerBrowserTest() {} | 224 BetterPopupBlockerBrowserTest() {} |
225 virtual ~BetterPopupBlockerBrowserTest() {} | 225 virtual ~BetterPopupBlockerBrowserTest() {} |
226 | 226 |
227 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 227 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
228 InProcessBrowserTest::SetUpCommandLine(command_line); | 228 InProcessBrowserTest::SetUpCommandLine(command_line); |
229 } | 229 } |
230 | 230 |
| 231 // Navigates to the test indicated by |test_name| which is expected to try to |
| 232 // open a popup. Verifies that the popup was blocked and then opens the |
| 233 // blocked popup. Once the popup stopped loading, verifies that the title of |
| 234 // the page is "PASS". |
| 235 // |
| 236 // If |expect_new_browser| is true, the popup is expected to open a new |
| 237 // window, or a background tab if it is false. |
| 238 void RunCheckTest(const base::FilePath& test_name, bool expect_new_browser) { |
| 239 GURL url(ui_test_utils::GetTestUrl(base::FilePath(kTestDir), test_name)); |
| 240 |
| 241 CountRenderViewHosts counter; |
| 242 |
| 243 ui_test_utils::NavigateToURL(browser(), url); |
| 244 |
| 245 // Since the popup blocker blocked the window.open, there should be only one |
| 246 // tab. |
| 247 EXPECT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), |
| 248 browser()->host_desktop_type())); |
| 249 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 250 WebContents* web_contents = |
| 251 browser()->tab_strip_model()->GetActiveWebContents(); |
| 252 EXPECT_EQ(url, web_contents->GetURL()); |
| 253 |
| 254 // And no new RVH created. |
| 255 EXPECT_EQ(0, counter.GetRenderViewHostCreatedCount()); |
| 256 |
| 257 content::WindowedNotificationObserver observer( |
| 258 chrome::NOTIFICATION_TAB_ADDED, |
| 259 content::NotificationService::AllSources()); |
| 260 ui_test_utils::BrowserAddedObserver browser_observer; |
| 261 |
| 262 // Launch the blocked popup. |
| 263 PopupBlockerTabHelper* popup_blocker_helper = |
| 264 PopupBlockerTabHelper::FromWebContents(web_contents); |
| 265 EXPECT_EQ(1u, popup_blocker_helper->GetBlockedPopupsCount()); |
| 266 std::map<int32, GURL> blocked_requests = |
| 267 popup_blocker_helper->GetBlockedPopupRequests(); |
| 268 std::map<int32, GURL>::const_iterator iter = blocked_requests.begin(); |
| 269 popup_blocker_helper->ShowBlockedPopup(iter->first); |
| 270 |
| 271 observer.Wait(); |
| 272 Browser* new_browser; |
| 273 if (expect_new_browser) { |
| 274 new_browser = browser_observer.WaitForSingleNewBrowser(); |
| 275 web_contents = new_browser->tab_strip_model()->GetActiveWebContents(); |
| 276 } else { |
| 277 new_browser = browser(); |
| 278 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| 279 web_contents = browser()->tab_strip_model()->GetWebContentsAt(1); |
| 280 } |
| 281 |
| 282 // Check that the check passed. |
| 283 base::string16 expected_title(base::ASCIIToUTF16("PASS")); |
| 284 content::TitleWatcher title_watcher(web_contents, expected_title); |
| 285 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 286 } |
| 287 |
231 private: | 288 private: |
232 DISALLOW_COPY_AND_ASSIGN(BetterPopupBlockerBrowserTest); | 289 DISALLOW_COPY_AND_ASSIGN(BetterPopupBlockerBrowserTest); |
233 }; | 290 }; |
234 | 291 |
235 IN_PROC_BROWSER_TEST_F(BetterPopupBlockerBrowserTest, | 292 IN_PROC_BROWSER_TEST_F(BetterPopupBlockerBrowserTest, |
236 BlockWebContentsCreation) { | 293 BlockWebContentsCreation) { |
237 #if defined(OS_WIN) && defined(USE_ASH) | 294 #if defined(OS_WIN) && defined(USE_ASH) |
238 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 295 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
239 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 296 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
240 return; | 297 return; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 Browser* new_browser = browser_observer.WaitForSingleNewBrowser(); | 419 Browser* new_browser = browser_observer.WaitForSingleNewBrowser(); |
363 | 420 |
364 // Check that the new popup has (roughly) the requested size. | 421 // Check that the new popup has (roughly) the requested size. |
365 web_contents = new_browser->tab_strip_model()->GetActiveWebContents(); | 422 web_contents = new_browser->tab_strip_model()->GetActiveWebContents(); |
366 gfx::Size window_size = web_contents->GetView()->GetContainerSize(); | 423 gfx::Size window_size = web_contents->GetView()->GetContainerSize(); |
367 EXPECT_TRUE(349 <= window_size.width() && window_size.width() <= 351); | 424 EXPECT_TRUE(349 <= window_size.width() && window_size.width() <= 351); |
368 EXPECT_TRUE(249 <= window_size.height() && window_size.height() <= 251); | 425 EXPECT_TRUE(249 <= window_size.height() && window_size.height() <= 251); |
369 } | 426 } |
370 | 427 |
371 IN_PROC_BROWSER_TEST_F(BetterPopupBlockerBrowserTest, CorrectReferrer) { | 428 IN_PROC_BROWSER_TEST_F(BetterPopupBlockerBrowserTest, CorrectReferrer) { |
372 GURL url(ui_test_utils::GetTestUrl( | 429 RunCheckTest(base::FilePath(FILE_PATH_LITERAL("popup-referrer.html")), true); |
373 base::FilePath(kTestDir), | |
374 base::FilePath(FILE_PATH_LITERAL("popup-referrer.html")))); | |
375 | |
376 CountRenderViewHosts counter; | |
377 | |
378 ui_test_utils::NavigateToURL(browser(), url); | |
379 | |
380 // If the popup blocker blocked the blank post, there should be only one tab. | |
381 EXPECT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), | |
382 browser()->host_desktop_type())); | |
383 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
384 WebContents* web_contents = | |
385 browser()->tab_strip_model()->GetActiveWebContents(); | |
386 EXPECT_EQ(url, web_contents->GetURL()); | |
387 | |
388 // And no new RVH created. | |
389 EXPECT_EQ(0, counter.GetRenderViewHostCreatedCount()); | |
390 | |
391 content::WindowedNotificationObserver observer( | |
392 chrome::NOTIFICATION_TAB_ADDED, | |
393 content::NotificationService::AllSources()); | |
394 ui_test_utils::BrowserAddedObserver browser_observer; | |
395 | |
396 // Launch the blocked popup. | |
397 PopupBlockerTabHelper* popup_blocker_helper = | |
398 PopupBlockerTabHelper::FromWebContents(web_contents); | |
399 EXPECT_EQ(1u, popup_blocker_helper->GetBlockedPopupsCount()); | |
400 std::map<int32, GURL> blocked_requests = | |
401 popup_blocker_helper->GetBlockedPopupRequests(); | |
402 std::map<int32, GURL>::const_iterator iter = blocked_requests.begin(); | |
403 popup_blocker_helper->ShowBlockedPopup(iter->first); | |
404 | |
405 observer.Wait(); | |
406 Browser* new_browser = browser_observer.WaitForSingleNewBrowser(); | |
407 | |
408 // Check that the referrer was correctly set. | |
409 web_contents = new_browser->tab_strip_model()->GetActiveWebContents(); | |
410 base::string16 expected_title(base::ASCIIToUTF16("PASS")); | |
411 content::TitleWatcher title_watcher(web_contents, expected_title); | |
412 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | |
413 } | 430 } |
414 | 431 |
415 IN_PROC_BROWSER_TEST_F(BetterPopupBlockerBrowserTest, WindowFeaturesBarProps) { | 432 IN_PROC_BROWSER_TEST_F(BetterPopupBlockerBrowserTest, WindowFeaturesBarProps) { |
416 GURL url(ui_test_utils::GetTestUrl( | 433 RunCheckTest(base::FilePath(FILE_PATH_LITERAL("popup-windowfeatures.html")), |
417 base::FilePath(kTestDir), | 434 true); |
418 base::FilePath(FILE_PATH_LITERAL("popup-windowfeatures.html")))); | 435 } |
419 | 436 |
420 CountRenderViewHosts counter; | 437 IN_PROC_BROWSER_TEST_F(BetterPopupBlockerBrowserTest, SessionStorage) { |
| 438 RunCheckTest(base::FilePath(FILE_PATH_LITERAL("popup-sessionstorage.html")), |
| 439 true); |
| 440 } |
421 | 441 |
422 ui_test_utils::NavigateToURL(browser(), url); | 442 IN_PROC_BROWSER_TEST_F(BetterPopupBlockerBrowserTest, Opener) { |
| 443 RunCheckTest(base::FilePath(FILE_PATH_LITERAL("popup-opener.html")), true); |
| 444 } |
423 | 445 |
424 // If the popup blocker blocked the blank post, there should be only one tab. | 446 IN_PROC_BROWSER_TEST_F(BetterPopupBlockerBrowserTest, OpenerSuppressed) { |
425 EXPECT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), | 447 RunCheckTest( |
426 browser()->host_desktop_type())); | 448 base::FilePath(FILE_PATH_LITERAL("popup-openersuppressed.html")), false); |
427 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
428 WebContents* web_contents = | |
429 browser()->tab_strip_model()->GetActiveWebContents(); | |
430 EXPECT_EQ(url, web_contents->GetURL()); | |
431 | |
432 // And no new RVH created. | |
433 EXPECT_EQ(0, counter.GetRenderViewHostCreatedCount()); | |
434 | |
435 content::WindowedNotificationObserver observer( | |
436 chrome::NOTIFICATION_TAB_ADDED, | |
437 content::NotificationService::AllSources()); | |
438 ui_test_utils::BrowserAddedObserver browser_observer; | |
439 | |
440 // Launch the blocked popup. | |
441 PopupBlockerTabHelper* popup_blocker_helper = | |
442 PopupBlockerTabHelper::FromWebContents(web_contents); | |
443 EXPECT_EQ(1u, popup_blocker_helper->GetBlockedPopupsCount()); | |
444 std::map<int32, GURL> blocked_requests = | |
445 popup_blocker_helper->GetBlockedPopupRequests(); | |
446 std::map<int32, GURL>::const_iterator iter = blocked_requests.begin(); | |
447 popup_blocker_helper->ShowBlockedPopup(iter->first); | |
448 | |
449 observer.Wait(); | |
450 Browser* new_browser = browser_observer.WaitForSingleNewBrowser(); | |
451 | |
452 // Check that the referrer was correctly set. | |
453 web_contents = new_browser->tab_strip_model()->GetActiveWebContents(); | |
454 base::string16 expected_title(base::ASCIIToUTF16("PASS")); | |
455 content::TitleWatcher title_watcher(web_contents, expected_title); | |
456 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | |
457 } | 449 } |
458 | 450 |
459 } // namespace | 451 } // namespace |
OLD | NEW |