Bug 765203 - Support mode 'unknown' when parsing cache manifest, r=jduell
authorHonza Bambas <honzab.moz@firemni.cz>
Sat, 14 Jul 2012 11:52:35 +0200
changeset 99288 2ff61044edbd8c8418cbb00dd12e15788fb3e544
parent 99287 6bfce37d7fa494b499b96dfea3ba0a6dce8a58dd
child 99289 9046ecf4db8fafb4ce1c2a28aaefff597f018b8b
child 99309 06ba7dd9f841264ef6506a173107e1ab8df76e1f
push id23116
push userryanvm@gmail.com
push dateSat, 14 Jul 2012 16:58:48 +0000
treeherdermozilla-central@9046ecf4db8f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjduell
bugs765203
milestone16.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 765203 - Support mode 'unknown' when parsing cache manifest, r=jduell
dom/tests/mochitest/ajax/offline/Makefile.in
dom/tests/mochitest/ajax/offline/test_bug765203.html
dom/tests/mochitest/ajax/offline/unknownSection.cacheManifest
dom/tests/mochitest/ajax/offline/unknownSection.cacheManifest^headers^
uriloader/prefetch/nsOfflineCacheUpdate.cpp
uriloader/prefetch/nsOfflineCacheUpdate.h
--- a/dom/tests/mochitest/ajax/offline/Makefile.in
+++ b/dom/tests/mochitest/ajax/offline/Makefile.in
@@ -27,16 +27,19 @@ MOCHITEST_FILES	= \
 	test_offlineIFrame.html \
 	test_bug445544.html \
 	test_bug460353.html \
 	test_bug474696.html \
 	test_bug544462.html \
 	test_bug744719.html \
 	744719.cacheManifest \
 	744719.cacheManifest^headers^ \
+	test_bug765203.html \
+	unknownSection.cacheManifest \
+	unknownSection.cacheManifest^headers^ \
 	test_bug744719-cancel.html \
 	744719-cancel.cacheManifest \
 	744719-cancel.cacheManifest^headers^ \
 	subresource744719.html \
 	test_foreign.html \
 	test_fallback.html \
 	test_overlap.html \
 	test_redirectManifest.html \
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/ajax/offline/test_bug765203.html
@@ -0,0 +1,74 @@
+<html xmlns="http://www.w3.org/1999/xhtml" manifest="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/unknownSection.cacheManifest">
+<head>
+<title>unknown section</title>
+
+<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+<script type="text/javascript" src="/tests/dom/tests/mochitest/ajax/offline/offlineTests.js"></script>
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+
+<script type="text/javascript">
+
+var gGotChecking = false;
+var gGotDownloading = false;
+
+function manifestUpdated()
+{
+  OfflineTest.ok(gGotChecking, "Should get a checking event");
+  OfflineTest.ok(gGotDownloading, "Should get a downloading event");
+
+  OfflineTest.is(applicationCache.status, 1, "Cache status should be 1 (CACHED)");
+
+  var entries = [
+    // The manifest itself should be in the cache
+    ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/unknownSection.cacheManifest", true],
+
+    // The document that requested the manifest should be in the cache
+    [window.location.href, true],
+
+    // The entries from the manifest should be in the cache
+    ["http://mochi.test:8888/tests/SimpleTest/SimpleTest.js", true],
+    ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/offlineTests.js", true],
+
+    // The bad entries from the manifest should not be in the cache
+    ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/jupiter.jpg", false]
+  ];
+  OfflineTest.checkCacheEntries(
+    entries,
+    function() {
+       OfflineTest.teardown();
+       OfflineTest.finish();
+    });
+}
+
+if (OfflineTest.setup()) {
+  OfflineTest.ok(applicationCache instanceof EventTarget,
+                 "applicationCache should be an event target");
+
+  applicationCache.onerror = OfflineTest.failEvent;
+
+  applicationCache.addEventListener("checking", function() {
+    // We should get the "checking" event during an initial update,
+    // but until we are associated it will not affect applicationCache.status
+    OfflineTest.is(applicationCache.status, applicationCache.UNCACHED,
+                   "CHECKING state during initial update");
+    gGotChecking = true;
+    }, true);
+  applicationCache.ondownloading = function() {
+    // We should get the "downloading" event during an initial update,
+    // but until we are associated it will not affect applicationCache.status
+    OfflineTest.is(applicationCache.status, applicationCache.UNCACHED,
+                   "DOWNLOADING state during initial update")
+    gGotDownloading = true; };
+  applicationCache.oncached = OfflineTest.priv(manifestUpdated);
+}
+
+SimpleTest.waitForExplicitFinish();
+
+</script>
+
+</head>
+
+<body>
+
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/ajax/offline/unknownSection.cacheManifest
@@ -0,0 +1,10 @@
+CACHE MANIFEST
+http://mochi.test:8888/tests/SimpleTest/SimpleTest.js
+
+UNKNOWN-SECTION:
+http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/jupiter.jpg
+here can be anything the current implementaion
+is not able to parse at all and is just silently ignored
+
+CACHE:
+http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/offlineTests.js
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/ajax/offline/unknownSection.cacheManifest^headers^
@@ -0,0 +1,2 @@
+Content-Type: text/cache-manifest
+
--- a/uriloader/prefetch/nsOfflineCacheUpdate.cpp
+++ b/uriloader/prefetch/nsOfflineCacheUpdate.cpp
@@ -826,25 +826,37 @@ nsOfflineManifestItem::HandleManifestLin
         return NS_OK;
     }
 
     if (line.EqualsLiteral("NETWORK:")) {
         mParserState = PARSE_BYPASS_ENTRIES;
         return NS_OK;
     }
 
+    // Every other section type we don't know must be silently ignored.
+    nsCString::const_iterator lastChar = end;
+    if (*(--lastChar) == ':') {
+        mParserState = PARSE_UNKNOWN_SECTION;
+        return NS_OK;
+    }
+
     nsresult rv;
 
     switch(mParserState) {
     case PARSE_INIT:
     case PARSE_ERROR: {
         // this should have been dealt with earlier
         return NS_ERROR_FAILURE;
     }
 
+    case PARSE_UNKNOWN_SECTION: {
+        // just jump over
+        return NS_OK;
+    }
+
     case PARSE_CACHE_ENTRIES: {
         nsCOMPtr<nsIURI> uri;
         rv = NS_NewURI(getter_AddRefs(uri), line, nsnull, mURI);
         if (NS_FAILED(rv))
             break;
         if (NS_FAILED(DropReferenceFromURL(uri)))
             break;
 
--- a/uriloader/prefetch/nsOfflineCacheUpdate.h
+++ b/uriloader/prefetch/nsOfflineCacheUpdate.h
@@ -143,16 +143,17 @@ private:
 
     void ReadStrictFileOriginPolicyPref();
 
     enum {
         PARSE_INIT,
         PARSE_CACHE_ENTRIES,
         PARSE_FALLBACK_ENTRIES,
         PARSE_BYPASS_ENTRIES,
+        PARSE_UNKNOWN_SECTION,
         PARSE_ERROR
     } mParserState;
 
     nsCString mReadBuf;
 
     nsCOMArray<nsIURI> mExplicitURIs;
     nsCOMArray<nsIURI> mFallbackURIs;