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
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGING_TEST_UTIL_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGING_TEST_UTIL_H_
7 
8 #include <memory>
9 
10 #include "base/files/scoped_temp_dir.h"
11 #include "base/macros.h"
12 #include "build/build_config.h"
13 
14 #if defined(OS_WIN)
15 #include "base/test/test_reg_util_win.h"
16 #else
17 #include "base/test/scoped_path_override.h"
18 #endif
19 
20 namespace extensions {
21 
22 // Helper class for native messaging tests. When RegisterTestHost() is called it
23 // creates the following manifest files:
24 //   kHostName ("com.google.chrome.test.echo") - Echo NM host that runs, see
25 //       chrome/test/data/native_messaging/native_hosts/echo.py .
26 //   kBinaryMissingHostName ("com.google.chrome.test.host_binary_missing") -
27 //        Manifest file that points to a nonexistent host binary.
28 class ScopedTestNativeMessagingHost {
29  public:
30   static const char kHostName[];
31   static const char kBinaryMissingHostName[];
32   static const char kSupportsNativeInitiatedConnectionsHostName[];
33 
34   static const char kExtensionId[];
35 
36   ScopedTestNativeMessagingHost();
37   ~ScopedTestNativeMessagingHost();
38 
39   void RegisterTestHost(bool user_level);
40 
temp_dir()41   const base::FilePath& temp_dir() { return temp_dir_.GetPath(); }
42 
43  private:
44   base::ScopedTempDir temp_dir_;
45 
46 #if defined(OS_WIN)
47   registry_util::RegistryOverrideManager registry_override_;
48 #else
49   std::unique_ptr<base::ScopedPathOverride> path_override_;
50 #endif
51 
52   DISALLOW_COPY_AND_ASSIGN(ScopedTestNativeMessagingHost);
53 };
54 
55 }  // namespace extensions
56 
57 #endif  // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGING_TEST_UTIL_H_
58