OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <limits.h> | 5 #include <limits.h> |
6 #include <stddef.h> | 6 #include <stddef.h> |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 2146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2157 GURL extension_url = extension->GetResourceURL("file.html"); | 2157 GURL extension_url = extension->GetResourceURL("file.html"); |
2158 ui_test_utils::NavigateToURL(browser(), extension_url); | 2158 ui_test_utils::NavigateToURL(browser(), extension_url); |
2159 content::WebContents* old_contents = | 2159 content::WebContents* old_contents = |
2160 browser()->tab_strip_model()->GetActiveWebContents(); | 2160 browser()->tab_strip_model()->GetActiveWebContents(); |
2161 | 2161 |
2162 // Execute chrome.windows.create and store the new tab in |new_contents|. | 2162 // Execute chrome.windows.create and store the new tab in |new_contents|. |
2163 content::WebContents* new_contents = nullptr; | 2163 content::WebContents* new_contents = nullptr; |
2164 { | 2164 { |
2165 content::WebContentsAddedObserver observer; | 2165 content::WebContentsAddedObserver observer; |
2166 ASSERT_TRUE(content::ExecuteScript(old_contents, | 2166 ASSERT_TRUE(content::ExecuteScript(old_contents, |
2167 "window.name = 'test-name';\n" | 2167 "window.name = 'old-contents';\n" |
2168 "chrome.windows.create({url: '" + | 2168 "chrome.windows.create({url: '" + |
2169 extension_url.spec() + "'})")); | 2169 extension_url.spec() + "'})")); |
2170 new_contents = observer.GetWebContents(); | 2170 new_contents = observer.GetWebContents(); |
| 2171 ASSERT_TRUE(content::WaitForLoadStop(new_contents)); |
2171 } | 2172 } |
2172 | 2173 |
2173 // Verify that the old and new tab are in the same process and SiteInstance. | 2174 // Verify that the old and new tab are in the same process and SiteInstance. |
2174 // Note: both test assertions are important - one observed failure mode was | 2175 // Note: both test assertions are important - one observed failure mode was |
2175 // having the same process, but different SiteInstance. | 2176 // having the same process, but different SiteInstance. |
2176 EXPECT_EQ(old_contents->GetMainFrame()->GetProcess(), | 2177 EXPECT_EQ(old_contents->GetMainFrame()->GetProcess(), |
2177 new_contents->GetMainFrame()->GetProcess()); | 2178 new_contents->GetMainFrame()->GetProcess()); |
2178 EXPECT_EQ(old_contents->GetMainFrame()->GetSiteInstance(), | 2179 EXPECT_EQ(old_contents->GetMainFrame()->GetSiteInstance(), |
2179 new_contents->GetMainFrame()->GetSiteInstance()); | 2180 new_contents->GetMainFrame()->GetSiteInstance()); |
2180 | 2181 |
2181 // Verify that the |new_contents| doesn't have a |window.opener| set. | 2182 // Verify that the |new_contents| doesn't have a |window.opener| set. |
2182 bool window_opener_cast_to_bool = true; | 2183 bool window_opener_cast_to_bool = true; |
2183 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 2184 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
2184 new_contents, "window.domAutomationController.send(!!window.opener)", | 2185 new_contents, "window.domAutomationController.send(!!window.opener)", |
2185 &window_opener_cast_to_bool)); | 2186 &window_opener_cast_to_bool)); |
2186 EXPECT_FALSE(window_opener_cast_to_bool); | 2187 EXPECT_FALSE(window_opener_cast_to_bool); |
| 2188 |
| 2189 // Verify that |new_contents| can find |old_contents| using window.open/name. |
| 2190 std::string location_of_other_window; |
| 2191 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 2192 new_contents, |
| 2193 "var w = window.open('', 'old-contents');\n" |
| 2194 "window.domAutomationController.send(w.location.href);", |
| 2195 &location_of_other_window)); |
| 2196 EXPECT_EQ(old_contents->GetMainFrame()->GetLastCommittedURL().spec(), |
| 2197 location_of_other_window); |
2187 } | 2198 } |
2188 | 2199 |
2189 } // namespace extensions | 2200 } // namespace extensions |
OLD | NEW |