OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_host_manifest
.h" | 5 #include "chrome/browser/extensions/api/messaging/native_messaging_host_manifest
.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/json/string_escape.h" | 10 #include "base/json/string_escape.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 public: | 27 public: |
28 virtual void SetUp() OVERRIDE { | 28 virtual void SetUp() OVERRIDE { |
29 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 29 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
30 manifest_path_ = temp_dir_.path().AppendASCII("test.json"); | 30 manifest_path_ = temp_dir_.path().AppendASCII("test.json"); |
31 } | 31 } |
32 | 32 |
33 protected: | 33 protected: |
34 bool WriteManifest(const std::string& name, | 34 bool WriteManifest(const std::string& name, |
35 const std::string& path, | 35 const std::string& path, |
36 const std::string& origin) { | 36 const std::string& origin) { |
| 37 std::string escaped_path; |
| 38 base::JsonDoubleQuote(path, false, &escaped_path); |
37 return WriteManifest("{" | 39 return WriteManifest("{" |
38 " \"name\": \"" + name + "\"," | 40 " \"name\": \"" + name + "\"," |
39 " \"description\": \"Native Messaging Test\"," | 41 " \"description\": \"Native Messaging Test\"," |
40 " \"path\": " + base::GetQuotedJSONString(path) + "," | 42 " \"path\": \"" + escaped_path + "\"," |
41 " \"type\": \"stdio\"," | 43 " \"type\": \"stdio\"," |
42 " \"allowed_origins\": [" | 44 " \"allowed_origins\": [" |
43 " \"" + origin + "\"" | 45 " \"" + origin + "\"" |
44 " ]" | 46 " ]" |
45 "}"); | 47 "}"); |
46 } | 48 } |
47 | 49 |
48 bool WriteManifest(const std::string& manifest_content) { | 50 bool WriteManifest(const std::string& manifest_content) { |
49 return file_util::WriteFile( | 51 return file_util::WriteFile( |
50 manifest_path_, manifest_content.data(), manifest_content.size()); | 52 manifest_path_, manifest_content.data(), manifest_content.size()); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 "chrome-extension://*/")); | 108 "chrome-extension://*/")); |
107 | 109 |
108 std::string error_message; | 110 std::string error_message; |
109 scoped_ptr<NativeMessagingHostManifest> manifest = | 111 scoped_ptr<NativeMessagingHostManifest> manifest = |
110 NativeMessagingHostManifest::Load(manifest_path_, &error_message); | 112 NativeMessagingHostManifest::Load(manifest_path_, &error_message); |
111 ASSERT_FALSE(manifest); | 113 ASSERT_FALSE(manifest); |
112 EXPECT_FALSE(error_message.empty()); | 114 EXPECT_FALSE(error_message.empty()); |
113 } | 115 } |
114 | 116 |
115 } // namespace extensions | 117 } // namespace extensions |
OLD | NEW |