| 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 #include "ppapi/shared_impl/ppapi_constants.h" |
| 13 | 13 |
| 14 namespace ppapi { | 14 namespace ppapi { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 bool RegisterPlugin( | 18 bool RegisterPlugin( |
| 19 base::CommandLine* command_line, | 19 base::CommandLine* command_line, |
| 20 const base::FilePath::StringType& library_name, | 20 const base::FilePath::StringType& library_name, |
| 21 const base::FilePath::StringType& extra_registration_parameters) { | 21 const base::FilePath::StringType& extra_registration_parameters, |
| 22 const base::FilePath::StringType& mime_type) { |
| 22 base::FilePath plugin_dir; | 23 base::FilePath plugin_dir; |
| 23 if (!PathService::Get(base::DIR_MODULE, &plugin_dir)) | 24 if (!PathService::Get(base::DIR_MODULE, &plugin_dir)) |
| 24 return false; | 25 return false; |
| 25 | 26 |
| 26 base::FilePath plugin_path = plugin_dir.Append(library_name); | 27 base::FilePath plugin_path = plugin_dir.Append(library_name); |
| 27 | 28 |
| 28 // Append the switch to register the pepper plugin. | 29 // Append the switch to register the pepper plugin. |
| 29 if (!base::PathExists(plugin_path)) | 30 if (!base::PathExists(plugin_path)) |
| 30 return false; | 31 return false; |
| 31 base::FilePath::StringType pepper_plugin = plugin_path.value(); | 32 base::FilePath::StringType pepper_plugin = plugin_path.value(); |
| 32 pepper_plugin.append(extra_registration_parameters); | 33 pepper_plugin.append(extra_registration_parameters); |
| 33 pepper_plugin.append(FILE_PATH_LITERAL(";application/x-ppapi-tests")); | 34 pepper_plugin.append(FILE_PATH_LITERAL(";")); |
| 35 pepper_plugin.append(mime_type); |
| 34 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins, | 36 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins, |
| 35 pepper_plugin); | 37 pepper_plugin); |
| 36 return true; | 38 return true; |
| 37 } | 39 } |
| 38 | 40 |
| 41 bool RegisterPluginWithDefaultMimeType( |
| 42 base::CommandLine* command_line, |
| 43 const base::FilePath::StringType& library_name, |
| 44 const base::FilePath::StringType& extra_registration_parameters) { |
| 45 return RegisterPlugin(command_line, library_name, |
| 46 extra_registration_parameters, |
| 47 FILE_PATH_LITERAL("application/x-ppapi-tests")); |
| 48 } |
| 49 |
| 39 } // namespace | 50 } // namespace |
| 40 | 51 |
| 41 bool RegisterTestPlugin(base::CommandLine* command_line) { | 52 bool RegisterTestPlugin(base::CommandLine* command_line) { |
| 42 return RegisterTestPluginWithExtraParameters(command_line, | 53 return RegisterTestPluginWithExtraParameters(command_line, |
| 43 FILE_PATH_LITERAL("")); | 54 FILE_PATH_LITERAL("")); |
| 44 } | 55 } |
| 45 | 56 |
| 46 bool RegisterTestPluginWithExtraParameters( | 57 bool RegisterTestPluginWithExtraParameters( |
| 47 base::CommandLine* command_line, | 58 base::CommandLine* command_line, |
| 48 const base::FilePath::StringType& extra_registration_parameters) { | 59 const base::FilePath::StringType& extra_registration_parameters) { |
| 49 #if defined(OS_WIN) | 60 #if defined(OS_WIN) |
| 50 base::FilePath::StringType plugin_library = L"ppapi_tests.dll"; | 61 base::FilePath::StringType plugin_library = L"ppapi_tests.dll"; |
| 51 #elif defined(OS_MACOSX) | 62 #elif defined(OS_MACOSX) |
| 52 base::FilePath::StringType plugin_library = "ppapi_tests.plugin"; | 63 base::FilePath::StringType plugin_library = "ppapi_tests.plugin"; |
| 53 #elif defined(OS_POSIX) | 64 #elif defined(OS_POSIX) |
| 54 base::FilePath::StringType plugin_library = "libppapi_tests.so"; | 65 base::FilePath::StringType plugin_library = "libppapi_tests.so"; |
| 55 #endif | 66 #endif |
| 56 return RegisterPlugin(command_line, plugin_library, | 67 return RegisterPluginWithDefaultMimeType(command_line, plugin_library, |
| 57 extra_registration_parameters); | 68 extra_registration_parameters); |
| 58 } | 69 } |
| 59 | 70 |
| 60 bool RegisterPowerSaverTestPlugin(base::CommandLine* command_line) { | 71 bool RegisterPowerSaverTestPlugin(base::CommandLine* command_line) { |
| 61 base::FilePath::StringType library_name = | 72 base::FilePath::StringType library_name = |
| 62 base::FilePath::FromUTF8Unsafe(ppapi::kPowerSaverTestPluginName).value(); | 73 base::FilePath::FromUTF8Unsafe(ppapi::kPowerSaverTestPluginName).value(); |
| 63 return RegisterPlugin(command_line, library_name, FILE_PATH_LITERAL("")); | 74 return RegisterPluginWithDefaultMimeType(command_line, library_name, |
| 75 FILE_PATH_LITERAL("")); |
| 64 } | 76 } |
| 65 | 77 |
| 78 bool RegisterBlinkTestPlugin(base::CommandLine* command_line) { |
| 79 #if defined(OS_WIN) |
| 80 static const base::FilePath::CharType kPluginLibrary[] = |
| 81 L"blink_test_plugin.dll"; |
| 82 #elif defined(OS_MACOSX) |
| 83 static const base::FilePath::CharType kPluginLibrary[] = |
| 84 "blink_test_plugin.plugin"; |
| 85 #elif defined(OS_POSIX) |
| 86 static const base::FilePath::CharType kPluginLibrary[] = |
| 87 "libblink_test_plugin.so"; |
| 88 #endif |
| 89 // #name#description#version |
| 90 static const base::FilePath::CharType kExtraParameters[] = |
| 91 FILE_PATH_LITERAL("#Blink Test Plugin#Interesting description.#0.8"); |
| 92 return RegisterPlugin(command_line, kPluginLibrary, kExtraParameters, |
| 93 FILE_PATH_LITERAL("application/x-blink-test-plugin")); |
| 94 } |
| 66 } // namespace ppapi | 95 } // namespace ppapi |
| OLD | NEW |