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