Removing uses of X11 native key events.
[chromium-blink-merge.git] / content / test / ppapi / ppapi_test.cc
blob0807b6138b8a7576587ecdbf59f28121e33c23e9
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/files/file_path.h"
9 #include "base/files/file_util.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);
53 // Allow manual garbage collection.
54 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose_gc");
57 GURL PPAPITestBase::GetTestFileUrl(const std::string& test_case) {
58 base::FilePath test_path;
59 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_path));
60 test_path = test_path.Append(FILE_PATH_LITERAL("ppapi"));
61 test_path = test_path.Append(FILE_PATH_LITERAL("tests"));
62 test_path = test_path.Append(FILE_PATH_LITERAL("test_case.html"));
64 // Sanity check the file name.
65 EXPECT_TRUE(base::PathExists(test_path));
66 GURL test_url = net::FilePathToFileURL(test_path);
68 GURL::Replacements replacements;
69 std::string query = BuildQuery(std::string(), test_case);
70 replacements.SetQuery(query.c_str(), url::Component(0, query.size()));
71 return test_url.ReplaceComponents(replacements);
74 void PPAPITestBase::RunTest(const std::string& test_case) {
75 GURL url = GetTestFileUrl(test_case);
76 RunTestURL(url);
79 void PPAPITestBase::RunTestAndReload(const std::string& test_case) {
80 GURL url = GetTestFileUrl(test_case);
81 RunTestURL(url);
82 // If that passed, we simply run the test again, which navigates again.
83 RunTestURL(url);
86 void PPAPITestBase::RunTestURL(const GURL& test_url) {
87 // See comment above TestingInstance in ppapi/test/testing_instance.h.
88 // Basically it sends messages using the DOM automation controller. The
89 // value of "..." means it's still working and we should continue to wait,
90 // any other value indicates completion (in this case it will start with
91 // "PASS" or "FAIL"). This keeps us from timing out on waits for long tests.
92 PPAPITestMessageHandler handler;
93 JavascriptTestObserver observer(shell()->web_contents(), &handler);
94 shell()->LoadURL(test_url);
96 ASSERT_TRUE(observer.Run()) << handler.error_message();
97 EXPECT_STREQ("PASS", handler.message().c_str());
100 PPAPITest::PPAPITest() : in_process_(true) {
103 void PPAPITest::SetUpCommandLine(base::CommandLine* command_line) {
104 PPAPITestBase::SetUpCommandLine(command_line);
106 // Append the switch to register the pepper plugin.
107 // library name = <out dir>/<test_name>.<library_extension>
108 // MIME type = application/x-ppapi-<test_name>
109 base::FilePath plugin_dir;
110 EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir));
112 base::FilePath plugin_lib = plugin_dir.Append(ppapi::GetTestLibraryName());
113 EXPECT_TRUE(base::PathExists(plugin_lib));
114 base::FilePath::StringType pepper_plugin = plugin_lib.value();
115 pepper_plugin.append(FILE_PATH_LITERAL(";application/x-ppapi-tests"));
116 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins,
117 pepper_plugin);
119 if (in_process_)
120 command_line->AppendSwitch(switches::kPpapiInProcess);
123 std::string PPAPITest::BuildQuery(const std::string& base,
124 const std::string& test_case){
125 return base::StringPrintf("%stestcase=%s", base.c_str(), test_case.c_str());
128 OutOfProcessPPAPITest::OutOfProcessPPAPITest() {
129 in_process_ = false;
132 } // namespace content