Bug 482370 - after noupdate documents are associated with the wrong application cache. r+sr=jst
authorDave Camp <dcamp@mozilla.com>
Tue, 10 Mar 2009 14:58:00 -0700
changeset 26006 d8359a8477a6af47f6e992749bd392d86a7f9d06
parent 26005 38ce0b3beaec8851f950905a0a344727daff1d46
child 26007 42cc5b6b32e8b59a5ad084a7b7c16ba21e37940a
push idunknown
push userunknown
push dateunknown
bugs482370
milestone1.9.2a1pre
Bug 482370 - after noupdate documents are associated with the wrong application cache. r+sr=jst
dom/tests/mochitest/ajax/offline/updatingImplicit.html
uriloader/prefetch/nsOfflineCacheUpdate.cpp
uriloader/prefetch/nsOfflineCacheUpdate.h
--- a/dom/tests/mochitest/ajax/offline/updatingImplicit.html
+++ b/dom/tests/mochitest/ajax/offline/updatingImplicit.html
@@ -15,18 +15,24 @@ function manifestUpdated()
   req.open("GET", "namespace2/script3.js", false);
   try {
     req.send(null);
     window.opener.OfflineTest.ok(false, "Able to fetch unlisted resource, not properly associated.");
   } catch(ex) {
     window.opener.OfflineTest.ok(true, "Unable to fetch unlisted resource, properly associated.");
   }
 
-  window.opener.OfflineTest.checkCache("http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html",
-                                       true);
+  req = new XMLHttpRequest;
+  req.open("GET", "updatingImplicit.html", false);
+  try {
+    req.send(null);
+    window.opener.OfflineTest.ok(true, "Able to fetch listed resource, properly associated.");
+  } catch(ex) {
+    window.opener.OfflineTest.ok(false, "Unable to fetch listed resource, not properly associated.");
+  }
 
   window.opener.implicitLoaded(window, false);
 }
 
 function manifestError()
 {
   window.opener.implicitLoaded(window, true);
 }
--- a/uriloader/prefetch/nsOfflineCacheUpdate.cpp
+++ b/uriloader/prefetch/nsOfflineCacheUpdate.cpp
@@ -1366,17 +1366,17 @@ nsOfflineCacheUpdate::LoadCompleted()
             Finish();
             return;
         }
 
         if (!doUpdate) {
             mSucceeded = PR_FALSE;
 
             for (PRInt32 i = 0; i < mDocuments.Count(); i++) {
-                AssociateDocument(mDocuments[i]);
+                AssociateDocument(mDocuments[i], mPreviousApplicationCache);
             }
 
             ScheduleImplicit();
 
             // If we didn't need an implicit update, we can
             // send noupdate and end the update now.
             if (!mImplicitUpdate) {
                 NotifyNoUpdate();
@@ -1865,33 +1865,44 @@ nsOfflineCacheUpdate::ScheduleImplicit()
     NS_ENSURE_SUCCESS(rv, rv);
 
     mImplicitUpdate = update;
 
     return NS_OK;
 }
 
 nsresult
-nsOfflineCacheUpdate::AssociateDocument(nsIDOMDocument *aDocument)
+nsOfflineCacheUpdate::AssociateDocument(nsIDOMDocument *aDocument,
+                                        nsIApplicationCache *aApplicationCache)
 {
     // Check that the document that requested this update was
     // previously associated with an application cache.  If not, it
     // should be associated with the new one.
     nsCOMPtr<nsIApplicationCacheContainer> container =
         do_QueryInterface(aDocument);
     if (!container)
         return NS_OK;
 
     nsCOMPtr<nsIApplicationCache> existingCache;
     nsresult rv = container->GetApplicationCache(getter_AddRefs(existingCache));
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (!existingCache) {
-        LOG(("Update %p: associating app cache %s to document %p", this, mClientID.get(), aDocument));
-        rv = container->SetApplicationCache(mApplicationCache);
+#if defined(PR_LOGGING)
+        if (LOG_ENABLED()) {
+            nsCAutoString clientID;
+            if (aApplicationCache) {
+                aApplicationCache->GetClientID(clientID);
+            }
+            LOG(("Update %p: associating app cache %s to document %p",
+                 this, clientID.get(), aDocument));
+        }
+#endif
+
+        rv = container->SetApplicationCache(aApplicationCache);
         NS_ENSURE_SUCCESS(rv, rv);
     }
 
     return NS_OK;
 }
 
 nsresult
 nsOfflineCacheUpdate::Finish()
@@ -1918,17 +1929,17 @@ nsOfflineCacheUpdate::Finish()
 
             rv = mApplicationCache->Activate();
             if (NS_FAILED(rv)) {
                 NotifyError();
                 mSucceeded = PR_FALSE;
             }
 
             for (PRInt32 i = 0; i < mDocuments.Count(); i++) {
-                AssociateDocument(mDocuments[i]);
+                AssociateDocument(mDocuments[i], mApplicationCache);
             }
         }
 
         if (mObsolete) {
             nsCOMPtr<nsIApplicationCacheService> appCacheService =
                 do_GetService(NS_APPLICATIONCACHESERVICE_CONTRACTID);
             if (appCacheService) {
                 nsCAutoString groupID;
--- a/uriloader/prefetch/nsOfflineCacheUpdate.h
+++ b/uriloader/prefetch/nsOfflineCacheUpdate.h
@@ -251,17 +251,18 @@ private:
     nsresult GatherObservers(nsCOMArray<nsIOfflineCacheUpdateObserver> &aObservers);
     nsresult NotifyError();
     nsresult NotifyChecking();
     nsresult NotifyNoUpdate();
     nsresult NotifyObsolete();
     nsresult NotifyDownloading();
     nsresult NotifyStarted(nsOfflineCacheUpdateItem *aItem);
     nsresult NotifyCompleted(nsOfflineCacheUpdateItem *aItem);
-    nsresult AssociateDocument(nsIDOMDocument *aDocument);
+    nsresult AssociateDocument(nsIDOMDocument *aDocument,
+                               nsIApplicationCache *aApplicationCache);
     nsresult ScheduleImplicit();
     nsresult Finish();
 
     enum {
         STATE_UNINITIALIZED,
         STATE_INITIALIZED,
         STATE_CHECKING,
         STATE_DOWNLOADING,