diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-20 17:26:13 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-20 17:26:13 +0000 |
commit | 7edafd5302f9885e89f8b803349e9ad1bd6f7eb5 (patch) | |
tree | 04a20826478cfcd2893bcea10f6c67e4ba3c7f53 | |
parent | 4e2eb35838d42017542959dbef29d84ca6d2bbc4 (diff) | |
download | chromium_src-7edafd5302f9885e89f8b803349e9ad1bd6f7eb5.zip chromium_src-7edafd5302f9885e89f8b803349e9ad1bd6f7eb5.tar.gz chromium_src-7edafd5302f9885e89f8b803349e9ad1bd6f7eb5.tar.bz2 |
Move some extensions tests to RenderFrameHost.
BUG=304341
TEST=no change
Review URL: https://codereview.chromium.org/204103003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@258319 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/extensions/chrome_app_api_browsertest.cc | 119 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_messages_apitest.cc | 154 | ||||
-rw-r--r-- | chrome/browser/extensions/subscribe_page_action_browsertest.cc | 28 | ||||
-rw-r--r-- | content/public/test/browser_test_utils.cc | 16 | ||||
-rw-r--r-- | content/public/test/browser_test_utils.h | 5 |
5 files changed, 159 insertions, 163 deletions
diff --git a/chrome/browser/extensions/chrome_app_api_browsertest.cc b/chrome/browser/extensions/chrome_app_api_browsertest.cc index b0ace91..86428bf 100644 --- a/chrome/browser/extensions/chrome_app_api_browsertest.cc +++ b/chrome/browser/extensions/chrome_app_api_browsertest.cc @@ -27,51 +27,66 @@ using extensions::Extension; class ChromeAppAPITest : public ExtensionBrowserTest { protected: - bool IsAppInstalled() { return IsAppInstalled(""); } - bool IsAppInstalled(const char* frame_xpath) { + bool IsAppInstalledInMainFrame() { + return IsAppInstalledInFrame( + browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()); + } + bool IsAppInstalledInIFrame() { + return IsAppInstalledInFrame(GetIFrame()); + } + bool IsAppInstalledInFrame(content::RenderFrameHost* frame) { const char kGetAppIsInstalled[] = "window.domAutomationController.send(window.chrome.app.isInstalled);"; bool result; - CHECK( - content::ExecuteScriptInFrameAndExtractBool( - browser()->tab_strip_model()->GetActiveWebContents(), - frame_xpath, - kGetAppIsInstalled, - &result)); + CHECK(content::ExecuteScriptAndExtractBool(frame, + kGetAppIsInstalled, + &result)); return result; } - std::string InstallState() { return InstallState(""); } - std::string InstallState(const char* frame_xpath) { + std::string InstallStateInMainFrame() { + return InstallStateInFrame( + browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()); + } + std::string InstallStateInIFrame() { + return InstallStateInFrame(GetIFrame()); + } + std::string InstallStateInFrame(content::RenderFrameHost* frame) { const char kGetAppInstallState[] = "window.chrome.app.installState(" " function(s) { window.domAutomationController.send(s); });"; std::string result; - CHECK( - content::ExecuteScriptInFrameAndExtractString( - browser()->tab_strip_model()->GetActiveWebContents(), - frame_xpath, - kGetAppInstallState, - &result)); + CHECK(content::ExecuteScriptAndExtractString(frame, + kGetAppInstallState, + &result)); return result; } - std::string RunningState() { return RunningState(""); } - std::string RunningState(const char* frame_xpath) { + std::string RunningStateInMainFrame() { + return RunningStateInFrame( + browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()); + } + std::string RunningStateInIFrame() { + return RunningStateInFrame(GetIFrame()); + } + std::string RunningStateInFrame(content::RenderFrameHost* frame) { const char kGetAppRunningState[] = "window.domAutomationController.send(" " window.chrome.app.runningState());"; std::string result; - CHECK( - content::ExecuteScriptInFrameAndExtractString( - browser()->tab_strip_model()->GetActiveWebContents(), - frame_xpath, - kGetAppRunningState, - &result)); + CHECK(content::ExecuteScriptAndExtractString(frame, + kGetAppRunningState, + &result)); return result; } private: + content::RenderFrameHost* GetIFrame() { + return content::FrameMatchingPredicate( + browser()->tab_strip_model()->GetActiveWebContents(), + base::Bind(&content::FrameIsChildOfMainFrame)); + } + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { ExtensionBrowserTest::SetUpCommandLine(command_line); command_line->AppendSwitchASCII(switches::kAppsCheckoutURL, @@ -104,7 +119,7 @@ IN_PROC_BROWSER_TEST_F(ChromeAppAPITest, MAYBE_IsInstalled) { // Before the app is installed, app.com does not think that it is installed ui_test_utils::NavigateToURL(browser(), app_url); - EXPECT_FALSE(IsAppInstalled()); + EXPECT_FALSE(IsAppInstalledInMainFrame()); // Load an app which includes app.com in its extent. const Extension* extension = LoadExtension( @@ -113,11 +128,11 @@ IN_PROC_BROWSER_TEST_F(ChromeAppAPITest, MAYBE_IsInstalled) { // Even after the app is installed, the existing app.com tab is not in an // app process, so chrome.app.isInstalled should return false. - EXPECT_FALSE(IsAppInstalled()); + EXPECT_FALSE(IsAppInstalledInMainFrame()); // Test that a non-app page has chrome.app.isInstalled = false. ui_test_utils::NavigateToURL(browser(), non_app_url); - EXPECT_FALSE(IsAppInstalled()); + EXPECT_FALSE(IsAppInstalledInMainFrame()); // Test that a non-app page returns null for chrome.app.getDetails(). const char kGetAppDetails[] = @@ -133,7 +148,7 @@ IN_PROC_BROWSER_TEST_F(ChromeAppAPITest, MAYBE_IsInstalled) { // Check that an app page has chrome.app.isInstalled = true. ui_test_utils::NavigateToURL(browser(), app_url); - EXPECT_TRUE(IsAppInstalled()); + EXPECT_TRUE(IsAppInstalledInMainFrame()); // Check that an app page returns the correct result for // chrome.app.getDetails(). @@ -252,48 +267,48 @@ IN_PROC_BROWSER_TEST_F(ChromeAppAPITest, InstallAndRunningState) { // Before the app is installed, app.com does not think that it is installed ui_test_utils::NavigateToURL(browser(), app_url); - EXPECT_EQ("not_installed", InstallState()); - EXPECT_EQ("cannot_run", RunningState()); - EXPECT_FALSE(IsAppInstalled()); + EXPECT_EQ("not_installed", InstallStateInMainFrame()); + EXPECT_EQ("cannot_run", RunningStateInMainFrame()); + EXPECT_FALSE(IsAppInstalledInMainFrame()); const Extension* extension = LoadExtension( test_data_dir_.AppendASCII("app_dot_com_app")); ASSERT_TRUE(extension); - EXPECT_EQ("installed", InstallState()); - EXPECT_EQ("ready_to_run", RunningState()); - EXPECT_FALSE(IsAppInstalled()); + EXPECT_EQ("installed", InstallStateInMainFrame()); + EXPECT_EQ("ready_to_run", RunningStateInMainFrame()); + EXPECT_FALSE(IsAppInstalledInMainFrame()); // Reloading the page should put the tab in an app process. ui_test_utils::NavigateToURL(browser(), app_url); - EXPECT_EQ("installed", InstallState()); - EXPECT_EQ("running", RunningState()); - EXPECT_TRUE(IsAppInstalled()); + EXPECT_EQ("installed", InstallStateInMainFrame()); + EXPECT_EQ("running", RunningStateInMainFrame()); + EXPECT_TRUE(IsAppInstalledInMainFrame()); // Disable the extension and verify the state. browser()->profile()->GetExtensionService()->DisableExtension( extension->id(), Extension::DISABLE_PERMISSIONS_INCREASE); ui_test_utils::NavigateToURL(browser(), app_url); - EXPECT_EQ("disabled", InstallState()); - EXPECT_EQ("cannot_run", RunningState()); - EXPECT_FALSE(IsAppInstalled()); + EXPECT_EQ("disabled", InstallStateInMainFrame()); + EXPECT_EQ("cannot_run", RunningStateInMainFrame()); + EXPECT_FALSE(IsAppInstalledInMainFrame()); browser()->profile()->GetExtensionService()->EnableExtension(extension->id()); - EXPECT_EQ("installed", InstallState()); - EXPECT_EQ("ready_to_run", RunningState()); - EXPECT_FALSE(IsAppInstalled()); + EXPECT_EQ("installed", InstallStateInMainFrame()); + EXPECT_EQ("ready_to_run", RunningStateInMainFrame()); + EXPECT_FALSE(IsAppInstalledInMainFrame()); // The non-app URL should still not be installed or running. ui_test_utils::NavigateToURL(browser(), non_app_url); - EXPECT_EQ("not_installed", InstallState()); - EXPECT_EQ("cannot_run", RunningState()); - EXPECT_FALSE(IsAppInstalled()); + EXPECT_EQ("not_installed", InstallStateInMainFrame()); + EXPECT_EQ("cannot_run", RunningStateInMainFrame()); + EXPECT_FALSE(IsAppInstalledInMainFrame()); - EXPECT_EQ("installed", InstallState("//html/iframe[1]")); - EXPECT_EQ("cannot_run", RunningState("//html/iframe[1]")); - EXPECT_FALSE(IsAppInstalled("//html/iframe[1]")); + EXPECT_EQ("installed", InstallStateInIFrame()); + EXPECT_EQ("cannot_run", RunningStateInIFrame()); + EXPECT_FALSE(IsAppInstalledInIFrame()); } @@ -319,7 +334,7 @@ IN_PROC_BROWSER_TEST_F(ChromeAppAPITest, InstallAndRunningStateFrame) { // within an app. ui_test_utils::NavigateToURL(browser(), app_url); - EXPECT_EQ("not_installed", InstallState("//html/iframe[1]")); - EXPECT_EQ("cannot_run", RunningState("//html/iframe[1]")); - EXPECT_FALSE(IsAppInstalled("//html/iframe[1]")); + EXPECT_EQ("not_installed", InstallStateInIFrame()); + EXPECT_EQ("cannot_run", RunningStateInIFrame()); + EXPECT_FALSE(IsAppInstalledInIFrame()); } diff --git a/chrome/browser/extensions/extension_messages_apitest.cc b/chrome/browser/extensions/extension_messages_apitest.cc index 36e2f38..2157e07 100644 --- a/chrome/browser/extensions/extension_messages_apitest.cc +++ b/chrome/browser/extensions/extension_messages_apitest.cc @@ -166,49 +166,51 @@ class ExternallyConnectableMessagingTest : public ExtensionApiTest { return result; } - Result CanConnectAndSendMessages(const std::string& extension_id) { - return CanConnectAndSendMessages(browser(), extension_id, ""); + Result CanConnectAndSendMessagesToMainFrame(const std::string& extension_id, + const char* message = NULL) { + return CanConnectAndSendMessagesToFrame( + browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), + extension_id, + message); } - Result CanConnectAndSendMessages(const std::string& extension_id, - const char* frame_xpath, - const char* message) { - return CanConnectAndSendMessages(browser(), extension_id, frame_xpath, - message); - } - - Result CanConnectAndSendMessages(Browser* browser, - const std::string& extension_id) { - return CanConnectAndSendMessages(browser, extension_id, ""); - } - - Result CanConnectAndSendMessages(const std::string& extension_id, - const char* frame_xpath) { - return CanConnectAndSendMessages(browser(), extension_id, frame_xpath); + Result CanConnectAndSendMessagesToIFrame(const std::string& extension_id, + const char* message = NULL) { + content::RenderFrameHost* frame = content::FrameMatchingPredicate( + browser()->tab_strip_model()->GetActiveWebContents(), + base::Bind(&content::FrameIsChildOfMainFrame)); + return CanConnectAndSendMessagesToFrame(frame, extension_id, message); } - Result CanConnectAndSendMessages(Browser* browser, - const std::string& extension_id, - const char* frame_xpath, - const char* message = NULL) { + Result CanConnectAndSendMessagesToFrame(content::RenderFrameHost* frame, + const std::string& extension_id, + const char* message) { int result; std::string args = "'" + extension_id + "'"; if (message) args += std::string(", '") + message + "'"; - CHECK(content::ExecuteScriptInFrameAndExtractInt( - browser->tab_strip_model()->GetActiveWebContents(), - frame_xpath, + CHECK(content::ExecuteScriptAndExtractInt( + frame, base::StringPrintf("assertions.canConnectAndSendMessages(%s)", args.c_str()), &result)); return static_cast<Result>(result); } - testing::AssertionResult AreAnyNonWebApisDefined() { - return AreAnyNonWebApisDefined(""); + testing::AssertionResult AreAnyNonWebApisDefinedForMainFrame() { + return AreAnyNonWebApisDefinedForFrame( + browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()); } - testing::AssertionResult AreAnyNonWebApisDefined(const char* frame_xpath) { + testing::AssertionResult AreAnyNonWebApisDefinedForIFrame() { + content::RenderFrameHost* frame = content::FrameMatchingPredicate( + browser()->tab_strip_model()->GetActiveWebContents(), + base::Bind(&content::FrameIsChildOfMainFrame)); + return AreAnyNonWebApisDefinedForFrame(frame); + } + + testing::AssertionResult AreAnyNonWebApisDefinedForFrame( + content::RenderFrameHost* frame) { // All runtime API methods are non-web except for sendRequest and connect. const char* non_messaging_apis[] = { "getBackgroundPage", @@ -243,9 +245,8 @@ class ExternallyConnectableMessagingTest : public ExtensionApiTest { as_js_array += "]"; bool any_defined; - CHECK(content::ExecuteScriptInFrameAndExtractBool( - browser()->tab_strip_model()->GetActiveWebContents(), - frame_xpath, + CHECK(content::ExecuteScriptAndExtractBool( + frame, "assertions.areAnyRuntimePropertiesDefined(" + as_js_array + ")", &any_defined)); return any_defined ? @@ -425,12 +426,14 @@ IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, NotInstalled) { const char kFakeId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; ui_test_utils::NavigateToURL(browser(), chromium_org_url()); - EXPECT_EQ(NAMESPACE_NOT_DEFINED, CanConnectAndSendMessages(kFakeId)); - EXPECT_FALSE(AreAnyNonWebApisDefined()); + EXPECT_EQ(NAMESPACE_NOT_DEFINED, + CanConnectAndSendMessagesToMainFrame(kFakeId)); + EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); ui_test_utils::NavigateToURL(browser(), google_com_url()); - EXPECT_EQ(NAMESPACE_NOT_DEFINED, CanConnectAndSendMessages(kFakeId)); - EXPECT_FALSE(AreAnyNonWebApisDefined()); + EXPECT_EQ(NAMESPACE_NOT_DEFINED, + CanConnectAndSendMessagesToMainFrame(kFakeId)); + EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); } // Tests two extensions on the same sites: one web connectable, one not. @@ -443,13 +446,14 @@ IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, const Extension* chromium_connectable = LoadChromiumConnectableExtension(); ui_test_utils::NavigateToURL(browser(), chromium_org_url()); - EXPECT_EQ(OK, CanConnectAndSendMessages(chromium_connectable->id())); - EXPECT_FALSE(AreAnyNonWebApisDefined()); + EXPECT_EQ(OK, + CanConnectAndSendMessagesToMainFrame(chromium_connectable->id())); + EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); ui_test_utils::NavigateToURL(browser(), google_com_url()); EXPECT_EQ(NAMESPACE_NOT_DEFINED, - CanConnectAndSendMessages(chromium_connectable->id())); - EXPECT_FALSE(AreAnyNonWebApisDefined()); + CanConnectAndSendMessagesToMainFrame(chromium_connectable->id())); + EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); // Install the non-connectable extension. Nothing can connect to it. const Extension* not_connectable = LoadNotConnectableExtension(); @@ -458,13 +462,13 @@ IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, // Namespace will be defined here because |chromium_connectable| can connect // to it - so this will be the "cannot establish connection" error. EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, - CanConnectAndSendMessages(not_connectable->id())); - EXPECT_FALSE(AreAnyNonWebApisDefined()); + CanConnectAndSendMessagesToMainFrame(not_connectable->id())); + EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); ui_test_utils::NavigateToURL(browser(), google_com_url()); EXPECT_EQ(NAMESPACE_NOT_DEFINED, - CanConnectAndSendMessages(not_connectable->id())); - EXPECT_FALSE(AreAnyNonWebApisDefined()); + CanConnectAndSendMessagesToMainFrame(not_connectable->id())); + EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); } // See http://crbug.com/297866 @@ -478,11 +482,12 @@ IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, ui_test_utils::NavigateToURL(browser(), chromium_org_url()); // If the background page closes after receipt of the message, it will still // reply to this message... - EXPECT_EQ(OK, CanConnectAndSendMessages(chromium_connectable->id(), - "", - close_background_message())); + EXPECT_EQ(OK, + CanConnectAndSendMessagesToMainFrame(chromium_connectable->id(), + close_background_message())); // and be re-opened by receipt of a subsequent message. - EXPECT_EQ(OK, CanConnectAndSendMessages(chromium_connectable->id())); + EXPECT_EQ(OK, + CanConnectAndSendMessagesToMainFrame(chromium_connectable->id())); } // Tests a web connectable extension that doesn't receive TLS channel id. @@ -599,18 +604,20 @@ IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, const Extension* not_connectable = LoadNotConnectableExtension(); ui_test_utils::NavigateToURL(browser(), chromium_org_url()); - EXPECT_EQ(OK, CanConnectAndSendMessages(chromium_connectable->id())); + EXPECT_EQ(OK, + CanConnectAndSendMessagesToMainFrame(chromium_connectable->id())); EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, - CanConnectAndSendMessages(not_connectable->id())); + CanConnectAndSendMessagesToMainFrame(not_connectable->id())); DisableExtension(chromium_connectable->id()); EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, - CanConnectAndSendMessages(chromium_connectable->id())); + CanConnectAndSendMessagesToMainFrame(chromium_connectable->id())); EnableExtension(chromium_connectable->id()); - EXPECT_EQ(OK, CanConnectAndSendMessages(chromium_connectable->id())); + EXPECT_EQ(OK, + CanConnectAndSendMessagesToMainFrame(chromium_connectable->id())); EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, - CanConnectAndSendMessages(not_connectable->id())); + CanConnectAndSendMessagesToMainFrame(not_connectable->id())); } // Tests connection from incognito tabs when the user denies the connection @@ -630,6 +637,8 @@ IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, FromIncognitoDeny) { Browser* incognito_browser = ui_test_utils::OpenURLOffTheRecord( profile()->GetOffTheRecordProfile(), chromium_org_url()); + content::RenderFrameHost* incognito_frame = incognito_browser-> + tab_strip_model()->GetActiveWebContents()->GetMainFrame(); // No connection because incognito-enabled hasn't been set for the extension, // and the user denied our interactive request. @@ -638,18 +647,18 @@ IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, FromIncognitoDeny) { IncognitoConnectability::ScopedAlertTracker::ALWAYS_DENY); EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, - CanConnectAndSendMessages(incognito_browser, id)); + CanConnectAndSendMessagesToFrame(incognito_frame, id, NULL)); EXPECT_EQ(1, alert_tracker.GetAndResetAlertCount()); // Try again. User has already denied. EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, - CanConnectAndSendMessages(incognito_browser, id)); + CanConnectAndSendMessagesToFrame(incognito_frame, id, NULL)); EXPECT_EQ(0, alert_tracker.GetAndResetAlertCount()); } // Allowing the extension in incognito mode will bypass the deny. ExtensionPrefs::Get(profile())->SetIsIncognitoEnabled(id, true); - EXPECT_EQ(OK, CanConnectAndSendMessages(incognito_browser, id)); + EXPECT_EQ(OK, CanConnectAndSendMessagesToFrame(incognito_frame, id, NULL)); } // Tests connection from incognito tabs when the user accepts the connection @@ -665,6 +674,8 @@ IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, FromIncognitoAllow) { Browser* incognito_browser = ui_test_utils::OpenURLOffTheRecord( profile()->GetOffTheRecordProfile(), chromium_org_url()); + content::RenderFrameHost* incognito_frame = incognito_browser-> + tab_strip_model()->GetActiveWebContents()->GetMainFrame(); // Connection allowed even with incognito disabled, because the user accepted // the interactive request. @@ -672,17 +683,17 @@ IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, FromIncognitoAllow) { IncognitoConnectability::ScopedAlertTracker alert_tracker( IncognitoConnectability::ScopedAlertTracker::ALWAYS_ALLOW); - EXPECT_EQ(OK, CanConnectAndSendMessages(incognito_browser, id)); + EXPECT_EQ(OK, CanConnectAndSendMessagesToFrame(incognito_frame, id, NULL)); EXPECT_EQ(1, alert_tracker.GetAndResetAlertCount()); // Try again. User has already allowed. - EXPECT_EQ(OK, CanConnectAndSendMessages(incognito_browser, id)); + EXPECT_EQ(OK, CanConnectAndSendMessagesToFrame(incognito_frame, id, NULL)); EXPECT_EQ(0, alert_tracker.GetAndResetAlertCount()); } // Allowing the extension in incognito mode will continue to allow. ExtensionPrefs::Get(profile())->SetIsIncognitoEnabled(id, true); - EXPECT_EQ(OK, CanConnectAndSendMessages(incognito_browser, id)); + EXPECT_EQ(OK, CanConnectAndSendMessagesToFrame(incognito_frame, id, NULL)); } // Tests a connection from an iframe within a tab which doesn't have @@ -694,14 +705,14 @@ IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, const Extension* extension = LoadChromiumConnectableExtension(); ui_test_utils::NavigateToURL(browser(), google_com_url()); - EXPECT_EQ(NAMESPACE_NOT_DEFINED, CanConnectAndSendMessages(extension->id())); - EXPECT_FALSE(AreAnyNonWebApisDefined()); + EXPECT_EQ(NAMESPACE_NOT_DEFINED, + CanConnectAndSendMessagesToMainFrame(extension->id())); + EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); ASSERT_TRUE(AppendIframe(chromium_org_url())); - const char* frame_xpath = "//iframe[1]"; - EXPECT_EQ(OK, CanConnectAndSendMessages(extension->id(), frame_xpath)); - EXPECT_FALSE(AreAnyNonWebApisDefined(frame_xpath)); + EXPECT_EQ(OK, CanConnectAndSendMessagesToIFrame(extension->id())); + EXPECT_FALSE(AreAnyNonWebApisDefinedForIFrame()); } // Tests connection from an iframe without permission within a tab that does. @@ -713,15 +724,14 @@ IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, const Extension* extension = LoadChromiumConnectableExtension(); ui_test_utils::NavigateToURL(browser(), chromium_org_url()); - EXPECT_EQ(OK, CanConnectAndSendMessages(extension->id())); - EXPECT_FALSE(AreAnyNonWebApisDefined()); + EXPECT_EQ(OK, CanConnectAndSendMessagesToMainFrame(extension->id())); + EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); ASSERT_TRUE(AppendIframe(google_com_url())); - const char* frame_xpath = "//iframe[1]"; EXPECT_EQ(NAMESPACE_NOT_DEFINED, - CanConnectAndSendMessages(extension->id(), frame_xpath)); - EXPECT_FALSE(AreAnyNonWebApisDefined(frame_xpath)); + CanConnectAndSendMessagesToIFrame(extension->id())); + EXPECT_FALSE(AreAnyNonWebApisDefinedForIFrame()); } // Tests externally_connectable between a web page and an extension with a @@ -930,13 +940,13 @@ IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, HostedAppOnWebsite) { // The presence of the hosted app shouldn't give the ability to send messages. ui_test_utils::NavigateToURL(browser(), chromium_org_url()); - EXPECT_EQ(NAMESPACE_NOT_DEFINED, CanConnectAndSendMessages("")); - EXPECT_FALSE(AreAnyNonWebApisDefined()); + EXPECT_EQ(NAMESPACE_NOT_DEFINED, CanConnectAndSendMessagesToMainFrame("")); + EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); // Once a connectable extension is installed, it should. const Extension* extension = LoadChromiumConnectableExtension(); - EXPECT_EQ(OK, CanConnectAndSendMessages(extension->id())); - EXPECT_FALSE(AreAnyNonWebApisDefined()); + EXPECT_EQ(OK, CanConnectAndSendMessagesToMainFrame(extension->id())); + EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); } // Tests that an invalid extension ID specified in a hosted app does not crash @@ -954,7 +964,7 @@ IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, ui_test_utils::NavigateToURL(browser(), chromium_org_url()); EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR , - CanConnectAndSendMessages("invalid")); + CanConnectAndSendMessagesToMainFrame("invalid")); } #endif // !defined(OS_WIN) - http://crbug.com/350517. diff --git a/chrome/browser/extensions/subscribe_page_action_browsertest.cc b/chrome/browser/extensions/subscribe_page_action_browsertest.cc index 37bd56b..f0a6515 100644 --- a/chrome/browser/extensions/subscribe_page_action_browsertest.cc +++ b/chrome/browser/extensions/subscribe_page_action_browsertest.cc @@ -76,15 +76,14 @@ GURL GetFeedUrl(net::SpawnedTestServer* server, const std::string& feed_page, } } -bool ValidatePageElement(WebContents* tab, - const std::string& frame_xpath, +bool ValidatePageElement(content::RenderFrameHost* frame, const std::string& javascript, const std::string& expected_value) { std::string returned_value; - if (!content::ExecuteScriptInFrameAndExtractString(tab, frame_xpath, - javascript, - &returned_value)) + if (!content::ExecuteScriptAndExtractString(frame, + javascript, + &returned_value)) return false; EXPECT_STREQ(expected_value.c_str(), returned_value.c_str()); @@ -113,20 +112,13 @@ void NavigateToFeedAndValidate(net::SpawnedTestServer* server, GetFeedUrl(server, url, true, extension_id)); WebContents* tab = browser->tab_strip_model()->GetActiveWebContents(); + content::RenderFrameHost* frame = content::FrameMatchingPredicate( + tab, base::Bind(&content::FrameIsChildOfMainFrame)); ASSERT_TRUE(ValidatePageElement( - tab, std::string(), kScriptFeedTitle, expected_feed_title)); - ASSERT_TRUE(ValidatePageElement(tab, - "//html/body/div/iframe[1]", - kScriptAnchor, - expected_item_title)); - ASSERT_TRUE(ValidatePageElement(tab, - "//html/body/div/iframe[1]", - kScriptDesc, - expected_item_desc)); - ASSERT_TRUE(ValidatePageElement(tab, - "//html/body/div/iframe[1]", - kScriptError, - expected_error)); + tab->GetMainFrame(), kScriptFeedTitle, expected_feed_title)); + ASSERT_TRUE(ValidatePageElement(frame, kScriptAnchor, expected_item_title)); + ASSERT_TRUE(ValidatePageElement(frame, kScriptDesc, expected_item_desc)); + ASSERT_TRUE(ValidatePageElement(frame, kScriptError, expected_error)); } } // namespace diff --git a/content/public/test/browser_test_utils.cc b/content/public/test/browser_test_utils.cc index 2fb55b2..29f2ac7 100644 --- a/content/public/test/browser_test_utils.cc +++ b/content/public/test/browser_test_utils.cc @@ -460,22 +460,6 @@ bool ExecuteScriptInFrame(const internal::ToRenderViewHost& adapter, adapter.render_view_host(), frame_xpath, script, NULL); } -bool ExecuteScriptInFrameAndExtractInt( - const internal::ToRenderViewHost& adapter, - const std::string& frame_xpath, - const std::string& script, - int* result) { - DCHECK(result); - scoped_ptr<base::Value> value; - if (!ExecuteScriptInFrameHelper(adapter.render_view_host(), - frame_xpath, script, &value) || - !value.get()) { - return false; - } - - return value->GetAsInteger(result); -} - bool ExecuteScriptInFrameAndExtractBool( const internal::ToRenderViewHost& adapter, const std::string& frame_xpath, diff --git a/content/public/test/browser_test_utils.h b/content/public/test/browser_test_utils.h index 424799c..c0e6ac0 100644 --- a/content/public/test/browser_test_utils.h +++ b/content/public/test/browser_test_utils.h @@ -164,11 +164,6 @@ bool ExecuteScriptInFrame(const internal::ToRenderViewHost& adapter, // evaluate to the expected type. // OBSOLETE; DO NOT USE! Use ExecuteScriptAndExtract[Int|Bool|String] and // specify a RenderFrameHost. -bool ExecuteScriptInFrameAndExtractInt( - const internal::ToRenderViewHost& adapter, - const std::string& frame_xpath, - const std::string& script, - int* result) WARN_UNUSED_RESULT; bool ExecuteScriptInFrameAndExtractBool( const internal::ToRenderViewHost& adapter, const std::string& frame_xpath, |