Title: [95588] trunk
Revision
95588
Author
[email protected]
Date
2011-09-20 17:48:14 -0700 (Tue, 20 Sep 2011)

Log Message

[NRWT] REGRESSION: Local loader tests are failing on machines that lost /tmp/LayoutTests symlink
https://bugs.webkit.org/show_bug.cgi?id=65781

Reviewed by Ryosuke Niwa.

Instead of making NRWT create the symlink, I made DumpRenderTree smart enough
to resolve the passed in url relative to the absolute url for the test.
For http tests, since the test url is an http url, we can't resolve relative
to the test path, and thus use a new LOCAL_RESOURCE_ROOT environment variable
for resolving.

I believe this is a better approach than the on used in the Qt and Chromium DRT's
(which resolves the path relative to the built location of the DRT executable)
and we should move this new code into a shared location in a follow-up patch.

It turns out that there was a second use for pathToLocalResource, used by one
test (http/tests/plugins/post-url-file.html) used for getting a path to /tmp.
To support this test I made the new pathToLocalResource smart enough to map
/tmp to DUMPRENDERTREE_TEMP (which is already defined for all ports).

* DumpRenderTree/mac/LayoutTestControllerMac.mm:
(LayoutTestController::pathToLocalResource):
* Scripts/webkitpy/layout_tests/port/webkit.py: Set LOCAL_RESOURCE_ROOT for use by DRT.

Modified Paths

Diff

Modified: trunk/LayoutTests/http/tests/security/local-user-CSS-from-remote.html (95587 => 95588)


--- trunk/LayoutTests/http/tests/security/local-user-CSS-from-remote.html	2011-09-21 00:34:41 UTC (rev 95587)
+++ trunk/LayoutTests/http/tests/security/local-user-CSS-from-remote.html	2011-09-21 00:48:14 UTC (rev 95588)
@@ -8,7 +8,8 @@
         // This won't work outside of DRT!
         if (window.location.hash == '') {
             layoutTestController.waitUntilDone();
-            layoutTestController.setUserStyleSheetLocation("file:///tmp/LayoutTests/http/tests/security/resources/cssStyle.css");
+            var stylesheetLocation = layoutTestController.pathToLocalResource("file:///tmp/LayoutTests/http/tests/security/resources/cssStyle.css");
+            layoutTestController.setUserStyleSheetLocation(stylesheetLocation);
             layoutTestController.setUserStyleSheetEnabled(true);
             location += '?#done';
         }

Modified: trunk/Tools/ChangeLog (95587 => 95588)


--- trunk/Tools/ChangeLog	2011-09-21 00:34:41 UTC (rev 95587)
+++ trunk/Tools/ChangeLog	2011-09-21 00:48:14 UTC (rev 95588)
@@ -1,3 +1,29 @@
+2011-09-20  Eric Seidel  <[email protected]>
+
+        [NRWT] REGRESSION: Local loader tests are failing on machines that lost /tmp/LayoutTests symlink
+        https://bugs.webkit.org/show_bug.cgi?id=65781
+
+        Reviewed by Ryosuke Niwa.
+
+        Instead of making NRWT create the symlink, I made DumpRenderTree smart enough
+        to resolve the passed in url relative to the absolute url for the test.
+        For http tests, since the test url is an http url, we can't resolve relative
+        to the test path, and thus use a new LOCAL_RESOURCE_ROOT environment variable
+        for resolving.
+
+        I believe this is a better approach than the on used in the Qt and Chromium DRT's
+        (which resolves the path relative to the built location of the DRT executable)
+        and we should move this new code into a shared location in a follow-up patch.
+
+        It turns out that there was a second use for pathToLocalResource, used by one
+        test (http/tests/plugins/post-url-file.html) used for getting a path to /tmp.
+        To support this test I made the new pathToLocalResource smart enough to map
+        /tmp to DUMPRENDERTREE_TEMP (which is already defined for all ports).
+
+        * DumpRenderTree/mac/LayoutTestControllerMac.mm:
+        (LayoutTestController::pathToLocalResource):
+        * Scripts/webkitpy/layout_tests/port/webkit.py: Set LOCAL_RESOURCE_ROOT for use by DRT.
+
 2011-09-20  Tom Zakrajsek  <[email protected]>
 
         Need to specify a django version, instead of using default

Modified: trunk/Tools/DumpRenderTree/mac/LayoutTestControllerMac.mm (95587 => 95588)


--- trunk/Tools/DumpRenderTree/mac/LayoutTestControllerMac.mm	2011-09-21 00:34:41 UTC (rev 95587)
+++ trunk/Tools/DumpRenderTree/mac/LayoutTestControllerMac.mm	2011-09-21 00:48:14 UTC (rev 95588)
@@ -355,11 +355,70 @@
     m_waitToDump = false;
 }
 
