Chromium Code Reviews| Index: chrome/test/ui/ppapi_uitest.cc |
| =================================================================== |
| --- chrome/test/ui/ppapi_uitest.cc (revision 126897) |
| +++ chrome/test/ui/ppapi_uitest.cc (working copy) |
| @@ -2,6 +2,8 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include "chrome/test/ui/ppapi_uitest.h" |
| + |
| #include "base/command_line.h" |
| #include "base/file_util.h" |
| #include "base/path_service.h" |
| @@ -110,231 +112,203 @@ |
| } // namespace |
| -class PPAPITestBase : public InProcessBrowserTest { |
| - public: |
| - PPAPITestBase() { |
| - EnableDOMAutomation(); |
| - } |
| +PPAPITestBase::PPAPITestBase() { |
| + EnableDOMAutomation(); |
| +} |
| - virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| - // The test sends us the result via a cookie. |
| - command_line->AppendSwitch(switches::kEnableFileCookies); |
| +void PPAPITestBase::SetUpCommandLine(CommandLine* command_line) { |
| + // The test sends us the result via a cookie. |
| + command_line->AppendSwitch(switches::kEnableFileCookies); |
| - // Some stuff is hung off of the testing interface which is not enabled |
| - // by default. |
| - command_line->AppendSwitch(switches::kEnablePepperTesting); |
| + // Some stuff is hung off of the testing interface which is not enabled |
| + // by default. |
| + command_line->AppendSwitch(switches::kEnablePepperTesting); |
| - // Smooth scrolling confuses the scrollbar test. |
| - command_line->AppendSwitch(switches::kDisableSmoothScrolling); |
| - } |
| + // Smooth scrolling confuses the scrollbar test. |
| + command_line->AppendSwitch(switches::kDisableSmoothScrolling); |
| +} |
| - virtual std::string BuildQuery(const std::string& base, |
| - const std::string& test_case) = 0; |
| +GURL PPAPITestBase::GetTestFileUrl(const std::string& test_case) { |
| + FilePath test_path; |
| + EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_path)); |
| + test_path = test_path.Append(FILE_PATH_LITERAL("ppapi")); |
| + test_path = test_path.Append(FILE_PATH_LITERAL("tests")); |
| + test_path = test_path.Append(FILE_PATH_LITERAL("test_case.html")); |
| - // Returns the URL to load for file: tests. |
| - GURL GetTestFileUrl(const std::string& test_case) { |
| - FilePath test_path; |
| - EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_path)); |
| - test_path = test_path.Append(FILE_PATH_LITERAL("ppapi")); |
| - test_path = test_path.Append(FILE_PATH_LITERAL("tests")); |
| - test_path = test_path.Append(FILE_PATH_LITERAL("test_case.html")); |
| + // Sanity check the file name. |
| + EXPECT_TRUE(file_util::PathExists(test_path)); |
| - // Sanity check the file name. |
| - EXPECT_TRUE(file_util::PathExists(test_path)); |
| + GURL test_url = net::FilePathToFileURL(test_path); |
| - GURL test_url = net::FilePathToFileURL(test_path); |
| + GURL::Replacements replacements; |
| + std::string query = BuildQuery("", test_case); |
| + replacements.SetQuery(query.c_str(), url_parse::Component(0, query.size())); |
| + return test_url.ReplaceComponents(replacements); |
| +} |
| - GURL::Replacements replacements; |
| - std::string query = BuildQuery("", test_case); |
| - replacements.SetQuery(query.c_str(), url_parse::Component(0, query.size())); |
| - return test_url.ReplaceComponents(replacements); |
| - } |
| +void PPAPITestBase::RunTest(const std::string& test_case) { |
| + GURL url = GetTestFileUrl(test_case); |
| + RunTestURL(url); |
| +} |
| - void RunTest(const std::string& test_case) { |
| - GURL url = GetTestFileUrl(test_case); |
| - RunTestURL(url); |
| - } |
| +void PPAPITestBase::RunTestViaHTTP(const std::string& test_case) { |
| + // For HTTP tests, we use the output DIR to grab the generated files such |
| + // as the NEXEs. |
| + FilePath exe_dir = CommandLine::ForCurrentProcess()->GetProgram().DirName(); |
| + FilePath src_dir; |
| + ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)); |
| + // TestServer expects a path relative to source. So we must first |
|
Mark Seaborn
2012/03/16 17:47:11
You've changed the whitespace with your move here.
halyavin
2012/03/16 17:57:42
Done.
|
| + // generate absolute paths to SRC and EXE and from there generate |
| + // a relative path. |
| + if (!exe_dir.IsAbsolute()) file_util::AbsolutePath(&exe_dir); |
| + if (!src_dir.IsAbsolute()) file_util::AbsolutePath(&src_dir); |
| + ASSERT_TRUE(exe_dir.IsAbsolute()); |
| + ASSERT_TRUE(src_dir.IsAbsolute()); |
| - void RunTestViaHTTP(const std::string& test_case) { |
| - // For HTTP tests, we use the output DIR to grab the generated files such |
| - // as the NEXEs. |
| - FilePath exe_dir = CommandLine::ForCurrentProcess()->GetProgram().DirName(); |
| - FilePath src_dir; |
| - ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)); |
| + size_t match, exe_size, src_size; |
| + std::vector<FilePath::StringType> src_parts, exe_parts; |
| - // TestServer expects a path relative to source. So we must first |
| - // generate absolute paths to SRC and EXE and from there generate |
| - // a relative path. |
| - if (!exe_dir.IsAbsolute()) file_util::AbsolutePath(&exe_dir); |
| - if (!src_dir.IsAbsolute()) file_util::AbsolutePath(&src_dir); |
| - ASSERT_TRUE(exe_dir.IsAbsolute()); |
| - ASSERT_TRUE(src_dir.IsAbsolute()); |
| - |
| - size_t match, exe_size, src_size; |
| - std::vector<FilePath::StringType> src_parts, exe_parts; |
| - |
| - // Determine point at which src and exe diverge, and create a relative path. |
| - exe_dir.GetComponents(&exe_parts); |
| - src_dir.GetComponents(&src_parts); |
| - exe_size = exe_parts.size(); |
| - src_size = src_parts.size(); |
| - for (match = 0; match < exe_size && match < src_size; ++match) { |
| - if (exe_parts[match] != src_parts[match]) |
| - break; |
| - } |
| - FilePath web_dir; |
| - for (size_t tmp_itr = match; tmp_itr < src_size; ++tmp_itr) { |
| - web_dir = web_dir.Append(FILE_PATH_LITERAL("..")); |
| - } |
| - for (; match < exe_size; ++match) { |
| - web_dir = web_dir.Append(exe_parts[match]); |
| - } |
| - |
| - net::TestServer test_server(net::TestServer::TYPE_HTTP, |
| - net::TestServer::kLocalhost, |
| - web_dir); |
| - ASSERT_TRUE(test_server.Start()); |
| - std::string query = BuildQuery("files/test_case.html?", test_case); |
| - |
| - GURL url = test_server.GetURL(query); |
| - RunTestURL(url); |
| + // Determine point at which src and exe diverge, and create a relative path. |
| + exe_dir.GetComponents(&exe_parts); |
| + src_dir.GetComponents(&src_parts); |
| + exe_size = exe_parts.size(); |
| + src_size = src_parts.size(); |
| + for (match = 0; match < exe_size && match < src_size; ++match) { |
| + if (exe_parts[match] != src_parts[match]) |
| + break; |
| } |
| + FilePath web_dir; |
| + for (size_t tmp_itr = match; tmp_itr < src_size; ++tmp_itr) { |
| + web_dir = web_dir.Append(FILE_PATH_LITERAL("..")); |
| + } |
| + for (; match < exe_size; ++match) { |
| + web_dir = web_dir.Append(exe_parts[match]); |
| + } |
| - void RunTestWithWebSocketServer(const std::string& test_case) { |
| - FilePath websocket_root_dir; |
| - ASSERT_TRUE( |
| - PathService::Get(chrome::DIR_LAYOUT_TESTS, &websocket_root_dir)); |
| + net::TestServer test_server(net::TestServer::TYPE_HTTP, |
| + net::TestServer::kLocalhost, |
| + web_dir); |
| + ASSERT_TRUE(test_server.Start()); |
| + std::string query = BuildQuery("files/test_case.html?", test_case); |
| - ui_test_utils::TestWebSocketServer server; |
| - ASSERT_TRUE(server.Start(websocket_root_dir)); |
| - RunTestViaHTTP(test_case); |
| - } |
| + GURL url = test_server.GetURL(query); |
| + RunTestURL(url); |
| +} |
| - std::string StripPrefixes(const std::string& test_name) { |
| - const char* const prefixes[] = { "FAILS_", "FLAKY_", "DISABLED_" }; |
| - for (size_t i = 0; i < sizeof(prefixes)/sizeof(prefixes[0]); ++i) |
| - if (test_name.find(prefixes[i]) == 0) |
| - return test_name.substr(strlen(prefixes[i])); |
| - return test_name; |
| - } |
| +void PPAPITestBase::RunTestWithWebSocketServer(const std::string& test_case) { |
| + FilePath websocket_root_dir; |
| + ASSERT_TRUE( |
| + PathService::Get(chrome::DIR_LAYOUT_TESTS, &websocket_root_dir)); |
| - protected: |
| - // Runs the test for a tab given the tab that's already navigated to the |
| - // given URL. |
| - void RunTestURL(const GURL& test_url) { |
| - // See comment above TestingInstance in ppapi/test/testing_instance.h. |
| - // Basically it sends messages using the DOM automation controller. The |
| - // value of "..." means it's still working and we should continue to wait, |
| - // any other value indicates completion (in this case it will start with |
| - // "PASS" or "FAIL"). This keeps us from timing out on waits for long tests. |
| - TestFinishObserver observer( |
| - browser()->GetSelectedWebContents()->GetRenderViewHost(), kTimeoutMs); |
| + ui_test_utils::TestWebSocketServer server; |
| + ASSERT_TRUE(server.Start(websocket_root_dir)); |
| + RunTestViaHTTP(test_case); |
| +} |
| - ui_test_utils::NavigateToURL(browser(), test_url); |
| +std::string PPAPITestBase::StripPrefixes(const std::string& test_name) { |
| + const char* const prefixes[] = { "FAILS_", "FLAKY_", "DISABLED_" }; |
| + for (size_t i = 0; i < sizeof(prefixes)/sizeof(prefixes[0]); ++i) |
| + if (test_name.find(prefixes[i]) == 0) |
| + return test_name.substr(strlen(prefixes[i])); |
| + return test_name; |
| +} |
| - ASSERT_TRUE(observer.WaitForFinish()) << "Test timed out."; |
| +void PPAPITestBase::RunTestURL(const GURL& test_url) { |
| + // See comment above TestingInstance in ppapi/test/testing_instance.h. |
| + // Basically it sends messages using the DOM automation controller. The |
| + // value of "..." means it's still working and we should continue to wait, |
| + // any other value indicates completion (in this case it will start with |
| + // "PASS" or "FAIL"). This keeps us from timing out on waits for long tests. |
| + TestFinishObserver observer( |
| + browser()->GetSelectedWebContents()->GetRenderViewHost(), kTimeoutMs); |
| - EXPECT_STREQ("PASS", observer.result().c_str()); |
| - } |
| -}; |
| + ui_test_utils::NavigateToURL(browser(), test_url); |
| -// In-process plugin test runner. See OutOfProcessPPAPITest below for the |
| -// out-of-process version. |
| -class PPAPITest : public PPAPITestBase { |
| - public: |
| - PPAPITest() { |
| - } |
| + ASSERT_TRUE(observer.WaitForFinish()) << "Test timed out."; |
| - virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| - PPAPITestBase::SetUpCommandLine(command_line); |
| + EXPECT_STREQ("PASS", observer.result().c_str()); |
| +} |
| - // Append the switch to register the pepper plugin. |
| - // library name = <out dir>/<test_name>.<library_extension> |
| - // MIME type = application/x-ppapi-<test_name> |
| - FilePath plugin_dir; |
| - EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir)); |
| +PPAPITest::PPAPITest() { |
| +} |
| - FilePath plugin_lib = plugin_dir.Append(library_name); |
| - EXPECT_TRUE(file_util::PathExists(plugin_lib)); |
| - FilePath::StringType pepper_plugin = plugin_lib.value(); |
| - pepper_plugin.append(FILE_PATH_LITERAL(";application/x-ppapi-tests")); |
| - command_line->AppendSwitchNative(switches::kRegisterPepperPlugins, |
| - pepper_plugin); |
| - command_line->AppendSwitchASCII(switches::kAllowNaClSocketAPI, "127.0.0.1"); |
| - } |
| +void PPAPITest::SetUpCommandLine(CommandLine* command_line) { |
| + PPAPITestBase::SetUpCommandLine(command_line); |
| - std::string BuildQuery(const std::string& base, |
| - const std::string& test_case){ |
| - return StringPrintf("%stestcase=%s", base.c_str(), test_case.c_str()); |
| - } |
| + // Append the switch to register the pepper plugin. |
| + // library name = <out dir>/<test_name>.<library_extension> |
| + // MIME type = application/x-ppapi-<test_name> |
| + FilePath plugin_dir; |
| + EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir)); |
| -}; |
| + FilePath plugin_lib = plugin_dir.Append(library_name); |
| + EXPECT_TRUE(file_util::PathExists(plugin_lib)); |
| + FilePath::StringType pepper_plugin = plugin_lib.value(); |
| + pepper_plugin.append(FILE_PATH_LITERAL(";application/x-ppapi-tests")); |
| + command_line->AppendSwitchNative(switches::kRegisterPepperPlugins, |
| + pepper_plugin); |
| + command_line->AppendSwitchASCII(switches::kAllowNaClSocketAPI, "127.0.0.1"); |
| +} |
| -// Variant of PPAPITest that runs plugins out-of-process to test proxy |
| -// codepaths. |
| -class OutOfProcessPPAPITest : public PPAPITest { |
| - public: |
| - OutOfProcessPPAPITest() { |
| +std::string PPAPITest::BuildQuery(const std::string& base, |
| + const std::string& test_case){ |
| + return StringPrintf("%stestcase=%s", base.c_str(), test_case.c_str()); |
| +} |
| - } |
| +OutOfProcessPPAPITest::OutOfProcessPPAPITest() { |
| +} |
| - virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| - PPAPITest::SetUpCommandLine(command_line); |
| +void OutOfProcessPPAPITest::SetUpCommandLine(CommandLine* command_line) { |
| + PPAPITest::SetUpCommandLine(command_line); |
| - // Run PPAPI out-of-process to exercise proxy implementations. |
| - command_line->AppendSwitch(switches::kPpapiOutOfProcess); |
| - } |
| -}; |
| + // Run PPAPI out-of-process to exercise proxy implementations. |
| + command_line->AppendSwitch(switches::kPpapiOutOfProcess); |
| +} |
| -// NaCl plugin test runner. |
| -class PPAPINaClTest : public PPAPITestBase { |
| - public: |
| - PPAPINaClTest() { |
| - } |
| +PPAPINaClTest::PPAPINaClTest() { |
| +} |
| - virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| - PPAPITestBase::SetUpCommandLine(command_line); |
| +void PPAPINaClTest::SetUpCommandLine(CommandLine* command_line) { |
| + PPAPITestBase::SetUpCommandLine(command_line); |
| - FilePath plugin_lib; |
| - EXPECT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib)); |
| - EXPECT_TRUE(file_util::PathExists(plugin_lib)); |
| + FilePath plugin_lib; |
| + EXPECT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib)); |
| + EXPECT_TRUE(file_util::PathExists(plugin_lib)); |
| - // Enable running NaCl outside of the store. |
| - command_line->AppendSwitch(switches::kEnableNaCl); |
| - command_line->AppendSwitchASCII(switches::kAllowNaClSocketAPI, "127.0.0.1"); |
| - } |
| + // Enable running NaCl outside of the store. |
| + command_line->AppendSwitch(switches::kEnableNaCl); |
| + command_line->AppendSwitchASCII(switches::kAllowNaClSocketAPI, "127.0.0.1"); |
| +} |
| - // Append the correct mode and testcase string |
| - std::string BuildQuery(const std::string& base, |
| - const std::string& test_case) { |
| - return StringPrintf("%smode=nacl&testcase=%s", base.c_str(), |
| - test_case.c_str()); |
| - } |
| -}; |
| +// Append the correct mode and testcase string |
| +std::string PPAPINaClTest::BuildQuery(const std::string& base, |
| + const std::string& test_case) { |
| + return StringPrintf("%smode=nacl&testcase=%s", base.c_str(), |
| + test_case.c_str()); |
| +} |
| -class PPAPINaClTestDisallowedSockets : public PPAPITestBase { |
| - public: |
| - PPAPINaClTestDisallowedSockets() { |
| - } |
| +PPAPINaClTestDisallowedSockets::PPAPINaClTestDisallowedSockets() { |
| +} |
| - virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| - PPAPITestBase::SetUpCommandLine(command_line); |
| +void PPAPINaClTestDisallowedSockets::SetUpCommandLine( |
| + CommandLine* command_line) { |
| + PPAPITestBase::SetUpCommandLine(command_line); |
| - FilePath plugin_lib; |
| - EXPECT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib)); |
| - EXPECT_TRUE(file_util::PathExists(plugin_lib)); |
| + FilePath plugin_lib; |
| + EXPECT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib)); |
| + EXPECT_TRUE(file_util::PathExists(plugin_lib)); |
| - // Enable running NaCl outside of the store. |
| - command_line->AppendSwitch(switches::kEnableNaCl); |
| - } |
| + // Enable running NaCl outside of the store. |
| + command_line->AppendSwitch(switches::kEnableNaCl); |
| +} |
| - // Append the correct mode and testcase string |
| - std::string BuildQuery(const std::string& base, |
| - const std::string& test_case) { |
| - return StringPrintf("%smode=nacl&testcase=%s", base.c_str(), |
| - test_case.c_str()); |
| - } |
| -}; |
| +// Append the correct mode and testcase string |
| +std::string PPAPINaClTestDisallowedSockets::BuildQuery( |
| + const std::string& base, |
| + const std::string& test_case) { |
| + return StringPrintf("%smode=nacl&testcase=%s", base.c_str(), |
| + test_case.c_str()); |
| +} |
| // This macro finesses macro expansion to do what we want. |
| #define STRIP_PREFIXES(test_name) StripPrefixes(#test_name) |