OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/extensions/api/messaging/native_messaging_test_util.h" | 5 #include "chrome/browser/extensions/api/messaging/native_messaging_test_util.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> |
8 | 9 |
9 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
10 #include "base/json/json_file_value_serializer.h" | 11 #include "base/json/json_file_value_serializer.h" |
11 #include "base/path_service.h" | 12 #include "base/path_service.h" |
12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "base/values.h" | 15 #include "base/values.h" |
15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
16 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 12 matching lines...) Expand all Loading... |
30 bool user_level) { | 31 bool user_level) { |
31 std::unique_ptr<base::DictionaryValue> manifest(new base::DictionaryValue()); | 32 std::unique_ptr<base::DictionaryValue> manifest(new base::DictionaryValue()); |
32 manifest->SetString("name", host_name); | 33 manifest->SetString("name", host_name); |
33 manifest->SetString("description", "Native Messaging Echo Test"); | 34 manifest->SetString("description", "Native Messaging Echo Test"); |
34 manifest->SetString("type", "stdio"); | 35 manifest->SetString("type", "stdio"); |
35 manifest->SetString("path", host_path.AsUTF8Unsafe()); | 36 manifest->SetString("path", host_path.AsUTF8Unsafe()); |
36 | 37 |
37 std::unique_ptr<base::ListValue> origins(new base::ListValue()); | 38 std::unique_ptr<base::ListValue> origins(new base::ListValue()); |
38 origins->AppendString(base::StringPrintf( | 39 origins->AppendString(base::StringPrintf( |
39 "chrome-extension://%s/", ScopedTestNativeMessagingHost::kExtensionId)); | 40 "chrome-extension://%s/", ScopedTestNativeMessagingHost::kExtensionId)); |
40 manifest->Set("allowed_origins", origins.release()); | 41 manifest->Set("allowed_origins", std::move(origins)); |
41 | 42 |
42 base::FilePath manifest_path = target_dir.AppendASCII(host_name + ".json"); | 43 base::FilePath manifest_path = target_dir.AppendASCII(host_name + ".json"); |
43 JSONFileValueSerializer serializer(manifest_path); | 44 JSONFileValueSerializer serializer(manifest_path); |
44 ASSERT_TRUE(serializer.Serialize(*manifest)); | 45 ASSERT_TRUE(serializer.Serialize(*manifest)); |
45 | 46 |
46 #if defined(OS_WIN) | 47 #if defined(OS_WIN) |
47 HKEY root_key = user_level ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; | 48 HKEY root_key = user_level ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; |
48 base::string16 key = L"SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\" + | 49 base::string16 key = L"SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\" + |
49 base::UTF8ToUTF16(host_name); | 50 base::UTF8ToUTF16(host_name); |
50 base::win::RegKey manifest_key( | 51 base::win::RegKey manifest_key( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 temp_dir_.GetPath(), kHostName, host_path, user_level)); | 95 temp_dir_.GetPath(), kHostName, host_path, user_level)); |
95 | 96 |
96 ASSERT_NO_FATAL_FAILURE(WriteTestNativeHostManifest( | 97 ASSERT_NO_FATAL_FAILURE(WriteTestNativeHostManifest( |
97 temp_dir_.GetPath(), kBinaryMissingHostName, | 98 temp_dir_.GetPath(), kBinaryMissingHostName, |
98 test_user_data_dir.AppendASCII("missing_nm_binary.exe"), user_level)); | 99 test_user_data_dir.AppendASCII("missing_nm_binary.exe"), user_level)); |
99 } | 100 } |
100 | 101 |
101 ScopedTestNativeMessagingHost::~ScopedTestNativeMessagingHost() {} | 102 ScopedTestNativeMessagingHost::~ScopedTestNativeMessagingHost() {} |
102 | 103 |
103 } // namespace extensions | 104 } // namespace extensions |
OLD | NEW |