WebCore:
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 May 2008 21:11:07 +0000 (21:11 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 May 2008 21:11:07 +0000 (21:11 +0000)
2008-05-12  Anders Carlsson  <andersca@apple.com>

        Reviewed by Adam.

        Make it possible to perform synchronous loads from the application cache.

        * loader/DocumentLoader.cpp:
        (WebCore::DocumentLoader::shouldLoadResourceFromApplicationCache):
        Factor out code from scheduleApplicationCacheLoad in its own method.

        (WebCore::DocumentLoader::scheduleApplicationCacheLoad):
        Call shouldLoadResourceFromApplicationCache here instead.

        * loader/DocumentLoader.h:

        * loader/FrameLoader.cpp:
        (WebCore::FrameLoader::loadResourceSynchronously):
        Call shouldLoadResourceFromApplicationCache.

WebKitTools:

2008-05-12  Anders Carlsson  <andersca@apple.com>

        Reviewed by Adam.

        Add support for testing application caches.

        * DumpRenderTree/mac/DumpRenderTree.mm:
        (dumpRenderTree):
        Empty the cache.

        (resetWebViewToConsistentStateBeforeTesting):
        Turn on support for the application cache.

LayoutTests:

2008-05-12  Anders Carlsson  <andersca@apple.com>

        Reviewed by Adam.

        Add simple appcache test.

        * http/conf/mime.types:
        * http/tests/appcache: Added.
        * http/tests/appcache/resources: Added.
        * http/tests/appcache/resources/not-in-cache.txt: Added.
        * http/tests/appcache/resources/simple.manifest: Added.
        * http/tests/appcache/resources/simple.txt: Added.
        * http/tests/appcache/simple-expected.txt: Added.
        * http/tests/appcache/simple.html: Added.
        * platform/gtk/Skipped:
        * platform/qt/Skipped:
        * platform/win/Skipped:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@33057 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
LayoutTests/ChangeLog
LayoutTests/http/conf/mime.types
LayoutTests/http/tests/appcache/resources/not-in-cache.txt [new file with mode: 0644]
LayoutTests/http/tests/appcache/resources/simple.manifest [new file with mode: 0644]
LayoutTests/http/tests/appcache/resources/simple.txt [new file with mode: 0644]
LayoutTests/http/tests/appcache/simple-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/appcache/simple.html [new file with mode: 0644]
LayoutTests/platform/gtk/Skipped
LayoutTests/platform/qt/Skipped
LayoutTests/platform/win/Skipped
WebCore/ChangeLog
WebCore/loader/DocumentLoader.cpp
WebCore/loader/DocumentLoader.h
WebCore/loader/FrameLoader.cpp
WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/mac/DumpRenderTree.mm

index af09937..8c78b9b 100644 (file)
@@ -1,3 +1,21 @@
+2008-05-12  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Adam.
+
+        Add simple appcache test.
+
+        * http/conf/mime.types:
+        * http/tests/appcache: Added.
+        * http/tests/appcache/resources: Added.
+        * http/tests/appcache/resources/not-in-cache.txt: Added.
+        * http/tests/appcache/resources/simple.manifest: Added.
+        * http/tests/appcache/resources/simple.txt: Added.
+        * http/tests/appcache/simple-expected.txt: Added.
+        * http/tests/appcache/simple.html: Added.
+        * platform/gtk/Skipped:
+        * platform/qt/Skipped:
+        * platform/win/Skipped:
+
 2008-05-09  Sam Weinig  <sam@webkit.org>
 
         Reviewed by Mark Rowe.
index 6735f1b..cfb9d53 100644 (file)
@@ -529,6 +529,7 @@ multipart/related
 multipart/report
 multipart/signed
 multipart/voice-message
+text/cache-manifest         manifest
 text/calendar                  ics ifb
 text/css                       css
 text/directory
diff --git a/LayoutTests/http/tests/appcache/resources/not-in-cache.txt b/LayoutTests/http/tests/appcache/resources/not-in-cache.txt
new file mode 100644 (file)
index 0000000..a580081
--- /dev/null
@@ -0,0 +1 @@
+This file is not in the cache and is thus not possible to load.
\ No newline at end of file
diff --git a/LayoutTests/http/tests/appcache/resources/simple.manifest b/LayoutTests/http/tests/appcache/resources/simple.manifest
new file mode 100644 (file)
index 0000000..3a210f3
--- /dev/null
@@ -0,0 +1,2 @@
+CACHE MANIFEST
+simple.txt
diff --git a/LayoutTests/http/tests/appcache/resources/simple.txt b/LayoutTests/http/tests/appcache/resources/simple.txt
new file mode 100644 (file)
index 0000000..b45ef6f
--- /dev/null
@@ -0,0 +1 @@
+Hello, World!
\ No newline at end of file
diff --git a/LayoutTests/http/tests/appcache/simple-expected.txt b/LayoutTests/http/tests/appcache/simple-expected.txt
new file mode 100644 (file)
index 0000000..68e4f7d
--- /dev/null
@@ -0,0 +1,2 @@
+ALERT: whee cached!
+This tests that the application cache works by loading a simple text file from the cache using XMLHttpRequest.
diff --git a/LayoutTests/http/tests/appcache/simple.html b/LayoutTests/http/tests/appcache/simple.html
new file mode 100644 (file)
index 0000000..f8b950b
--- /dev/null
@@ -0,0 +1,54 @@
+<html manifest="resources/simple.manifest">
+<script>
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText()
+    layoutTestController.waitUntilDone();
+}
+
+function cached()
+{
+    var hadError = false;
+    
+    // Load a resource that does not exist in the cache.
+    try {
+        var req = new XMLHttpRequest();
+        req.open("GET", "resources/not-in-cache.txt", false);
+        req.send();
+    } catch (e) {
+        if (e.code == XMLHttpRequestException.NETWORK_ERR)
+            hadError = true;
+    }
+
+    if (!hadError) {
+        document.getElementById('result').innerHTML = "FAILURE: Did not get the right exception"
+        return;
+    }
+   
+    // Load a resource that exists in the cache.
+    try {
+        var req = new XMLHttpRequest();
+        req.open("GET", "resources/simple.txt", false);
+        req.send();
+    } catch (e) {
+        document.getElementById('result').innerHTML = "FAILURE: Could not load data from cache"
+        return;
+    }
+        
+    if (req.responseText != 'Hello, World!') {
+        document.getElementById('result').innerHTML = "FAILURE: Did not get correct data from cached resource"
+        return;
+    }
+    
+    document.getElementById('result').innerHTML = "SUCCESS"
+    
+    if (window.layoutTestController)
+        layoutTestController.notifyDone();
+}
+
+applicationCache.addEventListener('cached', cached, false);
+
+</script>
+<div>This tests that the application cache works by first loading a file that does not exist in the cache (to verify that a cache has been associated) and then loads a file that is in the cache</div>
+
+<div id="result">FAILURE</div>
+</html>
index 3f82ae9..0bf1dfb 100644 (file)
@@ -3,3 +3,5 @@ editing/execCommand/print.html
 # Missing LayoutTestController implementations and database related delegate callback
 storage/quota-tracking.html
 storage/success-callback.html
