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

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

Issue 9195018: Disable modal JavaScript dialogs for platform apps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit Created 8 years, 11 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 "chrome/browser/extensions/extension_apitest.h" 5 #include "chrome/browser/extensions/extension_apitest.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "chrome/browser/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/extension_test_api.h" 10 #include "chrome/browser/extensions/extension_test_api.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 net::FilePathToFileURL(test_data_dir_).spec()); 98 net::FilePathToFileURL(test_data_dir_).spec());
99 ExtensionTestGetConfigFunction::set_test_config_state(test_config_.get()); 99 ExtensionTestGetConfigFunction::set_test_config_state(test_config_.get());
100 } 100 }
101 101
102 void ExtensionApiTest::TearDownInProcessBrowserTestFixture() { 102 void ExtensionApiTest::TearDownInProcessBrowserTestFixture() {
103 ExtensionTestGetConfigFunction::set_test_config_state(NULL); 103 ExtensionTestGetConfigFunction::set_test_config_state(NULL);
104 test_config_.reset(NULL); 104 test_config_.reset(NULL);
105 } 105 }
106 106
107 bool ExtensionApiTest::RunExtensionTest(const char* extension_name) { 107 bool ExtensionApiTest::RunExtensionTest(const char* extension_name) {
108 return RunExtensionTestImpl(extension_name, "", false, true, false); 108 return RunExtensionTestImpl(extension_name, "", kFlagEnableFileaccess);
109 } 109 }
110 110
111 bool ExtensionApiTest::RunExtensionTestIncognito(const char* extension_name) { 111 bool ExtensionApiTest::RunExtensionTestIncognito(const char* extension_name) {
112 return RunExtensionTestImpl(extension_name, "", true, true, false); 112 return RunExtensionTestImpl(
113 extension_name, "", kFlagEnableIncognito | kFlagEnableFileaccess);
113 } 114 }
114 115
115 bool ExtensionApiTest::RunComponentExtensionTest(const char* extension_name) { 116 bool ExtensionApiTest::RunComponentExtensionTest(const char* extension_name) {
116 return RunExtensionTestImpl(extension_name, "", false, true, true); 117 return RunExtensionTestImpl(
118 extension_name, "", kFlagEnableIncognito | kFlagLoadAsComponent);
117 } 119 }
118 120
119 bool ExtensionApiTest::RunExtensionTestNoFileAccess( 121 bool ExtensionApiTest::RunExtensionTestNoFileAccess(
120 const char* extension_name) { 122 const char* extension_name) {
121 return RunExtensionTestImpl(extension_name, "", false, false, false); 123 return RunExtensionTestImpl(extension_name, "", kFlagNone);
122 } 124 }
123 125
124 bool ExtensionApiTest::RunExtensionTestIncognitoNoFileAccess( 126 bool ExtensionApiTest::RunExtensionTestIncognitoNoFileAccess(
125 const char* extension_name) { 127 const char* extension_name) {
126 return RunExtensionTestImpl(extension_name, "", true, false, false); 128 return RunExtensionTestImpl(extension_name, "", kFlagEnableIncognito);
127 } 129 }
128 130
129 bool ExtensionApiTest::RunExtensionSubtest(const char* extension_name, 131 bool ExtensionApiTest::RunExtensionSubtest(const char* extension_name,
130 const std::string& page_url) { 132 const std::string& page_url) {
131 DCHECK(!page_url.empty()) << "Argument page_url is required."; 133 DCHECK(!page_url.empty()) << "Argument page_url is required.";
132 return RunExtensionTestImpl(extension_name, page_url, false, true, false); 134 return RunExtensionTestImpl(extension_name, page_url, kFlagEnableFileaccess);
133 } 135 }
134 136
135 bool ExtensionApiTest::RunExtensionSubtestNoFileAccess( 137 bool ExtensionApiTest::RunExtensionSubtestNoFileAccess(
136 const char* extension_name, 138 const char* extension_name,
137 const std::string& page_url) { 139 const std::string& page_url) {
138 DCHECK(!page_url.empty()) << "Argument page_url is required."; 140 DCHECK(!page_url.empty()) << "Argument page_url is required.";
139 return RunExtensionTestImpl(extension_name, page_url, false, false, false); 141 return RunExtensionTestImpl(extension_name, page_url, kFlagNone);
140 } 142 }
141 143
142 bool ExtensionApiTest::RunExtensionSubtestIncognito( 144 bool ExtensionApiTest::RunExtensionSubtestIncognito(
143 const char* extension_name, 145 const char* extension_name,
144 const std::string& page_url) { 146 const std::string& page_url) {
145 DCHECK(!page_url.empty()) << "Argument page_url is required."; 147 DCHECK(!page_url.empty()) << "Argument page_url is required.";
146 return RunExtensionTestImpl(extension_name, page_url, true, true, false); 148 return RunExtensionTestImpl(extension_name, page_url,
149 kFlagEnableIncognito | kFlagEnableFileaccess);
147 } 150 }
148 151
149 bool ExtensionApiTest::RunExtensionSubtestIncognitoNoFileAccess( 152 bool ExtensionApiTest::RunExtensionSubtestIncognitoNoFileAccess(
150 const char* extension_name, 153 const char* extension_name,
151 const std::string& page_url) { 154 const std::string& page_url) {
152 DCHECK(!page_url.empty()) << "Argument page_url is required."; 155 DCHECK(!page_url.empty()) << "Argument page_url is required.";
153 return RunExtensionTestImpl(extension_name, page_url, true, false, false); 156 return RunExtensionTestImpl(extension_name, page_url, kFlagEnableIncognito);
154 } 157 }
155 158
156 bool ExtensionApiTest::RunPageTest(const std::string& page_url) { 159 bool ExtensionApiTest::RunPageTest(const std::string& page_url) {
157 return RunExtensionSubtest("", page_url); 160 return RunExtensionSubtest("", page_url);
158 } 161 }
159 162
163 bool ExtensionApiTest::RunPlatformAppTest(const char* extension_name) {
164 return RunExtensionTestImpl(extension_name, "", kFlagLaunchAppShell);
165 }
166
160 // Load |extension_name| extension and/or |page_url| and wait for 167 // Load |extension_name| extension and/or |page_url| and wait for
161 // PASSED or FAILED notification. 168 // PASSED or FAILED notification.
162 bool ExtensionApiTest::RunExtensionTestImpl(const char* extension_name, 169 bool ExtensionApiTest::RunExtensionTestImpl(const char* extension_name,
163 const std::string& page_url, 170 const std::string& page_url,
164 bool enable_incognito, 171 int flags) {
165 bool enable_fileaccess, 172 bool enable_incognito = (flags & kFlagEnableIncognito) != 0;
166 bool load_as_component) { 173 bool enable_fileaccess = (flags & kFlagEnableFileaccess) != 0;
174 bool load_as_component = (flags & kFlagLoadAsComponent) != 0;
175 bool launch_shell = (flags & kFlagLaunchAppShell) != 0;
176
167 ResultCatcher catcher; 177 ResultCatcher catcher;
168 DCHECK(!std::string(extension_name).empty() || !page_url.empty()) << 178 DCHECK(!std::string(extension_name).empty() || !page_url.empty()) <<
169 "extension_name and page_url cannot both be empty"; 179 "extension_name and page_url cannot both be empty";
170 180
171 if (!std::string(extension_name).empty()) { 181 if (!std::string(extension_name).empty()) {
172 bool loaded = false; 182 bool loaded = false;
173 FilePath extension_path = test_data_dir_.AppendASCII(extension_name); 183 FilePath extension_path = test_data_dir_.AppendASCII(extension_name);
174 if (load_as_component) { 184 if (load_as_component) {
175 loaded = LoadExtensionAsComponent(extension_path); 185 loaded = LoadExtensionAsComponent(extension_path);
176 } else { 186 } else {
177 loaded = LoadExtensionWithOptions(extension_path, 187 loaded = LoadExtensionWithOptions(extension_path,
178 enable_incognito, enable_fileaccess); 188 enable_incognito, enable_fileaccess);
179 } 189 }
180 if (!loaded) { 190 if (!loaded) {
181 message_ = "Failed to load extension."; 191 message_ = "Failed to load extension.";
182 return false; 192 return false;
183 } 193 }
184 } 194 }
185 195
196 ExtensionService* service = browser()->profile()->GetExtensionService();
197 const Extension* extension =
198 service->GetExtensionById(last_loaded_extension_id_, false);
199 if (!extension) {
200 message_ = "Failed to find extension in ExtensionService.";
201 return false;
202 }
203
186 // If there is a page_url to load, navigate it. 204 // If there is a page_url to load, navigate it.
187 if (!page_url.empty()) { 205 if (!page_url.empty()) {
188 GURL url = GURL(page_url); 206 GURL url = GURL(page_url);
189 207
190 // Note: We use is_valid() here in the expectation that the provided url 208 // Note: We use is_valid() here in the expectation that the provided url
191 // may lack a scheme & host and thus be a relative url within the loaded 209 // may lack a scheme & host and thus be a relative url within the loaded
192 // extension. 210 // extension.
193 if (!url.is_valid()) { 211 if (!url.is_valid()) {
194 DCHECK(!std::string(extension_name).empty()) << 212 DCHECK(!std::string(extension_name).empty()) <<
195 "Relative page_url given with no extension_name"; 213 "Relative page_url given with no extension_name";
196
197 ExtensionService* service = browser()->profile()->GetExtensionService();
198 const Extension* extension =
199 service->GetExtensionById(last_loaded_extension_id_, false);
200 if (!extension) {
201 message_ = "Failed to find extension in ExtensionService.";
202 return false;
203 }
204
205 url = extension->GetResourceURL(page_url); 214 url = extension->GetResourceURL(page_url);
206 } 215 }
207 216
208 ui_test_utils::NavigateToURL(browser(), url); 217 ui_test_utils::NavigateToURL(browser(), url);
218
219 } else if (launch_shell) {
220 Browser::OpenApplication(
221 browser()->profile(),
222 extension,
223 extension_misc::LAUNCH_SHELL,
224 GURL(),
225 NEW_WINDOW);
209 } 226 }
210 227
211 if (!catcher.GetNextResult()) { 228 if (!catcher.GetNextResult()) {
212 message_ = catcher.message(); 229 message_ = catcher.message();
213 return false; 230 return false;
214 } else { 231 } else {
215 return true; 232 return true;
216 } 233 }
217 } 234 }
218 235
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 test_config_->SetInteger(kTestServerPort, 273 test_config_->SetInteger(kTestServerPort,
257 test_server()->host_port_pair().port()); 274 test_server()->host_port_pair().port());
258 275
259 return true; 276 return true;
260 } 277 }
261 278
262 void ExtensionApiTest::SetUpCommandLine(CommandLine* command_line) { 279 void ExtensionApiTest::SetUpCommandLine(CommandLine* command_line) {
263 ExtensionBrowserTest::SetUpCommandLine(command_line); 280 ExtensionBrowserTest::SetUpCommandLine(command_line);
264 test_data_dir_ = test_data_dir_.AppendASCII("api_test"); 281 test_data_dir_ = test_data_dir_.AppendASCII("api_test");
265 } 282 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698