[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / content / test / ppapi / ppapi_test.cc
blob20d4c6dc8ac367823d4b8736cc798354c3313708
1 // Copyright 2014 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.
5 #include "content/test/ppapi/ppapi_test.h"
7 #include "base/command_line.h"
8 #include "base/file_util.h"
9 #include "base/files/file_path.h"
10 #include "base/path_service.h"
11 #include "base/strings/string_util.h"
12 #include "base/strings/stringprintf.h"
13 #include "content/public/browser/web_contents.h"
14 #include "content/public/common/content_switches.h"
15 #include "content/shell/browser/shell.h"
16 #include "net/base/filename_util.h"
17 #include "ppapi/shared_impl/ppapi_switches.h"
18 #include "ppapi/shared_impl/test_harness_utils.h"
20 namespace content {
22 PPAPITestMessageHandler::PPAPITestMessageHandler() {
25 TestMessageHandler::MessageResponse PPAPITestMessageHandler::HandleMessage(
26 const std::string& json) {
27 std::string trimmed;
28 base::TrimString(json, "\"", &trimmed);
29 if (trimmed == "...")
30 return CONTINUE;
31 message_ = trimmed;
32 return DONE;
35 void PPAPITestMessageHandler::Reset() {
36 TestMessageHandler::Reset();
37 message_.clear();
40 PPAPITestBase::PPAPITestBase() { }
42 void PPAPITestBase::SetUpCommandLine(base::CommandLine* command_line) {
43 // The test sends us the result via a cookie.
44 command_line->AppendSwitch(switches::kEnableFileCookies);
46 // Some stuff is hung off of the testing interface which is not enabled
47 // by default.
48 command_line->AppendSwitch(switches::kEnablePepperTesting);
50 // Smooth scrolling confuses the scrollbar test.
51 command_line->AppendSwitch(switches::kDisableSmoothScrolling);
54 GURL PPAPITestBase::GetTestFileUrl(const std::string& test_case) {
55 base::FilePath test_path;
56 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_path));
57 test_path = test_path.Append(FILE_PATH_LITERAL("ppapi"));
58 test_path = test_path.Append(FILE_PATH_LITERAL("tests"));
59 test_path = test_path.Append(FILE_PATH_LITERAL("test_case.html"));
61 // Sanity check the file name.
62 EXPECT_TRUE(base::PathExists(test_path));
63 GURL test_url = net::FilePathToFileURL(test_path);
65 GURL::Replacements replacements;
66 std::string query = BuildQuery(std::string(), test_case);
67 replacements.SetQuery(query.c_str(), url::Component(0, query.size()));
68 return test_url.ReplaceComponents(replacements);
71 void PPAPITestBase::RunTest(const std::string& test_case) {
72 GURL url = GetTestFileUrl(test_case);
73 RunTestURL(url);
76 void PPAPITestBase::RunTestAndReload(const std::string& test_case) {
77 GURL url = GetTestFileUrl(test_case);
78 RunTestURL(url);
79 // If that passed, we simply run the test again, which navigates again.
80 RunTestURL(url);
83 void PPAPITestBase::RunTestURL(const GURL& test_url) {
84 // See comment above TestingInstance in ppapi/test/testing_instance.h.
85 // Basically it sends messages using the DOM automation controller. The
86 // value of "..." means it's still working and we should continue to wait,
87 // any other value indicates completion (in this case it will start with
88 // "PASS" or "FAIL"). This keeps us from timing out on waits for long tests.
89 PPAPITestMessageHandler handler;
90 JavascriptTestObserver observer(shell()->web_contents(), &handler);
91 shell()->LoadURL(test_url);
93 ASSERT_TRUE(observer.Run()) << handler.error_message();
94 EXPECT_STREQ("PASS", handler.message().c_str());
97 PPAPITest::PPAPITest() : in_process_(true) {
100 void PPAPITest::SetUpCommandLine(base::CommandLine* command_line) {
101 PPAPITestBase::SetUpCommandLine(command_line);
103 // Append the switch to register the pepper plugin.
104 // library name = <out dir>/<test_name>.<library_extension>
105 // MIME type = application/x-ppapi-<test_name>
106 base::FilePath plugin_dir;
107 EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir));
109 base::FilePath plugin_lib = plugin_dir.Append(ppapi::GetTestLibraryName());
110 EXPECT_TRUE(base::PathExists(plugin_lib));
111 base::FilePath::StringType pepper_plugin = plugin_lib.value();
112 pepper_plugin.append(FILE_PATH_LITERAL(";application/x-ppapi-tests"));
113 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins,
114 pepper_plugin);
116 if (in_process_)
117 command_line->AppendSwitch(switches::kPpapiInProcess);
120 std::string PPAPITest::BuildQuery(const std::string& base,
121 const std::string& test_case){
122 return base::StringPrintf("%stestcase=%s", base.c_str(), test_case.c_str());
125 OutOfProcessPPAPITest::OutOfProcessPPAPITest() {
126 in_process_ = false;
129 } // namespace content