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 "chrome/common/extensions/extension.h" | 5 #include "chrome/common/extensions/extension.h" |
6 | 6 |
| 7 #include "base/values.h" |
7 #include "googleurl/src/gurl.h" | 8 #include "googleurl/src/gurl.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
9 | 10 |
10 namespace { | 11 namespace { |
11 | 12 |
12 void AddPattern(URLPatternSet* set, const std::string& pattern) { | 13 void AddPattern(URLPatternSet* set, const std::string& pattern) { |
13 int schemes = URLPattern::SCHEME_ALL; | 14 int schemes = URLPattern::SCHEME_ALL; |
14 set->AddPattern(URLPattern(schemes, pattern)); | 15 set->AddPattern(URLPattern(schemes, pattern)); |
15 } | 16 } |
16 | 17 |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 | 209 |
209 AddPattern(&set1, "http://www.google.com/*"); | 210 AddPattern(&set1, "http://www.google.com/*"); |
210 AddPattern(&set2, "http://www.google.com/*"); | 211 AddPattern(&set2, "http://www.google.com/*"); |
211 | 212 |
212 AddPattern(&set1, "http://www.google.com/*"); | 213 AddPattern(&set1, "http://www.google.com/*"); |
213 | 214 |
214 // The sets should still be equal after adding a duplicate. | 215 // The sets should still be equal after adding a duplicate. |
215 EXPECT_EQ(set2, set1); | 216 EXPECT_EQ(set2, set1); |
216 } | 217 } |
217 | 218 |
| 219 TEST(URLPatternSetTest, ToValueAndPopulate) { |
| 220 URLPatternSet set1; |
| 221 URLPatternSet set2; |
| 222 |
| 223 std::vector<std::string> patterns; |
| 224 patterns.push_back("http://www.google.com/*"); |
| 225 patterns.push_back("http://www.yahoo.com/*"); |
| 226 |
| 227 for (size_t i = 0; i < patterns.size(); ++i) |
| 228 AddPattern(&set1, patterns[i]); |
| 229 |
| 230 std::string error; |
| 231 bool allow_file_access = false; |
| 232 scoped_ptr<base::ListValue> value(set1.ToValue()); |
| 233 set2.Populate(*value, URLPattern::SCHEME_ALL, allow_file_access, &error); |
| 234 EXPECT_EQ(set1, set2); |
| 235 |
| 236 set2.ClearPatterns(); |
| 237 set2.Populate(patterns, URLPattern::SCHEME_ALL, allow_file_access, &error); |
| 238 EXPECT_EQ(set1, set2); |
| 239 } |
| 240 |
218 TEST(URLPatternSetTest, NwayUnion) { | 241 TEST(URLPatternSetTest, NwayUnion) { |
219 std::string google_a = "http://www.google.com/a*"; | 242 std::string google_a = "http://www.google.com/a*"; |
220 std::string google_b = "http://www.google.com/b*"; | 243 std::string google_b = "http://www.google.com/b*"; |
221 std::string google_c = "http://www.google.com/c*"; | 244 std::string google_c = "http://www.google.com/c*"; |
222 std::string yahoo_a = "http://www.yahoo.com/a*"; | 245 std::string yahoo_a = "http://www.yahoo.com/a*"; |
223 std::string yahoo_b = "http://www.yahoo.com/b*"; | 246 std::string yahoo_b = "http://www.yahoo.com/b*"; |
224 std::string yahoo_c = "http://www.yahoo.com/c*"; | 247 std::string yahoo_c = "http://www.yahoo.com/c*"; |
225 std::string reddit_a = "http://www.reddit.com/a*"; | 248 std::string reddit_a = "http://www.reddit.com/a*"; |
226 std::string reddit_b = "http://www.reddit.com/b*"; | 249 std::string reddit_b = "http://www.reddit.com/b*"; |
227 std::string reddit_c = "http://www.reddit.com/c*"; | 250 std::string reddit_c = "http://www.reddit.com/c*"; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 AddPattern(&expected, google_c); | 383 AddPattern(&expected, google_c); |
361 AddPattern(&expected, yahoo_a); | 384 AddPattern(&expected, yahoo_a); |
362 AddPattern(&expected, yahoo_b); | 385 AddPattern(&expected, yahoo_b); |
363 AddPattern(&expected, yahoo_c); | 386 AddPattern(&expected, yahoo_c); |
364 AddPattern(&expected, reddit_a); | 387 AddPattern(&expected, reddit_a); |
365 AddPattern(&expected, reddit_b); | 388 AddPattern(&expected, reddit_b); |
366 AddPattern(&expected, reddit_c); | 389 AddPattern(&expected, reddit_c); |
367 EXPECT_EQ(expected, result); | 390 EXPECT_EQ(expected, result); |
368 } | 391 } |
369 } | 392 } |
OLD | NEW |