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. | |
|
Mark Seaborn
2012/09/11 22:10:06
Commenting this based on where the code came from
Nick Bray (chromium)
2012/09/12 01:19:13
Done.
| |
| 100 class NaClIntegrationMessageHandler : public StructuredMessageHandler { | |
| 101 public: | |
| 102 NaClIntegrationMessageHandler(); | |
| 103 | |
| 104 void Log(const std::string& message); | |
| 105 | |
| 106 virtual MessageResponse HandleStructuredMessage( | |
| 107 const std::string& type, | |
| 108 base::DictionaryValue* msg) OVERRIDE; | |
| 109 | |
| 110 bool test_passed() const { | |
| 111 return test_passed_; | |
| 112 } | |
| 113 | |
| 114 private: | |
| 115 bool test_passed_; | |
| 116 | |
| 117 DISALLOW_COPY_AND_ASSIGN(NaClIntegrationMessageHandler); | |
| 118 }; | |
| 119 | |
| 120 NaClIntegrationMessageHandler::NaClIntegrationMessageHandler() | |
| 121 : test_passed_(false) { | |
| 122 } | |
| 123 | |
| 124 void NaClIntegrationMessageHandler::Log(const std::string& message) { | |
| 125 // TODO(ncbray) better logging. | |
| 126 LOG(INFO) << "|||| " << message; | |
|
Mark Seaborn
2012/09/11 22:10:06
Aren't LOG(INFO) omitted from the buildbot logs (a
| |
| 127 } | |
| 128 | |
| 129 MessageResponse NaClIntegrationMessageHandler::HandleStructuredMessage( | |
| 130 const std::string& type, | |
|
Mark Seaborn
2012/09/11 22:10:06
Indent by 1 more space
Nick Bray (chromium)
2012/09/12 01:19:13
Done.
| |
| 131 DictionaryValue* msg) { | |
| 132 if (type == "TestLog") { | |
| 133 std::string message; | |
| 134 if (!msg->GetString("message", &message)) | |
| 135 return MissingField(type, "message"); | |
| 136 Log(message); | |
| 137 return CONTINUE; | |
| 138 } else if (type == "Shutdown") { | |
| 139 std::string message; | |
| 140 if (!msg->GetString("message", &message)) | |
| 141 return MissingField(type, "message"); | |
| 142 if (!msg->GetBoolean("passed", &test_passed_)) | |
| 143 return MissingField(type, "passed"); | |
| 144 Log(message); | |
| 145 return DONE; | |
| 146 } else if (type == "Ping") { | |
| 147 return CONTINUE; | |
| 148 } else if (type == "JavaScriptIsAlive") { | |
| 149 return CONTINUE; | |
| 150 } else { | |
| 151 return InternalError("Unknown message type: " + type); | |
| 152 } | |
| 153 } | |
| 154 | |
| 99 // NaCl browser tests serve files out of the build directory because nexes and | 155 // 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 | 156 // 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 | 157 // 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 | 158 // linked against newlib and when linked against glibc. These variants are kept |
| 103 // in different subdirectories. For example, the build directory will look | 159 // in different subdirectories. For example, the build directory will look |
| 104 // something like this on Linux: | 160 // something like this on Linux: |
| 105 // out/ | 161 // out/ |
| 106 // Release/ | 162 // Release/ |
| 107 // nacl_test_data/ | 163 // nacl_test_data/ |
| 108 // newlib/ | 164 // newlib/ |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 130 void NaClBrowserTestBase::SetUpInProcessBrowserTestFixture() { | 186 void NaClBrowserTestBase::SetUpInProcessBrowserTestFixture() { |
| 131 // Sanity check. | 187 // Sanity check. |
| 132 FilePath plugin_lib; | 188 FilePath plugin_lib; |
| 133 ASSERT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib)); | 189 ASSERT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib)); |
| 134 ASSERT_TRUE(file_util::PathExists(plugin_lib)) << plugin_lib.value(); | 190 ASSERT_TRUE(file_util::PathExists(plugin_lib)) << plugin_lib.value(); |
| 135 | 191 |
| 136 ASSERT_TRUE(StartTestServer()) << "Cannot start test server."; | 192 ASSERT_TRUE(StartTestServer()) << "Cannot start test server."; |
| 137 } | 193 } |
| 138 | 194 |
| 139 GURL NaClBrowserTestBase::TestURL(const FilePath::StringType& test_file) { | 195 GURL NaClBrowserTestBase::TestURL(const FilePath::StringType& test_file) { |
| 140 FilePath real_path = test_server_->document_root().Append(test_file); | |
|
Mark Seaborn
2012/09/11 22:10:06
Why does this go? Comment in commit message. I d
Nick Bray (chromium)
2012/09/12 01:19:13
Because the new tests put a query string at the en
Mark Seaborn
2012/09/12 18:09:45
So please add a note in the commit message that yo
| |
| 141 EXPECT_TRUE(file_util::PathExists(real_path)) << real_path.value(); | |
| 142 | |
| 143 FilePath url_path = FilePath(FILE_PATH_LITERAL("files")); | 196 FilePath url_path = FilePath(FILE_PATH_LITERAL("files")); |
| 144 url_path = url_path.Append(test_file); | 197 url_path = url_path.Append(test_file); |
| 145 return test_server_->GetURL(url_path.MaybeAsASCII()); | 198 return test_server_->GetURL(url_path.MaybeAsASCII()); |
| 146 } | 199 } |
| 147 | 200 |
| 148 bool NaClBrowserTestBase::RunJavascriptTest(const GURL& url, | 201 bool NaClBrowserTestBase::RunJavascriptTest(const GURL& url, |
| 149 TestMessageHandler* handler) { | 202 TestMessageHandler* handler) { |
| 150 JavascriptTestObserver observer( | 203 JavascriptTestObserver observer( |
| 151 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), | 204 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), |
| 152 handler); | 205 handler); |
| 153 ui_test_utils::NavigateToURL(browser(), url); | 206 ui_test_utils::NavigateToURL(browser(), url); |
| 154 return observer.Run(); | 207 return observer.Run(); |
| 155 } | 208 } |
| 156 | 209 |
| 157 void NaClBrowserTestBase::RunLoadTest(const FilePath::StringType& test_file) { | 210 void NaClBrowserTestBase::RunLoadTest(const FilePath::StringType& test_file) { |
| 158 LoadTestMessageHandler handler; | 211 LoadTestMessageHandler handler; |
| 159 bool ok = RunJavascriptTest(TestURL(test_file), &handler); | 212 bool ok = RunJavascriptTest(TestURL(test_file), &handler); |
| 160 ASSERT_TRUE(ok) << handler.error_message(); | 213 ASSERT_TRUE(ok) << handler.error_message(); |
| 161 ASSERT_TRUE(handler.test_passed()) << "Test failed."; | 214 ASSERT_TRUE(handler.test_passed()) << "Test failed."; |
| 162 } | 215 } |
| 163 | 216 |
| 217 void NaClBrowserTestBase::RunNaClIntegrationTest( | |
| 218 const FilePath::StringType& test_file) { | |
| 219 NaClIntegrationMessageHandler handler; | |
| 220 bool ok = RunJavascriptTest(TestURL(test_file), &handler); | |
| 221 ASSERT_TRUE(ok) << handler.error_message(); | |
| 222 ASSERT_TRUE(handler.test_passed()) << "Test failed."; | |
| 223 } | |
| 224 | |
| 164 bool NaClBrowserTestBase::StartTestServer() { | 225 bool NaClBrowserTestBase::StartTestServer() { |
| 165 // Launch the web server. | 226 // Launch the web server. |
| 166 FilePath document_root; | 227 FilePath document_root; |
| 167 if (!GetNaClVariantRoot(Variant(), &document_root)) | 228 if (!GetNaClVariantRoot(Variant(), &document_root)) |
| 168 return false; | 229 return false; |
| 169 test_server_.reset(new net::TestServer(net::TestServer::TYPE_HTTP, | 230 test_server_.reset(new net::TestServer(net::TestServer::TYPE_HTTP, |
| 170 net::TestServer::kLocalhost, | 231 net::TestServer::kLocalhost, |
| 171 document_root)); | 232 document_root)); |
| 172 return test_server_->Start(); | 233 return test_server_->Start(); |
| 173 } | 234 } |
| 174 | 235 |
| 175 FilePath::StringType NaClBrowserTestNewlib::Variant() { | 236 FilePath::StringType NaClBrowserTestNewlib::Variant() { |
| 176 return FILE_PATH_LITERAL("newlib"); | 237 return FILE_PATH_LITERAL("newlib"); |
| 177 } | 238 } |
| 178 | 239 |
| 179 FilePath::StringType NaClBrowserTestGLibc::Variant() { | 240 FilePath::StringType NaClBrowserTestGLibc::Variant() { |
| 180 return FILE_PATH_LITERAL("glibc"); | 241 return FILE_PATH_LITERAL("glibc"); |
| 181 } | 242 } |
| OLD | NEW |