Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(411)

Side by Side Diff: chrome/browser/extensions/api/messaging/native_messaging_host_manifest_unittest.cc

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fix header Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 EXPECT_FALSE(NativeMessagingHostManifest::IsValidName("a..b")); 67 EXPECT_FALSE(NativeMessagingHostManifest::IsValidName("a..b"));
68 EXPECT_FALSE(NativeMessagingHostManifest::IsValidName(".a")); 68 EXPECT_FALSE(NativeMessagingHostManifest::IsValidName(".a"));
69 EXPECT_FALSE(NativeMessagingHostManifest::IsValidName("b.")); 69 EXPECT_FALSE(NativeMessagingHostManifest::IsValidName("b."));
70 EXPECT_FALSE(NativeMessagingHostManifest::IsValidName("a*")); 70 EXPECT_FALSE(NativeMessagingHostManifest::IsValidName("a*"));
71 } 71 }
72 72
73 TEST_F(NativeMessagingHostManifestTest, LoadValid) { 73 TEST_F(NativeMessagingHostManifestTest, LoadValid) {
74 ASSERT_TRUE(WriteManifest(kTestHostName, kTestHostPath, kTestOrigin)); 74 ASSERT_TRUE(WriteManifest(kTestHostName, kTestHostPath, kTestOrigin));
75 75
76 std::string error_message; 76 std::string error_message;
77 scoped_ptr<NativeMessagingHostManifest> manifest = 77 std::unique_ptr<NativeMessagingHostManifest> manifest =
78 NativeMessagingHostManifest::Load(manifest_path_, &error_message); 78 NativeMessagingHostManifest::Load(manifest_path_, &error_message);
79 ASSERT_TRUE(manifest) << "Failed to load manifest: " << error_message; 79 ASSERT_TRUE(manifest) << "Failed to load manifest: " << error_message;
80 EXPECT_TRUE(error_message.empty()); 80 EXPECT_TRUE(error_message.empty());
81 81
82 EXPECT_EQ(manifest->name(), "com.chrome.test.native_host"); 82 EXPECT_EQ(manifest->name(), "com.chrome.test.native_host");
83 EXPECT_EQ(manifest->description(), "Native Messaging Test"); 83 EXPECT_EQ(manifest->description(), "Native Messaging Test");
84 EXPECT_EQ(manifest->interface(), 84 EXPECT_EQ(manifest->interface(),
85 NativeMessagingHostManifest::HOST_INTERFACE_STDIO); 85 NativeMessagingHostManifest::HOST_INTERFACE_STDIO);
86 EXPECT_EQ(manifest->path(), base::FilePath::FromUTF8Unsafe(kTestHostPath)); 86 EXPECT_EQ(manifest->path(), base::FilePath::FromUTF8Unsafe(kTestHostPath));
87 EXPECT_TRUE(manifest->allowed_origins().MatchesSecurityOrigin( 87 EXPECT_TRUE(manifest->allowed_origins().MatchesSecurityOrigin(
88 GURL("chrome-extension://knldjmfmopnpolahpmmgbagdohdnhkik/"))); 88 GURL("chrome-extension://knldjmfmopnpolahpmmgbagdohdnhkik/")));
89 EXPECT_FALSE(manifest->allowed_origins().MatchesSecurityOrigin( 89 EXPECT_FALSE(manifest->allowed_origins().MatchesSecurityOrigin(
90 GURL("chrome-extension://jnldjmfmopnpolahpmmgbagdohdnhkik/"))); 90 GURL("chrome-extension://jnldjmfmopnpolahpmmgbagdohdnhkik/")));
91 } 91 }
92 92
93 TEST_F(NativeMessagingHostManifestTest, InvalidName) { 93 TEST_F(NativeMessagingHostManifestTest, InvalidName) {
94 ASSERT_TRUE(WriteManifest(".com.chrome.test.native_host", 94 ASSERT_TRUE(WriteManifest(".com.chrome.test.native_host",
95 kTestHostPath, kTestOrigin)); 95 kTestHostPath, kTestOrigin));
96 96
97 std::string error_message; 97 std::string error_message;
98 scoped_ptr<NativeMessagingHostManifest> manifest = 98 std::unique_ptr<NativeMessagingHostManifest> manifest =
99 NativeMessagingHostManifest::Load(manifest_path_, &error_message); 99 NativeMessagingHostManifest::Load(manifest_path_, &error_message);
100 ASSERT_FALSE(manifest); 100 ASSERT_FALSE(manifest);
101 EXPECT_FALSE(error_message.empty()); 101 EXPECT_FALSE(error_message.empty());
102 } 102 }
103 103
104 // Verify that match-all origins are rejected. 104 // Verify that match-all origins are rejected.
105 TEST_F(NativeMessagingHostManifestTest, MatchAllOrigin) { 105 TEST_F(NativeMessagingHostManifestTest, MatchAllOrigin) {
106 ASSERT_TRUE(WriteManifest(kTestHostName, kTestHostPath, 106 ASSERT_TRUE(WriteManifest(kTestHostName, kTestHostPath,
107 "chrome-extension://*/")); 107 "chrome-extension://*/"));
108 108
109 std::string error_message; 109 std::string error_message;
110 scoped_ptr<NativeMessagingHostManifest> manifest = 110 std::unique_ptr<NativeMessagingHostManifest> manifest =
111 NativeMessagingHostManifest::Load(manifest_path_, &error_message); 111 NativeMessagingHostManifest::Load(manifest_path_, &error_message);
112 ASSERT_FALSE(manifest); 112 ASSERT_FALSE(manifest);
113 EXPECT_FALSE(error_message.empty()); 113 EXPECT_FALSE(error_message.empty());
114 } 114 }
115 115
116 } // namespace extensions 116 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698