| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/macros.h" | 6 #include "base/macros.h" |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "content/public/browser/web_contents.h" | 8 #include "content/public/browser/web_contents.h" |
| 9 #include "content/public/browser/web_contents_delegate.h" | 9 #include "content/public/browser/web_contents_delegate.h" |
| 10 #include "content/public/test/browser_test_utils.h" | 10 #include "content/public/test/browser_test_utils.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 } // namespace | 41 } // namespace |
| 42 | 42 |
| 43 class OpenedByDOMTest : public ContentBrowserTest { | 43 class OpenedByDOMTest : public ContentBrowserTest { |
| 44 protected: | 44 protected: |
| 45 void SetUpCommandLine(base::CommandLine* command_line) override { | 45 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 46 // Use --site-per-process to force process swaps on cross-site navigations. | 46 // Use --site-per-process to force process swaps on cross-site navigations. |
| 47 IsolateAllSitesForTesting(command_line); | 47 IsolateAllSitesForTesting(command_line); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void SetUpOnMainThread() override { |
| 51 host_resolver()->AddRule("*", "127.0.0.1"); |
| 52 } |
| 53 |
| 50 bool AttemptCloseFromJavaScript(WebContents* web_contents) { | 54 bool AttemptCloseFromJavaScript(WebContents* web_contents) { |
| 51 CloseTrackingDelegate close_tracking_delegate; | 55 CloseTrackingDelegate close_tracking_delegate; |
| 52 WebContentsDelegate* old_delegate = web_contents->GetDelegate(); | 56 WebContentsDelegate* old_delegate = web_contents->GetDelegate(); |
| 53 web_contents->SetDelegate(&close_tracking_delegate); | 57 web_contents->SetDelegate(&close_tracking_delegate); |
| 54 | 58 |
| 55 const char kCloseWindowScript[] = | 59 const char kCloseWindowScript[] = |
| 56 // Close the window. | 60 // Close the window. |
| 57 "window.close();" | 61 "window.close();" |
| 58 // Report back after an event loop iteration; the close IPC isn't sent | 62 // Report back after an event loop iteration; the close IPC isn't sent |
| 59 // immediately. | 63 // immediately. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 NavigateToURL(shell(), url1); | 111 NavigateToURL(shell(), url1); |
| 108 | 112 |
| 109 Shell* popup = OpenWindowFromJavaScript(shell(), url2); | 113 Shell* popup = OpenWindowFromJavaScript(shell(), url2); |
| 110 NavigateToURL(popup, url3); | 114 NavigateToURL(popup, url3); |
| 111 EXPECT_TRUE(AttemptCloseFromJavaScript(popup->web_contents())); | 115 EXPECT_TRUE(AttemptCloseFromJavaScript(popup->web_contents())); |
| 112 } | 116 } |
| 113 | 117 |
| 114 // Tests that window.close() works in a popup window that has navigated a few | 118 // Tests that window.close() works in a popup window that has navigated a few |
| 115 // times and swapped processes. | 119 // times and swapped processes. |
| 116 IN_PROC_BROWSER_TEST_F(OpenedByDOMTest, CrossProcessPopup) { | 120 IN_PROC_BROWSER_TEST_F(OpenedByDOMTest, CrossProcessPopup) { |
| 117 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 118 ASSERT_TRUE(embedded_test_server()->Start()); | 121 ASSERT_TRUE(embedded_test_server()->Start()); |
| 119 | 122 |
| 120 GURL url1 = embedded_test_server()->GetURL("/site_isolation/blank.html?1"); | 123 GURL url1 = embedded_test_server()->GetURL("/site_isolation/blank.html?1"); |
| 121 | 124 |
| 122 GURL url2 = embedded_test_server()->GetURL("/site_isolation/blank.html?2"); | 125 GURL url2 = embedded_test_server()->GetURL("/site_isolation/blank.html?2"); |
| 123 GURL::Replacements replace_host; | 126 GURL::Replacements replace_host; |
| 124 replace_host.SetHostStr("foo.com"); | 127 replace_host.SetHostStr("foo.com"); |
| 125 url2 = url2.ReplaceComponents(replace_host); | 128 url2 = url2.ReplaceComponents(replace_host); |
| 126 | 129 |
| 127 GURL url3 = embedded_test_server()->GetURL("/site_isolation/blank.html?3"); | 130 GURL url3 = embedded_test_server()->GetURL("/site_isolation/blank.html?3"); |
| 128 url3 = url3.ReplaceComponents(replace_host); | 131 url3 = url3.ReplaceComponents(replace_host); |
| 129 | 132 |
| 130 NavigateToURL(shell(), url1); | 133 NavigateToURL(shell(), url1); |
| 131 | 134 |
| 132 Shell* popup = OpenWindowFromJavaScript(shell(), url2); | 135 Shell* popup = OpenWindowFromJavaScript(shell(), url2); |
| 133 NavigateToURL(popup, url3); | 136 NavigateToURL(popup, url3); |
| 134 EXPECT_TRUE(AttemptCloseFromJavaScript(popup->web_contents())); | 137 EXPECT_TRUE(AttemptCloseFromJavaScript(popup->web_contents())); |
| 135 } | 138 } |
| 136 | 139 |
| 137 } // namespace content | 140 } // namespace content |
| OLD | NEW |