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

Side by Side Diff: chrome/common/extensions/manifest_handlers/externally_connectable_unittest.cc

Issue 16464004: Turn disallowed URL patterns such as <all_urls> for externally_connectable into (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test that warnings also imply failure Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
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 <algorithm> 5 #include <algorithm>
6 6
7 #include "chrome/common/extensions/extension_manifest_constants.h" 7 #include "chrome/common/extensions/extension_manifest_constants.h"
8 #include "chrome/common/extensions/features/feature.h" 8 #include "chrome/common/extensions/features/feature.h"
9 #include "chrome/common/extensions/manifest_handlers/externally_connectable.h" 9 #include "chrome/common/extensions/manifest_handlers/externally_connectable.h"
10 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h" 10 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h"
11 #include "extensions/common/error_utils.h" 11 #include "extensions/common/error_utils.h"
12 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 using testing::ElementsAre; 15 using testing::ElementsAre;
16 16
17 namespace extensions { 17 namespace extensions {
18 18
19 namespace errors = externally_connectable_errors; 19 namespace errors = externally_connectable_errors;
20 20
21 class ExternallyConnectableTest : public ExtensionManifestTest { 21 class ExternallyConnectableTest : public ExtensionManifestTest {
22 public: 22 public:
23 ExternallyConnectableTest() : channel_(chrome::VersionInfo::CHANNEL_DEV) {} 23 ExternallyConnectableTest() : channel_(chrome::VersionInfo::CHANNEL_DEV) {}
24 24
25 protected:
26 ExternallyConnectableInfo* GetExternallyConnectableInfo(
27 scoped_refptr<Extension> extension) {
28 return static_cast<ExternallyConnectableInfo*>(extension->GetManifestData(
29 extension_manifest_keys::kExternallyConnectable));
30 }
31
25 private: 32 private:
26 Feature::ScopedCurrentChannel channel_; 33 Feature::ScopedCurrentChannel channel_;
27 }; 34 };
28 35
29 TEST_F(ExternallyConnectableTest, IDsAndMatches) { 36 TEST_F(ExternallyConnectableTest, IDsAndMatches) {
30 scoped_refptr<Extension> extension = 37 scoped_refptr<Extension> extension =
31 LoadAndExpectSuccess("externally_connectable_ids_and_matches.json"); 38 LoadAndExpectSuccess("externally_connectable_ids_and_matches.json");
32 ASSERT_TRUE(extension.get()); 39 ASSERT_TRUE(extension.get());
33 40
34 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kWebConnectable)); 41 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kWebConnectable));
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 { 192 {
186 ExternallyConnectableInfo info(URLPatternSet(), matches_ids, true); 193 ExternallyConnectableInfo info(URLPatternSet(), matches_ids, true);
187 for (size_t i = 0; i < matches_ids.size(); ++i) 194 for (size_t i = 0; i < matches_ids.size(); ++i)
188 EXPECT_TRUE(info.IdCanConnect(matches_ids[i])); 195 EXPECT_TRUE(info.IdCanConnect(matches_ids[i]));
189 for (size_t i = 0; i < arraysize(nomatches_ids_array); ++i) 196 for (size_t i = 0; i < arraysize(nomatches_ids_array); ++i)
190 EXPECT_TRUE(info.IdCanConnect(nomatches_ids_array[i])); 197 EXPECT_TRUE(info.IdCanConnect(nomatches_ids_array[i]));
191 } 198 }
192 } 199 }
193 200
194 TEST_F(ExternallyConnectableTest, ErrorWrongFormat) { 201 TEST_F(ExternallyConnectableTest, ErrorWrongFormat) {
195 RunTestcase(Testcase("externally_connectable_error_wrong_format.json", 202 LoadAndExpectError("externally_connectable_error_wrong_format.json",
196 errors::kErrorInvalid), 203 errors::kErrorInvalid);
197 EXPECT_TYPE_ERROR);
198 } 204 }
199 205
200 TEST_F(ExternallyConnectableTest, ErrorBadID) { 206 TEST_F(ExternallyConnectableTest, ErrorBadID) {
201 RunTestcase(Testcase("externally_connectable_bad_id.json", 207 LoadAndExpectError(
202 ErrorUtils::FormatErrorMessage(errors::kErrorInvalidId, 208 "externally_connectable_bad_id.json",
203 "badid")), 209 ErrorUtils::FormatErrorMessage(errors::kErrorInvalidId, "badid"));
204 EXPECT_TYPE_ERROR);
205 } 210 }
206 211
207 TEST_F(ExternallyConnectableTest, ErrorBadMatches) { 212 TEST_F(ExternallyConnectableTest, ErrorBadMatches) {
208 RunTestcase( 213 LoadAndExpectError(
209 Testcase("externally_connectable_error_bad_matches.json", 214 "externally_connectable_error_bad_matches.json",
210 ErrorUtils::FormatErrorMessage(errors::kErrorInvalidMatchPattern, 215 ErrorUtils::FormatErrorMessage(errors::kErrorInvalidMatchPattern,
211 "www.yahoo.com")), 216 "www.yahoo.com"));
212 EXPECT_TYPE_ERROR);
213 } 217 }
214 218
215 TEST_F(ExternallyConnectableTest, ErrorNoAllURLs) { 219 TEST_F(ExternallyConnectableTest, WarningNoAllURLs) {
216 RunTestcase( 220 scoped_refptr<Extension> extension = LoadAndExpectWarning(
217 Testcase( 221 "externally_connectable_error_all_urls.json",
218 "externally_connectable_error_all_urls.json", 222 ErrorUtils::FormatErrorMessage(errors::kErrorWildcardHostsNotAllowed,
219 ErrorUtils::FormatErrorMessage(errors::kErrorWildcardHostsNotAllowed, 223 "<all_urls>"));
220 "<all_urls>")), 224 ExternallyConnectableInfo* info = GetExternallyConnectableInfo(extension);
221 EXPECT_TYPE_ERROR); 225 EXPECT_FALSE(info->matches.ContainsPattern(
226 URLPattern(URLPattern::SCHEME_ALL, "<all_urls>")));
227 EXPECT_TRUE(info->matches.MatchesURL(GURL("https://example.com")));
228 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://build.chromium.org")));
222 } 229 }
223 230
224 TEST_F(ExternallyConnectableTest, ErrorWildcardHost) { 231 TEST_F(ExternallyConnectableTest, WarningWildcardHost) {
225 RunTestcase( 232 scoped_refptr<Extension> extension = LoadAndExpectWarning(
226 Testcase( 233 "externally_connectable_error_wildcard_host.json",
227 "externally_connectable_error_wildcard_host.json", 234 ErrorUtils::FormatErrorMessage(errors::kErrorWildcardHostsNotAllowed,
228 ErrorUtils::FormatErrorMessage(errors::kErrorWildcardHostsNotAllowed, 235 "http://*/*"));
229 "http://*/*")), 236 ExternallyConnectableInfo* info = GetExternallyConnectableInfo(extension);
230 EXPECT_TYPE_ERROR); 237 EXPECT_FALSE(info->matches.ContainsPattern(
238 URLPattern(URLPattern::SCHEME_ALL, "http://*/*")));
239 EXPECT_TRUE(info->matches.MatchesURL(GURL("https://example.com")));
240 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://build.chromium.org")));
231 } 241 }
232 242
233 TEST_F(ExternallyConnectableTest, ErrorNoTLD) { 243 TEST_F(ExternallyConnectableTest, WarningNoTLD) {
234 RunTestcase( 244 scoped_refptr<Extension> extension = LoadAndExpectWarning(
235 Testcase( 245 "externally_connectable_error_tld.json",
236 "externally_connectable_error_tld.json", 246 ErrorUtils::FormatErrorMessage(
237 ErrorUtils::FormatErrorMessage( 247 errors::kErrorTopLevelDomainsNotAllowed,
238 errors::kErrorTopLevelDomainsNotAllowed, 248 "co.uk",
239 "co.uk", 249 "http://*.co.uk/*"));
240 "http://*.co.uk/*")), 250 ExternallyConnectableInfo* info = GetExternallyConnectableInfo(extension);
241 EXPECT_TYPE_ERROR); 251 EXPECT_FALSE(info->matches.ContainsPattern(
252 URLPattern(URLPattern::SCHEME_ALL, "http://*.co.uk/*")));
253 EXPECT_TRUE(info->matches.MatchesURL(GURL("https://example.com")));
254 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://build.chromium.org")));
242 } 255 }
243 256
244 TEST_F(ExternallyConnectableTest, ErrorNoEffectiveTLD) { 257 TEST_F(ExternallyConnectableTest, WarningNoEffectiveTLD) {
245 RunTestcase( 258 scoped_refptr<Extension> extension = LoadAndExpectWarning(
246 Testcase( 259 "externally_connectable_error_effective_tld.json",
247 "externally_connectable_error_effective_tld.json", 260 ErrorUtils::FormatErrorMessage(
248 ErrorUtils::FormatErrorMessage( 261 errors::kErrorTopLevelDomainsNotAllowed,
249 errors::kErrorTopLevelDomainsNotAllowed, 262 "appspot.com",
250 "appspot.com", 263 "http://*.appspot.com/*"));
251 "http://*.appspot.com/*")), 264 ExternallyConnectableInfo* info = GetExternallyConnectableInfo(extension);
252 EXPECT_TYPE_ERROR); 265 EXPECT_FALSE(info->matches.ContainsPattern(
266 URLPattern(URLPattern::SCHEME_ALL, "http://*.appspot.com/*")));
267 EXPECT_TRUE(info->matches.MatchesURL(GURL("https://example.com")));
268 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://build.chromium.org")));
253 } 269 }
254 270
255 TEST_F(ExternallyConnectableTest, ErrorUnknownTLD) { 271 TEST_F(ExternallyConnectableTest, WarningUnknownTLD) {
256 RunTestcase( 272 scoped_refptr<Extension> extension = LoadAndExpectWarning(
257 Testcase( 273 "externally_connectable_error_unknown_tld.json",
258 "externally_connectable_error_unknown_tld.json", 274 ErrorUtils::FormatErrorMessage(
259 ErrorUtils::FormatErrorMessage( 275 errors::kErrorTopLevelDomainsNotAllowed,
260 errors::kErrorTopLevelDomainsNotAllowed, 276 "notatld",
261 "notatld", 277 "http://*.notatld/*"));
262 "http://*.notatld/*")), 278 ExternallyConnectableInfo* info = GetExternallyConnectableInfo(extension);
263 EXPECT_TYPE_ERROR); 279 EXPECT_FALSE(info->matches.ContainsPattern(
280 URLPattern(URLPattern::SCHEME_ALL, "http://*.notatld/*")));
281 EXPECT_TRUE(info->matches.MatchesURL(GURL("https://example.com")));
282 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://build.chromium.org")));
264 } 283 }
265 284
266 } // namespace extensions 285 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/manifest_handlers/externally_connectable.cc ('k') | extensions/common/install_warning.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698