Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: extensions/common/url_pattern_set_unittest.cc

Issue 300573002: Add stream operators for URLPattern and URLPatternSet and unit test for URLPatternSet (Closed) Base URL: https://chromium.googlesource.com/chromium/src@permissions
Patch Set: rebase Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/common/url_pattern_set.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "extensions/common/url_pattern_set.h" 5 #include "extensions/common/url_pattern_set.h"
6 6
7 #include <sstream>
8
7 #include "base/values.h" 9 #include "base/values.h"
8 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
9 #include "url/gurl.h" 11 #include "url/gurl.h"
10 12
11 namespace extensions { 13 namespace extensions {
12 14
13 namespace { 15 namespace {
14 16
15 void AddPattern(URLPatternSet* set, const std::string& pattern) { 17 void AddPattern(URLPatternSet* set, const std::string& pattern) {
16 int schemes = URLPattern::SCHEME_ALL; 18 int schemes = URLPattern::SCHEME_ALL;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 TEST(URLPatternSetTest, Two) { 55 TEST(URLPatternSetTest, Two) {
54 URLPatternSet set; 56 URLPatternSet set;
55 AddPattern(&set, "http://www.google.com/*"); 57 AddPattern(&set, "http://www.google.com/*");
56 AddPattern(&set, "http://www.yahoo.com/*"); 58 AddPattern(&set, "http://www.yahoo.com/*");
57 59
58 EXPECT_TRUE(set.MatchesURL(GURL("http://www.google.com/monkey"))); 60 EXPECT_TRUE(set.MatchesURL(GURL("http://www.google.com/monkey")));
59 EXPECT_TRUE(set.MatchesURL(GURL("http://www.yahoo.com/monkey"))); 61 EXPECT_TRUE(set.MatchesURL(GURL("http://www.yahoo.com/monkey")));
60 EXPECT_FALSE(set.MatchesURL(GURL("https://www.apple.com/monkey"))); 62 EXPECT_FALSE(set.MatchesURL(GURL("https://www.apple.com/monkey")));
61 } 63 }
62 64
65 TEST(URLPatternSetTest, StreamOperatorEmpty) {
66 URLPatternSet set;
67
68 std::ostringstream stream;
69 stream << set;
70 EXPECT_EQ("{ }", stream.str());
71 }
72
73 TEST(URLPatternSetTest, StreamOperatorOne) {
74 URLPatternSet set;
75 AddPattern(&set, "http://www.google.com/*");
76
77 std::ostringstream stream;
78 stream << set;
79 EXPECT_EQ("{ \"http://www.google.com/*\" }", stream.str());
80 }
81
82 TEST(URLPatternSetTest, StreamOperatorTwo) {
83 URLPatternSet set;
84 AddPattern(&set, "http://www.google.com/*");
85 AddPattern(&set, "http://www.yahoo.com/*");
86
87 std::ostringstream stream;
88 stream << set;
89 EXPECT_EQ("{ \"http://www.google.com/*\", \"http://www.yahoo.com/*\" }",
90 stream.str());
91 }
92
63 TEST(URLPatternSetTest, OverlapsWith) { 93 TEST(URLPatternSetTest, OverlapsWith) {
64 URLPatternSet set1; 94 URLPatternSet set1;
65 AddPattern(&set1, "http://www.google.com/f*"); 95 AddPattern(&set1, "http://www.google.com/f*");
66 AddPattern(&set1, "http://www.yahoo.com/b*"); 96 AddPattern(&set1, "http://www.yahoo.com/b*");
67 97
68 URLPatternSet set2; 98 URLPatternSet set2;
69 AddPattern(&set2, "http://www.reddit.com/f*"); 99 AddPattern(&set2, "http://www.reddit.com/f*");
70 AddPattern(&set2, "http://www.yahoo.com/z*"); 100 AddPattern(&set2, "http://www.yahoo.com/z*");
71 101
72 URLPatternSet set3; 102 URLPatternSet set3;
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 AddPattern(&expected, yahoo_b); 415 AddPattern(&expected, yahoo_b);
386 AddPattern(&expected, yahoo_c); 416 AddPattern(&expected, yahoo_c);
387 AddPattern(&expected, reddit_a); 417 AddPattern(&expected, reddit_a);
388 AddPattern(&expected, reddit_b); 418 AddPattern(&expected, reddit_b);
389 AddPattern(&expected, reddit_c); 419 AddPattern(&expected, reddit_c);
390 EXPECT_EQ(expected, result); 420 EXPECT_EQ(expected, result);
391 } 421 }
392 } 422 }
393 423
394 } // namespace extensions 424 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/url_pattern_set.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698