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

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

Issue 12066003: Remove TabStripModel wrapper use. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: gtk Created 7 years, 10 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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" 13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_tabstrip.h" 16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/extensions/extension.h" 18 #include "chrome/common/extensions/extension.h"
19 #include "chrome/common/extensions/manifest.h" 19 #include "chrome/common/extensions/manifest.h"
20 #include "chrome/test/base/ui_test_utils.h" 20 #include "chrome/test/base/ui_test_utils.h"
21 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
22 #include "content/public/test/browser_test_utils.h" 22 #include "content/public/test/browser_test_utils.h"
23 #include "googleurl/src/gurl.h" 23 #include "googleurl/src/gurl.h"
24 #include "net/base/mock_host_resolver.h" 24 #include "net/base/mock_host_resolver.h"
25 25
26 using extensions::Extension; 26 using extensions::Extension;
27 27
28 class ChromeAppAPITest : public ExtensionBrowserTest { 28 class ChromeAppAPITest : public ExtensionBrowserTest {
29 protected: 29 protected:
30 bool IsAppInstalled() { return IsAppInstalled(""); } 30 bool IsAppInstalled() { return IsAppInstalled(""); }
31 bool IsAppInstalled(const char* frame_xpath) { 31 bool IsAppInstalled(const char* frame_xpath) {
32 const char kGetAppIsInstalled[] = 32 const char kGetAppIsInstalled[] =
33 "window.domAutomationController.send(window.chrome.app.isInstalled);"; 33 "window.domAutomationController.send(window.chrome.app.isInstalled);";
34 bool result; 34 bool result;
35 CHECK( 35 CHECK(
36 content::ExecuteScriptInFrameAndExtractBool( 36 content::ExecuteScriptInFrameAndExtractBool(
37 chrome::GetActiveWebContents(browser()), 37 browser()->tab_strip_model()->GetActiveWebContents(),
38 frame_xpath, 38 frame_xpath,
39 kGetAppIsInstalled, 39 kGetAppIsInstalled,
40 &result)); 40 &result));
41 return result; 41 return result;
42 } 42 }
43 43
44 std::string InstallState() { return InstallState(""); } 44 std::string InstallState() { return InstallState(""); }
45 std::string InstallState(const char* frame_xpath) { 45 std::string InstallState(const char* frame_xpath) {
46 const char kGetAppInstallState[] = 46 const char kGetAppInstallState[] =
47 "window.chrome.app.installState(" 47 "window.chrome.app.installState("
48 " function(s) { window.domAutomationController.send(s); });"; 48 " function(s) { window.domAutomationController.send(s); });";
49 std::string result; 49 std::string result;
50 CHECK( 50 CHECK(
51 content::ExecuteScriptInFrameAndExtractString( 51 content::ExecuteScriptInFrameAndExtractString(
52 chrome::GetActiveWebContents(browser()), 52 browser()->tab_strip_model()->GetActiveWebContents(),
53 frame_xpath, 53 frame_xpath,
54 kGetAppInstallState, 54 kGetAppInstallState,
55 &result)); 55 &result));
56 return result; 56 return result;
57 } 57 }
58 58
59 std::string RunningState() { return RunningState(""); } 59 std::string RunningState() { return RunningState(""); }
60 std::string RunningState(const char* frame_xpath) { 60 std::string RunningState(const char* frame_xpath) {
61 const char kGetAppRunningState[] = 61 const char kGetAppRunningState[] =
62 "window.domAutomationController.send(" 62 "window.domAutomationController.send("
63 " window.chrome.app.runningState());"; 63 " window.chrome.app.runningState());";
64 std::string result; 64 std::string result;
65 CHECK( 65 CHECK(
66 content::ExecuteScriptInFrameAndExtractString( 66 content::ExecuteScriptInFrameAndExtractString(
67 chrome::GetActiveWebContents(browser()), 67 browser()->tab_strip_model()->GetActiveWebContents(),
68 frame_xpath, 68 frame_xpath,
69 kGetAppRunningState, 69 kGetAppRunningState,
70 &result)); 70 &result));
71 return result; 71 return result;
72 } 72 }
73 73
74 private: 74 private:
75 virtual void SetUpCommandLine(CommandLine* command_line) { 75 virtual void SetUpCommandLine(CommandLine* command_line) {
76 ExtensionBrowserTest::SetUpCommandLine(command_line); 76 ExtensionBrowserTest::SetUpCommandLine(command_line);
77 command_line->AppendSwitchASCII(switches::kAppsCheckoutURL, 77 command_line->AppendSwitchASCII(switches::kAppsCheckoutURL,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 ui_test_utils::NavigateToURL(browser(), non_app_url); 113 ui_test_utils::NavigateToURL(browser(), non_app_url);
114 EXPECT_FALSE(IsAppInstalled()); 114 EXPECT_FALSE(IsAppInstalled());
115 115
116 // Test that a non-app page returns null for chrome.app.getDetails(). 116 // Test that a non-app page returns null for chrome.app.getDetails().
117 const char kGetAppDetails[] = 117 const char kGetAppDetails[] =
118 "window.domAutomationController.send(" 118 "window.domAutomationController.send("
119 " JSON.stringify(window.chrome.app.getDetails()));"; 119 " JSON.stringify(window.chrome.app.getDetails()));";
120 std::string result; 120 std::string result;
121 ASSERT_TRUE( 121 ASSERT_TRUE(
122 content::ExecuteScriptAndExtractString( 122 content::ExecuteScriptAndExtractString(
123 chrome::GetActiveWebContents(browser()), 123 browser()->tab_strip_model()->GetActiveWebContents(),
124 kGetAppDetails, 124 kGetAppDetails,
125 &result)); 125 &result));
126 EXPECT_EQ("null", result); 126 EXPECT_EQ("null", result);
127 127
128 // Check that an app page has chrome.app.isInstalled = true. 128 // Check that an app page has chrome.app.isInstalled = true.
129 ui_test_utils::NavigateToURL(browser(), app_url); 129 ui_test_utils::NavigateToURL(browser(), app_url);
130 EXPECT_TRUE(IsAppInstalled()); 130 EXPECT_TRUE(IsAppInstalled());
131 131
132 // Check that an app page returns the correct result for 132 // Check that an app page returns the correct result for
133 // chrome.app.getDetails(). 133 // chrome.app.getDetails().
134 ui_test_utils::NavigateToURL(browser(), app_url); 134 ui_test_utils::NavigateToURL(browser(), app_url);
135 ASSERT_TRUE( 135 ASSERT_TRUE(
136 content::ExecuteScriptAndExtractString( 136 content::ExecuteScriptAndExtractString(
137 chrome::GetActiveWebContents(browser()), 137 browser()->tab_strip_model()->GetActiveWebContents(),
138 kGetAppDetails, 138 kGetAppDetails,
139 &result)); 139 &result));
140 scoped_ptr<DictionaryValue> app_details( 140 scoped_ptr<DictionaryValue> app_details(
141 static_cast<DictionaryValue*>(base::JSONReader::Read(result))); 141 static_cast<DictionaryValue*>(base::JSONReader::Read(result)));
142 // extension->manifest() does not contain the id. 142 // extension->manifest() does not contain the id.
143 app_details->Remove("id", NULL); 143 app_details->Remove("id", NULL);
144 EXPECT_TRUE(app_details.get()); 144 EXPECT_TRUE(app_details.get());
145 EXPECT_TRUE(app_details->Equals(extension->manifest()->value())); 145 EXPECT_TRUE(app_details->Equals(extension->manifest()->value()));
146 146
147 // Try to change app.isInstalled. Should silently fail, so 147 // Try to change app.isInstalled. Should silently fail, so
148 // that isInstalled should have the initial value. 148 // that isInstalled should have the initial value.
149 ASSERT_TRUE( 149 ASSERT_TRUE(
150 content::ExecuteScriptAndExtractString( 150 content::ExecuteScriptAndExtractString(
151 chrome::GetActiveWebContents(browser()), 151 browser()->tab_strip_model()->GetActiveWebContents(),
152 "window.domAutomationController.send(" 152 "window.domAutomationController.send("
153 " function() {" 153 " function() {"
154 " var value = window.chrome.app.isInstalled;" 154 " var value = window.chrome.app.isInstalled;"
155 " window.chrome.app.isInstalled = !value;" 155 " window.chrome.app.isInstalled = !value;"
156 " if (window.chrome.app.isInstalled == value) {" 156 " if (window.chrome.app.isInstalled == value) {"
157 " return 'true';" 157 " return 'true';"
158 " } else {" 158 " } else {"
159 " return 'false';" 159 " return 'false';"
160 " }" 160 " }"
161 " }()" 161 " }()"
(...skipping 29 matching lines...) Expand all
191 test_data_dir_.AppendASCII("app_dot_com_app")); 191 test_data_dir_.AppendASCII("app_dot_com_app"));
192 ASSERT_TRUE(extension); 192 ASSERT_TRUE(extension);
193 193
194 // Test that normal pages (even apps) cannot use getDetailsForFrame(). 194 // Test that normal pages (even apps) cannot use getDetailsForFrame().
195 ui_test_utils::NavigateToURL(browser(), app_url); 195 ui_test_utils::NavigateToURL(browser(), app_url);
196 const char kTestUnsuccessfulAccess[] = 196 const char kTestUnsuccessfulAccess[] =
197 "window.domAutomationController.send(window.testUnsuccessfulAccess())"; 197 "window.domAutomationController.send(window.testUnsuccessfulAccess())";
198 bool result = false; 198 bool result = false;
199 ASSERT_TRUE( 199 ASSERT_TRUE(
200 content::ExecuteScriptAndExtractBool( 200 content::ExecuteScriptAndExtractBool(
201 chrome::GetActiveWebContents(browser()), 201 browser()->tab_strip_model()->GetActiveWebContents(),
202 kTestUnsuccessfulAccess, 202 kTestUnsuccessfulAccess,
203 &result)); 203 &result));
204 EXPECT_TRUE(result); 204 EXPECT_TRUE(result);
205 205
206 // Test that checkout can use getDetailsForFrame() and that it works 206 // Test that checkout can use getDetailsForFrame() and that it works
207 // correctly. 207 // correctly.
208 ui_test_utils::NavigateToURL(browser(), checkout_url); 208 ui_test_utils::NavigateToURL(browser(), checkout_url);
209 const char kGetDetailsForFrame[] = 209 const char kGetDetailsForFrame[] =
210 "window.domAutomationController.send(" 210 "window.domAutomationController.send("
211 " JSON.stringify(chrome.app.getDetailsForFrame(frames[0])))"; 211 " JSON.stringify(chrome.app.getDetailsForFrame(frames[0])))";
212 std::string json; 212 std::string json;
213 ASSERT_TRUE( 213 ASSERT_TRUE(
214 content::ExecuteScriptAndExtractString( 214 content::ExecuteScriptAndExtractString(
215 chrome::GetActiveWebContents(browser()), 215 browser()->tab_strip_model()->GetActiveWebContents(),
216 kGetDetailsForFrame, 216 kGetDetailsForFrame,
217 &json)); 217 &json));
218 218
219 scoped_ptr<DictionaryValue> app_details( 219 scoped_ptr<DictionaryValue> app_details(
220 static_cast<DictionaryValue*>(base::JSONReader::Read(json))); 220 static_cast<DictionaryValue*>(base::JSONReader::Read(json)));
221 // extension->manifest() does not contain the id. 221 // extension->manifest() does not contain the id.
222 app_details->Remove("id", NULL); 222 app_details->Remove("id", NULL);
223 EXPECT_TRUE(app_details.get()); 223 EXPECT_TRUE(app_details.get());
224 EXPECT_TRUE(app_details->Equals(extension->manifest()->value())); 224 EXPECT_TRUE(app_details->Equals(extension->manifest()->value()));
225 } 225 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 GURL non_app_url(test_file_url.ReplaceComponents(replace_host)); 310 GURL non_app_url(test_file_url.ReplaceComponents(replace_host));
311 311
312 // Check the install and running state of a non-app iframe running 312 // Check the install and running state of a non-app iframe running
313 // within an app. 313 // within an app.
314 ui_test_utils::NavigateToURL(browser(), app_url); 314 ui_test_utils::NavigateToURL(browser(), app_url);
315 315
316 EXPECT_EQ("not_installed", InstallState("//html/iframe[1]")); 316 EXPECT_EQ("not_installed", InstallState("//html/iframe[1]"));
317 EXPECT_EQ("cannot_run", RunningState("//html/iframe[1]")); 317 EXPECT_EQ("cannot_run", RunningState("//html/iframe[1]"));
318 EXPECT_FALSE(IsAppInstalled("//html/iframe[1]")); 318 EXPECT_FALSE(IsAppInstalled("//html/iframe[1]"));
319 } 319 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698