Chromium Code Reviews| Index: chrome/browser/extensions/chrome_app_api_browsertest.cc |
| diff --git a/chrome/browser/extensions/chrome_app_api_browsertest.cc b/chrome/browser/extensions/chrome_app_api_browsertest.cc |
| index 44e91cc21be815e601f4ef207e261ab3560b30d8..a0847a737afb93b9858e7e05e14d5a4565596af9 100644 |
| --- a/chrome/browser/extensions/chrome_app_api_browsertest.cc |
| +++ b/chrome/browser/extensions/chrome_app_api_browsertest.cc |
| @@ -10,6 +10,8 @@ |
| #include "base/string_number_conversions.h" |
| #include "base/values.h" |
| #include "chrome/browser/extensions/extension_browsertest.h" |
| +#include "chrome/browser/extensions/extension_service.h" |
| +#include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/common/extensions/extension.h" |
| @@ -21,14 +23,41 @@ |
| class ChromeAppAPITest : public ExtensionBrowserTest { |
| protected: |
| - bool IsAppInstalled() { |
| + bool IsAppInstalled() { return IsAppInstalled(L""); } |
| + bool IsAppInstalled(const std::wstring& frame_xpath) { |
| std::wstring get_app_is_installed = |
| L"window.domAutomationController.send(window.chrome.app.isInstalled);"; |
| bool result; |
| CHECK( |
| ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| browser()->GetSelectedWebContents()->GetRenderViewHost(), |
| - L"", get_app_is_installed, &result)); |
| + frame_xpath, get_app_is_installed, &result)); |
| + return result; |
| + } |
| + |
| + std::string InstallState() { return InstallState(L""); } |
| + std::string InstallState(const std::wstring& frame_xpath) { |
| + std::wstring get_app_install_state = |
| + L"window.chrome.app.installState(" |
| + L"function(s) { window.domAutomationController.send(s); });"; |
| + std::string result; |
| + CHECK( |
| + ui_test_utils::ExecuteJavaScriptAndExtractString( |
| + browser()->GetSelectedWebContents()->GetRenderViewHost(), |
| + frame_xpath, get_app_install_state, &result)); |
| + return result; |
| + } |
| + |
| + std::string RunningState() { return RunningState(L""); } |
| + std::string RunningState(const std::wstring& frame_xpath) { |
| + std::wstring get_app_install_state = |
| + L"window.domAutomationController.send(" |
| + L"window.chrome.app.runningState());"; |
| + std::string result; |
| + CHECK( |
| + ui_test_utils::ExecuteJavaScriptAndExtractString( |
| + browser()->GetSelectedWebContents()->GetRenderViewHost(), |
| + frame_xpath, get_app_install_state, &result)); |
| return result; |
| } |
| @@ -181,3 +210,84 @@ IN_PROC_BROWSER_TEST_F(ChromeAppAPITest, GetDetailsForFrame) { |
| EXPECT_TRUE(app_details.get()); |
| EXPECT_TRUE(app_details->Equals(extension->manifest()->value())); |
| } |
| + |
| + |
| +IN_PROC_BROWSER_TEST_F(ChromeAppAPITest, InstallAndRunningState) { |
| + std::string app_host("app.com"); |
| + std::string non_app_host("nonapp.com"); |
| + |
| + host_resolver()->AddRule(app_host, "127.0.0.1"); |
| + host_resolver()->AddRule(non_app_host, "127.0.0.1"); |
| + ASSERT_TRUE(test_server()->Start()); |
| + |
| + GURL test_file_url(test_server()->GetURL( |
| + "files/extensions/get_app_details_for_frame.html")); |
| + GURL::Replacements replace_host; |
| + |
| + replace_host.SetHostStr(app_host); |
| + GURL app_url(test_file_url.ReplaceComponents(replace_host)); |
| + |
| + replace_host.SetHostStr(non_app_host); |
| + GURL non_app_url(test_file_url.ReplaceComponents(replace_host)); |
| + |
| + // 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()); |
| + |
| + 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()); |
| + |
| + // Reloading the page should put the tab in an app process. |
| + CHECK(ui_test_utils::ExecuteJavaScript( |
| + browser()->GetSelectedWebContents()->GetRenderViewHost(), |
| + L"", L"window.location.reload();")); |
| + |
| + EXPECT_EQ("installed", InstallState()); |
| + EXPECT_EQ("running", RunningState()); |
| + EXPECT_TRUE(IsAppInstalled()); |
| + |
| + // Disable the extension and verify the state. |
| + browser()->profile()->GetExtensionService()->DisableExtension( |
| + extension->id(), Extension::DISABLE_PERMISSIONS_INCREASE); |
| + CHECK(ui_test_utils::ExecuteJavaScript( |
| + browser()->GetSelectedWebContents()->GetRenderViewHost(), |
| + L"", L"window.location.reload();")); |
| + |
| + EXPECT_EQ("disabled", InstallState()); |
| + EXPECT_EQ("cannot_run", RunningState()); |
| + EXPECT_FALSE(IsAppInstalled()); |
| + |
| + browser()->profile()->GetExtensionService()->EnableExtension(extension->id()); |
| + EXPECT_EQ("installed", InstallState()); |
| + EXPECT_EQ("ready_to_run", RunningState()); |
| + EXPECT_FALSE(IsAppInstalled()); |
| + |
| + // 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(L"//html/iframe[1]")); |
| + EXPECT_EQ("cannot_run", RunningState(L"//html/iframe[1]")); |
|
jstritar
2012/04/22 17:57:31
This part returns "running" .... what's supposed t
|
| + EXPECT_FALSE(IsAppInstalled(L"//html/iframe[1]")); |
| + |
| + // Swap the iframe and the parent frame. |
| + ui_test_utils::NavigateToURL(browser(), app_url); |
| + CHECK(ui_test_utils::ExecuteJavaScript( |
| + browser()->GetSelectedWebContents()->GetRenderViewHost(), |
| + L"", L"newFrame('nonapp.com');")); |
| + |
| + EXPECT_EQ("not_installed", InstallState(L"//html/iframe[1]")); |
| + EXPECT_EQ("cannot_run", RunningState(L"//html/iframe[1]")); |
| + EXPECT_FALSE(IsAppInstalled(L"//html/iframe[1]")); |
| +} |