+# Application cache
+http/tests/appcache
\ No newline at end of file
index 13e8375..3a99bf4 100644 (file)
@@ -910,6 +910,9 @@ http/tests/ssl
 http/tests/uri
 http/tests/xmlhttprequest
 
+# Application cache
+http/tests/appcache
+
 # Tests that currently fail but perhaps used to work at some point.
 editing/selection/skip-non-editable-1.html
 editing/selection/skip-non-editable-2.html
index 036411a..edf672f 100644 (file)
@@ -421,3 +421,7 @@ storage/success-callback.html
 
 # Crashes, probably needs new SQLite
 storage/multiple-transactions.html
+
+# Application cache
+http/tests/appcache
+
index 2edcbe8..dffe5ec 100644 (file)
@@ -1,3 +1,22 @@
+2008-05-12  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Adam.
+
+        Make it possible to perform synchronous loads from the application cache.
+        
+        * loader/DocumentLoader.cpp:
+        (WebCore::DocumentLoader::shouldLoadResourceFromApplicationCache):
+        Factor out code from scheduleApplicationCacheLoad in its own method.
+        
+        (WebCore::DocumentLoader::scheduleApplicationCacheLoad):
+        Call shouldLoadResourceFromApplicationCache here instead.
+        
+        * loader/DocumentLoader.h:
+        
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::loadResourceSynchronously):
+        Call shouldLoadResourceFromApplicationCache.
+
 2008-05-12  Dan Bernstein  <mitz@apple.com>
 
         Reviewed by Ada Chan and Sam Weinig.
index dfdfec4..b1882b5 100644 (file)
@@ -856,14 +856,8 @@ ApplicationCache* DocumentLoader::mainResourceApplicationCache() const
     return 0;
 }
 
