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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 ASSERT_TRUE(info); | 149 ASSERT_TRUE(info); |
150 | 150 |
151 EXPECT_THAT(info->ids, ElementsAre("abcdefghijklmnopabcdefghijklmnop", | 151 EXPECT_THAT(info->ids, ElementsAre("abcdefghijklmnopabcdefghijklmnop", |
152 "ponmlkjihgfedcbaponmlkjihgfedcba")); | 152 "ponmlkjihgfedcbaponmlkjihgfedcba")); |
153 | 153 |
154 EXPECT_TRUE(info->matches_all_ids); | 154 EXPECT_TRUE(info->matches_all_ids); |
155 | 155 |
156 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://google.com/index.html"))); | 156 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://google.com/index.html"))); |
157 } | 157 } |
158 | 158 |
| 159 TEST_F(ExternallyConnectableTest, MatchesIdOrAllIds) { |
| 160 // Not in order to test that ExternallyConnectableInfo sorts it. |
| 161 std::string matches_ids_array[] = { "g", "h", "c", "i", "a", "z", "b" }; |
| 162 std::vector<std::string> matches_ids( |
| 163 matches_ids_array, matches_ids_array + arraysize(matches_ids_array)); |
| 164 |
| 165 std::string nomatches_ids_array[] = { "2", "3", "1" }; |
| 166 |
| 167 // matches_all_ids = false. |
| 168 { |
| 169 ExternallyConnectableInfo info(URLPatternSet(), matches_ids, false); |
| 170 for (size_t i = 0; i < matches_ids.size(); ++i) |
| 171 EXPECT_TRUE(info.MatchesIdOrAllIds(matches_ids[i])); |
| 172 for (size_t i = 0; i < arraysize(nomatches_ids_array); ++i) |
| 173 EXPECT_FALSE(info.MatchesIdOrAllIds(nomatches_ids_array[i])); |
| 174 } |
| 175 |
| 176 // matches_all_ids = true. |
| 177 { |
| 178 ExternallyConnectableInfo info(URLPatternSet(), matches_ids, true); |
| 179 for (size_t i = 0; i < matches_ids.size(); ++i) |
| 180 EXPECT_TRUE(info.MatchesIdOrAllIds(matches_ids[i])); |
| 181 for (size_t i = 0; i < arraysize(nomatches_ids_array); ++i) |
| 182 EXPECT_TRUE(info.MatchesIdOrAllIds(nomatches_ids_array[i])); |
| 183 } |
| 184 } |
| 185 |
159 TEST_F(ExternallyConnectableTest, ErrorWrongFormat) { | 186 TEST_F(ExternallyConnectableTest, ErrorWrongFormat) { |
160 RunTestcase(Testcase("externally_connectable_error_wrong_format.json", | 187 RunTestcase(Testcase("externally_connectable_error_wrong_format.json", |
161 errors::kErrorInvalid), | 188 errors::kErrorInvalid), |
162 EXPECT_TYPE_ERROR); | 189 EXPECT_TYPE_ERROR); |
163 } | 190 } |
164 | 191 |
165 TEST_F(ExternallyConnectableTest, ErrorBadID) { | 192 TEST_F(ExternallyConnectableTest, ErrorBadID) { |
166 RunTestcase(Testcase("externally_connectable_bad_id.json", | 193 RunTestcase(Testcase("externally_connectable_bad_id.json", |
167 ErrorUtils::FormatErrorMessage(errors::kErrorInvalidId, | 194 ErrorUtils::FormatErrorMessage(errors::kErrorInvalidId, |
168 "badid")), | 195 "badid")), |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 Testcase( | 249 Testcase( |
223 "externally_connectable_error_unknown_tld.json", | 250 "externally_connectable_error_unknown_tld.json", |
224 ErrorUtils::FormatErrorMessage( | 251 ErrorUtils::FormatErrorMessage( |
225 errors::kErrorTopLevelDomainsNotAllowed, | 252 errors::kErrorTopLevelDomainsNotAllowed, |
226 "notatld", | 253 "notatld", |
227 "http://*.notatld/*")), | 254 "http://*.notatld/*")), |
228 EXPECT_TYPE_ERROR); | 255 EXPECT_TYPE_ERROR); |
229 } | 256 } |
230 | 257 |
231 } // namespace extensions | 258 } // namespace extensions |
OLD | NEW |