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

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

Issue 225493002: cleanup: cpplint src/extension/* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comment Created 6 years, 8 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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "extensions/common/url_pattern.h" 6 #include "extensions/common/url_pattern.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "url/gurl.h" 8 #include "url/gurl.h"
9 9
10 namespace { 10 namespace {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 TEST(ExtensionURLPatternTest, Ports) { 49 TEST(ExtensionURLPatternTest, Ports) {
50 const struct { 50 const struct {
51 const char* pattern; 51 const char* pattern;
52 URLPattern::ParseResult expected_result; 52 URLPattern::ParseResult expected_result;
53 const char* expected_port; 53 const char* expected_port;
54 } kTestPatterns[] = { 54 } kTestPatterns[] = {
55 { "http://foo:1234/", URLPattern::PARSE_SUCCESS, "1234" }, 55 { "http://foo:1234/", URLPattern::PARSE_SUCCESS, "1234" },
56 { "http://foo:1234/bar", URLPattern::PARSE_SUCCESS, "1234" }, 56 { "http://foo:1234/bar", URLPattern::PARSE_SUCCESS, "1234" },
57 { "http://*.foo:1234/", URLPattern::PARSE_SUCCESS, "1234" }, 57 { "http://*.foo:1234/", URLPattern::PARSE_SUCCESS, "1234" },
58 { "http://*.foo:1234/bar", URLPattern::PARSE_SUCCESS,"1234" }, 58 { "http://*.foo:1234/bar", URLPattern::PARSE_SUCCESS, "1234" },
59 { "http://:1234/", URLPattern::PARSE_SUCCESS, "1234" }, 59 { "http://:1234/", URLPattern::PARSE_SUCCESS, "1234" },
60 { "http://foo:/", URLPattern::PARSE_ERROR_INVALID_PORT, "*" }, 60 { "http://foo:/", URLPattern::PARSE_ERROR_INVALID_PORT, "*" },
61 { "http://foo:*/", URLPattern::PARSE_SUCCESS, "*" }, 61 { "http://foo:*/", URLPattern::PARSE_SUCCESS, "*" },
62 { "http://*.foo:/", URLPattern::PARSE_ERROR_INVALID_PORT, "*" }, 62 { "http://*.foo:/", URLPattern::PARSE_ERROR_INVALID_PORT, "*" },
63 { "http://foo:com/", URLPattern::PARSE_ERROR_INVALID_PORT, "*" }, 63 { "http://foo:com/", URLPattern::PARSE_ERROR_INVALID_PORT, "*" },
64 { "http://foo:123456/", URLPattern::PARSE_ERROR_INVALID_PORT, "*" }, 64 { "http://foo:123456/", URLPattern::PARSE_ERROR_INVALID_PORT, "*" },
65 { "http://foo:80:80/monkey", URLPattern::PARSE_ERROR_INVALID_PORT, "*" }, 65 { "http://foo:80:80/monkey", URLPattern::PARSE_ERROR_INVALID_PORT, "*" },
66 { "file://foo:1234/bar", URLPattern::PARSE_SUCCESS, "*" }, 66 { "file://foo:1234/bar", URLPattern::PARSE_SUCCESS, "*" },
67 { "chrome://foo:1234/bar", URLPattern::PARSE_ERROR_INVALID_PORT, "*" }, 67 { "chrome://foo:1234/bar", URLPattern::PARSE_ERROR_INVALID_PORT, "*" },
68 68
69 // Port-like strings in the path should not trigger a warning. 69 // Port-like strings in the path should not trigger a warning.
70 { "http://*/:1234", URLPattern::PARSE_SUCCESS, "*" }, 70 { "http://*/:1234", URLPattern::PARSE_SUCCESS, "*" },
71 { "http://*.foo/bar:1234", URLPattern::PARSE_SUCCESS, "*" }, 71 { "http://*.foo/bar:1234", URLPattern::PARSE_SUCCESS, "*" },
72 { "http://foo/bar:1234/path", URLPattern::PARSE_SUCCESS,"*" }, 72 { "http://foo/bar:1234/path", URLPattern::PARSE_SUCCESS, "*" },
73 }; 73 };
74 74
75 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestPatterns); ++i) { 75 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestPatterns); ++i) {
76 URLPattern pattern(URLPattern::SCHEME_ALL); 76 URLPattern pattern(URLPattern::SCHEME_ALL);
77 EXPECT_EQ(kTestPatterns[i].expected_result, 77 EXPECT_EQ(kTestPatterns[i].expected_result,
78 pattern.Parse(kTestPatterns[i].pattern)) 78 pattern.Parse(kTestPatterns[i].pattern))
79 << "Got unexpected result for URL pattern: " 79 << "Got unexpected result for URL pattern: "
80 << kTestPatterns[i].pattern; 80 << kTestPatterns[i].pattern;
81 EXPECT_EQ(kTestPatterns[i].expected_port, pattern.port()) 81 EXPECT_EQ(kTestPatterns[i].expected_port, pattern.port())
82 << "Got unexpected port for URL pattern: " << kTestPatterns[i].pattern; 82 << "Got unexpected port for URL pattern: " << kTestPatterns[i].pattern;
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 EXPECT_EQ("www.example.com", pattern.host()); 373 EXPECT_EQ("www.example.com", pattern.host());
374 EXPECT_FALSE(pattern.match_subdomains()); 374 EXPECT_FALSE(pattern.match_subdomains());
375 EXPECT_FALSE(pattern.match_all_urls()); 375 EXPECT_FALSE(pattern.match_all_urls());
376 EXPECT_EQ("/foo", pattern.path()); 376 EXPECT_EQ("/foo", pattern.path());
377 EXPECT_EQ("80", pattern.port()); 377 EXPECT_EQ("80", pattern.port());
378 EXPECT_TRUE(pattern.MatchesURL(GURL("http://www.example.com:80/foo"))); 378 EXPECT_TRUE(pattern.MatchesURL(GURL("http://www.example.com:80/foo")));
379 EXPECT_TRUE(pattern.MatchesURL(GURL("http://www.example.com/foo"))); 379 EXPECT_TRUE(pattern.MatchesURL(GURL("http://www.example.com/foo")));
380 EXPECT_FALSE(pattern.MatchesURL(GURL("http://www.example.com:8080/foo"))); 380 EXPECT_FALSE(pattern.MatchesURL(GURL("http://www.example.com:8080/foo")));
381 EXPECT_FALSE(pattern.MatchesURL( 381 EXPECT_FALSE(pattern.MatchesURL(
382 GURL("filesystem:http://www.example.com:8080/foo/"))); 382 GURL("filesystem:http://www.example.com:8080/foo/")));
383 EXPECT_FALSE(pattern.MatchesURL(GURL("filesystem:http://www.example.com/f/foo" ))); 383 EXPECT_FALSE(pattern.MatchesURL(
384 GURL("filesystem:http://www.example.com/f/foo")));
384 } 385 }
385 386
386 // Explicit port wildcard 387 // Explicit port wildcard
387 TEST(ExtensionURLPatternTest, Match18) { 388 TEST(ExtensionURLPatternTest, Match18) {
388 URLPattern pattern(kAllSchemes); 389 URLPattern pattern(kAllSchemes);
389 EXPECT_EQ(URLPattern::PARSE_SUCCESS, 390 EXPECT_EQ(URLPattern::PARSE_SUCCESS,
390 pattern.Parse("http://www.example.com:*/foo")); 391 pattern.Parse("http://www.example.com:*/foo"));
391 EXPECT_EQ("http", pattern.scheme()); 392 EXPECT_EQ("http", pattern.scheme());
392 EXPECT_EQ("www.example.com", pattern.host()); 393 EXPECT_EQ("www.example.com", pattern.host());
393 EXPECT_FALSE(pattern.match_subdomains()); 394 EXPECT_FALSE(pattern.match_subdomains());
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 EXPECT_TRUE(StrictlyContains(pattern10, pattern12)); 794 EXPECT_TRUE(StrictlyContains(pattern10, pattern12));
794 EXPECT_TRUE(StrictlyContains(pattern10, pattern13)); 795 EXPECT_TRUE(StrictlyContains(pattern10, pattern13));
795 796
796 // More... 797 // More...
797 EXPECT_TRUE(StrictlyContains(pattern12, pattern11)); 798 EXPECT_TRUE(StrictlyContains(pattern12, pattern11));
798 EXPECT_TRUE(NeitherContains(pattern11, pattern13)); 799 EXPECT_TRUE(NeitherContains(pattern11, pattern13));
799 EXPECT_TRUE(StrictlyContains(pattern12, pattern13)); 800 EXPECT_TRUE(StrictlyContains(pattern12, pattern13));
800 } 801 }
801 802
802 } // namespace 803 } // namespace
OLDNEW
« no previous file with comments | « extensions/common/url_pattern_set_unittest.cc ('k') | extensions/common/user_script_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698