#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_switches.h"
-#include "chrome/common/extensions/extension.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
+#include "extensions/common/extension.h"
#include "extensions/common/manifest.h"
#include "net/dns/mock_host_resolver.h"
#include "url/gurl.h"
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:
- virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
+ content::RenderFrameHost* GetIFrame() {
+ return content::FrameMatchingPredicate(
+ browser()->tab_strip_model()->GetActiveWebContents(),
+ base::Bind(&content::FrameIsChildOfMainFrame));
+ }
+
+ void SetUpCommandLine(CommandLine* command_line) override {
ExtensionBrowserTest::SetUpCommandLine(command_line);
command_line->AppendSwitchASCII(switches::kAppsCheckoutURL,
"http://checkout.com:");
// 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(
// 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[] =
// 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().
browser()->tab_strip_model()->GetActiveWebContents(),
kGetAppDetails,
&result));
- scoped_ptr<DictionaryValue> app_details(
- static_cast<DictionaryValue*>(base::JSONReader::Read(result)));
+ scoped_ptr<base::DictionaryValue> app_details(
+ static_cast<base::DictionaryValue*>(base::JSONReader::Read(result)));
// extension->manifest() does not contain the id.
app_details->Remove("id", NULL);
EXPECT_TRUE(app_details.get());
kGetDetailsForFrame,
&json));
- scoped_ptr<DictionaryValue> app_details(
- static_cast<DictionaryValue*>(base::JSONReader::Read(json)));
+ scoped_ptr<base::DictionaryValue> app_details(
+ static_cast<base::DictionaryValue*>(base::JSONReader::Read(json)));
// extension->manifest() does not contain the id.
app_details->Remove("id", NULL);
EXPECT_TRUE(app_details.get());
// 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);
+ ExtensionService* service = extensions::ExtensionSystem::Get(
+ browser()->profile())->extension_service();
+ service->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());
+ service->EnableExtension(extension->id());
+ 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("installed", InstallState("//html/iframe[1]"));
- EXPECT_EQ("cannot_run", RunningState("//html/iframe[1]"));
- EXPECT_FALSE(IsAppInstalled("//html/iframe[1]"));
+ EXPECT_EQ("not_installed", InstallStateInMainFrame());
+ EXPECT_EQ("cannot_run", RunningStateInMainFrame());
+ EXPECT_FALSE(IsAppInstalledInMainFrame());
+ EXPECT_EQ("installed", InstallStateInIFrame());
+ EXPECT_EQ("cannot_run", RunningStateInIFrame());
+ EXPECT_FALSE(IsAppInstalledInIFrame());
}
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());
}