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

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: Created 6 years, 7 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
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 "base/values.h" 7 #include "base/values.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "url/gurl.h" 9 #include "url/gurl.h"
10 10
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 TEST(URLPatternSetTest, Two) { 53 TEST(URLPatternSetTest, Two) {
54 URLPatternSet set; 54 URLPatternSet set;
55 AddPattern(&set, "http://www.google.com/*"); 55 AddPattern(&set, "http://www.google.com/*");
56 AddPattern(&set, "http://www.yahoo.com/*"); 56 AddPattern(&set, "http://www.yahoo.com/*");
57 57
58 EXPECT_TRUE(set.MatchesURL(GURL("http://www.google.com/monkey"))); 58 EXPECT_TRUE(set.MatchesURL(GURL("http://www.google.com/monkey")));
59 EXPECT_TRUE(set.MatchesURL(GURL("http://www.yahoo.com/monkey"))); 59 EXPECT_TRUE(set.MatchesURL(GURL("http://www.yahoo.com/monkey")));
60 EXPECT_FALSE(set.MatchesURL(GURL("https://www.apple.com/monkey"))); 60 EXPECT_FALSE(set.MatchesURL(GURL("https://www.apple.com/monkey")));
61 } 61 }
62 62
63 TEST(URLPatternSetTest, StreamOperatorEmpty) {
64 URLPatternSet set;
65
66 std::ostringstream stream;
67 stream << set;
68 EXPECT_STREQ("{ }", stream.str().c_str());
Jeffrey Yasskin 2014/05/28 21:06:08 You can use EXPECT_EQ("{ }", stream.str());
aboxhall 2014/05/28 22:06:44 Done.
69 }
70
71 TEST(URLPatternSetTest, StreamOperatorOne) {
72 URLPatternSet set;
73 AddPattern(&set, "http://www.google.com/*");
74
75 std::ostringstream stream;
76 stream << set;
77 EXPECT_STREQ("{ \"http://www.google.com/*\" }", stream.str().c_str());
78 }
79
80 TEST(URLPatternSetTest, StreamOperatorTwo) {
81 URLPatternSet set;
82 AddPattern(&set, "http://www.google.com/*");
83 AddPattern(&set, "http://www.yahoo.com/*");
84
85 std::ostringstream stream;
86 stream << set;
87 EXPECT_STREQ("{ \"http://www.google.com/*\", \"http://www.yahoo.com/*\" }",
88 stream.str().c_str());
89 }
90
63 TEST(URLPatternSetTest, OverlapsWith) { 91 TEST(URLPatternSetTest, OverlapsWith) {
64 URLPatternSet set1; 92 URLPatternSet set1;
65 AddPattern(&set1, "http://www.google.com/f*"); 93 AddPattern(&set1, "http://www.google.com/f*");
66 AddPattern(&set1, "http://www.yahoo.com/b*"); 94 AddPattern(&set1, "http://www.yahoo.com/b*");
67 95
68 URLPatternSet set2; 96 URLPatternSet set2;
69 AddPattern(&set2, "http://www.reddit.com/f*"); 97 AddPattern(&set2, "http://www.reddit.com/f*");
70 AddPattern(&set2, "http://www.yahoo.com/z*"); 98 AddPattern(&set2, "http://www.yahoo.com/z*");
71 99
72 URLPatternSet set3; 100 URLPatternSet set3;
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 AddPattern(&expected, yahoo_b); 413 AddPattern(&expected, yahoo_b);
386 AddPattern(&expected, yahoo_c); 414 AddPattern(&expected, yahoo_c);
387 AddPattern(&expected, reddit_a); 415 AddPattern(&expected, reddit_a);
388 AddPattern(&expected, reddit_b); 416 AddPattern(&expected, reddit_b);
389 AddPattern(&expected, reddit_c); 417 AddPattern(&expected, reddit_c);
390 EXPECT_EQ(expected, result); 418 EXPECT_EQ(expected, result);
391 } 419 }
392 } 420 }
393 421
394 } // namespace extensions 422 } // namespace extensions
OLDNEW
« extensions/common/url_pattern_set.cc ('K') | « extensions/common/url_pattern_set.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698