Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4107)

Unified Diff: chrome/browser/extensions/api/tabs/tabs_test.cc

Issue 2921753002: NOT YET READY: Making chrome.windows.create establish an actual "opener" relationship.
Patch Set: Fix incognito profile transitions Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/tabs/tabs_test.cc
diff --git a/chrome/browser/extensions/api/tabs/tabs_test.cc b/chrome/browser/extensions/api/tabs/tabs_test.cc
index 55dd8156623ca832e07dea5de04a97c3bd3c6864..da3b858dfc6e7974dd378ed13ee2068f53a197ee 100644
--- a/chrome/browser/extensions/api/tabs/tabs_test.cc
+++ b/chrome/browser/extensions/api/tabs/tabs_test.cc
@@ -45,6 +45,7 @@
#include "content/public/common/page_zoom.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/browser_test_utils.h"
+#include "content/public/test/test_navigation_observer.h"
#include "extensions/browser/api_test_utils.h"
#include "extensions/browser/app_window/app_window.h"
#include "extensions/browser/app_window/app_window_registry.h"
@@ -2149,10 +2150,10 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TemporaryAddressSpoof) {
EXPECT_EQ(url, second_web_contents->GetVisibleURL());
}
-// Window created by chrome.windows.create should be in the same SiteInstance
-// and BrowsingInstance as the opener - this is a regression test for
+// Window created by chrome.windows.create should be in the same
+// BrowsingInstance as the opener - this is a regression test for
// https://crbug.com/597750.
-IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowsCreateVsSiteInstance) {
+IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowsCreateVsBrowsingInstance) {
const extensions::Extension* extension =
LoadExtension(test_data_dir_.AppendASCII("../simple_with_file"));
ASSERT_TRUE(extension);
@@ -2175,20 +2176,42 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowsCreateVsSiteInstance) {
ASSERT_TRUE(content::WaitForLoadStop(new_contents));
}
+ // Navigate the old and the new tab to a web URL.
+ ASSERT_TRUE(StartEmbeddedTestServer());
+ GURL web_url1 = embedded_test_server()->GetURL("/title1.html");
+ GURL web_url2 = embedded_test_server()->GetURL("/title2.html");
+ {
+ content::TestNavigationObserver nav_observer(new_contents, 1);
+ ASSERT_TRUE(content::ExecuteScript(
+ new_contents, "window.location = '" + web_url1.spec() + "';"));
+ nav_observer.Wait();
+ }
+ {
+ content::TestNavigationObserver nav_observer(old_contents, 1);
+ ASSERT_TRUE(content::ExecuteScript(
+ old_contents, "window.location = '" + web_url2.spec() + "';"));
+ nav_observer.Wait();
+ }
+ EXPECT_EQ(web_url1, new_contents->GetMainFrame()->GetLastCommittedURL());
+ EXPECT_EQ(web_url2, old_contents->GetMainFrame()->GetLastCommittedURL());
+
// 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.
- // Note: both test assertions are important - one observed failure mode was
- // having the same process, but different SiteInstance.
EXPECT_EQ(old_contents->GetMainFrame()->GetProcess(),
new_contents->GetMainFrame()->GetProcess());
- EXPECT_EQ(old_contents->GetMainFrame()->GetSiteInstance(),
- new_contents->GetMainFrame()->GetSiteInstance());
-
- // Verify that the |new_contents| doesn't have a |window.opener| set.
- bool window_opener_cast_to_bool = true;
- EXPECT_TRUE(ExecuteScriptAndExtractBool(
- new_contents, "window.domAutomationController.send(!!window.opener)",
- &window_opener_cast_to_bool));
- EXPECT_FALSE(window_opener_cast_to_bool);
+
+ // 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.
+ EXPECT_TRUE(
+ old_contents->GetMainFrame()->GetSiteInstance()->IsRelatedSiteInstance(
+ new_contents->GetMainFrame()->GetSiteInstance()));
+
+ // Verify that the |new_contents| has |window.opener| set.
+ std::string location_of_opener;
+ EXPECT_TRUE(ExecuteScriptAndExtractString(
+ new_contents,
+ "window.domAutomationController.send(window.opener.location.href)",
+ &location_of_opener));
+ EXPECT_EQ(old_contents->GetMainFrame()->GetLastCommittedURL().spec(),
+ location_of_opener);
// Verify that |new_contents| can find |old_contents| using window.open/name.
std::string location_of_other_window;

Powered by Google App Engine
This is Rietveld 408576698