OLD | NEW |
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/test/nacl/nacl_browsertest_util.h" | 5 #include "chrome/test/nacl/nacl_browsertest_util.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 | 181 |
182 static void AddPnaclParm(const base::FilePath::StringType& url, | 182 static void AddPnaclParm(const base::FilePath::StringType& url, |
183 base::FilePath::StringType* url_with_parm) { | 183 base::FilePath::StringType* url_with_parm) { |
184 if (url.find(FILE_PATH_LITERAL("?")) == base::FilePath::StringType::npos) { | 184 if (url.find(FILE_PATH_LITERAL("?")) == base::FilePath::StringType::npos) { |
185 *url_with_parm = url + FILE_PATH_LITERAL("?pnacl=1"); | 185 *url_with_parm = url + FILE_PATH_LITERAL("?pnacl=1"); |
186 } else { | 186 } else { |
187 *url_with_parm = url + FILE_PATH_LITERAL("&pnacl=1"); | 187 *url_with_parm = url + FILE_PATH_LITERAL("&pnacl=1"); |
188 } | 188 } |
189 } | 189 } |
190 | 190 |
191 static void AddPnaclDisabledParm(const base::FilePath::StringType& url, | |
192 base::FilePath::StringType* url_with_parm) { | |
193 if (url.find(FILE_PATH_LITERAL("?")) == base::FilePath::StringType::npos) { | |
194 *url_with_parm = url + FILE_PATH_LITERAL("?pnacl_disabled=1"); | |
195 } else { | |
196 *url_with_parm = url + FILE_PATH_LITERAL("&pnacl_disabled=1"); | |
197 } | |
198 } | |
199 | |
200 NaClBrowserTestBase::NaClBrowserTestBase() { | 191 NaClBrowserTestBase::NaClBrowserTestBase() { |
201 } | 192 } |
202 | 193 |
203 NaClBrowserTestBase::~NaClBrowserTestBase() { | 194 NaClBrowserTestBase::~NaClBrowserTestBase() { |
204 } | 195 } |
205 | 196 |
206 void NaClBrowserTestBase::SetUpCommandLine(base::CommandLine* command_line) { | 197 void NaClBrowserTestBase::SetUpCommandLine(base::CommandLine* command_line) { |
207 command_line->AppendSwitch(switches::kEnableNaCl); | 198 command_line->AppendSwitch(switches::kEnableNaCl); |
208 } | 199 } |
209 | 200 |
210 void NaClBrowserTestBase::SetUpOnMainThread() { | 201 void NaClBrowserTestBase::SetUpOnMainThread() { |
211 // Sanity check. | 202 // Sanity check. |
212 base::FilePath plugin_lib; | 203 base::FilePath plugin_lib; |
213 ASSERT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib)); | 204 ASSERT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib)); |
214 ASSERT_TRUE(base::PathExists(plugin_lib)) << plugin_lib.value(); | 205 ASSERT_TRUE(base::PathExists(plugin_lib)) << plugin_lib.value(); |
215 | 206 |
216 ASSERT_TRUE(StartTestServer()) << "Cannot start test server."; | 207 ASSERT_TRUE(StartTestServer()) << "Cannot start test server."; |
217 } | 208 } |
218 | 209 |
219 bool NaClBrowserTestBase::GetDocumentRoot(base::FilePath* document_root) { | 210 bool NaClBrowserTestBase::GetDocumentRoot(base::FilePath* document_root) { |
220 return GetNaClVariantRoot(Variant(), document_root); | 211 return GetNaClVariantRoot(Variant(), document_root); |
221 } | 212 } |
222 | 213 |
223 bool NaClBrowserTestBase::IsAPnaclTest() { | 214 bool NaClBrowserTestBase::IsAPnaclTest() { |
224 return false; | 215 return false; |
225 } | 216 } |
226 | 217 |
227 bool NaClBrowserTestBase::IsPnaclDisabled() { | |
228 return false; | |
229 } | |
230 | |
231 GURL NaClBrowserTestBase::TestURL( | 218 GURL NaClBrowserTestBase::TestURL( |
232 const base::FilePath::StringType& url_fragment) { | 219 const base::FilePath::StringType& url_fragment) { |
233 base::FilePath expanded_url = base::FilePath(FILE_PATH_LITERAL("files")); | 220 base::FilePath expanded_url = base::FilePath(FILE_PATH_LITERAL("files")); |
234 expanded_url = expanded_url.Append(url_fragment); | 221 expanded_url = expanded_url.Append(url_fragment); |
235 return test_server_->GetURL(expanded_url.MaybeAsASCII()); | 222 return test_server_->GetURL(expanded_url.MaybeAsASCII()); |
236 } | 223 } |
237 | 224 |
238 bool NaClBrowserTestBase::RunJavascriptTest( | 225 bool NaClBrowserTestBase::RunJavascriptTest( |
239 const GURL& url, | 226 const GURL& url, |
240 content::TestMessageHandler* handler) { | 227 content::TestMessageHandler* handler) { |
241 content::JavascriptTestObserver observer( | 228 content::JavascriptTestObserver observer( |
242 browser()->tab_strip_model()->GetActiveWebContents(), | 229 browser()->tab_strip_model()->GetActiveWebContents(), |
243 handler); | 230 handler); |
244 ui_test_utils::NavigateToURL(browser(), url); | 231 ui_test_utils::NavigateToURL(browser(), url); |
245 return observer.Run(); | 232 return observer.Run(); |
246 } | 233 } |
247 | 234 |
248 void NaClBrowserTestBase::RunLoadTest( | 235 void NaClBrowserTestBase::RunLoadTest( |
249 const base::FilePath::StringType& test_file) { | 236 const base::FilePath::StringType& test_file) { |
250 LoadTestMessageHandler handler; | 237 LoadTestMessageHandler handler; |
251 base::FilePath::StringType test_file_with_pnacl = test_file; | 238 base::FilePath::StringType test_file_with_pnacl = test_file; |
252 if (IsAPnaclTest()) { | 239 if (IsAPnaclTest()) { |
253 AddPnaclParm(test_file, &test_file_with_pnacl); | 240 AddPnaclParm(test_file, &test_file_with_pnacl); |
254 } | 241 } |
255 base::FilePath::StringType test_file_with_both = test_file_with_pnacl; | 242 base::FilePath::StringType test_file_with_both = test_file_with_pnacl; |
256 if (IsPnaclDisabled()) { | |
257 AddPnaclDisabledParm(test_file_with_pnacl, &test_file_with_both); | |
258 } | |
259 bool ok = RunJavascriptTest(TestURL(test_file_with_both), &handler); | 243 bool ok = RunJavascriptTest(TestURL(test_file_with_both), &handler); |
260 ASSERT_TRUE(ok) << handler.error_message(); | 244 ASSERT_TRUE(ok) << handler.error_message(); |
261 ASSERT_TRUE(handler.test_passed()) << "Test failed."; | 245 ASSERT_TRUE(handler.test_passed()) << "Test failed."; |
262 } | 246 } |
263 | 247 |
264 void NaClBrowserTestBase::RunNaClIntegrationTest( | 248 void NaClBrowserTestBase::RunNaClIntegrationTest( |
265 const base::FilePath::StringType& url_fragment, bool full_url) { | 249 const base::FilePath::StringType& url_fragment, bool full_url) { |
266 NaClIntegrationMessageHandler handler; | 250 NaClIntegrationMessageHandler handler; |
267 base::FilePath::StringType url_fragment_with_pnacl = url_fragment; | 251 base::FilePath::StringType url_fragment_with_pnacl = url_fragment; |
268 if (IsAPnaclTest()) { | 252 if (IsAPnaclTest()) { |
269 AddPnaclParm(url_fragment, &url_fragment_with_pnacl); | 253 AddPnaclParm(url_fragment, &url_fragment_with_pnacl); |
270 } | 254 } |
271 base::FilePath::StringType url_fragment_with_both = url_fragment_with_pnacl; | 255 base::FilePath::StringType url_fragment_with_both = url_fragment_with_pnacl; |
272 if (IsPnaclDisabled()) { | |
273 AddPnaclDisabledParm(url_fragment_with_pnacl, &url_fragment_with_both); | |
274 } | |
275 bool ok = RunJavascriptTest(full_url | 256 bool ok = RunJavascriptTest(full_url |
276 ? GURL(url_fragment_with_both) | 257 ? GURL(url_fragment_with_both) |
277 : TestURL(url_fragment_with_both), | 258 : TestURL(url_fragment_with_both), |
278 &handler); | 259 &handler); |
279 ASSERT_TRUE(ok) << handler.error_message(); | 260 ASSERT_TRUE(ok) << handler.error_message(); |
280 ASSERT_TRUE(handler.test_passed()) << "Test failed."; | 261 ASSERT_TRUE(handler.test_passed()) << "Test failed."; |
281 } | 262 } |
282 | 263 |
283 bool NaClBrowserTestBase::StartTestServer() { | 264 bool NaClBrowserTestBase::StartTestServer() { |
284 // Launch the web server. | 265 // Launch the web server. |
(...skipping 16 matching lines...) Expand all Loading... |
301 } | 282 } |
302 | 283 |
303 base::FilePath::StringType NaClBrowserTestPnacl::Variant() { | 284 base::FilePath::StringType NaClBrowserTestPnacl::Variant() { |
304 return FILE_PATH_LITERAL("pnacl"); | 285 return FILE_PATH_LITERAL("pnacl"); |
305 } | 286 } |
306 | 287 |
307 bool NaClBrowserTestPnacl::IsAPnaclTest() { | 288 bool NaClBrowserTestPnacl::IsAPnaclTest() { |
308 return true; | 289 return true; |
309 } | 290 } |
310 | 291 |
311 base::FilePath::StringType NaClBrowserTestPnaclDisabled::Variant() { | |
312 return FILE_PATH_LITERAL("pnacl"); | |
313 } | |
314 | |
315 bool NaClBrowserTestPnaclDisabled::IsAPnaclTest() { | |
316 return true; | |
317 } | |
318 | |
319 bool NaClBrowserTestPnaclDisabled::IsPnaclDisabled() { | |
320 return true; | |
321 } | |
322 void NaClBrowserTestPnaclDisabled::SetUpCommandLine( | |
323 base::CommandLine* command_line) { | |
324 NaClBrowserTestBase::SetUpCommandLine(command_line); | |
325 command_line->AppendSwitch(switches::kDisablePnacl); | |
326 } | |
327 | |
328 base::FilePath::StringType NaClBrowserTestNonSfiMode::Variant() { | 292 base::FilePath::StringType NaClBrowserTestNonSfiMode::Variant() { |
329 return FILE_PATH_LITERAL("libc-free"); | 293 return FILE_PATH_LITERAL("libc-free"); |
330 } | 294 } |
331 | 295 |
332 void NaClBrowserTestNonSfiMode::SetUpCommandLine( | 296 void NaClBrowserTestNonSfiMode::SetUpCommandLine( |
333 base::CommandLine* command_line) { | 297 base::CommandLine* command_line) { |
334 NaClBrowserTestBase::SetUpCommandLine(command_line); | 298 NaClBrowserTestBase::SetUpCommandLine(command_line); |
335 command_line->AppendSwitch(switches::kEnableNaClNonSfiMode); | 299 command_line->AppendSwitch(switches::kEnableNaClNonSfiMode); |
336 } | 300 } |
337 | 301 |
(...skipping 26 matching lines...) Expand all Loading... |
364 // to point at the isolated the test extension directory. | 328 // to point at the isolated the test extension directory. |
365 // Otherwise, multiple NaCl extensions tests will end up sharing the | 329 // Otherwise, multiple NaCl extensions tests will end up sharing the |
366 // same directory when loading the extension files. | 330 // same directory when loading the extension files. |
367 base::FilePath document_root; | 331 base::FilePath document_root; |
368 ASSERT_TRUE(GetDocumentRoot(&document_root)); | 332 ASSERT_TRUE(GetDocumentRoot(&document_root)); |
369 | 333 |
370 // Document root is relative to source root, and source root may not be CWD. | 334 // Document root is relative to source root, and source root may not be CWD. |
371 command_line->AppendSwitchPath(switches::kLoadExtension, | 335 command_line->AppendSwitchPath(switches::kLoadExtension, |
372 src_root.Append(document_root)); | 336 src_root.Append(document_root)); |
373 } | 337 } |
OLD | NEW |