OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/extensions/extension_browsertest.h" | 12 #include "chrome/browser/extensions/extension_browsertest.h" |
13 #include "chrome/browser/extensions/extension_service.h" | |
14 #include "chrome/browser/profiles/profile.h" | |
13 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
15 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
16 #include "chrome/common/extensions/manifest.h" | 18 #include "chrome/common/extensions/manifest.h" |
17 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
18 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
19 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
20 #include "net/base/mock_host_resolver.h" | 22 #include "net/base/mock_host_resolver.h" |
21 | 23 |
22 class ChromeAppAPITest : public ExtensionBrowserTest { | 24 class ChromeAppAPITest : public ExtensionBrowserTest { |
23 protected: | 25 protected: |
24 bool IsAppInstalled() { | 26 bool IsAppInstalled() { return IsAppInstalled(L""); } |
27 bool IsAppInstalled(const std::wstring& frame_xpath) { | |
25 std::wstring get_app_is_installed = | 28 std::wstring get_app_is_installed = |
26 L"window.domAutomationController.send(window.chrome.app.isInstalled);"; | 29 L"window.domAutomationController.send(window.chrome.app.isInstalled);"; |
27 bool result; | 30 bool result; |
28 CHECK( | 31 CHECK( |
29 ui_test_utils::ExecuteJavaScriptAndExtractBool( | 32 ui_test_utils::ExecuteJavaScriptAndExtractBool( |
30 browser()->GetSelectedWebContents()->GetRenderViewHost(), | 33 browser()->GetSelectedWebContents()->GetRenderViewHost(), |
31 L"", get_app_is_installed, &result)); | 34 frame_xpath, get_app_is_installed, &result)); |
32 return result; | 35 return result; |
33 } | 36 } |
34 | 37 |
38 std::string InstallState() { return InstallState(L""); } | |
39 std::string InstallState(const std::wstring& frame_xpath) { | |
40 std::wstring get_app_install_state = | |
41 L"window.chrome.app.installState(" | |
42 L"function(s) { window.domAutomationController.send(s); });"; | |
43 std::string result; | |
44 CHECK( | |
45 ui_test_utils::ExecuteJavaScriptAndExtractString( | |
46 browser()->GetSelectedWebContents()->GetRenderViewHost(), | |
47 frame_xpath, get_app_install_state, &result)); | |
48 return result; | |
49 } | |
50 | |
51 std::string RunningState() { return RunningState(L""); } | |
52 std::string RunningState(const std::wstring& frame_xpath) { | |
53 std::wstring get_app_install_state = | |
54 L"window.domAutomationController.send(" | |
55 L"window.chrome.app.runningState());"; | |
56 std::string result; | |
57 CHECK( | |
58 ui_test_utils::ExecuteJavaScriptAndExtractString( | |
59 browser()->GetSelectedWebContents()->GetRenderViewHost(), | |
60 frame_xpath, get_app_install_state, &result)); | |
61 return result; | |
62 } | |
63 | |
35 private: | 64 private: |
36 virtual void SetUpCommandLine(CommandLine* command_line) { | 65 virtual void SetUpCommandLine(CommandLine* command_line) { |
37 ExtensionBrowserTest::SetUpCommandLine(command_line); | 66 ExtensionBrowserTest::SetUpCommandLine(command_line); |
38 command_line->AppendSwitchASCII(switches::kAppsCheckoutURL, | 67 command_line->AppendSwitchASCII(switches::kAppsCheckoutURL, |
39 "http://checkout.com:"); | 68 "http://checkout.com:"); |
40 } | 69 } |
41 }; | 70 }; |
42 | 71 |
43 IN_PROC_BROWSER_TEST_F(ChromeAppAPITest, IsInstalled) { | 72 IN_PROC_BROWSER_TEST_F(ChromeAppAPITest, IsInstalled) { |
44 std::string app_host("app.com"); | 73 std::string app_host("app.com"); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 browser()->GetSelectedWebContents()->GetRenderViewHost(), | 203 browser()->GetSelectedWebContents()->GetRenderViewHost(), |
175 L"", get_details_for_frame, &json)); | 204 L"", get_details_for_frame, &json)); |
176 | 205 |
177 scoped_ptr<DictionaryValue> app_details( | 206 scoped_ptr<DictionaryValue> app_details( |
178 static_cast<DictionaryValue*>(base::JSONReader::Read(json))); | 207 static_cast<DictionaryValue*>(base::JSONReader::Read(json))); |
179 // extension->manifest() does not contain the id. | 208 // extension->manifest() does not contain the id. |
180 app_details->Remove("id", NULL); | 209 app_details->Remove("id", NULL); |
181 EXPECT_TRUE(app_details.get()); | 210 EXPECT_TRUE(app_details.get()); |
182 EXPECT_TRUE(app_details->Equals(extension->manifest()->value())); | 211 EXPECT_TRUE(app_details->Equals(extension->manifest()->value())); |
183 } | 212 } |
213 | |
214 | |
215 IN_PROC_BROWSER_TEST_F(ChromeAppAPITest, InstallAndRunningState) { | |
216 std::string app_host("app.com"); | |
217 std::string non_app_host("nonapp.com"); | |
218 | |
219 host_resolver()->AddRule(app_host, "127.0.0.1"); | |
220 host_resolver()->AddRule(non_app_host, "127.0.0.1"); | |
221 ASSERT_TRUE(test_server()->Start()); | |
222 | |
223 GURL test_file_url(test_server()->GetURL( | |
224 "files/extensions/get_app_details_for_frame.html")); | |
225 GURL::Replacements replace_host; | |
226 | |
227 replace_host.SetHostStr(app_host); | |
228 GURL app_url(test_file_url.ReplaceComponents(replace_host)); | |
229 | |
230 replace_host.SetHostStr(non_app_host); | |
231 GURL non_app_url(test_file_url.ReplaceComponents(replace_host)); | |
232 | |
233 // Before the app is installed, app.com does not think that it is installed | |
234 ui_test_utils::NavigateToURL(browser(), app_url); | |
235 | |
236 EXPECT_EQ("not_installed", InstallState()); | |
237 EXPECT_EQ("cannot_run", RunningState()); | |
238 EXPECT_FALSE(IsAppInstalled()); | |
239 | |
240 const Extension* extension = LoadExtension( | |
241 test_data_dir_.AppendASCII("app_dot_com_app")); | |
242 ASSERT_TRUE(extension); | |
243 | |
244 EXPECT_EQ("installed", InstallState()); | |
245 EXPECT_EQ("ready_to_run", RunningState()); | |
246 EXPECT_FALSE(IsAppInstalled()); | |
247 | |
248 // Reloading the page should put the tab in an app process. | |
249 CHECK(ui_test_utils::ExecuteJavaScript( | |
250 browser()->GetSelectedWebContents()->GetRenderViewHost(), | |
251 L"", L"window.location.reload();")); | |
252 | |
253 EXPECT_EQ("installed", InstallState()); | |
254 EXPECT_EQ("running", RunningState()); | |
255 EXPECT_TRUE(IsAppInstalled()); | |
256 | |
257 // Disable the extension and verify the state. | |
258 browser()->profile()->GetExtensionService()->DisableExtension( | |
259 extension->id(), Extension::DISABLE_PERMISSIONS_INCREASE); | |
260 CHECK(ui_test_utils::ExecuteJavaScript( | |
261 browser()->GetSelectedWebContents()->GetRenderViewHost(), | |
262 L"", L"window.location.reload();")); | |
263 | |
264 EXPECT_EQ("disabled", InstallState()); | |
265 EXPECT_EQ("cannot_run", RunningState()); | |
266 EXPECT_FALSE(IsAppInstalled()); | |
267 | |
268 browser()->profile()->GetExtensionService()->EnableExtension(extension->id()); | |
269 EXPECT_EQ("installed", InstallState()); | |
270 EXPECT_EQ("ready_to_run", RunningState()); | |
271 EXPECT_FALSE(IsAppInstalled()); | |
272 | |
273 // The non-app URL should still not be installed or running. | |
274 ui_test_utils::NavigateToURL(browser(), non_app_url); | |
275 | |
276 EXPECT_EQ("not_installed", InstallState()); | |
277 EXPECT_EQ("cannot_run", RunningState()); | |
278 EXPECT_FALSE(IsAppInstalled()); | |
279 | |
280 EXPECT_EQ("installed", InstallState(L"//html/iframe[1]")); | |
281 EXPECT_EQ("cannot_run", RunningState(L"//html/iframe[1]")); | |
jstritar
2012/04/22 17:57:31
This part returns "running" .... what's supposed t
| |
282 EXPECT_FALSE(IsAppInstalled(L"//html/iframe[1]")); | |
283 | |
284 // Swap the iframe and the parent frame. | |
285 ui_test_utils::NavigateToURL(browser(), app_url); | |
286 CHECK(ui_test_utils::ExecuteJavaScript( | |
287 browser()->GetSelectedWebContents()->GetRenderViewHost(), | |
288 L"", L"newFrame('nonapp.com');")); | |
289 | |
290 EXPECT_EQ("not_installed", InstallState(L"//html/iframe[1]")); | |
291 EXPECT_EQ("cannot_run", RunningState(L"//html/iframe[1]")); | |
292 EXPECT_FALSE(IsAppInstalled(L"//html/iframe[1]")); | |
293 } | |
OLD | NEW |