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

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

Issue 10535077: TabContentsWrapper -> TabContents, part 12. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 6 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"
(...skipping 14 matching lines...) Expand all
25 25
26 class ChromeAppAPITest : public ExtensionBrowserTest { 26 class ChromeAppAPITest : public ExtensionBrowserTest {
27 protected: 27 protected:
28 bool IsAppInstalled() { return IsAppInstalled(L""); } 28 bool IsAppInstalled() { return IsAppInstalled(L""); }
29 bool IsAppInstalled(const std::wstring& frame_xpath) { 29 bool IsAppInstalled(const std::wstring& frame_xpath) {
30 std::wstring get_app_is_installed = 30 std::wstring get_app_is_installed =
31 L"window.domAutomationController.send(window.chrome.app.isInstalled);"; 31 L"window.domAutomationController.send(window.chrome.app.isInstalled);";
32 bool result; 32 bool result;
33 CHECK( 33 CHECK(
34 ui_test_utils::ExecuteJavaScriptAndExtractBool( 34 ui_test_utils::ExecuteJavaScriptAndExtractBool(
35 browser()->GetSelectedWebContents()->GetRenderViewHost(), 35 browser()->GetActiveWebContents()->GetRenderViewHost(),
36 frame_xpath, get_app_is_installed, &result)); 36 frame_xpath, get_app_is_installed, &result));
37 return result; 37 return result;
38 } 38 }
39 39
40 std::string InstallState() { return InstallState(L""); } 40 std::string InstallState() { return InstallState(L""); }
41 std::string InstallState(const std::wstring& frame_xpath) { 41 std::string InstallState(const std::wstring& frame_xpath) {
42 std::wstring get_app_install_state = 42 std::wstring get_app_install_state =
43 L"window.chrome.app.installState(" 43 L"window.chrome.app.installState("
44 L"function(s) { window.domAutomationController.send(s); });"; 44 L"function(s) { window.domAutomationController.send(s); });";
45 std::string result; 45 std::string result;
46 CHECK( 46 CHECK(
47 ui_test_utils::ExecuteJavaScriptAndExtractString( 47 ui_test_utils::ExecuteJavaScriptAndExtractString(
48 browser()->GetSelectedWebContents()->GetRenderViewHost(), 48 browser()->GetActiveWebContents()->GetRenderViewHost(),
49 frame_xpath, get_app_install_state, &result)); 49 frame_xpath, get_app_install_state, &result));
50 return result; 50 return result;
51 } 51 }
52 52
53 std::string RunningState() { return RunningState(L""); } 53 std::string RunningState() { return RunningState(L""); }
54 std::string RunningState(const std::wstring& frame_xpath) { 54 std::string RunningState(const std::wstring& frame_xpath) {
55 std::wstring get_app_install_state = 55 std::wstring get_app_install_state =
56 L"window.domAutomationController.send(" 56 L"window.domAutomationController.send("
57 L"window.chrome.app.runningState());"; 57 L"window.chrome.app.runningState());";
58 std::string result; 58 std::string result;
59 CHECK( 59 CHECK(
60 ui_test_utils::ExecuteJavaScriptAndExtractString( 60 ui_test_utils::ExecuteJavaScriptAndExtractString(
61 browser()->GetSelectedWebContents()->GetRenderViewHost(), 61 browser()->GetActiveWebContents()->GetRenderViewHost(),
62 frame_xpath, get_app_install_state, &result)); 62 frame_xpath, get_app_install_state, &result));
63 return result; 63 return result;
64 } 64 }
65 65
66 private: 66 private:
67 virtual void SetUpCommandLine(CommandLine* command_line) { 67 virtual void SetUpCommandLine(CommandLine* command_line) {
68 ExtensionBrowserTest::SetUpCommandLine(command_line); 68 ExtensionBrowserTest::SetUpCommandLine(command_line);
69 command_line->AppendSwitchASCII(switches::kAppsCheckoutURL, 69 command_line->AppendSwitchASCII(switches::kAppsCheckoutURL,
70 "http://checkout.com:"); 70 "http://checkout.com:");
71 } 71 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 ui_test_utils::NavigateToURL(browser(), non_app_url); 105 ui_test_utils::NavigateToURL(browser(), non_app_url);
106 EXPECT_FALSE(IsAppInstalled()); 106 EXPECT_FALSE(IsAppInstalled());
107 107
108 // Test that a non-app page returns null for chrome.app.getDetails(). 108 // Test that a non-app page returns null for chrome.app.getDetails().
109 std::wstring get_app_details = 109 std::wstring get_app_details =
110 L"window.domAutomationController.send(" 110 L"window.domAutomationController.send("
111 L" JSON.stringify(window.chrome.app.getDetails()));"; 111 L" JSON.stringify(window.chrome.app.getDetails()));";
112 std::string result; 112 std::string result;
113 ASSERT_TRUE( 113 ASSERT_TRUE(
114 ui_test_utils::ExecuteJavaScriptAndExtractString( 114 ui_test_utils::ExecuteJavaScriptAndExtractString(
115 browser()->GetSelectedWebContents()->GetRenderViewHost(), 115 browser()->GetActiveWebContents()->GetRenderViewHost(),
116 L"", get_app_details, &result)); 116 L"", get_app_details, &result));
117 EXPECT_EQ("null", result); 117 EXPECT_EQ("null", result);
118 118
119 // Check that an app page has chrome.app.isInstalled = true. 119 // Check that an app page has chrome.app.isInstalled = true.
120 ui_test_utils::NavigateToURL(browser(), app_url); 120 ui_test_utils::NavigateToURL(browser(), app_url);
121 EXPECT_TRUE(IsAppInstalled()); 121 EXPECT_TRUE(IsAppInstalled());
122 122
123 // Check that an app page returns the correct result for 123 // Check that an app page returns the correct result for
124 // chrome.app.getDetails(). 124 // chrome.app.getDetails().
125 ui_test_utils::NavigateToURL(browser(), app_url); 125 ui_test_utils::NavigateToURL(browser(), app_url);
126 ASSERT_TRUE( 126 ASSERT_TRUE(
127 ui_test_utils::ExecuteJavaScriptAndExtractString( 127 ui_test_utils::ExecuteJavaScriptAndExtractString(
128 browser()->GetSelectedWebContents()->GetRenderViewHost(), 128 browser()->GetActiveWebContents()->GetRenderViewHost(),
129 L"", get_app_details, &result)); 129 L"", get_app_details, &result));
130 scoped_ptr<DictionaryValue> app_details( 130 scoped_ptr<DictionaryValue> app_details(
131 static_cast<DictionaryValue*>(base::JSONReader::Read(result))); 131 static_cast<DictionaryValue*>(base::JSONReader::Read(result)));
132 // extension->manifest() does not contain the id. 132 // extension->manifest() does not contain the id.
133 app_details->Remove("id", NULL); 133 app_details->Remove("id", NULL);
134 EXPECT_TRUE(app_details.get()); 134 EXPECT_TRUE(app_details.get());
135 EXPECT_TRUE(app_details->Equals(extension->manifest()->value())); 135 EXPECT_TRUE(app_details->Equals(extension->manifest()->value()));
136 136
137 // Try to change app.isInstalled. Should silently fail, so 137 // Try to change app.isInstalled. Should silently fail, so
138 // that isInstalled should have the initial value. 138 // that isInstalled should have the initial value.
139 ASSERT_TRUE( 139 ASSERT_TRUE(
140 ui_test_utils::ExecuteJavaScriptAndExtractString( 140 ui_test_utils::ExecuteJavaScriptAndExtractString(
141 browser()->GetSelectedWebContents()->GetRenderViewHost(), 141 browser()->GetActiveWebContents()->GetRenderViewHost(),
142 L"", 142 L"",
143 L"window.domAutomationController.send(" 143 L"window.domAutomationController.send("
144 L" function() {" 144 L" function() {"
145 L" var value = window.chrome.app.isInstalled;" 145 L" var value = window.chrome.app.isInstalled;"
146 L" window.chrome.app.isInstalled = !value;" 146 L" window.chrome.app.isInstalled = !value;"
147 L" if (window.chrome.app.isInstalled == value) {" 147 L" if (window.chrome.app.isInstalled == value) {"
148 L" return 'true';" 148 L" return 'true';"
149 L" } else {" 149 L" } else {"
150 L" return 'false';" 150 L" return 'false';"
151 L" }" 151 L" }"
(...skipping 30 matching lines...) Expand all
182 test_data_dir_.AppendASCII("app_dot_com_app")); 182 test_data_dir_.AppendASCII("app_dot_com_app"));
183 ASSERT_TRUE(extension); 183 ASSERT_TRUE(extension);
184 184
185 // Test that normal pages (even apps) cannot use getDetailsForFrame(). 185 // Test that normal pages (even apps) cannot use getDetailsForFrame().
186 ui_test_utils::NavigateToURL(browser(), app_url); 186 ui_test_utils::NavigateToURL(browser(), app_url);
187 std::wstring test_unsuccessful_access = 187 std::wstring test_unsuccessful_access =
188 L"window.domAutomationController.send(window.testUnsuccessfulAccess())"; 188 L"window.domAutomationController.send(window.testUnsuccessfulAccess())";
189 bool result = false; 189 bool result = false;
190 ASSERT_TRUE( 190 ASSERT_TRUE(
191 ui_test_utils::ExecuteJavaScriptAndExtractBool( 191 ui_test_utils::ExecuteJavaScriptAndExtractBool(
192 browser()->GetSelectedWebContents()->GetRenderViewHost(), 192 browser()->GetActiveWebContents()->GetRenderViewHost(),
193 L"", test_unsuccessful_access, &result)); 193 L"", test_unsuccessful_access, &result));
194 EXPECT_TRUE(result); 194 EXPECT_TRUE(result);
195 195
196 // Test that checkout can use getDetailsForFrame() and that it works 196 // Test that checkout can use getDetailsForFrame() and that it works
197 // correctly. 197 // correctly.
198 ui_test_utils::NavigateToURL(browser(), checkout_url); 198 ui_test_utils::NavigateToURL(browser(), checkout_url);
199 std::wstring get_details_for_frame = 199 std::wstring get_details_for_frame =
200 L"window.domAutomationController.send(" 200 L"window.domAutomationController.send("
201 L" JSON.stringify(chrome.app.getDetailsForFrame(frames[0])))"; 201 L" JSON.stringify(chrome.app.getDetailsForFrame(frames[0])))";
202 std::string json; 202 std::string json;
203 ASSERT_TRUE( 203 ASSERT_TRUE(
204 ui_test_utils::ExecuteJavaScriptAndExtractString( 204 ui_test_utils::ExecuteJavaScriptAndExtractString(
205 browser()->GetSelectedWebContents()->GetRenderViewHost(), 205 browser()->GetActiveWebContents()->GetRenderViewHost(),
206 L"", get_details_for_frame, &json)); 206 L"", get_details_for_frame, &json));
207 207
208 scoped_ptr<DictionaryValue> app_details( 208 scoped_ptr<DictionaryValue> app_details(
209 static_cast<DictionaryValue*>(base::JSONReader::Read(json))); 209 static_cast<DictionaryValue*>(base::JSONReader::Read(json)));
210 // extension->manifest() does not contain the id. 210 // extension->manifest() does not contain the id.
211 app_details->Remove("id", NULL); 211 app_details->Remove("id", NULL);
212 EXPECT_TRUE(app_details.get()); 212 EXPECT_TRUE(app_details.get());
213 EXPECT_TRUE(app_details->Equals(extension->manifest()->value())); 213 EXPECT_TRUE(app_details->Equals(extension->manifest()->value()));
214 } 214 }
215 215
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 GURL non_app_url(test_file_url.ReplaceComponents(replace_host)); 299 GURL non_app_url(test_file_url.ReplaceComponents(replace_host));
300 300
301 // Check the install and running state of a non-app iframe running 301 // Check the install and running state of a non-app iframe running
302 // within an app. 302 // within an app.
303 ui_test_utils::NavigateToURL(browser(), app_url); 303 ui_test_utils::NavigateToURL(browser(), app_url);
304 304
305 EXPECT_EQ("not_installed", InstallState(L"//html/iframe[1]")); 305 EXPECT_EQ("not_installed", InstallState(L"//html/iframe[1]"));
306 EXPECT_EQ("cannot_run", RunningState(L"//html/iframe[1]")); 306 EXPECT_EQ("cannot_run", RunningState(L"//html/iframe[1]"));
307 EXPECT_FALSE(IsAppInstalled(L"//html/iframe[1]")); 307 EXPECT_FALSE(IsAppInstalled(L"//html/iframe[1]"));
308 } 308 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/app_process_apitest.cc ('k') | chrome/browser/extensions/content_script_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698