-bool DocumentLoader::scheduleApplicationCacheLoad(ResourceLoader* loader, const ResourceRequest& request, const KURL& originalURL)
+bool DocumentLoader::shouldLoadResourceFromApplicationCache(const ResourceRequest& request, ApplicationCacheResource*& resource)
 {
-    if (!frameLoader()->frame()->settings() || !frameLoader()->frame()->settings()->offlineWebApplicationCacheEnabled())
-        return false;
-    
-    if (request.url() != originalURL)
-        return false;
-
     ApplicationCache* cache = topLevelApplicationCache();    
     if (!cache)
         return false;
@@ -871,18 +865,33 @@ bool DocumentLoader::scheduleApplicationCacheLoad(ResourceLoader* loader, const
     // If the resource is not a HTTP/HTTPS GET, then abort
     if (!ApplicationCache::requestIsHTTPOrHTTPSGet(request))
         return false;
-
+    
     if (cache->isURLInOnlineWhitelist(request.url()))
         return false;
     
-    ApplicationCacheResource* resource = cache->resourceForURL(request.url());
+    resource = cache->resourceForURL(request.url());
+    
+    // Don't load foreign resources.
+    if (resource && (resource->type() & ApplicationCacheResource::Foreign))
+        resource = 0;
+    
+    return true;
+}
+
+bool DocumentLoader::scheduleApplicationCacheLoad(ResourceLoader* loader, const ResourceRequest& request, const KURL& originalURL)
+{
+    if (!frameLoader()->frame()->settings() || !frameLoader()->frame()->settings()->offlineWebApplicationCacheEnabled())
+        return false;
+    
+    if (request.url() != originalURL)
+        return false;
+
+    ApplicationCacheResource* resource;
+    if (!shouldLoadResourceFromApplicationCache(request, resource))
+        // FIXME: Handle opportunistic caching namespaces
+        return false;
     
-    // FIXME: Handle opportunistic caching namespaces
-    if (!resource || (resource->type() & ApplicationCacheResource::Foreign))
-        // A null resource means that the load should fail.
-        m_pendingSubstituteResources.set(loader, 0);
-    else 
-        m_pendingSubstituteResources.set(loader, resource);
+    m_pendingSubstituteResources.set(loader, resource);
     deliverSubstituteResourcesAfterDelay();
         
     return true;
index ef73c4e..509e8ab 100644 (file)
@@ -192,7 +192,8 @@ namespace WebCore {
         
 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
         bool scheduleApplicationCacheLoad(ResourceLoader*, const ResourceRequest&, const KURL& originalURL);
-
+        bool shouldLoadResourceFromApplicationCache(const ResourceRequest&, ApplicationCacheResource*&);
+        
         void setCandidateApplicationCacheGroup(ApplicationCacheGroup* group);
         ApplicationCacheGroup* candidateApplicationCacheGroup() const { return m_candidateApplicationCacheGroup; }
         
index 54cf0b5..3f2e58f 100644 (file)
 #include "config.h"
 #include "FrameLoader.h"
 
+#if ENABLE(OFFLINE_WEB_APPLICATIONS)
+#include "ApplicationCache.h"
+#include "ApplicationCacheResource.h"
+#endif
 #include "Archive.h"
 #include "ArchiveFactory.h"
 #include "CString.h"
@@ -3432,7 +3436,18 @@ unsigned long FrameLoader::loadResourceSynchronously(const ResourceRequest& requ
     if (error.isNull()) {
         ASSERT(!newRequest.isNull());
         didTellClientAboutLoad(newRequest.url().string());
-        ResourceHandle::loadResourceSynchronously(newRequest, error, response, data, m_frame);
+        
+#if ENABLE(OFFLINE_WEB_APPLICATIONS)
+        ApplicationCacheResource* resource;
+        if (documentLoader()->shouldLoadResourceFromApplicationCache(newRequest, resource)) {
+            if (resource) {
+                response = resource->response();
+                    data.append(resource->data()->data(), resource->data()->size());
+            } else
+                error = cannotShowURLError(newRequest);
+        } else 
+#endif
+            ResourceHandle::loadResourceSynchronously(newRequest, error, response, data, m_frame);
     }
     
     sendRemainingDelegateMessages(identifier, response, data.size(), error);
index b799098..4325683 100644 (file)
@@ -1,3 +1,16 @@
+2008-05-12  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Adam.
+
+        Add support for testing application caches.
+        
+        * DumpRenderTree/mac/DumpRenderTree.mm:
+        (dumpRenderTree):
+        Empty the cache.
+        
+        (resetWebViewToConsistentStateBeforeTesting):
+        Turn on support for the application cache.
+
 2008-05-09  Mark Rowe  <mrowe@apple.com>
 
         Reviewed by Anders Carlsson.
index 1e76862..81548a6 100644 (file)
@@ -51,6 +51,7 @@
 #import <WebKit/DOMExtensions.h>
 #import <WebKit/DOMRange.h>
 #import <WebKit/WebBackForwardList.h>
+#import <WebKit/WebCache.h>
 #import <WebKit/WebCoreStatistics.h>
 #import <WebKit/WebDataSourcePrivate.h>
 #import <WebKit/WebDatabaseManagerPrivate.h>
@@ -456,6 +457,8 @@ void dumpRenderTree(int argc, const char *argv[])
 
     [[NSURLCache sharedURLCache] removeAllCachedResponses];
 
+    [WebCache empty];
+     
     // <rdar://problem/5222911>
     testStringByEvaluatingJavaScriptFromString();
 
@@ -878,7 +881,8 @@ static void resetWebViewToConsistentStateBeforeTesting()
     [preferences setPrivateBrowsingEnabled:NO];
     [preferences setAuthorAndUserStylesEnabled:YES];
     [preferences setJavaScriptCanOpenWindowsAutomatically:YES];
-
+    [preferences setOfflineWebApplicationCacheEnabled:YES];
+    
     if (persistentUserStyleSheetLocation) {
         [preferences setUserStyleSheetLocation:[NSURL URLWithString:(NSString *)(persistentUserStyleSheetLocation.get())]];
         [preferences setUserStyleSheetEnabled:YES];