Chromium Code Reviews| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 return MissingField(type, "message"); | 89 return MissingField(type, "message"); |
| 90 if (!msg->GetBoolean("passed", &test_passed_)) | 90 if (!msg->GetBoolean("passed", &test_passed_)) |
| 91 return MissingField(type, "passed"); | 91 return MissingField(type, "passed"); |
| 92 Log("SHUTDOWN", message); | 92 Log("SHUTDOWN", message); |
| 93 return DONE; | 93 return DONE; |
| 94 } else { | 94 } else { |
| 95 return InternalError("Unknown message type: " + type); | 95 return InternalError("Unknown message type: " + type); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 | 98 |
| 99 // A message handler for nacl_integration tests ported to be browser_tests. | |
| 100 // nacl_integration tests report to their test jig using a series of RPC calls | |
| 101 // that are encoded as URL requests. When these tests run as browser_tests, | |
| 102 // they make the same RPC requests, but use the automation channel instead of | |
| 103 // URL requests. This message handler decodes and responds to these requests. | |
|
Mark Seaborn
2012/09/12 18:09:45
Be consistent about using 1 or 2 spaces between se
Nick Bray (chromium)
2012/09/12 20:50:59
Done.
| |
| 104 class NaClIntegrationMessageHandler : public StructuredMessageHandler { | |
| 105 public: | |
| 106 NaClIntegrationMessageHandler(); | |
| 107 | |
| 108 void Log(const std::string& message); | |
| 109 | |
| 110 virtual MessageResponse HandleStructuredMessage( | |
| 111 const std::string& type, | |
| 112 base::DictionaryValue* msg) OVERRIDE; | |
| 113 | |
| 114 bool test_passed() const { | |
| 115 return test_passed_; | |
| 116 } | |
| 117 | |
| 118 private: | |
| 119 bool test_passed_; | |
| 120 | |
| 121 DISALLOW_COPY_AND_ASSIGN(NaClIntegrationMessageHandler); | |
| 122 }; | |
| 123 | |
| 124 NaClIntegrationMessageHandler::NaClIntegrationMessageHandler() | |
| 125 : test_passed_(false) { | |
| 126 } | |
| 127 | |
| 128 void NaClIntegrationMessageHandler::Log(const std::string& message) { | |
| 129 // TODO(ncbray) better logging. | |
| 130 LOG(INFO) << "|||| " << message; | |
| 131 } | |
| 132 | |
| 133 MessageResponse NaClIntegrationMessageHandler::HandleStructuredMessage( | |
| 134 const std::string& type, | |
| 135 DictionaryValue* msg) { | |
| 136 if (type == "TestLog") { | |
| 137 std::string message; | |
| 138 if (!msg->GetString("message", &message)) | |
| 139 return MissingField(type, "message"); | |
| 140 Log(message); | |
| 141 return CONTINUE; | |
| 142 } else if (type == "Shutdown") { | |
| 143 std::string message; | |
| 144 if (!msg->GetString("message", &message)) | |
| 145 return MissingField(type, "message"); | |
| 146 if (!msg->GetBoolean("passed", &test_passed_)) | |
| 147 return MissingField(type, "passed"); | |
| 148 Log(message); | |
| 149 return DONE; | |
| 150 } else if (type == "Ping") { | |
| 151 return CONTINUE; | |
| 152 } else if (type == "JavaScriptIsAlive") { | |
| 153 return CONTINUE; | |
| 154 } else { | |
| 155 return InternalError("Unknown message type: " + type); | |
| 156 } | |
| 157 } | |
| 158 | |
| 99 // NaCl browser tests serve files out of the build directory because nexes and | 159 // NaCl browser tests serve files out of the build directory because nexes and |
| 100 // pexes are artifacts of the build. To keep things tidy, all test data is kept | 160 // pexes are artifacts of the build. To keep things tidy, all test data is kept |
| 101 // in a subdirectory. Several variants of a test may be run, for example when | 161 // in a subdirectory. Several variants of a test may be run, for example when |
| 102 // linked against newlib and when linked against glibc. These variants are kept | 162 // linked against newlib and when linked against glibc. These variants are kept |
| 103 // in different subdirectories. For example, the build directory will look | 163 // in different subdirectories. For example, the build directory will look |
| 104 // something like this on Linux: | 164 // something like this on Linux: |
| 105 // out/ | 165 // out/ |
| 106 // Release/ | 166 // Release/ |
| 107 // nacl_test_data/ | 167 // nacl_test_data/ |
| 108 // newlib/ | 168 // newlib/ |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 129 | 189 |
| 130 void NaClBrowserTestBase::SetUpInProcessBrowserTestFixture() { | 190 void NaClBrowserTestBase::SetUpInProcessBrowserTestFixture() { |
| 131 // Sanity check. | 191 // Sanity check. |
| 132 FilePath plugin_lib; | 192 FilePath plugin_lib; |
| 133 ASSERT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib)); | 193 ASSERT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib)); |
| 134 ASSERT_TRUE(file_util::PathExists(plugin_lib)) << plugin_lib.value(); | 194 ASSERT_TRUE(file_util::PathExists(plugin_lib)) << plugin_lib.value(); |
| 135 | 195 |
| 136 ASSERT_TRUE(StartTestServer()) << "Cannot start test server."; | 196 ASSERT_TRUE(StartTestServer()) << "Cannot start test server."; |
| 137 } | 197 } |
| 138 | 198 |
| 139 GURL NaClBrowserTestBase::TestURL(const FilePath::StringType& test_file) { | 199 GURL NaClBrowserTestBase::TestURL(const FilePath::StringType& url_fragment) { |
| 140 FilePath real_path = test_server_->document_root().Append(test_file); | 200 FilePath expanded_url = FilePath(FILE_PATH_LITERAL("files")); |
| 141 EXPECT_TRUE(file_util::PathExists(real_path)) << real_path.value(); | 201 expanded_url = expanded_url.Append(url_fragment); |
| 142 | 202 return test_server_->GetURL(expanded_url.MaybeAsASCII()); |
| 143 FilePath url_path = FilePath(FILE_PATH_LITERAL("files")); | |
| 144 url_path = url_path.Append(test_file); | |
| 145 return test_server_->GetURL(url_path.MaybeAsASCII()); | |
| 146 } | 203 } |
| 147 | 204 |
| 148 bool NaClBrowserTestBase::RunJavascriptTest(const GURL& url, | 205 bool NaClBrowserTestBase::RunJavascriptTest(const GURL& url, |
| 149 TestMessageHandler* handler) { | 206 TestMessageHandler* handler) { |
| 150 JavascriptTestObserver observer( | 207 JavascriptTestObserver observer( |
| 151 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), | 208 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), |
| 152 handler); | 209 handler); |
| 153 ui_test_utils::NavigateToURL(browser(), url); | 210 ui_test_utils::NavigateToURL(browser(), url); |
| 154 return observer.Run(); | 211 return observer.Run(); |
| 155 } | 212 } |
| 156 | 213 |
| 157 void NaClBrowserTestBase::RunLoadTest(const FilePath::StringType& test_file) { | 214 void NaClBrowserTestBase::RunLoadTest(const FilePath::StringType& test_file) { |
| 158 LoadTestMessageHandler handler; | 215 LoadTestMessageHandler handler; |
| 159 bool ok = RunJavascriptTest(TestURL(test_file), &handler); | 216 bool ok = RunJavascriptTest(TestURL(test_file), &handler); |
| 160 ASSERT_TRUE(ok) << handler.error_message(); | 217 ASSERT_TRUE(ok) << handler.error_message(); |
| 161 ASSERT_TRUE(handler.test_passed()) << "Test failed."; | 218 ASSERT_TRUE(handler.test_passed()) << "Test failed."; |
| 162 } | 219 } |
| 163 | 220 |
| 221 void NaClBrowserTestBase::RunNaClIntegrationTest( | |
| 222 const FilePath::StringType& url_fragment) { | |
| 223 NaClIntegrationMessageHandler handler; | |
| 224 bool ok = RunJavascriptTest(TestURL(url_fragment), &handler); | |
| 225 ASSERT_TRUE(ok) << handler.error_message(); | |
| 226 ASSERT_TRUE(handler.test_passed()) << "Test failed."; | |
| 227 } | |
| 228 | |
| 164 bool NaClBrowserTestBase::StartTestServer() { | 229 bool NaClBrowserTestBase::StartTestServer() { |
| 165 // Launch the web server. | 230 // Launch the web server. |
| 166 FilePath document_root; | 231 FilePath document_root; |
| 167 if (!GetNaClVariantRoot(Variant(), &document_root)) | 232 if (!GetNaClVariantRoot(Variant(), &document_root)) |
| 168 return false; | 233 return false; |
| 169 test_server_.reset(new net::TestServer(net::TestServer::TYPE_HTTP, | 234 test_server_.reset(new net::TestServer(net::TestServer::TYPE_HTTP, |
| 170 net::TestServer::kLocalhost, | 235 net::TestServer::kLocalhost, |
| 171 document_root)); | 236 document_root)); |
| 172 return test_server_->Start(); | 237 return test_server_->Start(); |
| 173 } | 238 } |
| 174 | 239 |
| 175 FilePath::StringType NaClBrowserTestNewlib::Variant() { | 240 FilePath::StringType NaClBrowserTestNewlib::Variant() { |
| 176 return FILE_PATH_LITERAL("newlib"); | 241 return FILE_PATH_LITERAL("newlib"); |
| 177 } | 242 } |
| 178 | 243 |
| 179 FilePath::StringType NaClBrowserTestGLibc::Variant() { | 244 FilePath::StringType NaClBrowserTestGLibc::Variant() { |
| 180 return FILE_PATH_LITERAL("glibc"); | 245 return FILE_PATH_LITERAL("glibc"); |
| 181 } | 246 } |
| OLD | NEW |