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 "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/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 // glibc/ | 170 // glibc/ |
171 static bool GetNaClVariantRoot(const base::FilePath::StringType& variant, | 171 static bool GetNaClVariantRoot(const base::FilePath::StringType& variant, |
172 base::FilePath* document_root) { | 172 base::FilePath* document_root) { |
173 if (!ui_test_utils::GetRelativeBuildDirectory(document_root)) | 173 if (!ui_test_utils::GetRelativeBuildDirectory(document_root)) |
174 return false; | 174 return false; |
175 *document_root = document_root->Append(FILE_PATH_LITERAL("nacl_test_data")); | 175 *document_root = document_root->Append(FILE_PATH_LITERAL("nacl_test_data")); |
176 *document_root = document_root->Append(variant); | 176 *document_root = document_root->Append(variant); |
177 return true; | 177 return true; |
178 } | 178 } |
179 | 179 |
180 static void AddPnaclParm(const base::FilePath::StringType& url, | |
181 base::FilePath::StringType* url_with_parm) { | |
182 if (url.find(FILE_PATH_LITERAL("?")) == base::FilePath::StringType::npos) { | |
183 *url_with_parm = url + FILE_PATH_LITERAL("?pnacl=1"); | |
184 } else { | |
185 *url_with_parm = url + FILE_PATH_LITERAL("&pnacl=1"); | |
186 } | |
187 } | |
188 | |
189 NaClBrowserTestBase::NaClBrowserTestBase() { | 180 NaClBrowserTestBase::NaClBrowserTestBase() { |
190 } | 181 } |
191 | 182 |
192 NaClBrowserTestBase::~NaClBrowserTestBase() { | 183 NaClBrowserTestBase::~NaClBrowserTestBase() { |
193 } | 184 } |
194 | 185 |
195 void NaClBrowserTestBase::SetUpCommandLine(CommandLine* command_line) { | 186 void NaClBrowserTestBase::SetUpCommandLine(CommandLine* command_line) { |
196 command_line->AppendSwitch(switches::kNoFirstRun); | 187 command_line->AppendSwitch(switches::kNoFirstRun); |
197 command_line->AppendSwitch(switches::kEnableNaCl); | 188 command_line->AppendSwitch(switches::kEnableNaCl); |
198 } | 189 } |
(...skipping 27 matching lines...) Expand all Loading... |
226 JavascriptTestObserver observer( | 217 JavascriptTestObserver observer( |
227 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(), | 218 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(), |
228 handler); | 219 handler); |
229 ui_test_utils::NavigateToURL(browser(), url); | 220 ui_test_utils::NavigateToURL(browser(), url); |
230 return observer.Run(); | 221 return observer.Run(); |
231 } | 222 } |
232 | 223 |
233 void NaClBrowserTestBase::RunLoadTest( | 224 void NaClBrowserTestBase::RunLoadTest( |
234 const base::FilePath::StringType& test_file) { | 225 const base::FilePath::StringType& test_file) { |
235 LoadTestMessageHandler handler; | 226 LoadTestMessageHandler handler; |
236 base::FilePath::StringType test_file_with_parm = test_file; | 227 bool ok = RunJavascriptTest(TestURL(test_file), &handler); |
237 if (IsPnacl()) { | |
238 AddPnaclParm(test_file, &test_file_with_parm); | |
239 } | |
240 bool ok = RunJavascriptTest(TestURL(test_file_with_parm), &handler); | |
241 ASSERT_TRUE(ok) << handler.error_message(); | 228 ASSERT_TRUE(ok) << handler.error_message(); |
242 ASSERT_TRUE(handler.test_passed()) << "Test failed."; | 229 ASSERT_TRUE(handler.test_passed()) << "Test failed."; |
243 } | 230 } |
244 | 231 |
245 void NaClBrowserTestBase::RunNaClIntegrationTest( | 232 void NaClBrowserTestBase::RunNaClIntegrationTest( |
246 const base::FilePath::StringType& url_fragment) { | 233 const base::FilePath::StringType& url_fragment) { |
247 NaClIntegrationMessageHandler handler; | 234 NaClIntegrationMessageHandler handler; |
248 base::FilePath::StringType url_fragment_with_parm = url_fragment; | 235 bool ok = RunJavascriptTest(TestURL(url_fragment), &handler); |
249 if (IsPnacl()) { | |
250 AddPnaclParm(url_fragment, &url_fragment_with_parm); | |
251 } | |
252 bool ok = RunJavascriptTest(TestURL(url_fragment_with_parm), &handler); | |
253 ASSERT_TRUE(ok) << handler.error_message(); | 236 ASSERT_TRUE(ok) << handler.error_message(); |
254 ASSERT_TRUE(handler.test_passed()) << "Test failed."; | 237 ASSERT_TRUE(handler.test_passed()) << "Test failed."; |
255 } | 238 } |
256 | 239 |
257 bool NaClBrowserTestBase::StartTestServer() { | 240 bool NaClBrowserTestBase::StartTestServer() { |
258 // Launch the web server. | 241 // Launch the web server. |
259 base::FilePath document_root; | 242 base::FilePath document_root; |
260 if (!GetDocumentRoot(&document_root)) | 243 if (!GetDocumentRoot(&document_root)) |
261 return false; | 244 return false; |
262 test_server_.reset(new net::SpawnedTestServer( | 245 test_server_.reset(new net::SpawnedTestServer( |
(...skipping 25 matching lines...) Expand all Loading... |
288 } | 271 } |
289 | 272 |
290 base::FilePath::StringType NaClBrowserTestStatic::Variant() { | 273 base::FilePath::StringType NaClBrowserTestStatic::Variant() { |
291 return FILE_PATH_LITERAL("static"); | 274 return FILE_PATH_LITERAL("static"); |
292 } | 275 } |
293 | 276 |
294 bool NaClBrowserTestStatic::GetDocumentRoot(base::FilePath* document_root) { | 277 bool NaClBrowserTestStatic::GetDocumentRoot(base::FilePath* document_root) { |
295 *document_root = base::FilePath(FILE_PATH_LITERAL("chrome/test/data/nacl")); | 278 *document_root = base::FilePath(FILE_PATH_LITERAL("chrome/test/data/nacl")); |
296 return true; | 279 return true; |
297 } | 280 } |
OLD | NEW |