OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/public/test/ppapi_test_utils.h" | 5 #include "content/public/test/ppapi_test_utils.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "content/public/common/content_switches.h" | 11 #include "content/public/common/content_switches.h" |
| 12 #include "ppapi/shared_impl/ppapi_constants.h" |
12 | 13 |
13 namespace ppapi { | 14 namespace ppapi { |
14 | 15 |
| 16 namespace { |
| 17 |
| 18 bool RegisterPlugin( |
| 19 base::CommandLine* command_line, |
| 20 const base::FilePath::StringType& library_name, |
| 21 const base::FilePath::StringType& extra_registration_parameters) { |
| 22 base::FilePath plugin_dir; |
| 23 if (!PathService::Get(base::DIR_MODULE, &plugin_dir)) |
| 24 return false; |
| 25 |
| 26 base::FilePath plugin_path = plugin_dir.Append(library_name); |
| 27 |
| 28 // Append the switch to register the pepper plugin. |
| 29 if (!base::PathExists(plugin_path)) |
| 30 return false; |
| 31 base::FilePath::StringType pepper_plugin = plugin_path.value(); |
| 32 pepper_plugin.append(extra_registration_parameters); |
| 33 pepper_plugin.append(FILE_PATH_LITERAL(";application/x-ppapi-tests")); |
| 34 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins, |
| 35 pepper_plugin); |
| 36 return true; |
| 37 } |
| 38 |
| 39 } // namespace |
| 40 |
15 std::string StripTestPrefixes(const std::string& test_name) { | 41 std::string StripTestPrefixes(const std::string& test_name) { |
16 if (test_name.find("DISABLED_") == 0) | 42 if (test_name.find("DISABLED_") == 0) |
17 return test_name.substr(strlen("DISABLED_")); | 43 return test_name.substr(strlen("DISABLED_")); |
18 return test_name; | 44 return test_name; |
19 } | 45 } |
20 | 46 |
21 bool RegisterTestPlugin(base::CommandLine* command_line) { | 47 bool RegisterTestPlugin(base::CommandLine* command_line) { |
22 return RegisterTestPluginWithExtraParameters(command_line, | 48 return RegisterTestPluginWithExtraParameters(command_line, |
23 FILE_PATH_LITERAL("")); | 49 FILE_PATH_LITERAL("")); |
24 } | 50 } |
25 | 51 |
26 bool RegisterTestPluginWithExtraParameters( | 52 bool RegisterTestPluginWithExtraParameters( |
27 base::CommandLine* command_line, | 53 base::CommandLine* command_line, |
28 const base::FilePath::StringType& extra_registration_parameters) { | 54 const base::FilePath::StringType& extra_registration_parameters) { |
29 base::FilePath plugin_dir; | 55 #if defined(OS_WIN) |
30 if (!PathService::Get(base::DIR_MODULE, &plugin_dir)) | 56 base::FilePath::StringType plugin_library = L"ppapi_tests.dll"; |
31 return false; | 57 #elif defined(OS_MACOSX) |
| 58 base::FilePath::StringType plugin_library = "ppapi_tests.plugin"; |
| 59 #elif defined(OS_POSIX) |
| 60 base::FilePath::StringType plugin_library = "libppapi_tests.so"; |
| 61 #endif |
| 62 return RegisterPlugin(command_line, plugin_library, |
| 63 extra_registration_parameters); |
| 64 } |
32 | 65 |
33 #if defined(OS_WIN) | 66 bool RegisterPowerSaverTestPlugin(base::CommandLine* command_line) { |
34 base::FilePath plugin_path = plugin_dir.Append(L"ppapi_tests.dll"); | 67 base::FilePath::StringType library_name = |
35 #elif defined(OS_MACOSX) | 68 base::FilePath::FromUTF8Unsafe(ppapi::kPowerSaverTestPluginName).value(); |
36 base::FilePath plugin_path = plugin_dir.Append("ppapi_tests.plugin"); | 69 return RegisterPlugin(command_line, library_name, FILE_PATH_LITERAL("")); |
37 #elif defined(OS_POSIX) | |
38 base::FilePath plugin_path = plugin_dir.Append("libppapi_tests.so"); | |
39 #endif | |
40 | |
41 // Append the switch to register the pepper plugin. | |
42 if (!base::PathExists(plugin_path)) | |
43 return false; | |
44 base::FilePath::StringType pepper_plugin = plugin_path.value(); | |
45 pepper_plugin.append(extra_registration_parameters); | |
46 pepper_plugin.append(FILE_PATH_LITERAL(";application/x-ppapi-tests")); | |
47 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins, | |
48 pepper_plugin); | |
49 return true; | |
50 } | 70 } |
51 | 71 |
52 } // namespace ppapi | 72 } // namespace ppapi |
OLD | NEW |