Mac DRT should be able to load external URLs for replay performance tests
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 May 2012 20:21:45 +0000 (20:21 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 May 2012 20:21:45 +0000 (20:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=86191

Reviewed by Alexey Proskuryakov.

Let external URL requests go through if the test file is not a local file or hosted at localhost.
e.g. "DumpRenderTree http://webkit.org/" as supposed to "DumpRenderTree test.html" or
"DumpRenderTree http://localhost:8000/".

* DumpRenderTree/mac/ResourceLoadDelegate.mm:
(isLocalhost):
(hostIsUsedBySomeTestsToGenerateError):
(-[ResourceLoadDelegate webView:resource:willSendRequest:redirectResponse:fromDataSource:]):

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

Tools/ChangeLog
Tools/DumpRenderTree/mac/ResourceLoadDelegate.mm

index 84797b8..da7f433 100644 (file)
@@ -1,3 +1,19 @@
+2012-05-21  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Mac DRT should be able to load external URLs for replay performance tests
+        https://bugs.webkit.org/show_bug.cgi?id=86191
+
+        Reviewed by Alexey Proskuryakov.
+
+        Let external URL requests go through if the test file is not a local file or hosted at localhost.
+        e.g. "DumpRenderTree http://webkit.org/" as supposed to "DumpRenderTree test.html" or
+        "DumpRenderTree http://localhost:8000/".
+
+        * DumpRenderTree/mac/ResourceLoadDelegate.mm:
+        (isLocalhost):
+        (hostIsUsedBySomeTestsToGenerateError):
+        (-[ResourceLoadDelegate webView:resource:willSendRequest:redirectResponse:fromDataSource:]):
+
 2012-05-23  Malcolm MacLeod <malcolm.macleod@tshwanedje.com>
 
         [wx] In wxWebKit release builds on MSW, keep release settings but also build the 
index 9527324..a1e4f17 100644 (file)
@@ -127,6 +127,17 @@ using namespace std;
     return @"<unknown>";
 }
 
+BOOL isLocalhost(NSString *host)
+{
+    // FIXME: Support IPv6 loopbacks.
+    return NSOrderedSame == [host compare:@"127.0.0.1"] || NSOrderedSame == [host caseInsensitiveCompare:@"localhost"];
+}
+
+BOOL hostIsUsedBySomeTestsToGenerateError(NSString *host)
+{
+    return NSOrderedSame == [host compare:@"255.255.255.255"];
+}
+
 -(NSURLRequest *)webView: (WebView *)wv resource:identifier willSendRequest: (NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)dataSource
 {
     if (!done && gLayoutTestController->dumpResourceLoadCallbacks()) {
@@ -149,13 +160,16 @@ using namespace std;
 
     NSURL *url = [request URL];
     NSString *host = [url host];
-    if (host
-        && (NSOrderedSame == [[url scheme] caseInsensitiveCompare:@"http"] || NSOrderedSame == [[url scheme] caseInsensitiveCompare:@"https"])
-        && NSOrderedSame != [host compare:@"127.0.0.1"]
-        && NSOrderedSame != [host compare:@"255.255.255.255"] // used in some tests that expect to get back an error
-        && NSOrderedSame != [host caseInsensitiveCompare:@"localhost"]) {
-        printf("Blocked access to external URL %s\n", [[url absoluteString] cStringUsingEncoding:NSUTF8StringEncoding]);
-        return nil;
+    if (host && (NSOrderedSame == [[url scheme] caseInsensitiveCompare:@"http"] || NSOrderedSame == [[url scheme] caseInsensitiveCompare:@"https"])) {
+        NSString *testPathOrURL = [NSString stringWithUTF8String:gLayoutTestController->testPathOrURL().c_str()];
+        NSString *lowercaseTestPathOrURL = [testPathOrURL lowercaseString];
+        NSString *testHost = 0;
+        if ([lowercaseTestPathOrURL hasPrefix:@"http:"] || [lowercaseTestPathOrURL hasPrefix:@"https:"])
+            testHost = [[NSURL URLWithString:testPathOrURL] host];
+        if (!isLocalhost(host) && !hostIsUsedBySomeTestsToGenerateError(host) && (!testHost || isLocalhost(testHost))) {
+            printf("Blocked access to external URL %s\n", [[url absoluteString] cStringUsingEncoding:NSUTF8StringEncoding]);
+            return nil;
+        }
     }
 
     if (disallowedURLs && CFSetContainsValue(disallowedURLs, url))