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

Unified Diff: chrome/common/extensions/url_pattern_unittest.cc

Issue 7229012: Use extension match pattern syntax in content settings extension API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: unit test Created 9 years, 6 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 side-by-side diff with in-line comments
Download patch
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..359fde7e78ae6e2c06ed4f1a5bc9cfab85d1bb7e 100644
--- a/chrome/common/extensions/url_pattern_unittest.cc
+++ b/chrome/common/extensions/url_pattern_unittest.cc
@@ -43,37 +43,56 @@ 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: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 +390,7 @@ static const struct GetAsStringPatterns {
{ "data:monkey" },
{ "javascript:*" },
{ "javascript:atemyhomework" },
+ { "http://www.example.com:8080/foo" },
};
TEST(ExtensionURLPatternTest, GetAsString) {
@@ -378,7 +398,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());
}

Powered by Google App Engine
This is Rietveld 408576698