OLD | NEW |
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" |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kWebConnectable)); | 34 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kWebConnectable)); |
35 | 35 |
36 ExternallyConnectableInfo* info = | 36 ExternallyConnectableInfo* info = |
37 ExternallyConnectableInfo::Get(extension.get()); | 37 ExternallyConnectableInfo::Get(extension.get()); |
38 ASSERT_TRUE(info); | 38 ASSERT_TRUE(info); |
39 | 39 |
40 EXPECT_THAT(info->ids, ElementsAre("abcdefghijklmnopabcdefghijklmnop", | 40 EXPECT_THAT(info->ids, ElementsAre("abcdefghijklmnopabcdefghijklmnop", |
41 "ponmlkjihgfedcbaponmlkjihgfedcba")); | 41 "ponmlkjihgfedcbaponmlkjihgfedcba")); |
42 | 42 |
43 EXPECT_FALSE(info->matches_all_ids); | 43 EXPECT_FALSE(info->all_ids); |
44 | 44 |
45 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://example.com"))); | 45 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://example.com"))); |
46 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://example.com/"))); | 46 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://example.com/"))); |
47 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://example.com/index.html"))); | 47 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://example.com/index.html"))); |
48 | 48 |
49 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://google.com"))); | 49 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://google.com"))); |
50 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://google.com/"))); | 50 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://google.com/"))); |
51 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://google.com/index.html"))); | 51 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://google.com/index.html"))); |
52 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.google.com"))); | 52 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.google.com"))); |
53 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.google.com/"))); | 53 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.google.com/"))); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 93 |
94 EXPECT_FALSE(extension->HasAPIPermission(APIPermission::kWebConnectable)); | 94 EXPECT_FALSE(extension->HasAPIPermission(APIPermission::kWebConnectable)); |
95 | 95 |
96 ExternallyConnectableInfo* info = | 96 ExternallyConnectableInfo* info = |
97 ExternallyConnectableInfo::Get(extension.get()); | 97 ExternallyConnectableInfo::Get(extension.get()); |
98 ASSERT_TRUE(info); | 98 ASSERT_TRUE(info); |
99 | 99 |
100 EXPECT_THAT(info->ids, ElementsAre("abcdefghijklmnopabcdefghijklmnop", | 100 EXPECT_THAT(info->ids, ElementsAre("abcdefghijklmnopabcdefghijklmnop", |
101 "ponmlkjihgfedcbaponmlkjihgfedcba")); | 101 "ponmlkjihgfedcbaponmlkjihgfedcba")); |
102 | 102 |
103 EXPECT_FALSE(info->matches_all_ids); | 103 EXPECT_FALSE(info->all_ids); |
104 | 104 |
105 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://google.com/index.html"))); | 105 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://google.com/index.html"))); |
106 } | 106 } |
107 | 107 |
108 TEST_F(ExternallyConnectableTest, Matches) { | 108 TEST_F(ExternallyConnectableTest, Matches) { |
109 scoped_refptr<Extension> extension = | 109 scoped_refptr<Extension> extension = |
110 LoadAndExpectSuccess("externally_connectable_matches.json"); | 110 LoadAndExpectSuccess("externally_connectable_matches.json"); |
111 ASSERT_TRUE(extension.get()); | 111 ASSERT_TRUE(extension.get()); |
112 | 112 |
113 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kWebConnectable)); | 113 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kWebConnectable)); |
114 | 114 |
115 ExternallyConnectableInfo* info = | 115 ExternallyConnectableInfo* info = |
116 ExternallyConnectableInfo::Get(extension.get()); | 116 ExternallyConnectableInfo::Get(extension.get()); |
117 ASSERT_TRUE(info); | 117 ASSERT_TRUE(info); |
118 | 118 |
119 EXPECT_THAT(info->ids, ElementsAre()); | 119 EXPECT_THAT(info->ids, ElementsAre()); |
120 | 120 |
121 EXPECT_FALSE(info->matches_all_ids); | 121 EXPECT_FALSE(info->all_ids); |
122 | 122 |
123 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://example.com"))); | 123 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://example.com"))); |
124 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://example.com/"))); | 124 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://example.com/"))); |
125 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://example.com/index.html"))); | 125 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://example.com/index.html"))); |
126 | 126 |
127 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://google.com"))); | 127 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://google.com"))); |
128 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://google.com/"))); | 128 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://google.com/"))); |
129 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://google.com/index.html"))); | 129 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://google.com/index.html"))); |
130 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.google.com"))); | 130 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.google.com"))); |
131 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.google.com/"))); | 131 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://www.google.com/"))); |
(...skipping 20 matching lines...) Expand all Loading... |
152 | 152 |
153 EXPECT_FALSE(extension->HasAPIPermission(APIPermission::kWebConnectable)); | 153 EXPECT_FALSE(extension->HasAPIPermission(APIPermission::kWebConnectable)); |
154 | 154 |
155 ExternallyConnectableInfo* info = | 155 ExternallyConnectableInfo* info = |
156 ExternallyConnectableInfo::Get(extension.get()); | 156 ExternallyConnectableInfo::Get(extension.get()); |
157 ASSERT_TRUE(info); | 157 ASSERT_TRUE(info); |
158 | 158 |
159 EXPECT_THAT(info->ids, ElementsAre("abcdefghijklmnopabcdefghijklmnop", | 159 EXPECT_THAT(info->ids, ElementsAre("abcdefghijklmnopabcdefghijklmnop", |
160 "ponmlkjihgfedcbaponmlkjihgfedcba")); | 160 "ponmlkjihgfedcbaponmlkjihgfedcba")); |
161 | 161 |
162 EXPECT_TRUE(info->matches_all_ids); | 162 EXPECT_TRUE(info->all_ids); |
163 | 163 |
164 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://google.com/index.html"))); | 164 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://google.com/index.html"))); |
165 } | 165 } |
166 | 166 |
| 167 TEST_F(ExternallyConnectableTest, IdCanConnect) { |
| 168 // Not in order to test that ExternallyConnectableInfo sorts it. |
| 169 std::string matches_ids_array[] = { "g", "h", "c", "i", "a", "z", "b" }; |
| 170 std::vector<std::string> matches_ids( |
| 171 matches_ids_array, matches_ids_array + arraysize(matches_ids_array)); |
| 172 |
| 173 std::string nomatches_ids_array[] = { "2", "3", "1" }; |
| 174 |
| 175 // all_ids = false. |
| 176 { |
| 177 ExternallyConnectableInfo info(URLPatternSet(), matches_ids, false); |
| 178 for (size_t i = 0; i < matches_ids.size(); ++i) |
| 179 EXPECT_TRUE(info.IdCanConnect(matches_ids[i])); |
| 180 for (size_t i = 0; i < arraysize(nomatches_ids_array); ++i) |
| 181 EXPECT_FALSE(info.IdCanConnect(nomatches_ids_array[i])); |
| 182 } |
| 183 |
| 184 // all_ids = true. |
| 185 { |
| 186 ExternallyConnectableInfo info(URLPatternSet(), matches_ids, true); |
| 187 for (size_t i = 0; i < matches_ids.size(); ++i) |
| 188 EXPECT_TRUE(info.IdCanConnect(matches_ids[i])); |
| 189 for (size_t i = 0; i < arraysize(nomatches_ids_array); ++i) |
| 190 EXPECT_TRUE(info.IdCanConnect(nomatches_ids_array[i])); |
| 191 } |
| 192 } |
| 193 |
167 TEST_F(ExternallyConnectableTest, ErrorWrongFormat) { | 194 TEST_F(ExternallyConnectableTest, ErrorWrongFormat) { |
168 RunTestcase(Testcase("externally_connectable_error_wrong_format.json", | 195 RunTestcase(Testcase("externally_connectable_error_wrong_format.json", |
169 errors::kErrorInvalid), | 196 errors::kErrorInvalid), |
170 EXPECT_TYPE_ERROR); | 197 EXPECT_TYPE_ERROR); |
171 } | 198 } |
172 | 199 |
173 TEST_F(ExternallyConnectableTest, ErrorBadID) { | 200 TEST_F(ExternallyConnectableTest, ErrorBadID) { |
174 RunTestcase(Testcase("externally_connectable_bad_id.json", | 201 RunTestcase(Testcase("externally_connectable_bad_id.json", |
175 ErrorUtils::FormatErrorMessage(errors::kErrorInvalidId, | 202 ErrorUtils::FormatErrorMessage(errors::kErrorInvalidId, |
176 "badid")), | 203 "badid")), |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 Testcase( | 257 Testcase( |
231 "externally_connectable_error_unknown_tld.json", | 258 "externally_connectable_error_unknown_tld.json", |
232 ErrorUtils::FormatErrorMessage( | 259 ErrorUtils::FormatErrorMessage( |
233 errors::kErrorTopLevelDomainsNotAllowed, | 260 errors::kErrorTopLevelDomainsNotAllowed, |
234 "notatld", | 261 "notatld", |
235 "http://*.notatld/*")), | 262 "http://*.notatld/*")), |
236 EXPECT_TYPE_ERROR); | 263 EXPECT_TYPE_ERROR); |
237 } | 264 } |
238 | 265 |
239 } // namespace extensions | 266 } // namespace extensions |
OLD | NEW |