| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 virtual ~CountRenderViewHosts() {} |
| 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 virtual 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 virtual void WebContentsDestroyed() override { |
| 85 close_loop_.Quit(); | 85 close_loop_.Quit(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 private: | 88 private: |
| 89 base::RunLoop close_loop_; | 89 base::RunLoop close_loop_; |
| 90 | 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(CloseObserver); | 91 DISALLOW_COPY_AND_ASSIGN(CloseObserver); |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 class PopupBlockerBrowserTest : public InProcessBrowserTest { | 94 class PopupBlockerBrowserTest : public InProcessBrowserTest { |
| 95 public: | 95 public: |
| 96 PopupBlockerBrowserTest() {} | 96 PopupBlockerBrowserTest() {} |
| 97 virtual ~PopupBlockerBrowserTest() {} | 97 virtual ~PopupBlockerBrowserTest() {} |
| 98 | 98 |
| 99 virtual void SetUpOnMainThread() OVERRIDE { | 99 virtual void SetUpOnMainThread() override { |
| 100 InProcessBrowserTest::SetUpOnMainThread(); | 100 InProcessBrowserTest::SetUpOnMainThread(); |
| 101 | 101 |
| 102 host_resolver()->AddRule("*", "127.0.0.1"); | 102 host_resolver()->AddRule("*", "127.0.0.1"); |
| 103 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 103 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 104 } | 104 } |
| 105 | 105 |
| 106 int GetBlockedContentsCount() { | 106 int GetBlockedContentsCount() { |
| 107 // Do a round trip to the renderer first to flush any in-flight IPCs to | 107 // Do a round trip to the renderer first to flush any in-flight IPCs to |
| 108 // create a to-be-blocked window. | 108 // create a to-be-blocked window. |
| 109 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 109 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 | 481 |
| 482 // Verify that the renderer can't DOS the browser by creating arbitrarily many | 482 // Verify that the renderer can't DOS the browser by creating arbitrarily many |
| 483 // popups. | 483 // popups. |
| 484 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, DenialOfService) { | 484 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, DenialOfService) { |
| 485 GURL url(embedded_test_server()->GetURL("/popup_blocker/popup-dos.html")); | 485 GURL url(embedded_test_server()->GetURL("/popup_blocker/popup-dos.html")); |
| 486 ui_test_utils::NavigateToURL(browser(), url); | 486 ui_test_utils::NavigateToURL(browser(), url); |
| 487 ASSERT_EQ(25, GetBlockedContentsCount()); | 487 ASSERT_EQ(25, GetBlockedContentsCount()); |
| 488 } | 488 } |
| 489 | 489 |
| 490 } // namespace | 490 } // namespace |
| OLD | NEW |