Changeset 95588 in webkit


Ignore:
Timestamp:
Sep 20, 2011 5:48:14 PM (13 years ago)
Author:
eric@webkit.org
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.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/http/tests/security/local-user-CSS-from-remote.html

    r28690 r95588  
    99        if (window.location.hash == '') {
    1010            layoutTestController.waitUntilDone();
    11             layoutTestController.setUserStyleSheetLocation("file:///tmp/LayoutTests/http/tests/security/resources/cssStyle.css");
     11            var stylesheetLocation = layoutTestController.pathToLocalResource("file:///tmp/LayoutTests/http/tests/security/resources/cssStyle.css");
     12            layoutTestController.setUserStyleSheetLocation(stylesheetLocation);
    1213            layoutTestController.setUserStyleSheetEnabled(true);
    1314            location += '?#done';
  • trunk/Tools/ChangeLog

    r95587 r95588  
     12011-09-20  Eric Seidel  <eric@webkit.org>
     2
     3        [NRWT] REGRESSION: Local loader tests are failing on machines that lost /tmp/LayoutTests symlink
     4        https://bugs.webkit.org/show_bug.cgi?id=65781
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Instead of making NRWT create the symlink, I made DumpRenderTree smart enough
     9        to resolve the passed in url relative to the absolute url for the test.
     10        For http tests, since the test url is an http url, we can't resolve relative
     11        to the test path, and thus use a new LOCAL_RESOURCE_ROOT environment variable
     12        for resolving.
     13
     14        I believe this is a better approach than the on used in the Qt and Chromium DRT's
     15        (which resolves the path relative to the built location of the DRT executable)
     16        and we should move this new code into a shared location in a follow-up patch.
     17
     18        It turns out that there was a second use for pathToLocalResource, used by one
     19        test (http/tests/plugins/post-url-file.html) used for getting a path to /tmp.
     20        To support this test I made the new pathToLocalResource smart enough to map
     21        /tmp to DUMPRENDERTREE_TEMP (which is already defined for all ports).
     22
     23        * DumpRenderTree/mac/LayoutTestControllerMac.mm:
     24        (LayoutTestController::pathToLocalResource):
     25        * Scripts/webkitpy/layout_tests/port/webkit.py: Set LOCAL_RESOURCE_ROOT for use by DRT.
     26
    1272011-09-20  Tom Zakrajsek  <tomz@codeaurora.org>
    228
  • trunk/Tools/DumpRenderTree/mac/LayoutTestControllerMac.mm

    r94983 r95588  
    356356}
    357357
    358 JSStringRef LayoutTestController::pathToLocalResource(JSContextRef context, JSStringRef url)
    359 {
    360     return JSStringRetain(url); // Do nothing on mac.
     358static inline std::string stringFromJSString(JSStringRef jsString)
     359{
     360    size_t maxBufferSize = JSStringGetMaximumUTF8CStringSize(jsString);
     361    char* utf8Buffer = new char[maxBufferSize];
     362    size_t bytesWrittenToUTF8Buffer = JSStringGetUTF8CString(jsString, utf8Buffer, maxBufferSize);
     363    std::string stdString(utf8Buffer, bytesWrittenToUTF8Buffer - 1); // bytesWrittenToUTF8Buffer includes a trailing \0 which std::string doesn't need.
     364    delete[] utf8Buffer;
     365    return stdString;
     366}
     367
     368static inline size_t indexOfSeparatorAfterDirectoryName(const std::string& directoryName, const std::string& fullPath)
     369{
     370    std::string searchKey = "/" + directoryName + "/";
     371    size_t indexOfSearchKeyStart = fullPath.rfind(searchKey);
     372    if (indexOfSearchKeyStart == std::string::npos) {
     373        ASSERT_NOT_REACHED();
     374        return 0;
     375    }
     376    // Callers expect the return value not to end in "/", so searchKey.length() - 1.
     377    return indexOfSearchKeyStart + searchKey.length() - 1;
     378}
     379
     380static inline std::string resourceRootAbsolutePath(const std::string& testPathOrURL, const std::string& expectedRootName)
     381{
     382    char* localResourceRootEnv = getenv("LOCAL_RESOURCE_ROOT");
     383    if (localResourceRootEnv)
     384        return std::string(localResourceRootEnv);
     385
     386    // This fallback approach works for non-http tests and is useful
     387    // in the case when we're running DRT directly from the command line.
     388    return testPathOrURL.substr(0, indexOfSeparatorAfterDirectoryName(expectedRootName, testPathOrURL));
     389}
     390
     391JSStringRef LayoutTestController::pathToLocalResource(JSContextRef context, JSStringRef localResourceJSString)
     392{
     393    // The passed in path will be an absolute path to the resource starting
     394    // with "/tmp" or "/tmp/LayoutTests", optionally starting with the explicit file:// protocol.
     395    // /tmp maps to DUMPRENDERTREE_TEMP, and /tmp/LayoutTests maps to LOCAL_RESOURCE_ROOT.
     396    // FIXME: This code should work on all *nix platforms and can be moved into LayoutTestController.cpp.
     397    std::string expectedRootName;
     398    std::string absolutePathToResourceRoot;
     399    std::string localResourceString = stringFromJSString(localResourceJSString);
     400
     401    if (localResourceString.find("LayoutTests") != std::string::npos) {
     402        expectedRootName = "LayoutTests";
     403        absolutePathToResourceRoot = resourceRootAbsolutePath(m_testPathOrURL, expectedRootName);
     404    } else if (localResourceString.find("tmp") != std::string::npos) {
     405        expectedRootName = "tmp";
     406        absolutePathToResourceRoot = getenv("DUMPRENDERTREE_TEMP");
     407    } else {
     408        ASSERT_NOT_REACHED(); // pathToLocalResource was passed a path it doesn't know how to map.
     409    }
     410    ASSERT(!absolutePathToResourceRoot.empty());
     411    size_t indexOfSeparatorAfterRootName = indexOfSeparatorAfterDirectoryName(expectedRootName, localResourceString);
     412    std::string absolutePathToLocalResource = absolutePathToResourceRoot + localResourceString.substr(indexOfSeparatorAfterRootName);
     413
     414    // Note: It's important that we keep the file:// or http tests will get confused.
     415    if (localResourceString.find("file://") != std::string::npos) {
     416        ASSERT(absolutePathToLocalResource[0] == '/');
     417        absolutePathToLocalResource = std::string("file://") + absolutePathToLocalResource;
     418    }
     419    return JSStringCreateWithUTF8CString(absolutePathToLocalResource.c_str());
    361420}
    362421
  • trunk/Tools/Scripts/webkitpy/layout_tests/port/webkit.py

    r94973 r95588  
    447447        # FIXME: We're assuming that WebKitTestRunner checks this DumpRenderTree-named environment variable.
    448448        environment['DUMPRENDERTREE_TEMP'] = str(self._driver_tempdir)
     449        environment['LOCAL_RESOURCE_ROOT'] = self._port.layout_tests_dir()
    449450        self._server_process = server_process.ServerProcess(self._port, server_name, self.cmd_line(), environment)
    450451
Note: See TracChangeset for help on using the changeset viewer.