| 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 #include <utility> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/json/json_file_value_serializer.h" | 11 #include "base/json/json_file_value_serializer.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/threading/thread_restrictions.h" |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 16 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 17 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 20 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
| 21 #include "base/win/registry.h" | 22 #include "base/win/registry.h" |
| 22 #endif | 23 #endif |
| 23 | 24 |
| 24 namespace extensions { | 25 namespace extensions { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 const char ScopedTestNativeMessagingHost::kHostName[] = | 62 const char ScopedTestNativeMessagingHost::kHostName[] = |
| 62 "com.google.chrome.test.echo"; | 63 "com.google.chrome.test.echo"; |
| 63 const char ScopedTestNativeMessagingHost::kBinaryMissingHostName[] = | 64 const char ScopedTestNativeMessagingHost::kBinaryMissingHostName[] = |
| 64 "com.google.chrome.test.host_binary_missing"; | 65 "com.google.chrome.test.host_binary_missing"; |
| 65 const char ScopedTestNativeMessagingHost::kExtensionId[] = | 66 const char ScopedTestNativeMessagingHost::kExtensionId[] = |
| 66 "knldjmfmopnpolahpmmgbagdohdnhkik"; | 67 "knldjmfmopnpolahpmmgbagdohdnhkik"; |
| 67 | 68 |
| 68 ScopedTestNativeMessagingHost::ScopedTestNativeMessagingHost() {} | 69 ScopedTestNativeMessagingHost::ScopedTestNativeMessagingHost() {} |
| 69 | 70 |
| 70 void ScopedTestNativeMessagingHost::RegisterTestHost(bool user_level) { | 71 void ScopedTestNativeMessagingHost::RegisterTestHost(bool user_level) { |
| 72 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 71 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 73 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 72 ScopedTestNativeMessagingHost test_host; | 74 ScopedTestNativeMessagingHost test_host; |
| 73 | 75 |
| 74 base::FilePath test_user_data_dir; | 76 base::FilePath test_user_data_dir; |
| 75 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_user_data_dir)); | 77 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_user_data_dir)); |
| 76 test_user_data_dir = test_user_data_dir.AppendASCII("native_messaging") | 78 test_user_data_dir = test_user_data_dir.AppendASCII("native_messaging") |
| 77 .AppendASCII("native_hosts"); | 79 .AppendASCII("native_hosts"); |
| 78 | 80 |
| 79 #if defined(OS_WIN) | 81 #if defined(OS_WIN) |
| 80 HKEY root_key = user_level ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; | 82 HKEY root_key = user_level ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 92 base::FilePath host_path = test_user_data_dir.AppendASCII("echo.bat"); | 94 base::FilePath host_path = test_user_data_dir.AppendASCII("echo.bat"); |
| 93 #endif | 95 #endif |
| 94 ASSERT_NO_FATAL_FAILURE(WriteTestNativeHostManifest( | 96 ASSERT_NO_FATAL_FAILURE(WriteTestNativeHostManifest( |
| 95 temp_dir_.GetPath(), kHostName, host_path, user_level)); | 97 temp_dir_.GetPath(), kHostName, host_path, user_level)); |
| 96 | 98 |
| 97 ASSERT_NO_FATAL_FAILURE(WriteTestNativeHostManifest( | 99 ASSERT_NO_FATAL_FAILURE(WriteTestNativeHostManifest( |
| 98 temp_dir_.GetPath(), kBinaryMissingHostName, | 100 temp_dir_.GetPath(), kBinaryMissingHostName, |
| 99 test_user_data_dir.AppendASCII("missing_nm_binary.exe"), user_level)); | 101 test_user_data_dir.AppendASCII("missing_nm_binary.exe"), user_level)); |
| 100 } | 102 } |
| 101 | 103 |
| 102 ScopedTestNativeMessagingHost::~ScopedTestNativeMessagingHost() {} | 104 ScopedTestNativeMessagingHost::~ScopedTestNativeMessagingHost() { |
| 105 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 106 ignore_result(temp_dir_.Delete()); |
| 107 } |
| 103 | 108 |
| 104 } // namespace extensions | 109 } // namespace extensions |
| OLD | NEW |