| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/test/nacl/nacl_test.h" | |
| 6 | |
| 7 #include "base/file_util.h" | |
| 8 #include "base/path_service.h" | |
| 9 #include "chrome/common/chrome_paths.h" | |
| 10 #include "chrome/common/chrome_switches.h" | |
| 11 #include "chrome/test/automation/tab_proxy.h" | |
| 12 #include "native_client/src/trusted/platform_qualify/nacl_os_qualify.h" | |
| 13 #include "net/base/escape.h" | |
| 14 #include "net/base/net_util.h" | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 const char kTestCompleteCookie[] = "status"; | |
| 19 const char kTestCompleteSuccess[] = "OK"; | |
| 20 | |
| 21 const FilePath::CharType kBaseUrl[] = | |
| 22 FILE_PATH_LITERAL("http://localhost:5103/tests/prebuilt"); | |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 26 NaClTest::NaClTest() | |
| 27 : use_x64_nexes_(false), | |
| 28 multiarch_test_(false), | |
| 29 http_server_(GetTestRootDir(), 5103) { | |
| 30 launch_arguments_.AppendSwitch(switches::kEnableNaCl); | |
| 31 | |
| 32 // Currently we disable some of the sandboxes. See: | |
| 33 // Make NaCl work in Chromium's Linux seccomp sandbox and the Mac sandbox | |
| 34 // http://code.google.com/p/nativeclient/issues/detail?id=344 | |
| 35 #if defined(OS_LINUX) | |
| 36 launch_arguments_.AppendSwitch(switches::kDisableSeccompSandbox); | |
| 37 #endif | |
| 38 launch_arguments_.AppendSwitchASCII(switches::kLoggingLevel, "0"); | |
| 39 } | |
| 40 | |
| 41 NaClTest::~NaClTest() {} | |
| 42 | |
| 43 // static | |
| 44 FilePath NaClTest::GetTestRootDir() { | |
| 45 FilePath path; | |
| 46 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &path)); | |
| 47 return path.AppendASCII("native_client"); | |
| 48 } | |
| 49 | |
| 50 GURL NaClTest::GetTestUrl(const FilePath& filename) { | |
| 51 FilePath path(kBaseUrl); | |
| 52 // Multiarch tests are in the directory defined by kBaseUrl. | |
| 53 if (!multiarch_test_) { | |
| 54 if (use_x64_nexes_) | |
| 55 path = path.AppendASCII("x64"); | |
| 56 else | |
| 57 path = path.AppendASCII("x86"); | |
| 58 } | |
| 59 path = path.Append(filename); | |
| 60 return GURL(path.value()); | |
| 61 } | |
| 62 | |
| 63 void NaClTest::WaitForFinish(const FilePath& filename, | |
| 64 int wait_time) { | |
| 65 GURL url = GetTestUrl(filename); | |
| 66 scoped_refptr<TabProxy> tab(GetActiveTab()); | |
| 67 ASSERT_TRUE(tab.get()); | |
| 68 bool test_result = WaitUntilCookieValue(tab.get(), | |
| 69 url, | |
| 70 kTestCompleteCookie, | |
| 71 wait_time, | |
| 72 kTestCompleteSuccess); | |
| 73 EXPECT_TRUE(test_result); | |
| 74 } | |
| 75 | |
| 76 void NaClTest::RunTest(const FilePath& filename, int timeout) { | |
| 77 GURL url = GetTestUrl(filename); | |
| 78 NavigateToURL(url); | |
| 79 WaitForFinish(filename, timeout); | |
| 80 } | |
| 81 | |
| 82 void NaClTest::RunMultiarchTest(const FilePath& filename, int timeout) { | |
| 83 multiarch_test_ = true; | |
| 84 RunTest(filename, timeout); | |
| 85 } | |
| 86 | |
| 87 void NaClTest::SetUp() { | |
| 88 FilePath nacl_test_dir = GetTestRootDir(); | |
| 89 #if defined(OS_WIN) | |
| 90 if (NaClOsIs64BitWindows()) | |
| 91 use_x64_nexes_ = true; | |
| 92 #elif defined(OS_LINUX) && defined(__LP64__) | |
| 93 use_x64_nexes_ = true; | |
| 94 #endif | |
| 95 | |
| 96 UITest::SetUp(); | |
| 97 | |
| 98 ASSERT_TRUE(http_server_.Start()); | |
| 99 } | |
| 100 | |
| 101 void NaClTest::TearDown() { | |
| 102 ASSERT_TRUE(http_server_.Stop()); | |
| 103 UITest::TearDown(); | |
| 104 } | |
| OLD | NEW |