Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1261)

Unified Diff: chrome/test/nacl/nacl_browsertest_util.cc

Issue 10918152: Port nacl_integration exit_status test to browser_tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Edits Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/nacl/nacl_browsertest_util.cc
diff --git a/chrome/test/nacl/nacl_browsertest_util.cc b/chrome/test/nacl/nacl_browsertest_util.cc
index c2b7a0284c23e16482d53c4822f32ec46c1ee72c..c5be6066b8b45d76363a8ca2cf4004ef2c42266f 100644
--- a/chrome/test/nacl/nacl_browsertest_util.cc
+++ b/chrome/test/nacl/nacl_browsertest_util.cc
@@ -96,6 +96,66 @@ MessageResponse LoadTestMessageHandler::HandleStructuredMessage(
}
}
+// A message handler for nacl_integration tests ported to be browser_tests.
+// nacl_integration tests report to their test jig using a series of RPC calls
+// that are encoded as URL requests. When these tests run as browser_tests,
+// they make the same RPC requests, but use the automation channel instead of
+// 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.
+class NaClIntegrationMessageHandler : public StructuredMessageHandler {
+ public:
+ NaClIntegrationMessageHandler();
+
+ void Log(const std::string& message);
+
+ virtual MessageResponse HandleStructuredMessage(
+ const std::string& type,
+ base::DictionaryValue* msg) OVERRIDE;
+
+ bool test_passed() const {
+ return test_passed_;
+ }
+
+ private:
+ bool test_passed_;
+
+ DISALLOW_COPY_AND_ASSIGN(NaClIntegrationMessageHandler);
+};
+
+NaClIntegrationMessageHandler::NaClIntegrationMessageHandler()
+ : test_passed_(false) {
+}
+
+void NaClIntegrationMessageHandler::Log(const std::string& message) {
+ // TODO(ncbray) better logging.
+ LOG(INFO) << "|||| " << message;
+}
+
+MessageResponse NaClIntegrationMessageHandler::HandleStructuredMessage(
+ const std::string& type,
+ DictionaryValue* msg) {
+ if (type == "TestLog") {
+ std::string message;
+ if (!msg->GetString("message", &message))
+ return MissingField(type, "message");
+ Log(message);
+ return CONTINUE;
+ } else if (type == "Shutdown") {
+ std::string message;
+ if (!msg->GetString("message", &message))
+ return MissingField(type, "message");
+ if (!msg->GetBoolean("passed", &test_passed_))
+ return MissingField(type, "passed");
+ Log(message);
+ return DONE;
+ } else if (type == "Ping") {
+ return CONTINUE;
+ } else if (type == "JavaScriptIsAlive") {
+ return CONTINUE;
+ } else {
+ return InternalError("Unknown message type: " + type);
+ }
+}
+
// NaCl browser tests serve files out of the build directory because nexes and
// pexes are artifacts of the build. To keep things tidy, all test data is kept
// in a subdirectory. Several variants of a test may be run, for example when
@@ -136,13 +196,10 @@ void NaClBrowserTestBase::SetUpInProcessBrowserTestFixture() {
ASSERT_TRUE(StartTestServer()) << "Cannot start test server.";
}
-GURL NaClBrowserTestBase::TestURL(const FilePath::StringType& test_file) {
- FilePath real_path = test_server_->document_root().Append(test_file);
- EXPECT_TRUE(file_util::PathExists(real_path)) << real_path.value();
-
- FilePath url_path = FilePath(FILE_PATH_LITERAL("files"));
- url_path = url_path.Append(test_file);
- return test_server_->GetURL(url_path.MaybeAsASCII());
+GURL NaClBrowserTestBase::TestURL(const FilePath::StringType& url_fragment) {
+ FilePath expanded_url = FilePath(FILE_PATH_LITERAL("files"));
+ expanded_url = expanded_url.Append(url_fragment);
+ return test_server_->GetURL(expanded_url.MaybeAsASCII());
}
bool NaClBrowserTestBase::RunJavascriptTest(const GURL& url,
@@ -161,6 +218,14 @@ void NaClBrowserTestBase::RunLoadTest(const FilePath::StringType& test_file) {
ASSERT_TRUE(handler.test_passed()) << "Test failed.";
}
+void NaClBrowserTestBase::RunNaClIntegrationTest(
+ const FilePath::StringType& url_fragment) {
+ NaClIntegrationMessageHandler handler;
+ bool ok = RunJavascriptTest(TestURL(url_fragment), &handler);
+ ASSERT_TRUE(ok) << handler.error_message();
+ ASSERT_TRUE(handler.test_passed()) << "Test failed.";
+}
+
bool NaClBrowserTestBase::StartTestServer() {
// Launch the web server.
FilePath document_root;

Powered by Google App Engine
This is Rietveld 408576698