summaryrefslogtreecommitdiffstats
path: root/chrome/test/nacl
diff options
context:
space:
mode:
authorgregoryd@google.com <gregoryd@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-13 04:59:33 +0000
committergregoryd@google.com <gregoryd@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-13 04:59:33 +0000
commit6d2e6685cbbb2f9c503ae88f12ca93bfb462aa49 (patch)
tree9bf18ad3b1899fa0f5ddd6f1705d217a809e589a /chrome/test/nacl
parent5cc72b5b8a3677e3e22536a4547f2e2ae743f4f1 (diff)
downloadchromium_src-6d2e6685cbbb2f9c503ae88f12ca93bfb462aa49.zip
chromium_src-6d2e6685cbbb2f9c503ae88f12ca93bfb462aa49.tar.gz
chromium_src-6d2e6685cbbb2f9c503ae88f12ca93bfb462aa49.tar.bz2
This is a simple integration test that loads a simple nexe and verifies that Javascript can communicate with it. The required html, javascript and nexe files are checked in into the NaCl tree.
Review URL: http://codereview.chromium.org/272005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28796 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/nacl')
-rw-r--r--chrome/test/nacl/nacl_test.cc102
-rw-r--r--chrome/test/nacl/nacl_test.h35
2 files changed, 137 insertions, 0 deletions
diff --git a/chrome/test/nacl/nacl_test.cc b/chrome/test/nacl/nacl_test.cc
new file mode 100644
index 0000000..cf0e742
--- /dev/null
+++ b/chrome/test/nacl/nacl_test.cc
@@ -0,0 +1,102 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/test/nacl/nacl_test.h"
+
+#include "base/file_util.h"
+#include "chrome/common/chrome_paths.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/test/automation/tab_proxy.h"
+#include "net/base/escape.h"
+#include "net/base/net_util.h"
+
+const char kTestCompleteCookie[] = "status";
+const char kTestCompleteSuccess[] = "OK";
+
+static const FilePath::CharType kBaseUrl[] =
+ FILE_PATH_LITERAL("http://localhost:5103/");
+
+static const FilePath::CharType kSrpcHwHtmlFileName[] =
+ FILE_PATH_LITERAL("srpc_hw.html");
+static const FilePath::CharType kSrpcHwNexeFileName[] =
+ FILE_PATH_LITERAL("srpc_hw.nexe");
+
+NaClTest::NaClTest()
+ : UITest() {
+ launch_arguments_.AppendSwitch(switches::kInternalNaCl);
+ launch_arguments_.AppendSwitch(switches::kNoSandbox);
+}
+
+NaClTest::~NaClTest() {}
+
+FilePath NaClTest::GetTestRootDir() {
+ FilePath path;
+ PathService::Get(base::DIR_SOURCE_ROOT, &path);
+ path = path.AppendASCII("native_client");
+ path = path.AppendASCII("tests");
+ return path;
+}
+
+// Static
+GURL NaClTest::GetTestUrl(const FilePath& filename) {
+ FilePath path(kBaseUrl);
+ path = path.Append(filename);
+ return GURL(path.value());
+}
+
+
+// Waits for the test case to finish.
+void NaClTest::WaitForFinish(const FilePath& filename,
+ const int wait_time) {
+ GURL url = GetTestUrl(filename);
+ scoped_refptr<TabProxy> tab(GetActiveTab());
+ ASSERT_TRUE(tab.get());
+ bool test_result = WaitUntilCookieValue(tab.get(),
+ url,
+ kTestCompleteCookie,
+ action_timeout_ms(),
+ wait_time,
+ kTestCompleteSuccess);
+ EXPECT_TRUE(test_result);
+}
+
+void NaClTest::RunTest(const FilePath& filename, int timeout) {
+ GURL url = GetTestUrl(filename);
+ NavigateToURL(url);
+ WaitForFinish(filename, timeout);
+}
+
+void NaClTest::PrepareSrpcHwTest(FilePath test_root_dir) {
+ FilePath srpc_hw_dir = test_root_dir.AppendASCII("srpc_hw");
+ FilePath html_file = srpc_hw_dir.Append(kSrpcHwHtmlFileName);
+ FilePath nexe_file = srpc_hw_dir.Append(kSrpcHwNexeFileName);
+ ASSERT_TRUE(file_util::PathExists(html_file));
+ ASSERT_TRUE(file_util::PathExists(nexe_file));
+ // Now copy the files into the test directory
+ ASSERT_TRUE(file_util::CopyFile(
+ html_file,
+ test_root_dir.Append(kSrpcHwHtmlFileName)));
+ ASSERT_TRUE(file_util::CopyFile(
+ nexe_file,
+ test_root_dir.Append(kSrpcHwNexeFileName)));
+}
+
+void NaClTest::SetUp() {
+ FilePath nacl_test_dir = GetTestRootDir();
+ PrepareSrpcHwTest(nacl_test_dir);
+
+ UITest::SetUp();
+
+ StartHttpServerWithPort(nacl_test_dir, L"5103");
+}
+
+void NaClTest::TearDown() {
+ StopHttpServer();
+ UITest::TearDown();
+}
+
+TEST_F(NaClTest, SrpcHelloWorld) {
+ FilePath srpc_hw_file(kSrpcHwHtmlFileName);
+ RunTest(srpc_hw_file, action_max_timeout_ms());
+}
diff --git a/chrome/test/nacl/nacl_test.h b/chrome/test/nacl/nacl_test.h
new file mode 100644
index 0000000..7e82b951
--- /dev/null
+++ b/chrome/test/nacl/nacl_test.h
@@ -0,0 +1,35 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_TEST_NACL_NACL_TEST_H_
+#define CHROME_TEST_NACL_NACL_TEST_H_
+
+#include "chrome/test/ui/ui_test.h"
+
+class FilePath;
+
+// This class implements integration tests for Native Client.
+// For security reasons, Native Client currently loads modules from port 5103
+// only, therefore running the test currently requires starting
+// a local webserver on this port.
+// This limitation will be removed in the future.
+// Additional functionality used in this test is implemented in html and JS
+// files that are part of NaCl tree.
+class NaClTest : public UITest {
+ protected:
+ NaClTest();
+ virtual ~NaClTest();
+
+ FilePath GetTestRootDir();
+ // Waits for the test case to finish.
+ void WaitForFinish(const FilePath& filename, const int wait_time);
+ void RunTest(const FilePath& filename, int timeout);
+ void SetUp();
+ void TearDown();
+ GURL GetTestUrl(const FilePath& filename);
+ private:
+ void PrepareSrpcHwTest(FilePath test_root_dir);
+};
+
+#endif // CHROME_TEST_NACL_NACL_TEST_H_