Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(403)

Side by Side Diff: chrome/browser/extensions/chrome_app_api_browsertest.cc

Issue 10174001: Add an API for hosted apps to check their install and running states. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 ui_test_utils::NavigateToURL(browser(), app_url);
250 EXPECT_EQ("installed", InstallState());
251 EXPECT_EQ("running", RunningState());
252 EXPECT_TRUE(IsAppInstalled());
253
254 // Disable the extension and verify the state.
255 browser()->profile()->GetExtensionService()->DisableExtension(
256 extension->id(), Extension::DISABLE_PERMISSIONS_INCREASE);
257 ui_test_utils::NavigateToURL(browser(), app_url);
258
259 EXPECT_EQ("disabled", InstallState());
260 EXPECT_EQ("cannot_run", RunningState());
261 EXPECT_FALSE(IsAppInstalled());
262
263 browser()->profile()->GetExtensionService()->EnableExtension(extension->id());
264 EXPECT_EQ("installed", InstallState());
265 EXPECT_EQ("ready_to_run", RunningState());
266 EXPECT_FALSE(IsAppInstalled());
267
268 // The non-app URL should still not be installed or running.
269 ui_test_utils::NavigateToURL(browser(), non_app_url);
270
271 EXPECT_EQ("not_installed", InstallState());
272 EXPECT_EQ("cannot_run", RunningState());
273 EXPECT_FALSE(IsAppInstalled());
274
275 EXPECT_EQ("installed", InstallState(L"//html/iframe[1]"));
276 EXPECT_EQ("cannot_run", RunningState(L"//html/iframe[1]"));
277 EXPECT_FALSE(IsAppInstalled(L"//html/iframe[1]"));
278
279 }
280
281 IN_PROC_BROWSER_TEST_F(ChromeAppAPITest, InstallAndRunningStateFrame) {
282 std::string app_host("app.com");
283 std::string non_app_host("nonapp.com");
284
285 host_resolver()->AddRule(app_host, "127.0.0.1");
286 host_resolver()->AddRule(non_app_host, "127.0.0.1");
287 ASSERT_TRUE(test_server()->Start());
288
289 GURL test_file_url(test_server()->GetURL(
290 "files/extensions/get_app_details_for_frame_reversed.html"));
291 GURL::Replacements replace_host;
292
293 replace_host.SetHostStr(app_host);
294 GURL app_url(test_file_url.ReplaceComponents(replace_host));
295
296 replace_host.SetHostStr(non_app_host);
297 GURL non_app_url(test_file_url.ReplaceComponents(replace_host));
298
299 // Check the install and running state of a non-app iframe running
300 // within an app.
301 ui_test_utils::NavigateToURL(browser(), app_url);
302
303 EXPECT_EQ("not_installed", InstallState(L"//html/iframe[1]"));
304 EXPECT_EQ("cannot_run", RunningState(L"//html/iframe[1]"));
305 EXPECT_FALSE(IsAppInstalled(L"//html/iframe[1]"));
306 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698