Chromium Code Reviews| 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 27 matching lines...) Expand all Loading... | |
| 38 #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" | 38 #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" |
| 39 #include "chrome/test/base/ui_test_utils.h" | 39 #include "chrome/test/base/ui_test_utils.h" |
| 40 #include "components/prefs/pref_service.h" | 40 #include "components/prefs/pref_service.h" |
| 41 #include "content/public/browser/browser_context.h" | 41 #include "content/public/browser/browser_context.h" |
| 42 #include "content/public/browser/notification_service.h" | 42 #include "content/public/browser/notification_service.h" |
| 43 #include "content/public/browser/render_frame_host.h" | 43 #include "content/public/browser/render_frame_host.h" |
| 44 #include "content/public/browser/storage_partition.h" | 44 #include "content/public/browser/storage_partition.h" |
| 45 #include "content/public/common/page_zoom.h" | 45 #include "content/public/common/page_zoom.h" |
| 46 #include "content/public/common/url_constants.h" | 46 #include "content/public/common/url_constants.h" |
| 47 #include "content/public/test/browser_test_utils.h" | 47 #include "content/public/test/browser_test_utils.h" |
| 48 #include "content/public/test/test_navigation_observer.h" | |
| 48 #include "extensions/browser/api_test_utils.h" | 49 #include "extensions/browser/api_test_utils.h" |
| 49 #include "extensions/browser/app_window/app_window.h" | 50 #include "extensions/browser/app_window/app_window.h" |
| 50 #include "extensions/browser/app_window/app_window_registry.h" | 51 #include "extensions/browser/app_window/app_window_registry.h" |
| 51 #include "extensions/common/manifest_constants.h" | 52 #include "extensions/common/manifest_constants.h" |
| 52 #include "extensions/common/test_util.h" | 53 #include "extensions/common/test_util.h" |
| 53 #include "extensions/test/extension_test_message_listener.h" | 54 #include "extensions/test/extension_test_message_listener.h" |
| 54 #include "extensions/test/result_catcher.h" | 55 #include "extensions/test/result_catcher.h" |
| 55 #include "net/test/embedded_test_server/embedded_test_server.h" | 56 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 56 #include "ui/base/window_open_disposition.h" | 57 #include "ui/base/window_open_disposition.h" |
| 57 #include "ui/gfx/geometry/rect.h" | 58 #include "ui/gfx/geometry/rect.h" |
| (...skipping 2084 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2142 browser()->tab_strip_model()->ActivateTabAt(0, true); | 2143 browser()->tab_strip_model()->ActivateTabAt(0, true); |
| 2143 EXPECT_EQ(first_web_contents, | 2144 EXPECT_EQ(first_web_contents, |
| 2144 browser()->tab_strip_model()->GetActiveWebContents()); | 2145 browser()->tab_strip_model()->GetActiveWebContents()); |
| 2145 browser()->tab_strip_model()->ActivateTabAt(1, true); | 2146 browser()->tab_strip_model()->ActivateTabAt(1, true); |
| 2146 EXPECT_EQ(second_web_contents, | 2147 EXPECT_EQ(second_web_contents, |
| 2147 browser()->tab_strip_model()->GetActiveWebContents()); | 2148 browser()->tab_strip_model()->GetActiveWebContents()); |
| 2148 | 2149 |
| 2149 EXPECT_EQ(url, second_web_contents->GetVisibleURL()); | 2150 EXPECT_EQ(url, second_web_contents->GetVisibleURL()); |
| 2150 } | 2151 } |
| 2151 | 2152 |
| 2152 // Window created by chrome.windows.create should be in the same SiteInstance | 2153 // Window created by chrome.windows.create should be in the same |
| 2153 // and BrowsingInstance as the opener - this is a regression test for | 2154 // BrowsingInstance as the opener - this is a regression test for |
| 2154 // https://crbug.com/597750. | 2155 // https://crbug.com/597750. |
| 2155 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowsCreateVsSiteInstance) { | 2156 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowsCreateVsBrowsingInstance) { |
| 2156 const extensions::Extension* extension = | 2157 const extensions::Extension* extension = |
| 2157 LoadExtension(test_data_dir_.AppendASCII("../simple_with_file")); | 2158 LoadExtension(test_data_dir_.AppendASCII("../simple_with_file")); |
| 2158 ASSERT_TRUE(extension); | 2159 ASSERT_TRUE(extension); |
| 2159 | 2160 |
| 2160 // Navigate a tab to an extension page. | 2161 // Navigate a tab to an extension page. |
| 2161 GURL extension_url = extension->GetResourceURL("file.html"); | 2162 GURL extension_url = extension->GetResourceURL("file.html"); |
| 2162 ui_test_utils::NavigateToURL(browser(), extension_url); | 2163 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 2163 content::WebContents* old_contents = | 2164 content::WebContents* old_contents = |
| 2164 browser()->tab_strip_model()->GetActiveWebContents(); | 2165 browser()->tab_strip_model()->GetActiveWebContents(); |
| 2165 | 2166 |
| 2166 // Execute chrome.windows.create and store the new tab in |new_contents|. | 2167 // Execute chrome.windows.create and store the new tab in |new_contents|. |
| 2167 content::WebContents* new_contents = nullptr; | 2168 content::WebContents* new_contents = nullptr; |
| 2168 { | 2169 { |
| 2169 content::WebContentsAddedObserver observer; | 2170 content::WebContentsAddedObserver observer; |
| 2170 ASSERT_TRUE(content::ExecuteScript(old_contents, | 2171 ASSERT_TRUE(content::ExecuteScript(old_contents, |
| 2171 "window.name = 'old-contents';\n" | 2172 "window.name = 'old-contents';\n" |
| 2172 "chrome.windows.create({url: '" + | 2173 "chrome.windows.create({url: '" + |
| 2173 extension_url.spec() + "'})")); | 2174 extension_url.spec() + "'})")); |
| 2174 new_contents = observer.GetWebContents(); | 2175 new_contents = observer.GetWebContents(); |
| 2175 ASSERT_TRUE(content::WaitForLoadStop(new_contents)); | 2176 ASSERT_TRUE(content::WaitForLoadStop(new_contents)); |
| 2176 } | 2177 } |
| 2177 | 2178 |
| 2179 // Navigate the old and the new tab to a web URL. | |
| 2180 ASSERT_TRUE(StartEmbeddedTestServer()); | |
| 2181 GURL web_url1 = embedded_test_server()->GetURL("/title1.html"); | |
| 2182 GURL web_url2 = embedded_test_server()->GetURL("/title2.html"); | |
| 2183 { | |
| 2184 content::TestNavigationObserver nav_observer(new_contents, 1); | |
| 2185 ASSERT_TRUE(content::ExecuteScript( | |
| 2186 new_contents, "window.location = '" + web_url1.spec() + "';")); | |
| 2187 nav_observer.Wait(); | |
| 2188 } | |
| 2189 { | |
| 2190 content::TestNavigationObserver nav_observer(old_contents, 1); | |
| 2191 ASSERT_TRUE(content::ExecuteScript( | |
| 2192 old_contents, "window.location = '" + web_url2.spec() + "';")); | |
| 2193 nav_observer.Wait(); | |
| 2194 } | |
| 2195 EXPECT_EQ(web_url1, new_contents->GetMainFrame()->GetLastCommittedURL()); | |
| 2196 EXPECT_EQ(web_url2, old_contents->GetMainFrame()->GetLastCommittedURL()); | |
| 2197 | |
| 2178 // Verify that the old and new tab are in the same process and SiteInstance. | 2198 // Verify that the old and new tab are in the same process and SiteInstance. |
|
Charlie Reis
2017/06/05 21:06:28
nit: Remove "and SiteInstance" if we aren't checki
Łukasz Anforowicz
2017/06/05 22:06:54
Done.
| |
| 2179 // Note: both test assertions are important - one observed failure mode was | |
| 2180 // having the same process, but different SiteInstance. | |
| 2181 EXPECT_EQ(old_contents->GetMainFrame()->GetProcess(), | 2199 EXPECT_EQ(old_contents->GetMainFrame()->GetProcess(), |
| 2182 new_contents->GetMainFrame()->GetProcess()); | 2200 new_contents->GetMainFrame()->GetProcess()); |
| 2183 EXPECT_EQ(old_contents->GetMainFrame()->GetSiteInstance(), | |
| 2184 new_contents->GetMainFrame()->GetSiteInstance()); | |
| 2185 | 2201 |
| 2186 // Verify that the |new_contents| doesn't have a |window.opener| set. | 2202 // Verify the old and new contents are in the same browsing instance. |
|
Charlie Reis
2017/06/05 21:06:28
nit: BrowsingInstance
Łukasz Anforowicz
2017/06/05 22:06:54
Done.
| |
| 2187 bool window_opener_cast_to_bool = true; | 2203 EXPECT_TRUE( |
| 2188 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 2204 old_contents->GetMainFrame()->GetSiteInstance()->IsRelatedSiteInstance( |
| 2189 new_contents, "window.domAutomationController.send(!!window.opener)", | 2205 new_contents->GetMainFrame()->GetSiteInstance())); |
| 2190 &window_opener_cast_to_bool)); | 2206 |
| 2191 EXPECT_FALSE(window_opener_cast_to_bool); | 2207 // Verify that the |new_contents| has |window.opener| set. |
| 2208 std::string location_of_opener; | |
| 2209 EXPECT_TRUE(ExecuteScriptAndExtractString( | |
| 2210 new_contents, | |
| 2211 "window.domAutomationController.send(window.opener.location.href)", | |
| 2212 &location_of_opener)); | |
| 2213 EXPECT_EQ(old_contents->GetMainFrame()->GetLastCommittedURL().spec(), | |
| 2214 location_of_opener); | |
| 2192 | 2215 |
| 2193 // Verify that |new_contents| can find |old_contents| using window.open/name. | 2216 // Verify that |new_contents| can find |old_contents| using window.open/name. |
| 2194 std::string location_of_other_window; | 2217 std::string location_of_other_window; |
| 2195 EXPECT_TRUE(ExecuteScriptAndExtractString( | 2218 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 2196 new_contents, | 2219 new_contents, |
| 2197 "var w = window.open('', 'old-contents');\n" | 2220 "var w = window.open('', 'old-contents');\n" |
| 2198 "window.domAutomationController.send(w.location.href);", | 2221 "window.domAutomationController.send(w.location.href);", |
| 2199 &location_of_other_window)); | 2222 &location_of_other_window)); |
| 2200 EXPECT_EQ(old_contents->GetMainFrame()->GetLastCommittedURL().spec(), | 2223 EXPECT_EQ(old_contents->GetMainFrame()->GetLastCommittedURL().spec(), |
| 2201 location_of_other_window); | 2224 location_of_other_window); |
| 2202 } | 2225 } |
| 2203 | 2226 |
| 2204 } // namespace extensions | 2227 } // namespace extensions |
| OLD | NEW |