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/run_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 // Counts the number of RenderViewHosts created. | 48 // Counts the number of RenderViewHosts created. |
49 class CountRenderViewHosts : public content::NotificationObserver { | 49 class CountRenderViewHosts : public content::NotificationObserver { |
50 public: | 50 public: |
51 CountRenderViewHosts() | 51 CountRenderViewHosts() |
52 : count_(0) { | 52 : count_(0) { |
53 registrar_.Add(this, | 53 registrar_.Add(this, |
54 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, | 54 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, |
55 content::NotificationService::AllSources()); | 55 content::NotificationService::AllSources()); |
56 } | 56 } |
57 virtual ~CountRenderViewHosts() {} | 57 ~CountRenderViewHosts() override {} |
58 | 58 |
59 int GetRenderViewHostCreatedCount() const { return count_; } | 59 int GetRenderViewHostCreatedCount() const { return count_; } |
60 | 60 |
61 private: | 61 private: |
62 virtual void Observe(int type, | 62 void Observe(int type, |
63 const content::NotificationSource& source, | 63 const content::NotificationSource& source, |
64 const content::NotificationDetails& details) override { | 64 const content::NotificationDetails& details) override { |
65 count_++; | 65 count_++; |
66 } | 66 } |
67 | 67 |
68 content::NotificationRegistrar registrar_; | 68 content::NotificationRegistrar registrar_; |
69 | 69 |
70 int count_; | 70 int count_; |
71 | 71 |
72 DISALLOW_COPY_AND_ASSIGN(CountRenderViewHosts); | 72 DISALLOW_COPY_AND_ASSIGN(CountRenderViewHosts); |
73 }; | 73 }; |
74 | 74 |
75 class CloseObserver : public content::WebContentsObserver { | 75 class CloseObserver : public content::WebContentsObserver { |
76 public: | 76 public: |
77 explicit CloseObserver(WebContents* contents) | 77 explicit CloseObserver(WebContents* contents) |
78 : content::WebContentsObserver(contents) {} | 78 : content::WebContentsObserver(contents) {} |
79 | 79 |
80 void Wait() { | 80 void Wait() { |
81 close_loop_.Run(); | 81 close_loop_.Run(); |
82 } | 82 } |
83 | 83 |
84 virtual void WebContentsDestroyed() override { | 84 void WebContentsDestroyed() override { close_loop_.Quit(); } |
85 close_loop_.Quit(); | |
86 } | |
87 | 85 |
88 private: | 86 private: |
89 base::RunLoop close_loop_; | 87 base::RunLoop close_loop_; |
90 | 88 |
91 DISALLOW_COPY_AND_ASSIGN(CloseObserver); | 89 DISALLOW_COPY_AND_ASSIGN(CloseObserver); |
92 }; | 90 }; |
93 | 91 |
94 class PopupBlockerBrowserTest : public InProcessBrowserTest { | 92 class PopupBlockerBrowserTest : public InProcessBrowserTest { |
95 public: | 93 public: |
96 PopupBlockerBrowserTest() {} | 94 PopupBlockerBrowserTest() {} |
97 virtual ~PopupBlockerBrowserTest() {} | 95 virtual ~PopupBlockerBrowserTest() {} |
98 | 96 |
99 virtual void SetUpOnMainThread() override { | 97 void SetUpOnMainThread() override { |
100 InProcessBrowserTest::SetUpOnMainThread(); | 98 InProcessBrowserTest::SetUpOnMainThread(); |
101 | 99 |
102 host_resolver()->AddRule("*", "127.0.0.1"); | 100 host_resolver()->AddRule("*", "127.0.0.1"); |
103 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 101 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
104 } | 102 } |
105 | 103 |
106 int GetBlockedContentsCount() { | 104 int GetBlockedContentsCount() { |
107 // Do a round trip to the renderer first to flush any in-flight IPCs to | 105 // Do a round trip to the renderer first to flush any in-flight IPCs to |
108 // create a to-be-blocked window. | 106 // create a to-be-blocked window. |
109 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 107 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 | 479 |
482 // Verify that the renderer can't DOS the browser by creating arbitrarily many | 480 // Verify that the renderer can't DOS the browser by creating arbitrarily many |
483 // popups. | 481 // popups. |
484 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, DenialOfService) { | 482 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, DenialOfService) { |
485 GURL url(embedded_test_server()->GetURL("/popup_blocker/popup-dos.html")); | 483 GURL url(embedded_test_server()->GetURL("/popup_blocker/popup-dos.html")); |
486 ui_test_utils::NavigateToURL(browser(), url); | 484 ui_test_utils::NavigateToURL(browser(), url); |
487 ASSERT_EQ(25, GetBlockedContentsCount()); | 485 ASSERT_EQ(25, GetBlockedContentsCount()); |
488 } | 486 } |
489 | 487 |
490 } // namespace | 488 } // namespace |
OLD | NEW |