WebKitTools/DumpRenderTree/chromium/DumpRenderTree.cpp
changeset 2 303757a437d3
parent 0 4f2f89ce4247
equal deleted inserted replaced
0:4f2f89ce4247 2:303757a437d3
     1 /*
       
     2  * Copyright (C) 2010 Google Inc. All rights reserved.
       
     3  *
       
     4  * Redistribution and use in source and binary forms, with or without
       
     5  * modification, are permitted provided that the following conditions are
       
     6  * met:
       
     7  *
       
     8  *     * Redistributions of source code must retain the above copyright
       
     9  * notice, this list of conditions and the following disclaimer.
       
    10  *     * Redistributions in binary form must reproduce the above
       
    11  * copyright notice, this list of conditions and the following disclaimer
       
    12  * in the documentation and/or other materials provided with the
       
    13  * distribution.
       
    14  *     * Neither the name of Google Inc. nor the names of its
       
    15  * contributors may be used to endorse or promote products derived from
       
    16  * this software without specific prior written permission.
       
    17  *
       
    18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
       
    19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
       
    20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
       
    21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
       
    22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
       
    23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
       
    24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
       
    25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
       
    26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    29  */
       
    30 
       
    31 #include "config.h"
       
    32 
       
    33 #include "TestShell.h"
       
    34 #include "webkit/support/webkit_support.h"
       
    35 #include <wtf/Vector.h>
       
    36 
       
    37 using namespace std;
       
    38 
       
    39 void platformInit();
       
    40 
       
    41 static const char optionComplexText[] = "--complex-text";
       
    42 static const char optionDumpAllPixels[] = "--dump-all-pixels";
       
    43 static const char optionNotree[] = "--notree";
       
    44 static const char optionPixelTests[] = "--pixel-tests";
       
    45 static const char optionThreaded[] = "--threaded";
       
    46 static const char optionTree[] = "--tree";
       
    47 
       
    48 static const char optionPixelTestsWithName[] = "--pixel-tests=";
       
    49 static const char optionTestShell[] = "--test-shell";
       
    50 static const char optionAllowExternalPages[] = "--allow-external-pages";
       
    51 
       
    52 static void runTest(TestShell& shell, TestParams& params, const string& testName, bool testShellMode)
       
    53 {
       
    54     int oldTimeoutMsec = shell.layoutTestTimeout();
       
    55     params.pixelHash = "";
       
    56     string pathOrURL = testName;
       
    57     if (testShellMode) {
       
    58         string timeOut;
       
    59         string::size_type separatorPosition = pathOrURL.find(' ');
       
    60         if (separatorPosition != string::npos) {
       
    61             timeOut = pathOrURL.substr(separatorPosition + 1);
       
    62             pathOrURL.erase(separatorPosition);
       
    63             separatorPosition = timeOut.find_first_of(' ');
       
    64             if (separatorPosition != string::npos) {
       
    65                 params.pixelHash = timeOut.substr(separatorPosition + 1);
       
    66                 timeOut.erase(separatorPosition);
       
    67             }
       
    68             shell.setLayoutTestTimeout(atoi(timeOut.c_str()));
       
    69         }
       
    70     } else {
       
    71         string::size_type separatorPosition = pathOrURL.find("'");
       
    72         if (separatorPosition != string::npos) {
       
    73             params.pixelHash = pathOrURL.substr(separatorPosition + 1);
       
    74             pathOrURL.erase(separatorPosition);
       
    75         }
       
    76     }
       
    77     params.testUrl = webkit_support::CreateURLForPathOrURL(pathOrURL);
       
    78     webkit_support::SetCurrentDirectoryForFileURL(params.testUrl);
       
    79     shell.resetTestController();
       
    80     shell.runFileTest(params);
       
    81     shell.setLayoutTestTimeout(oldTimeoutMsec);
       
    82 }
       
    83 
       
    84 int main(int argc, char* argv[])
       
    85 {
       
    86     webkit_support::SetUpTestEnvironment();
       
    87     platformInit();
       
    88 
       
    89     TestParams params;
       
    90     Vector<string> tests;
       
    91     bool serverMode = false;
       
    92     bool testShellMode = false;
       
    93     bool allowExternalPages = false;
       
    94     for (int i = 1; i < argc; ++i) {
       
    95         string argument(argv[i]);
       
    96         if (argument == "-")
       
    97             serverMode = true;
       
    98         else if (argument == optionNotree)
       
    99             params.dumpTree = false;
       
   100         else if (argument == optionPixelTests)
       
   101             params.dumpPixels = true;
       
   102         else if (!argument.find(optionPixelTestsWithName)) {
       
   103             params.dumpPixels = true;
       
   104             params.pixelFileName = argument.substr(strlen(optionPixelTestsWithName));
       
   105         } else if (argument == optionTestShell) {
       
   106             testShellMode = true;
       
   107             serverMode = true;
       
   108         } else if (argument == optionAllowExternalPages)
       
   109             allowExternalPages = true;
       
   110         else if (argument.size() && argument[0] == '-')
       
   111             fprintf(stderr, "Unknown option: %s\n", argv[i]);
       
   112         else
       
   113             tests.append(argument);
       
   114     }
       
   115     if (testShellMode && params.dumpPixels && params.pixelFileName.empty()) {
       
   116         fprintf(stderr, "--pixel-tests with --test-shell requires a file name.\n");
       
   117         return EXIT_FAILURE;
       
   118     }
       
   119 
       
   120     { // Explicit scope for the TestShell instance.
       
   121         TestShell shell(testShellMode);
       
   122         shell.setAllowExternalPages(allowExternalPages);
       
   123         if (serverMode && !tests.size()) {
       
   124             params.printSeparators = true;
       
   125             char testString[2048]; // 2048 is the same as the sizes of other platforms.
       
   126             while (fgets(testString, sizeof(testString), stdin)) {
       
   127                 char* newLinePosition = strchr(testString, '\n');
       
   128                 if (newLinePosition)
       
   129                     *newLinePosition = '\0';
       
   130                 if (testString[0] == '\0')
       
   131                     continue;
       
   132                 runTest(shell, params, testString, testShellMode);
       
   133             }
       
   134         } else if (!tests.size())
       
   135             printf("#EOF\n");
       
   136         else {
       
   137             params.printSeparators = tests.size() > 1;
       
   138             for (unsigned i = 0; i < tests.size(); i++)
       
   139                 runTest(shell, params, tests[i], testShellMode);
       
   140         }
       
   141 
       
   142         shell.callJSGC();
       
   143         shell.callJSGC();
       
   144 
       
   145         // When we finish the last test, cleanup the LayoutTestController.
       
   146         // It may have references to not-yet-cleaned up windows.  By
       
   147         // cleaning up here we help purify reports.
       
   148         shell.resetTestController();
       
   149     }
       
   150 
       
   151     webkit_support::TearDownTestEnvironment();
       
   152     return EXIT_SUCCESS;
       
   153 }