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

Unified Diff: chrome/browser/extensions/app_background_page_apitest.cc

Issue 2882513005: Propagate opener to BackgroundsContents. (Closed)
Patch Set: Tweaked the comment in DriveWebContentsManager::ShouldCreateWebContents Created 3 years, 6 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/app_background_page_apitest.cc
diff --git a/chrome/browser/extensions/app_background_page_apitest.cc b/chrome/browser/extensions/app_background_page_apitest.cc
index 91ea277ed3a6605ca89911401b546bdae8be5cfe..771208f9d8271270505dbddbb2c3c061c433a5a4 100644
--- a/chrome/browser/extensions/app_background_page_apitest.cc
+++ b/chrome/browser/extensions/app_background_page_apitest.cc
@@ -25,6 +25,8 @@
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/notification_service.h"
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_notification_tracker.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/process_manager.h"
@@ -33,6 +35,7 @@
#include "extensions/test/extension_test_message_listener.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
+#include "url/gurl.h"
#if !defined(DISABLE_NACL)
#include "components/nacl/browser/nacl_process_host.h"
@@ -245,10 +248,24 @@ IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, ManifestBackgroundPage) {
// the app was loaded.
ASSERT_TRUE(WaitForBackgroundMode(true));
+ // Verify that the background contents exist.
const Extension* extension = GetSingleLoadedExtension();
- ASSERT_TRUE(
- BackgroundContentsServiceFactory::GetForProfile(browser()->profile())->
- GetAppBackgroundContents(ASCIIToUTF16(extension->id())));
+ BackgroundContents* background_contents =
+ BackgroundContentsServiceFactory::GetForProfile(browser()->profile())
+ ->GetAppBackgroundContents(ASCIIToUTF16(extension->id()));
+ ASSERT_TRUE(background_contents);
+
+ // Verify that window.opener in the background contents is not set when
+ // creating the background page through the manifest (not through
+ // window.open).
+ EXPECT_FALSE(background_contents->web_contents()->GetOpener());
+ bool window_opener_null_in_js;
+ EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
+ background_contents->web_contents(),
+ "domAutomationController.send(window.opener == null);",
+ &window_opener_null_in_js));
+ EXPECT_TRUE(window_opener_null_in_js);
+
UnloadExtension(extension->id());
}
@@ -296,9 +313,20 @@ IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, NoJsBackgroundPage) {
// The test makes sure that window.open returns null.
ASSERT_TRUE(RunExtensionTest("app_background_page/no_js")) << message_;
// And after it runs there should be a background page.
- ASSERT_TRUE(
- BackgroundContentsServiceFactory::GetForProfile(browser()->profile())->
- GetAppBackgroundContents(ASCIIToUTF16(extension->id())));
+ BackgroundContents* background_contents =
+ BackgroundContentsServiceFactory::GetForProfile(browser()->profile())
+ ->GetAppBackgroundContents(ASCIIToUTF16(extension->id()));
+ ASSERT_TRUE(background_contents);
+
+ // Verify that window.opener in the background contents is not set when
+ // allow_js_access=false.
+ EXPECT_FALSE(background_contents->web_contents()->GetOpener());
+ bool window_opener_null_in_js;
+ EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
+ background_contents->web_contents(),
+ "domAutomationController.send(window.opener == null);",
+ &window_opener_null_in_js));
+ EXPECT_TRUE(window_opener_null_in_js);
EXPECT_EQ(0u, background_deleted_tracker.size());
UnloadExtension(extension->id());
@@ -331,13 +359,36 @@ IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, NoJsManifestBackgroundPage) {
ASSERT_TRUE(CreateApp(app_manifest, &app_dir));
ASSERT_TRUE(LoadExtension(app_dir));
- // The background page should load, but window.open should return null.
+ // The background page should load.
const Extension* extension = GetSingleLoadedExtension();
- ASSERT_TRUE(
- BackgroundContentsServiceFactory::GetForProfile(browser()->profile())->
- GetAppBackgroundContents(ASCIIToUTF16(extension->id())));
+ BackgroundContents* background_contents =
+ BackgroundContentsServiceFactory::GetForProfile(browser()->profile())
+ ->GetAppBackgroundContents(ASCIIToUTF16(extension->id()));
+ ASSERT_TRUE(background_contents);
+
+ // Verify that window.opener in the background contents is not set when
+ // creating the background page through the manifest (not through
+ // window.open).
+ EXPECT_FALSE(background_contents->web_contents()->GetOpener());
+ bool window_opener_null_in_js;
+ EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
+ background_contents->web_contents(),
+ "domAutomationController.send(window.opener == null);",
+ &window_opener_null_in_js));
+ EXPECT_TRUE(window_opener_null_in_js);
+
+ // window.open should return null.
ASSERT_TRUE(RunExtensionTest("app_background_page/no_js_manifest")) <<
message_;
+
+ // Verify that window.opener in the background contents is still not set.
+ EXPECT_FALSE(background_contents->web_contents()->GetOpener());
+ EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
+ background_contents->web_contents(),
+ "domAutomationController.send(window.opener == null);",
+ &window_opener_null_in_js));
+ EXPECT_TRUE(window_opener_null_in_js);
+
UnloadExtension(extension->id());
}
@@ -426,7 +477,7 @@ IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, DISABLED_OpenPopupFromBGPage) {
ASSERT_TRUE(RunExtensionTest("app_background_page/bg_open")) << message_;
}
-IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, DISABLED_OpenThenClose) {
+IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, OpenThenClose) {
std::string app_manifest = base::StringPrintf(
"{"
" \"name\": \"App\","
@@ -457,11 +508,28 @@ IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, DISABLED_OpenThenClose) {
ASSERT_TRUE(RunExtensionTest("app_background_page/basic_open")) << message_;
// Background mode should be active now because a background page was created.
ASSERT_TRUE(WaitForBackgroundMode(true));
- ASSERT_TRUE(
- BackgroundContentsServiceFactory::GetForProfile(browser()->profile())->
- GetAppBackgroundContents(ASCIIToUTF16(extension->id())));
+
+ // Verify that the background contents exist.
+ BackgroundContents* background_contents =
+ BackgroundContentsServiceFactory::GetForProfile(browser()->profile())
+ ->GetAppBackgroundContents(ASCIIToUTF16(extension->id()));
+ ASSERT_TRUE(background_contents);
+
+ // Verify that window.opener in the background contents is set.
+ content::RenderFrameHost* background_opener =
+ background_contents->web_contents()->GetOpener();
+ ASSERT_TRUE(background_opener);
+ std::string window_opener_href;
+ EXPECT_TRUE(content::ExecuteScriptAndExtractString(
+ background_contents->web_contents(),
+ "domAutomationController.send(window.opener.location.href);",
+ &window_opener_href));
+ EXPECT_EQ(window_opener_href,
+ background_opener->GetLastCommittedURL().spec());
+
// Now close the BackgroundContents.
ASSERT_TRUE(RunExtensionTest("app_background_page/basic_close")) << message_;
+
// Background mode should no longer be active.
ASSERT_TRUE(WaitForBackgroundMode(false));
ASSERT_FALSE(

Powered by Google App Engine
This is Rietveld 408576698