-JSStringRef LayoutTestController::pathToLocalResource(JSContextRef context, JSStringRef url)
+static inline std::string stringFromJSString(JSStringRef jsString)
 {
-    return JSStringRetain(url); // Do nothing on mac.
+    size_t maxBufferSize = JSStringGetMaximumUTF8CStringSize(jsString);
+    char* utf8Buffer = new char[maxBufferSize];
+    size_t bytesWrittenToUTF8Buffer = JSStringGetUTF8CString(jsString, utf8Buffer, maxBufferSize);
+    std::string stdString(utf8Buffer, bytesWrittenToUTF8Buffer - 1); // bytesWrittenToUTF8Buffer includes a trailing \0 which std::string doesn't need.
+    delete[] utf8Buffer;
+    return stdString;
 }
 
+static inline size_t indexOfSeparatorAfterDirectoryName(const std::string& directoryName, const std::string& fullPath)
+{
+    std::string searchKey = "/" + directoryName + "/";
+    size_t indexOfSearchKeyStart = fullPath.rfind(searchKey);
+    if (indexOfSearchKeyStart == std::string::npos) {
+        ASSERT_NOT_REACHED();
+        return 0;
+    }
+    // Callers expect the return value not to end in "/", so searchKey.length() - 1.
+    return indexOfSearchKeyStart + searchKey.length() - 1;
+}
+
+static inline std::string resourceRootAbsolutePath(const std::string& testPathOrURL, const std::string& expectedRootName)
+{
+    char* localResourceRootEnv = getenv("LOCAL_RESOURCE_ROOT");
+    if (localResourceRootEnv)
+        return std::string(localResourceRootEnv);
+
+    // This fallback approach works for non-http tests and is useful
+    // in the case when we're running DRT directly from the command line.
+    return testPathOrURL.substr(0, indexOfSeparatorAfterDirectoryName(expectedRootName, testPathOrURL));
+}
+
+JSStringRef LayoutTestController::pathToLocalResource(JSContextRef context, JSStringRef localResourceJSString)
+{
+    // The passed in path will be an absolute path to the resource starting
+    // with "/tmp" or "/tmp/LayoutTests", optionally starting with the explicit file:// protocol.
+    // /tmp maps to DUMPRENDERTREE_TEMP, and /tmp/LayoutTests maps to LOCAL_RESOURCE_ROOT.
+    // FIXME: This code should work on all *nix platforms and can be moved into LayoutTestController.cpp.
+    std::string expectedRootName;
+    std::string absolutePathToResourceRoot;
+    std::string localResourceString = stringFromJSString(localResourceJSString);
+
+    if (localResourceString.find("LayoutTests") != std::string::npos) {
+        expectedRootName = "LayoutTests";
+        absolutePathToResourceRoot = resourceRootAbsolutePath(m_testPathOrURL, expectedRootName);
+    } else if (localResourceString.find("tmp") != std::string::npos) {
+        expectedRootName = "tmp";
+        absolutePathToResourceRoot = getenv("DUMPRENDERTREE_TEMP");
+    } else {
+        ASSERT_NOT_REACHED(); // pathToLocalResource was passed a path it doesn't know how to map.
+    }
+    ASSERT(!absolutePathToResourceRoot.empty());
+    size_t indexOfSeparatorAfterRootName = indexOfSeparatorAfterDirectoryName(expectedRootName, localResourceString);
+    std::string absolutePathToLocalResource = absolutePathToResourceRoot + localResourceString.substr(indexOfSeparatorAfterRootName);
+
+    // Note: It's important that we keep the file:// or http tests will get confused.
+    if (localResourceString.find("file://") != std::string::npos) {
+        ASSERT(absolutePathToLocalResource[0] == '/');
+        absolutePathToLocalResource = std::string("file://") + absolutePathToLocalResource;
+    }
+    return JSStringCreateWithUTF8CString(absolutePathToLocalResource.c_str());
+}
+
 void LayoutTestController::queueLoad(JSStringRef url, JSStringRef target)
 {
     RetainPtr<CFStringRef> urlCF(AdoptCF, JSStringCopyCFString(kCFAllocatorDefault, url));

Modified: trunk/Tools/Scripts/webkitpy/layout_tests/port/webkit.py (95587 => 95588)


--- trunk/Tools/Scripts/webkitpy/layout_tests/port/webkit.py	2011-09-21 00:34:41 UTC (rev 95587)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/port/webkit.py	2011-09-21 00:48:14 UTC (rev 95588)
@@ -446,6 +446,7 @@
         environment['DYLD_FRAMEWORK_PATH'] = self._port._build_path()
         # FIXME: We're assuming that WebKitTestRunner checks this DumpRenderTree-named environment variable.
         environment['DUMPRENDERTREE_TEMP'] = str(self._driver_tempdir)
+        environment['LOCAL_RESOURCE_ROOT'] = self._port.layout_tests_dir()
         self._server_process = server_process.ServerProcess(self._port, server_name, self.cmd_line(), environment)
 
     def poll(self):
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to