| 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/run_loop.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/autocomplete/autocomplete_match.h" | 11 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 11 #include "chrome/browser/autocomplete/autocomplete_result.h" | 12 #include "chrome/browser/autocomplete/autocomplete_result.h" |
| 12 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 13 #include "chrome/browser/content_settings/host_content_settings_map.h" | 14 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 14 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 15 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/search_engines/template_url_service_factory.h" | 17 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 17 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" | 18 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" |
| 18 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_commands.h" | 20 #include "chrome/browser/ui/browser_commands.h" |
| 20 #include "chrome/browser/ui/browser_finder.h" | 21 #include "chrome/browser/ui/browser_finder.h" |
| 21 #include "chrome/browser/ui/browser_window.h" | 22 #include "chrome/browser/ui/browser_window.h" |
| 22 #include "chrome/browser/ui/omnibox/location_bar.h" | 23 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 23 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" | 24 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
| 24 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 25 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
| 25 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 26 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 26 #include "chrome/common/chrome_paths.h" | 27 #include "chrome/common/chrome_paths.h" |
| 27 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
| 28 #include "chrome/test/base/in_process_browser_test.h" | 29 #include "chrome/test/base/in_process_browser_test.h" |
| 29 #include "chrome/test/base/test_switches.h" | 30 #include "chrome/test/base/test_switches.h" |
| 30 #include "chrome/test/base/ui_test_utils.h" | 31 #include "chrome/test/base/ui_test_utils.h" |
| 31 #include "content/public/browser/notification_registrar.h" | 32 #include "content/public/browser/notification_registrar.h" |
| 32 #include "content/public/browser/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
| 34 #include "content/public/browser/render_frame_host.h" |
| 33 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
| 36 #include "content/public/browser/web_contents_observer.h" |
| 34 #include "content/public/browser/web_contents_view.h" | 37 #include "content/public/browser/web_contents_view.h" |
| 35 #include "content/public/common/url_constants.h" | 38 #include "content/public/common/url_constants.h" |
| 36 #include "content/public/test/browser_test_utils.h" | 39 #include "content/public/test/browser_test_utils.h" |
| 40 #include "content/public/test/test_navigation_observer.h" |
| 37 #include "net/dns/mock_host_resolver.h" | 41 #include "net/dns/mock_host_resolver.h" |
| 38 #include "net/test/embedded_test_server/embedded_test_server.h" | 42 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 39 #include "testing/gtest/include/gtest/gtest.h" | 43 #include "testing/gtest/include/gtest/gtest.h" |
| 40 | 44 |
| 41 using content::WebContents; | 45 using content::WebContents; |
| 42 | 46 |
| 43 namespace { | 47 namespace { |
| 44 | 48 |
| 45 // Counts the number of RenderViewHosts created. | 49 // Counts the number of RenderViewHosts created. |
| 46 class CountRenderViewHosts : public content::NotificationObserver { | 50 class CountRenderViewHosts : public content::NotificationObserver { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 62 count_++; | 66 count_++; |
| 63 } | 67 } |
| 64 | 68 |
| 65 content::NotificationRegistrar registrar_; | 69 content::NotificationRegistrar registrar_; |
| 66 | 70 |
| 67 int count_; | 71 int count_; |
| 68 | 72 |
| 69 DISALLOW_COPY_AND_ASSIGN(CountRenderViewHosts); | 73 DISALLOW_COPY_AND_ASSIGN(CountRenderViewHosts); |
| 70 }; | 74 }; |
| 71 | 75 |
| 76 class CloseObserver : public content::WebContentsObserver { |
| 77 public: |
| 78 explicit CloseObserver(WebContents* contents) |
| 79 : content::WebContentsObserver(contents) {} |
| 80 |
| 81 void Wait() { |
| 82 close_loop_.Run(); |
| 83 } |
| 84 |
| 85 virtual void WebContentsDestroyed(WebContents* contents) OVERRIDE { |
| 86 close_loop_.Quit(); |
| 87 } |
| 88 |
| 89 private: |
| 90 base::RunLoop close_loop_; |
| 91 |
| 92 DISALLOW_COPY_AND_ASSIGN(CloseObserver); |
| 93 }; |
| 94 |
| 72 class PopupBlockerBrowserTest : public InProcessBrowserTest { | 95 class PopupBlockerBrowserTest : public InProcessBrowserTest { |
| 73 public: | 96 public: |
| 74 PopupBlockerBrowserTest() {} | 97 PopupBlockerBrowserTest() {} |
| 75 virtual ~PopupBlockerBrowserTest() {} | 98 virtual ~PopupBlockerBrowserTest() {} |
| 76 | 99 |
| 77 virtual void SetUpOnMainThread() OVERRIDE { | 100 virtual void SetUpOnMainThread() OVERRIDE { |
| 78 InProcessBrowserTest::SetUpOnMainThread(); | 101 InProcessBrowserTest::SetUpOnMainThread(); |
| 79 | 102 |
| 80 host_resolver()->AddRule("*", "127.0.0.1"); | 103 host_resolver()->AddRule("*", "127.0.0.1"); |
| 81 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 104 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 true); | 404 true); |
| 382 } | 405 } |
| 383 | 406 |
| 384 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, Opener) { | 407 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, Opener) { |
| 385 RunCheckTest(browser(), | 408 RunCheckTest(browser(), |
| 386 "/popup_blocker/popup-opener.html", | 409 "/popup_blocker/popup-opener.html", |
| 387 true, | 410 true, |
| 388 true); | 411 true); |
| 389 } | 412 } |
| 390 | 413 |
| 414 // Tests that the popup can still close itself after navigating. This tests that |
| 415 // the openedByDOM bit is preserved across blocked popups. |
| 416 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ClosableAfterNavigation) { |
| 417 // Open a popup. |
| 418 WebContents* popup = |
| 419 RunCheckTest(browser(), |
| 420 "/popup_blocker/popup-opener.html", |
| 421 true, |
| 422 true); |
| 423 |
| 424 // Navigate it elsewhere. |
| 425 content::TestNavigationObserver nav_observer(popup); |
| 426 popup->GetMainFrame()->ExecuteJavaScript( |
| 427 base::UTF8ToUTF16("location.href = '/empty.html'")); |
| 428 nav_observer.Wait(); |
| 429 |
| 430 // Have it close itself. |
| 431 CloseObserver close_observer(popup); |
| 432 popup->GetMainFrame()->ExecuteJavaScript( |
| 433 base::UTF8ToUTF16("window.close()")); |
| 434 close_observer.Wait(); |
| 435 } |
| 436 |
| 391 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, OpenerSuppressed) { | 437 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, OpenerSuppressed) { |
| 392 RunCheckTest(browser(), | 438 RunCheckTest(browser(), |
| 393 "/popup_blocker/popup-openersuppressed.html", | 439 "/popup_blocker/popup-openersuppressed.html", |
| 394 false, | 440 false, |
| 395 true); | 441 true); |
| 396 } | 442 } |
| 397 | 443 |
| 398 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ShiftClick) { | 444 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ShiftClick) { |
| 399 RunCheckTest( | 445 RunCheckTest( |
| 400 browser(), | 446 browser(), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 416 | 462 |
| 417 // Verify that the renderer can't DOS the browser by creating arbitrarily many | 463 // Verify that the renderer can't DOS the browser by creating arbitrarily many |
| 418 // popups. | 464 // popups. |
| 419 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, DenialOfService) { | 465 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, DenialOfService) { |
| 420 GURL url(embedded_test_server()->GetURL("/popup_blocker/popup-dos.html")); | 466 GURL url(embedded_test_server()->GetURL("/popup_blocker/popup-dos.html")); |
| 421 ui_test_utils::NavigateToURL(browser(), url); | 467 ui_test_utils::NavigateToURL(browser(), url); |
| 422 ASSERT_EQ(25, GetBlockedContentsCount()); | 468 ASSERT_EQ(25, GetBlockedContentsCount()); |
| 423 } | 469 } |
| 424 | 470 |
| 425 } // namespace | 471 } // namespace |
| OLD | NEW |