| Index: chrome/common/extensions/url_pattern_unittest.cc
|
| diff --git a/chrome/common/extensions/url_pattern_unittest.cc b/chrome/common/extensions/url_pattern_unittest.cc
|
| index cda955097de05b9dd5a1c5877f90f7b81f0500b5..b919c312e098b01bebf68c1232e8ecd7c02b971f 100644
|
| --- a/chrome/common/extensions/url_pattern_unittest.cc
|
| +++ b/chrome/common/extensions/url_pattern_unittest.cc
|
| @@ -43,37 +43,58 @@ TEST(ExtensionURLPatternTest, ParseInvalid) {
|
| }
|
| };
|
|
|
| -TEST(ExtensionURLPatternTest, Colons) {
|
| +TEST(ExtensionURLPatternTest, Ports) {
|
| const struct {
|
| const char* pattern;
|
| - URLPattern::ParseResult expected_result;
|
| + URLPattern::ParseResult expected_result_strict;
|
| + URLPattern::ParseResult expected_result_lenient;
|
| + const char* expected_port;
|
| } kTestPatterns[] = {
|
| - { "http://foo:1234/", URLPattern::PARSE_ERROR_HAS_COLON },
|
| - { "http://foo:1234/bar", URLPattern::PARSE_ERROR_HAS_COLON },
|
| - { "http://*.foo:1234/", URLPattern::PARSE_ERROR_HAS_COLON },
|
| - { "http://*.foo:1234/bar", URLPattern::PARSE_ERROR_HAS_COLON },
|
| - { "http://:1234/", URLPattern::PARSE_ERROR_HAS_COLON },
|
| - { "http://foo:/", URLPattern::PARSE_ERROR_HAS_COLON },
|
| - { "http://*.foo:/", URLPattern::PARSE_ERROR_HAS_COLON },
|
| - { "http://foo:com/", URLPattern::PARSE_ERROR_HAS_COLON },
|
| + { "http://foo:1234/", URLPattern::PARSE_ERROR_HAS_COLON,
|
| + URLPattern::PARSE_SUCCESS, "1234" },
|
| + { "http://foo:1234/bar", URLPattern::PARSE_ERROR_HAS_COLON,
|
| + URLPattern::PARSE_SUCCESS, "1234" },
|
| + { "http://*.foo:1234/", URLPattern::PARSE_ERROR_HAS_COLON,
|
| + URLPattern::PARSE_SUCCESS, "1234" },
|
| + { "http://*.foo:1234/bar", URLPattern::PARSE_ERROR_HAS_COLON,
|
| + URLPattern::PARSE_SUCCESS, "1234" },
|
| + { "http://:1234/", URLPattern::PARSE_ERROR_HAS_COLON,
|
| + URLPattern::PARSE_SUCCESS, "1234" },
|
| + { "http://foo:/", URLPattern::PARSE_ERROR_HAS_COLON,
|
| + URLPattern::PARSE_SUCCESS, "" },
|
| + { "http://foo:*/", URLPattern::PARSE_ERROR_HAS_COLON,
|
| + URLPattern::PARSE_SUCCESS, "*" },
|
| + { "http://*.foo:/", URLPattern::PARSE_ERROR_HAS_COLON,
|
| + URLPattern::PARSE_SUCCESS, "" },
|
| + { "http://foo:com/", URLPattern::PARSE_ERROR_HAS_COLON,
|
| + URLPattern::PARSE_ERROR_INVALID_PORT, "" },
|
| + { "http://foo:123456/", URLPattern::PARSE_ERROR_HAS_COLON,
|
| + URLPattern::PARSE_ERROR_INVALID_PORT, "" },
|
|
|
| // Port-like strings in the path should not trigger a warning.
|
| - { "http://*/:1234", URLPattern::PARSE_SUCCESS },
|
| - { "http://*.foo/bar:1234", URLPattern::PARSE_SUCCESS },
|
| - { "http://foo/bar:1234/path", URLPattern::PARSE_SUCCESS },
|
| + { "http://*/:1234", URLPattern::PARSE_SUCCESS,
|
| + URLPattern::PARSE_SUCCESS, "" },
|
| + { "http://*.foo/bar:1234", URLPattern::PARSE_SUCCESS,
|
| + URLPattern::PARSE_SUCCESS, "" },
|
| + { "http://foo/bar:1234/path", URLPattern::PARSE_SUCCESS,
|
| + URLPattern::PARSE_SUCCESS, "" },
|
| };
|
|
|
| for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestPatterns); ++i) {
|
| URLPattern pattern(URLPattern::SCHEME_ALL);
|
|
|
| - // Without |strict_error_checks|, expect success.
|
| - EXPECT_EQ(URLPattern::PARSE_SUCCESS,
|
| + // Check results without |strict_error_checks|.
|
| + EXPECT_EQ(kTestPatterns[i].expected_result_lenient,
|
| pattern.Parse(kTestPatterns[i].pattern,
|
| URLPattern::PARSE_LENIENT))
|
| - << "Got unexpected error for URL pattern: "
|
| + << "Got unexpected result for URL pattern: "
|
| + << kTestPatterns[i].pattern;
|
| + EXPECT_EQ(kTestPatterns[i].expected_port, pattern.port())
|
| + << "Got unexpected port for URL pattern: "
|
| << kTestPatterns[i].pattern;
|
|
|
| - EXPECT_EQ(kTestPatterns[i].expected_result,
|
| + // Check results with |strict_error_checks|.
|
| + EXPECT_EQ(kTestPatterns[i].expected_result_strict,
|
| pattern.Parse(kTestPatterns[i].pattern,
|
| URLPattern::PARSE_STRICT))
|
| << "Got unexpected result for URL pattern: "
|
| @@ -371,6 +392,7 @@ static const struct GetAsStringPatterns {
|
| { "data:monkey" },
|
| { "javascript:*" },
|
| { "javascript:atemyhomework" },
|
| + { "http://www.example.com:8080/foo" },
|
| };
|
|
|
| TEST(ExtensionURLPatternTest, GetAsString) {
|
| @@ -378,7 +400,7 @@ TEST(ExtensionURLPatternTest, GetAsString) {
|
| URLPattern pattern(URLPattern::SCHEME_ALL);
|
| EXPECT_EQ(URLPattern::PARSE_SUCCESS,
|
| pattern.Parse(kGetAsStringTestCases[i].pattern,
|
| - URLPattern::PARSE_STRICT));
|
| + URLPattern::PARSE_LENIENT));
|
| EXPECT_STREQ(kGetAsStringTestCases[i].pattern,
|
| pattern.GetAsString().c_str());
|
| }
|
| @@ -467,3 +489,22 @@ TEST(ExtensionURLPatternTest, ConvertToExplicitSchemes) {
|
|
|
| EXPECT_EQ("http://google.com/monkey", monkey[0].GetAsString());
|
| }
|
| +
|
| +TEST(ExtensionURLPatternTest, IgnorePorts) {
|
| + URLPattern pattern1(kAllSchemes);
|
| + EXPECT_EQ(URLPattern::PARSE_SUCCESS,
|
| + pattern1.Parse("http://www.example.com:8080/foo",
|
| + URLPattern::PARSE_LENIENT));
|
| +
|
| + EXPECT_EQ("http://www.example.com/foo", pattern1.GetAsString());
|
| + EXPECT_TRUE(pattern1.MatchesURL(GURL("http://www.example.com:1234/foo")));
|
| +
|
| + URLPattern pattern2(kAllSchemes);
|
| + pattern2.set_ignores_ports(false);
|
| + EXPECT_EQ(URLPattern::PARSE_SUCCESS,
|
| + pattern2.Parse("http://www.example.com:8080/foo",
|
| + URLPattern::PARSE_LENIENT));
|
| +
|
| + EXPECT_EQ("http://www.example.com:8080/foo", pattern2.GetAsString());
|
| + EXPECT_FALSE(pattern2.MatchesURL(GURL("http://www.example.com:1234/foo")));
|
| +}
|
|
|