Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / chrome_app_api_browsertest.cc
index b0ace91..13e37c6 100644 (file)
@@ -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,49 +267,50 @@ 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);
+  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) {
@@ -319,7 +335,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());
 }