OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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 #include "testing/gtest/include/gtest/gtest.h" | |
6 | |
7 #include "chrome/browser/extensions/extension_content_settings_helpers.h" | |
8 | |
9 namespace helpers = extension_content_settings_helpers; | |
10 | |
11 TEST(ExtensionContentSettingsHelpersTest, ParseExtensionPattern) { | |
12 const struct { | |
13 const char* extension_pattern; | |
14 const char* content_settings_pattern; | |
15 } kTestPatterns[] = { | |
16 { "<all_urls>", "*" }, | |
17 { "*://*.google.com/*", "[*.]google.com" }, | |
18 { "http://www.example.com/*", "http://www.example.com" }, | |
19 { "*://www.example.com/*", "www.example.com" }, | |
20 { "http://www.example.com:8080/*", "http://www.example.com:8080" }, | |
21 { "https://*/*", "https://*" }, | |
22 { "file:///foo/bar/baz", "file:///foo/bar/baz" }, | |
23 }; | |
24 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestPatterns); ++i) { | |
25 std::string error; | |
26 std::string pattern_str = helpers::ParseExtensionPattern( | |
27 kTestPatterns[i].extension_pattern, &error).ToString(); | |
28 EXPECT_EQ(kTestPatterns[i].content_settings_pattern, pattern_str) | |
29 << "Unexpected error parsing " << kTestPatterns[i].extension_pattern | |
30 << ": " << error; | |
31 } | |
32 | |
33 const struct { | |
34 const char* extension_pattern; | |
35 const char* expected_error; | |
36 } kInvalidTestPatterns[] = { | |
37 { "http://www.example.com/path", "Specific paths are not allowed." }, | |
38 { "file:///foo/bar/*", | |
39 "Path wildcards in file URL patterns are not allowed." }, | |
40 }; | |
41 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kInvalidTestPatterns); ++i) { | |
42 std::string error; | |
43 ContentSettingsPattern pattern = helpers::ParseExtensionPattern( | |
44 kInvalidTestPatterns[i].extension_pattern, &error); | |
45 EXPECT_FALSE(pattern.IsValid()); | |
46 EXPECT_EQ(kInvalidTestPatterns[i].expected_error, error) | |
47 << "Unexpected error parsing " | |
48 << kInvalidTestPatterns[i].extension_pattern; | |
49 } | |
50 | |
51 } | |
OLD | NEW |