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" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
14 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
17 #include "components/nacl/common/nacl_switches.h" | 17 #include "components/nacl/common/nacl_switches.h" |
18 #include "content/public/browser/plugin_service.h" | 18 #include "content/public/browser/plugin_service.h" |
19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
20 #include "content/public/common/webplugininfo.h" | 20 #include "content/public/common/webplugininfo.h" |
21 #include "net/base/net_util.h" | 21 #include "net/base/net_util.h" |
22 #include "net/test/embedded_test_server/embedded_test_server.h" | |
mmenke
2015/11/05 17:38:13
This is included in the header, so not needed (Cou
svaldez
2015/11/05 18:15:55
Done.
| |
22 | 23 |
23 typedef content::TestMessageHandler::MessageResponse MessageResponse; | 24 typedef content::TestMessageHandler::MessageResponse MessageResponse; |
24 | 25 |
25 MessageResponse StructuredMessageHandler::HandleMessage( | 26 MessageResponse StructuredMessageHandler::HandleMessage( |
26 const std::string& json) { | 27 const std::string& json) { |
27 base::JSONReader reader(base::JSON_ALLOW_TRAILING_COMMAS); | 28 base::JSONReader reader(base::JSON_ALLOW_TRAILING_COMMAS); |
28 // Automation messages are stringified before they are sent because the | 29 // Automation messages are stringified before they are sent because the |
29 // automation channel cannot handle arbitrary objects. This means we | 30 // automation channel cannot handle arbitrary objects. This means we |
30 // need to decode the json twice to get the original message. | 31 // need to decode the json twice to get the original message. |
31 scoped_ptr<base::Value> value = reader.ReadToValue(json); | 32 scoped_ptr<base::Value> value = reader.ReadToValue(json); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 bool NaClBrowserTestBase::GetDocumentRoot(base::FilePath* document_root) { | 204 bool NaClBrowserTestBase::GetDocumentRoot(base::FilePath* document_root) { |
204 return GetNaClVariantRoot(Variant(), document_root); | 205 return GetNaClVariantRoot(Variant(), document_root); |
205 } | 206 } |
206 | 207 |
207 bool NaClBrowserTestBase::IsAPnaclTest() { | 208 bool NaClBrowserTestBase::IsAPnaclTest() { |
208 return false; | 209 return false; |
209 } | 210 } |
210 | 211 |
211 GURL NaClBrowserTestBase::TestURL( | 212 GURL NaClBrowserTestBase::TestURL( |
212 const base::FilePath::StringType& url_fragment) { | 213 const base::FilePath::StringType& url_fragment) { |
213 base::FilePath expanded_url = base::FilePath(FILE_PATH_LITERAL("files")); | 214 base::FilePath expanded_url = base::FilePath(FILE_PATH_LITERAL("/")); |
214 expanded_url = expanded_url.Append(url_fragment); | 215 expanded_url = expanded_url.Append(url_fragment); |
215 return test_server_->GetURL(expanded_url.MaybeAsASCII()); | 216 return test_server_->GetURL(expanded_url.MaybeAsASCII()); |
216 } | 217 } |
217 | 218 |
218 bool NaClBrowserTestBase::RunJavascriptTest( | 219 bool NaClBrowserTestBase::RunJavascriptTest( |
219 const GURL& url, | 220 const GURL& url, |
220 content::TestMessageHandler* handler) { | 221 content::TestMessageHandler* handler) { |
221 content::JavascriptTestObserver observer( | 222 content::JavascriptTestObserver observer( |
222 browser()->tab_strip_model()->GetActiveWebContents(), | 223 browser()->tab_strip_model()->GetActiveWebContents(), |
223 handler); | 224 handler); |
(...skipping 28 matching lines...) Expand all Loading... | |
252 &handler); | 253 &handler); |
253 ASSERT_TRUE(ok) << handler.error_message(); | 254 ASSERT_TRUE(ok) << handler.error_message(); |
254 ASSERT_TRUE(handler.test_passed()) << "Test failed."; | 255 ASSERT_TRUE(handler.test_passed()) << "Test failed."; |
255 } | 256 } |
256 | 257 |
257 bool NaClBrowserTestBase::StartTestServer() { | 258 bool NaClBrowserTestBase::StartTestServer() { |
258 // Launch the web server. | 259 // Launch the web server. |
259 base::FilePath document_root; | 260 base::FilePath document_root; |
260 if (!GetDocumentRoot(&document_root)) | 261 if (!GetDocumentRoot(&document_root)) |
261 return false; | 262 return false; |
262 test_server_.reset(new net::SpawnedTestServer( | 263 test_server_.reset(new net::EmbeddedTestServer); |
263 net::SpawnedTestServer::TYPE_HTTP, | 264 test_server_->ServeFilesFromSourceDirectory(document_root); |
264 net::SpawnedTestServer::kLocalhost, | |
265 document_root)); | |
266 return test_server_->Start(); | 265 return test_server_->Start(); |
267 } | 266 } |
268 | 267 |
269 base::FilePath::StringType NaClBrowserTestNewlib::Variant() { | 268 base::FilePath::StringType NaClBrowserTestNewlib::Variant() { |
270 return FILE_PATH_LITERAL("newlib"); | 269 return FILE_PATH_LITERAL("newlib"); |
271 } | 270 } |
272 | 271 |
273 base::FilePath::StringType NaClBrowserTestGLibc::Variant() { | 272 base::FilePath::StringType NaClBrowserTestGLibc::Variant() { |
274 return FILE_PATH_LITERAL("glibc"); | 273 return FILE_PATH_LITERAL("glibc"); |
275 } | 274 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
345 // to point at the isolated the test extension directory. | 344 // to point at the isolated the test extension directory. |
346 // Otherwise, multiple NaCl extensions tests will end up sharing the | 345 // Otherwise, multiple NaCl extensions tests will end up sharing the |
347 // same directory when loading the extension files. | 346 // same directory when loading the extension files. |
348 base::FilePath document_root; | 347 base::FilePath document_root; |
349 ASSERT_TRUE(GetDocumentRoot(&document_root)); | 348 ASSERT_TRUE(GetDocumentRoot(&document_root)); |
350 | 349 |
351 // Document root is relative to source root, and source root may not be CWD. | 350 // Document root is relative to source root, and source root may not be CWD. |
352 command_line->AppendSwitchPath(switches::kLoadExtension, | 351 command_line->AppendSwitchPath(switches::kLoadExtension, |
353 src_root.Append(document_root)); | 352 src_root.Append(document_root)); |
354 } | 353 } |
OLD | NEW |