diff options
author | jennb@chromium.org <jennb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-10 23:58:18 +0000 |
---|---|---|
committer | jennb@chromium.org <jennb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-10 23:58:18 +0000 |
commit | b160d6dc73b9ce92827f81517d9b155006a4e422 (patch) | |
tree | aa90f4368acd71b1c2a670e4e5533723722d66ed /webkit | |
parent | 9cdef414f2d081d6144ca1578b4fe1d0d4cf7b4d (diff) | |
download | chromium_src-b160d6dc73b9ce92827f81517d9b155006a4e422.zip chromium_src-b160d6dc73b9ce92827f81517d9b155006a4e422.tar.gz chromium_src-b160d6dc73b9ce92827f81517d9b155006a4e422.tar.bz2 |
Update manifest parser code to match current HTML5 spec by
adding support for whitelisting all URLs using a wildcard
and using namespace in place of URL for fallback and network
sections.
BUG=none
TEST=added checks for wildcard character in all sections
Review URL: http://codereview.chromium.org/165151
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22972 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/appcache/manifest_parser.cc | 14 | ||||
-rw-r--r-- | webkit/appcache/manifest_parser.h | 10 | ||||
-rw-r--r-- | webkit/appcache/manifest_parser_unittest.cc | 48 |
3 files changed, 46 insertions, 26 deletions
diff --git a/webkit/appcache/manifest_parser.cc b/webkit/appcache/manifest_parser.cc index b5e8cb8..4930dd6 100644 --- a/webkit/appcache/manifest_parser.cc +++ b/webkit/appcache/manifest_parser.cc @@ -49,8 +49,9 @@ bool ParseManifest(const GURL& manifest_url, const char* data, int length, static const std::wstring kSignature(L"CACHE MANIFEST"); DCHECK(manifest.explicit_urls.empty()); - DCHECK(manifest.online_whitelisted_urls.empty()); - DCHECK(manifest.fallback_urls.empty()); + DCHECK(manifest.fallback_namespaces.empty()); + DCHECK(manifest.online_whitelist_namespaces.empty()); + DCHECK(!manifest.online_whitelist_all); Mode mode = kExplicit; @@ -125,6 +126,9 @@ bool ParseManifest(const GURL& manifest_url, const char* data, int length, mode = kUnknown; } else if (mode == kUnknown) { continue; + } else if (line == L"*" && mode == kOnlineWhitelist) { + manifest.online_whitelist_all = true; + continue; } else if (mode == kExplicit || mode == kOnlineWhitelist) { const wchar_t *line_p = line.c_str(); const wchar_t *line_end = line_p + line.length(); @@ -152,7 +156,7 @@ bool ParseManifest(const GURL& manifest_url, const char* data, int length, if (mode == kExplicit) { manifest.explicit_urls.insert(url.spec()); } else { - manifest.online_whitelisted_urls.push_back(url); + manifest.online_whitelist_namespaces.push_back(url); } } else if (mode == kFallback) { const wchar_t* line_p = line.c_str(); @@ -212,8 +216,8 @@ bool ParseManifest(const GURL& manifest_url, const char* data, int length, // Store regardless of duplicate namespace URL. Only first match // will ever be used. - manifest.fallback_urls.push_back( - std::make_pair(namespace_url, fallback_url)); + manifest.fallback_namespaces.push_back( + FallbackNamespace(namespace_url, fallback_url)); } else { NOTREACHED(); } diff --git a/webkit/appcache/manifest_parser.h b/webkit/appcache/manifest_parser.h index 3bff98a..e9f80d9 100644 --- a/webkit/appcache/manifest_parser.h +++ b/webkit/appcache/manifest_parser.h @@ -41,13 +41,15 @@ class GURL; namespace appcache { -typedef std::vector<std::pair<GURL, GURL> > FallbackUrlVector; +typedef std::pair<GURL, GURL> FallbackNamespace; -// TODO(jennb): spec changed since webkit implementation. Update in next CL. struct Manifest { - std::vector<GURL> online_whitelisted_urls; base::hash_set<std::string> explicit_urls; - FallbackUrlVector fallback_urls; + std::vector<FallbackNamespace> fallback_namespaces; + std::vector<GURL> online_whitelist_namespaces; + bool online_whitelist_all; + + Manifest() : online_whitelist_all(false) {} }; bool ParseManifest(const GURL& manifest_url, const char* data, int length, diff --git a/webkit/appcache/manifest_parser_unittest.cc b/webkit/appcache/manifest_parser_unittest.cc index 07721ab..bcc145b 100644 --- a/webkit/appcache/manifest_parser_unittest.cc +++ b/webkit/appcache/manifest_parser_unittest.cc @@ -8,7 +8,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webkit/appcache/manifest_parser.h" -using appcache::FallbackUrlVector; +using appcache::FallbackNamespace; using appcache::Manifest; using appcache::ParseManifest; @@ -71,8 +71,9 @@ TEST(ManifestParserTest, NoManifestUrl) { const GURL kUrl = GURL::EmptyGURL(); EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); EXPECT_TRUE(manifest.explicit_urls.empty()); - EXPECT_TRUE(manifest.online_whitelisted_urls.empty()); - EXPECT_TRUE(manifest.fallback_urls.empty()); + EXPECT_TRUE(manifest.fallback_namespaces.empty()); + EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); + EXPECT_FALSE(manifest.online_whitelist_all); } TEST(ManifestParserTest, ExplicitUrls) { @@ -92,19 +93,24 @@ TEST(ManifestParserTest, ExplicitUrls) { "CACHE: \r" "garbage:#!@\r" "https://www.foo.com/diffscheme \t \r" - " \t relative/four#stripme\n\r"); + " \t relative/four#stripme\n\r" + "*\r"); EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); - EXPECT_TRUE(manifest.online_whitelisted_urls.empty()); - EXPECT_TRUE(manifest.fallback_urls.empty()); + EXPECT_TRUE(manifest.fallback_namespaces.empty()); + EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); + EXPECT_FALSE(manifest.online_whitelist_all); base::hash_set<std::string> urls = manifest.explicit_urls; - const size_t kExpected = 4; + const size_t kExpected = 5; ASSERT_EQ(kExpected, urls.size()); EXPECT_TRUE(urls.find("http://www.foo.com/relative/one") != urls.end()); EXPECT_TRUE(urls.find("http://www.foo.com/two") != urls.end()); EXPECT_TRUE(urls.find("http://www.diff.com/three") != urls.end()); EXPECT_TRUE(urls.find("http://www.foo.com/relative/four") != urls.end()); + + // Wildcard is treated as a relative URL in explicit section. + EXPECT_TRUE(urls.find("http://www.foo.com/*") != urls.end()); } TEST(ManifestParserTest, WhitelistUrls) { @@ -124,20 +130,23 @@ TEST(ManifestParserTest, WhitelistUrls) { "NETWORK:\r" "https://www.wrongscheme.com\n" "relative/four#stripref \t \r" - "http://www.five.com\r\n"); + "http://www.five.com\r\n" + "*foo\r"); EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); EXPECT_TRUE(manifest.explicit_urls.empty()); - EXPECT_TRUE(manifest.fallback_urls.empty()); + EXPECT_TRUE(manifest.fallback_namespaces.empty()); + EXPECT_FALSE(manifest.online_whitelist_all); - std::vector<GURL> online = manifest.online_whitelisted_urls; - const size_t kExpected = 5; + std::vector<GURL> online = manifest.online_whitelist_namespaces; + const size_t kExpected = 6; ASSERT_EQ(kExpected, online.size()); EXPECT_EQ(GURL("http://www.bar.com/relative/one"), online[0]); EXPECT_EQ(GURL("http://www.bar.com/two"), online[1]); EXPECT_EQ(GURL("http://www.diff.com/three"), online[2]); EXPECT_EQ(GURL("http://www.bar.com/relative/four"), online[3]); EXPECT_EQ(GURL("http://www.five.com"), online[4]); + EXPECT_EQ(GURL("http://www.bar.com/*foo"), online[5]); } TEST(ManifestParserTest, FallbackUrls) { @@ -150,6 +159,7 @@ TEST(ManifestParserTest, FallbackUrls) { "UNKNOWN:\r" "FALLBACK:\r" "relative/one \t \t http://glorp.com/onefb \t \r" + "*\r" "https://glorp.com/wrong http://glorp.com/wrongfb\r" "http://glorp.com/two#strip relative/twofb\r" "HTTP://glorp.com/three relative/threefb#strip\n" @@ -167,9 +177,10 @@ TEST(ManifestParserTest, FallbackUrls) { EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); EXPECT_TRUE(manifest.explicit_urls.empty()); - EXPECT_TRUE(manifest.online_whitelisted_urls.empty()); + EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); + EXPECT_FALSE(manifest.online_whitelist_all); - FallbackUrlVector fallbacks = manifest.fallback_urls; + std::vector<FallbackNamespace> fallbacks = manifest.fallback_namespaces; const size_t kExpected = 5; ASSERT_EQ(kExpected, fallbacks.size()); EXPECT_EQ(GURL("http://glorp.com/relative/one"), @@ -209,9 +220,10 @@ TEST(ManifestParserTest, FallbackUrlsWithPort) { EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); EXPECT_TRUE(manifest.explicit_urls.empty()); - EXPECT_TRUE(manifest.online_whitelisted_urls.empty()); + EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); + EXPECT_FALSE(manifest.online_whitelist_all); - FallbackUrlVector fallbacks = manifest.fallback_urls; + std::vector<FallbackNamespace> fallbacks = manifest.fallback_namespaces; const size_t kExpected = 3; ASSERT_EQ(kExpected, fallbacks.size()); EXPECT_EQ(GURL("http://www.portme.com:1234/one"), @@ -238,6 +250,7 @@ TEST(ManifestParserTest, ComboUrls) { "NETWORK:\r" "http://combo.com/whitelist-1\r" "HTTP://www.diff.com/whitelist-2#strip\r" + "*\r" "CACHE:\n\r" "http://www.diff.com/explicit-3\r" "FALLBACK:\r" @@ -250,6 +263,7 @@ TEST(ManifestParserTest, ComboUrls) { "relative/whitelist-3#strip\r" "http://combo.com:99/whitelist-4\r"); EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); + EXPECT_TRUE(manifest.online_whitelist_all); base::hash_set<std::string> urls = manifest.explicit_urls; size_t expected = 3; @@ -259,7 +273,7 @@ TEST(ManifestParserTest, ComboUrls) { EXPECT_TRUE(urls.find("http://combo.com:99/explicit-2") != urls.end()); EXPECT_TRUE(urls.find("http://www.diff.com/explicit-3") != urls.end()); - std::vector<GURL> online = manifest.online_whitelisted_urls; + std::vector<GURL> online = manifest.online_whitelist_namespaces; expected = 4; ASSERT_EQ(expected, online.size()); EXPECT_EQ(GURL("http://combo.com/whitelist-1"), online[0]); @@ -267,7 +281,7 @@ TEST(ManifestParserTest, ComboUrls) { EXPECT_EQ(GURL("http://combo.com:42/relative/whitelist-3"), online[2]); EXPECT_EQ(GURL("http://combo.com:99/whitelist-4"), online[3]); - FallbackUrlVector fallbacks = manifest.fallback_urls; + std::vector<FallbackNamespace> fallbacks = manifest.fallback_namespaces; expected = 2; ASSERT_EQ(expected, fallbacks.size()); EXPECT_EQ(GURL("http://combo.com:42/fallback-1"), |