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 }; | |
jochen (gone - plz use gerrit)
2014/04/16 08:58:30
nit. DISALLOW_COPY_AND_ASSIGN()
davidben
2014/04/16 16:15:09
Done.
| |
92 | |
72 class PopupBlockerBrowserTest : public InProcessBrowserTest { | 93 class PopupBlockerBrowserTest : public InProcessBrowserTest { |
73 public: | 94 public: |
74 PopupBlockerBrowserTest() {} | 95 PopupBlockerBrowserTest() {} |
75 virtual ~PopupBlockerBrowserTest() {} | 96 virtual ~PopupBlockerBrowserTest() {} |
76 | 97 |
77 virtual void SetUpOnMainThread() OVERRIDE { | 98 virtual void SetUpOnMainThread() OVERRIDE { |
78 InProcessBrowserTest::SetUpOnMainThread(); | 99 InProcessBrowserTest::SetUpOnMainThread(); |
79 | 100 |
80 host_resolver()->AddRule("*", "127.0.0.1"); | 101 host_resolver()->AddRule("*", "127.0.0.1"); |
81 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 102 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
381 true); | 402 true); |
382 } | 403 } |
383 | 404 |
384 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, Opener) { | 405 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, Opener) { |
385 RunCheckTest(browser(), | 406 RunCheckTest(browser(), |
386 "/popup_blocker/popup-opener.html", | 407 "/popup_blocker/popup-opener.html", |
387 true, | 408 true, |
388 true); | 409 true); |
389 } | 410 } |
390 | 411 |
412 // Tests that the popup can still close itself after navigating. This tests that | |
413 // the openedByDOM bit is preserved across blocked popups. | |
414 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ClosableAfterNavigation) { | |
415 // Open a popup. | |
416 WebContents* popup = | |
417 RunCheckTest(browser(), | |
418 "/popup_blocker/popup-opener.html", | |
419 true, | |
420 true); | |
421 | |
422 // Navigate it elsewhere. | |
423 content::TestNavigationObserver nav_observer(popup); | |
424 popup->GetMainFrame()->ExecuteJavaScript( | |
425 base::UTF8ToUTF16("location.href = '/empty.html'")); | |
426 nav_observer.Wait(); | |
427 | |
428 // Have it close itself. | |
429 CloseObserver close_observer(popup); | |
430 popup->GetMainFrame()->ExecuteJavaScript( | |
431 base::UTF8ToUTF16("window.close()")); | |
432 close_observer.Wait(); | |
433 } | |
434 | |
391 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, OpenerSuppressed) { | 435 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, OpenerSuppressed) { |
392 RunCheckTest(browser(), | 436 RunCheckTest(browser(), |
393 "/popup_blocker/popup-openersuppressed.html", | 437 "/popup_blocker/popup-openersuppressed.html", |
394 false, | 438 false, |
395 true); | 439 true); |
396 } | 440 } |
397 | 441 |
398 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ShiftClick) { | 442 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ShiftClick) { |
399 RunCheckTest( | 443 RunCheckTest( |
400 browser(), | 444 browser(), |
(...skipping 15 matching lines...) Expand all Loading... | |
416 | 460 |
417 // Verify that the renderer can't DOS the browser by creating arbitrarily many | 461 // Verify that the renderer can't DOS the browser by creating arbitrarily many |
418 // popups. | 462 // popups. |
419 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, DenialOfService) { | 463 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, DenialOfService) { |
420 GURL url(embedded_test_server()->GetURL("/popup_blocker/popup-dos.html")); | 464 GURL url(embedded_test_server()->GetURL("/popup_blocker/popup-dos.html")); |
421 ui_test_utils::NavigateToURL(browser(), url); | 465 ui_test_utils::NavigateToURL(browser(), url); |
422 ASSERT_EQ(25, GetBlockedContentsCount()); | 466 ASSERT_EQ(25, GetBlockedContentsCount()); |
423 } | 467 } |
424 | 468 |
425 } // namespace | 469 } // namespace |
OLD | NEW |