<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[160627] trunk/Tools</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/160627">160627</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2013-12-15 20:58:10 -0800 (Sun, 15 Dec 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Refactor option handling in WebKitTestRunner.
https://bugs.webkit.org/show_bug.cgi?id=123185

Patch by Tamas Gergely &lt;tgergely.u-szeged@partner.samsung.com&gt; on 2013-12-15
Reviewed by Darin Adler.

Option handling is refactored (according to the FIXME) that allows
to automatically generate the help message.

* WebKitTestRunner/CMakeLists.txt:
* WebKitTestRunner/GNUmakefile.am:
* WebKitTestRunner/Options.cpp: Added.
(WTR::Options::Options):
(WTR::handleOptionTimeout):
(WTR::handleOptionNoTimeout):
(WTR::handleOptionNoTimeoutAtAll):
(WTR::handleOptionVerbose):
(WTR::handleOptionGcBetweenTests):
(WTR::handleOptionPixelTests):
(WTR::handleOptionPrintSupportedFeatures):
(WTR::handleOptionComplexText):
(WTR::handleOptionAcceleratedDrawing):
(WTR::handleOptionRemoteLayerTree):
(WTR::handleOptionUnmatched):
(WTR::OptionsHandler::OptionsHandler):
(WTR::Option::Option):
(WTR::Option::matches):
(WTR::OptionsHandler::parse):
(WTR::OptionsHandler::printHelp):
* WebKitTestRunner/Options.h: Added.
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::initialize):
* WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsWebKitTestRunnerCMakeListstxt">trunk/Tools/WebKitTestRunner/CMakeLists.txt</a></li>
<li><a href="#trunkToolsWebKitTestRunnerGNUmakefileam">trunk/Tools/WebKitTestRunner/GNUmakefile.am</a></li>
<li><a href="#trunkToolsWebKitTestRunnerTestControllercpp">trunk/Tools/WebKitTestRunner/TestController.cpp</a></li>
<li><a href="#trunkToolsWebKitTestRunnerWebKitTestRunnerxcodeprojprojectpbxproj">trunk/Tools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkToolsWebKitTestRunnerOptionscpp">trunk/Tools/WebKitTestRunner/Options.cpp</a></li>
<li><a href="#trunkToolsWebKitTestRunnerOptionsh">trunk/Tools/WebKitTestRunner/Options.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (160626 => 160627)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2013-12-16 04:04:10 UTC (rev 160626)
+++ trunk/Tools/ChangeLog        2013-12-16 04:58:10 UTC (rev 160627)
</span><span class="lines">@@ -1,3 +1,38 @@
</span><ins>+2013-12-15  Tamas Gergely  &lt;tgergely.u-szeged@partner.samsung.com&gt;
+
+        Refactor option handling in WebKitTestRunner.
+        https://bugs.webkit.org/show_bug.cgi?id=123185
+
+        Reviewed by Darin Adler.
+
+        Option handling is refactored (according to the FIXME) that allows
+        to automatically generate the help message.
+
+        * WebKitTestRunner/CMakeLists.txt:
+        * WebKitTestRunner/GNUmakefile.am:
+        * WebKitTestRunner/Options.cpp: Added.
+        (WTR::Options::Options):
+        (WTR::handleOptionTimeout):
+        (WTR::handleOptionNoTimeout):
+        (WTR::handleOptionNoTimeoutAtAll):
+        (WTR::handleOptionVerbose):
+        (WTR::handleOptionGcBetweenTests):
+        (WTR::handleOptionPixelTests):
+        (WTR::handleOptionPrintSupportedFeatures):
+        (WTR::handleOptionComplexText):
+        (WTR::handleOptionAcceleratedDrawing):
+        (WTR::handleOptionRemoteLayerTree):
+        (WTR::handleOptionUnmatched):
+        (WTR::OptionsHandler::OptionsHandler):
+        (WTR::Option::Option):
+        (WTR::Option::matches):
+        (WTR::OptionsHandler::parse):
+        (WTR::OptionsHandler::printHelp):
+        * WebKitTestRunner/Options.h: Added.
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::initialize):
+        * WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj:
+
</ins><span class="cx"> 2013-12-15  Dan Bernstein  &lt;mitz@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         32-bit build fix.
</span></span></pre></div>
<a id="trunkToolsWebKitTestRunnerCMakeListstxt"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebKitTestRunner/CMakeLists.txt (160626 => 160627)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/CMakeLists.txt        2013-12-16 04:04:10 UTC (rev 160626)
+++ trunk/Tools/WebKitTestRunner/CMakeLists.txt        2013-12-16 04:58:10 UTC (rev 160627)
</span><span class="lines">@@ -6,6 +6,7 @@
</span><span class="cx"> set(WebKitTestRunner_SOURCES
</span><span class="cx">     ${WEBKIT_TESTRUNNER_DIR}/CyclicRedundancyCheck.cpp
</span><span class="cx">     ${WEBKIT_TESTRUNNER_DIR}/GeolocationProviderMock.cpp
</span><ins>+    ${WEBKIT_TESTRUNNER_DIR}/Options.cpp
</ins><span class="cx">     ${WEBKIT_TESTRUNNER_DIR}/PixelDumpSupport.cpp
</span><span class="cx">     ${WEBKIT_TESTRUNNER_DIR}/TestController.cpp
</span><span class="cx">     ${WEBKIT_TESTRUNNER_DIR}/TestInvocation.cpp
</span></span></pre></div>
<a id="trunkToolsWebKitTestRunnerGNUmakefileam"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebKitTestRunner/GNUmakefile.am (160626 => 160627)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/GNUmakefile.am        2013-12-16 04:04:10 UTC (rev 160626)
+++ trunk/Tools/WebKitTestRunner/GNUmakefile.am        2013-12-16 04:58:10 UTC (rev 160627)
</span><span class="lines">@@ -21,6 +21,8 @@
</span><span class="cx">         Tools/WebKitTestRunner/CyclicRedundancyCheck.h \
</span><span class="cx">         Tools/WebKitTestRunner/GeolocationProviderMock.cpp \
</span><span class="cx">         Tools/WebKitTestRunner/GeolocationProviderMock.h \
</span><ins>+        Tools/WebKitTestRunner/Options.cpp \
+        Tools/WebKitTestRunner/Options.h \
</ins><span class="cx">         Tools/WebKitTestRunner/PixelDumpSupport.cpp \
</span><span class="cx">         Tools/WebKitTestRunner/PixelDumpSupport.h \
</span><span class="cx">         Tools/WebKitTestRunner/PlatformWebView.h \
</span></span></pre></div>
<a id="trunkToolsWebKitTestRunnerOptionscpp"></a>
<div class="addfile"><h4>Added: trunk/Tools/WebKitTestRunner/Options.cpp (0 => 160627)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/Options.cpp                                (rev 0)
+++ trunk/Tools/WebKitTestRunner/Options.cpp        2013-12-16 04:58:10 UTC (rev 160627)
</span><span class="lines">@@ -0,0 +1,195 @@
</span><ins>+/*
+ * Copyright (C) 2013 University of Szeged. All rights reserved.
+ * Copyright (C) 2013 Samsung Electronics. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF SZEGED OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include &quot;config.h&quot;
+#include &quot;Options.h&quot;
+
+#include &lt;string.h&gt;
+
+namespace WTR {
+
+Options::Options(double defaultLongTimeout, double defaultShortTimeout)
+    : longTimeout(defaultLongTimeout)
+    , shortTimeout(defaultShortTimeout)
+    , useWaitToDumpWatchdogTimer(true)
+    , forceNoTimeout(false)
+    , verbose(false)
+    , gcBetweenTests(false)
+    , shouldDumpPixelsForAllTests(false)
+    , printSupportedFeatures(false)
+    , forceComplexText(false)
+    , shouldUseAcceleratedDrawing(false)
+    , shouldUseRemoteLayerTree(false)
+    , defaultLongTimeout(defaultLongTimeout)
+    , defaultShortTimeout(defaultShortTimeout)
+{
+}
+
+bool handleOptionTimeout(Options&amp; options, const char*, const char* argument)
+{
+    options.longTimeout = atoi(argument);
+    // Scale up the short timeout to match.
+    options.shortTimeout = options.defaultShortTimeout * options.longTimeout / options.defaultLongTimeout;
+    return true;
+}
+
+bool handleOptionNoTimeout(Options&amp; options, const char*, const char*)
+{
+    options.useWaitToDumpWatchdogTimer = false;
+    return true;
+}
+
+bool handleOptionNoTimeoutAtAll(Options&amp; options, const char*, const char*)
+{
+    options.useWaitToDumpWatchdogTimer = false;
+    options.forceNoTimeout = true;
+    return true;
+}
+
+bool handleOptionVerbose(Options&amp; options, const char*, const char*)
+{
+    options.verbose = true;
+    return true;
+}
+
+bool handleOptionGcBetweenTests(Options&amp; options, const char*, const char*)
+{
+    options.gcBetweenTests = true;
+    return true;
+}
+
+bool handleOptionPixelTests(Options&amp; options, const char*, const char*)
+{
+    options.shouldDumpPixelsForAllTests = true;
+    return true;
+}
+
+bool handleOptionPrintSupportedFeatures(Options&amp; options, const char*, const char*)
+{
+    options.printSupportedFeatures = true;
+    return true;
+}
+
+bool handleOptionComplexText(Options&amp; options, const char*, const char*)
+{
+    options.forceComplexText = true;
+    return true;
+}
+
+bool handleOptionAcceleratedDrawing(Options&amp; options, const char*, const char*)
+{
+    options.shouldUseAcceleratedDrawing = true;
+    return true;
+}
+
+bool handleOptionRemoteLayerTree(Options&amp; options, const char*, const char*)
+{
+    options.shouldUseRemoteLayerTree = true;
+    return true;
+}
+
+bool handleOptionUnmatched(Options&amp; options, const char* option, const char*)
+{
+    if (option[0] &amp;&amp; option[1] &amp;&amp; option[0] == '-' &amp;&amp; option[1] == '-')
+        return true;
+    options.paths.push_back(option);
+    return true;
+}
+
+OptionsHandler::OptionsHandler(Options&amp; o)
+    : options(o)
+{
+    optionList.append(Option(&quot;--timeout&quot;, &quot;Sets long timeout to &lt;param&gt; and scales short timeout.&quot;, handleOptionTimeout, true));
+    optionList.append(Option(&quot;--no-timeout&quot;, &quot;Disables timeout.&quot;, handleOptionNoTimeout));
+    optionList.append(Option(&quot;--no-timeout-at-all&quot;, &quot;Disables all timeouts.&quot;, handleOptionNoTimeoutAtAll));
+    optionList.append(Option(&quot;--verbose&quot;, &quot;Turns on messages.&quot;, handleOptionVerbose));
+    optionList.append(Option(&quot;--gc-between-tests&quot;, &quot;Garbage collection between tests.&quot;, handleOptionGcBetweenTests));
+    optionList.append(Option(&quot;--pixel-tests&quot;, &quot;Check pixels.&quot;, handleOptionPixelTests));
+    optionList.append(Option(&quot;-p&quot;, &quot;Check pixels.&quot;, handleOptionPixelTests));
+    optionList.append(Option(&quot;--print-supported-features&quot;, &quot;For DumpRenderTree compatibility.&quot;, handleOptionPrintSupportedFeatures));
+    optionList.append(Option(&quot;--complex-text&quot;, &quot;Force complex tests.&quot;, handleOptionComplexText));
+    optionList.append(Option(&quot;--accelerated-drawing&quot;, &quot;Use accelerated drawing.&quot;, handleOptionAcceleratedDrawing));
+    optionList.append(Option(&quot;--remote-layer-tree&quot;, &quot;Use remote layer tree.&quot;, handleOptionRemoteLayerTree));
+    optionList.append(Option(0, 0, handleOptionUnmatched));
+}
+
+const char * OptionsHandler::usage = &quot;Usage: WebKitTestRunner [options] filename [filename2..n]&quot;;
+const char * OptionsHandler::help = &quot;Displays this help.&quot;;
+
+Option::Option(const char* name, const char* description, std::function&lt;bool(Options&amp;, const char*, const char*)&gt; parameterHandler, bool hasArgument)
+    : name(name), description(description), parameterHandler(parameterHandler), hasArgument(hasArgument) { };
+
+bool Option::matches(const char* option)
+{
+    return !name || !strcmp(name, option);
+}
+
+bool OptionsHandler::parse(int argc, const char* argv[])
+{
+    bool status = true;
+    for (int argCounter = 1; argCounter &lt; argc; ++argCounter) {
+        if (!strcmp(argv[argCounter], &quot;--help&quot;) || !strcmp(argv[argCounter], &quot;-h&quot;)) {
+            printHelp();
+            return false;
+        }
+        const char* currentOption = argv[argCounter];
+        for (Option&amp; option : optionList) {
+            if (option.matches(currentOption)) {
+                if (!option.parameterHandler)
+                    status = false;
+                else if (option.hasArgument) {
+                    const char * currentArgument = argv[++argCounter];
+                    if (currentArgument)
+                        status &amp;= option.parameterHandler(options, currentOption, currentArgument);
+                    else
+                        status = false;
+                } else
+                    status &amp;= option.parameterHandler(options, currentOption, 0);
+                break;
+            }
+        }
+    }
+    return status;
+}
+
+void OptionsHandler::printHelp(FILE* channel)
+{
+    fputs(usage, channel);
+    fputs(&quot;\n\n    -h|--help\n\t&quot;, channel);
+    fputs(help, channel);
+    fputs(&quot;\n\n&quot;, channel);
+    for (Option&amp; option : optionList) {
+        if (!option.name)
+            continue;
+        fputs(&quot;    &quot;, channel);
+        fputs(option.name, channel);
+        fputs((option.hasArgument ? &quot; &lt;param&gt;\n\t&quot; : &quot;\n\t&quot;), channel);
+        fputs(option.description, channel);
+        fputs(&quot;\n\n&quot;, channel);
+    }
+}
+
+} // namespace WTR
</ins></span></pre></div>
<a id="trunkToolsWebKitTestRunnerOptionsh"></a>
<div class="addfile"><h4>Added: trunk/Tools/WebKitTestRunner/Options.h (0 => 160627)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/Options.h                                (rev 0)
+++ trunk/Tools/WebKitTestRunner/Options.h        2013-12-16 04:58:10 UTC (rev 160627)
</span><span class="lines">@@ -0,0 +1,80 @@
</span><ins>+/*
+ * Copyright (C) 2013 University of Szeged. All rights reserved.
+ * Copyright (C) 2013 Samsung Electronics. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF SZEGED OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef Options_h
+#define Options_h
+
+#include &lt;functional&gt;
+#include &lt;stdio.h&gt;
+#include &lt;string&gt;
+#include &lt;vector&gt;
+#include &lt;wtf/Vector.h&gt;
+
+namespace WTR {
+
+struct Options {
+    Options(double, double);
+    double longTimeout;
+    double shortTimeout;
+    bool useWaitToDumpWatchdogTimer;
+    bool forceNoTimeout;
+    bool verbose;
+    bool gcBetweenTests;
+    bool shouldDumpPixelsForAllTests;
+    bool printSupportedFeatures;
+    bool forceComplexText;
+    bool shouldUseAcceleratedDrawing;
+    bool shouldUseRemoteLayerTree;
+    std::vector&lt;std::string&gt; paths;
+    double defaultLongTimeout;
+    double defaultShortTimeout;
+};
+
+class Option {
+public:
+    Option(const char* name, const char* description, std::function&lt;bool(Options&amp;, const char*, const char*)&gt; parameterHandler, bool hasArgument = false);
+    bool matches(const char*);
+    const char* name;
+    const char* description;
+    std::function&lt;bool(Options&amp;, const char*, const char*)&gt; parameterHandler;
+    bool hasArgument;
+};
+
+class OptionsHandler {
+public:
+    explicit OptionsHandler(Options&amp;);
+    bool parse(int argc, const char* argv[]);
+    void printHelp(FILE* channel = stderr);
+private:
+    Vector&lt;Option&gt; optionList;
+    Options&amp; options;
+    static const char* usage;
+    static const char* help;
+};
+
+} // namespace WTR
+
+#endif // Options_h
</ins></span></pre></div>
<a id="trunkToolsWebKitTestRunnerTestControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (160626 => 160627)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/TestController.cpp        2013-12-16 04:04:10 UTC (rev 160626)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp        2013-12-16 04:58:10 UTC (rev 160627)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx"> #include &quot;TestController.h&quot;
</span><span class="cx"> 
</span><span class="cx"> #include &quot;EventSenderProxy.h&quot;
</span><ins>+#include &quot;Options.h&quot;
</ins><span class="cx"> #include &quot;PlatformWebView.h&quot;
</span><span class="cx"> #include &quot;StringFunctions.h&quot;
</span><span class="cx"> #include &quot;TestInvocation.h&quot;
</span><span class="lines">@@ -266,74 +267,29 @@
</span><span class="cx"> {
</span><span class="cx">     platformInitialize();
</span><span class="cx"> 
</span><ins>+    Options options(defaultLongTimeout, defaultShortTimeout);
+    OptionsHandler optionsHandler(options);
+
</ins><span class="cx">     if (argc &lt; 2) {
</span><del>-        fputs(&quot;Usage: WebKitTestRunner [options] filename [filename2..n]\n&quot;, stderr);
-        // FIXME: Refactor option parsing to allow us to print
-        // an auto-generated list of options.
</del><ins>+        optionsHandler.printHelp();
</ins><span class="cx">         exit(1);
</span><span class="cx">     }
</span><ins>+    if (!optionsHandler.parse(argc, argv))
+        exit(1);
</ins><span class="cx"> 
</span><del>-    bool printSupportedFeatures = false;
</del><ins>+    m_longTimeout = options.longTimeout;
+    m_shortTimeout = options.shortTimeout;
+    m_useWaitToDumpWatchdogTimer = options.useWaitToDumpWatchdogTimer;
+    m_forceNoTimeout = options.forceNoTimeout;
+    m_verbose = options.verbose;
+    m_gcBetweenTests = options.gcBetweenTests;
+    m_shouldDumpPixelsForAllTests = options.shouldDumpPixelsForAllTests;
+    m_forceComplexText = options.forceComplexText;
+    m_shouldUseAcceleratedDrawing = options.shouldUseAcceleratedDrawing;
+    m_shouldUseRemoteLayerTree = options.shouldUseRemoteLayerTree;
+    m_paths = options.paths;
</ins><span class="cx"> 
</span><del>-    for (int i = 1; i &lt; argc; ++i) {
-        std::string argument(argv[i]);
-
-        if (argument == &quot;--timeout&quot; &amp;&amp; i + 1 &lt; argc) {
-            m_longTimeout = atoi(argv[++i]);
-            // Scale up the short timeout to match.
-            m_shortTimeout = defaultShortTimeout * m_longTimeout / defaultLongTimeout;
-            continue;
-        }
-
-        if (argument == &quot;--no-timeout&quot;) {
-            m_useWaitToDumpWatchdogTimer = false;
-            continue;
-        }
-
-        if (argument == &quot;--no-timeout-at-all&quot;) {
-            m_useWaitToDumpWatchdogTimer = false;
-            m_forceNoTimeout = true;
-            continue;
-        }
-
-        if (argument == &quot;--verbose&quot;) {
-            m_verbose = true;
-            continue;
-        }
-        if (argument == &quot;--gc-between-tests&quot;) {
-            m_gcBetweenTests = true;
-            continue;
-        }
-        if (argument == &quot;--pixel-tests&quot; || argument == &quot;-p&quot;) {
-            m_shouldDumpPixelsForAllTests = true;
-            continue;
-        }
-        if (argument == &quot;--print-supported-features&quot;) {
-            printSupportedFeatures = true;
-            break;
-        }
-        if (argument == &quot;--complex-text&quot;) {
-            m_forceComplexText = true;
-            continue;
-        }
-        if (argument == &quot;--accelerated-drawing&quot;) {
-            m_shouldUseAcceleratedDrawing = true;
-            continue;
-        }
-        if (argument == &quot;--remote-layer-tree&quot;) {
-            m_shouldUseRemoteLayerTree = true;
-            continue;
-        }
-
-
-        // Skip any other arguments that begin with '--'.
-        if (argument.length() &gt;= 2 &amp;&amp; argument[0] == '-' &amp;&amp; argument[1] == '-')
-            continue;
-
-        m_paths.push_back(argument);
-    }
-
-    if (printSupportedFeatures) {
</del><ins>+    if (options.printSupportedFeatures) {
</ins><span class="cx">         // FIXME: On Windows, DumpRenderTree uses this to expose whether it supports 3d
</span><span class="cx">         // transforms and accelerated compositing. When we support those features, we
</span><span class="cx">         // should match DRT's behavior.
</span></span></pre></div>
<a id="trunkToolsWebKitTestRunnerWebKitTestRunnerxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj (160626 => 160627)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj        2013-12-16 04:04:10 UTC (rev 160626)
+++ trunk/Tools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj        2013-12-16 04:58:10 UTC (rev 160627)
</span><span class="lines">@@ -59,6 +59,7 @@
</span><span class="cx">                 65EB85A011EC67CC0034D300 /* ActivateFonts.mm in Sources */ = {isa = PBXBuildFile; fileRef = 65EB859F11EC67CC0034D300 /* ActivateFonts.mm */; };
</span><span class="cx">                 8034C6621487636400AC32E9 /* AccessibilityControllerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 8034C6611487636400AC32E9 /* AccessibilityControllerMac.mm */; };
</span><span class="cx">                 8097338A14874A5A008156D9 /* AccessibilityNotificationHandler.mm in Sources */ = {isa = PBXBuildFile; fileRef = 8097338914874A5A008156D9 /* AccessibilityNotificationHandler.mm */; };
</span><ins>+                841CC00F181185BF0042E9B6 /* Options.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 841CC00D181185BF0042E9B6 /* Options.cpp */; };
</ins><span class="cx">                 8CCDA823151A570B0003F937 /* SampleFont.sfont in Resources */ = {isa = PBXBuildFile; fileRef = 8CCDA822151A570B0003F937 /* SampleFont.sfont */; };
</span><span class="cx">                 A664BC7613A5F3A9009A7B25 /* libWebCoreTestSupport.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 41230E16138C78BF00BCCFCA /* libWebCoreTestSupport.dylib */; };
</span><span class="cx">                 BC14E4DB120E02D000826C0C /* GCController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC14E4D9120E02D000826C0C /* GCController.cpp */; };
</span><span class="lines">@@ -174,6 +175,8 @@
</span><span class="cx">                 8034C6611487636400AC32E9 /* AccessibilityControllerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AccessibilityControllerMac.mm; path = mac/AccessibilityControllerMac.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 8097338814874A5A008156D9 /* AccessibilityNotificationHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AccessibilityNotificationHandler.h; path = mac/AccessibilityNotificationHandler.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 8097338914874A5A008156D9 /* AccessibilityNotificationHandler.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AccessibilityNotificationHandler.mm; path = mac/AccessibilityNotificationHandler.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                841CC00D181185BF0042E9B6 /* Options.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Options.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
+                841CC00E181185BF0042E9B6 /* Options.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Options.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 8CCDA822151A570B0003F937 /* SampleFont.sfont */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = SampleFont.sfont; path = fonts/SampleFont.sfont; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 8DD76FA10486AA7600D96B5E /* WebKitTestRunner */ = {isa = PBXFileReference; explicitFileType = &quot;compiled.mach-o.executable&quot;; includeInIndex = 0; path = WebKitTestRunner; sourceTree = BUILT_PRODUCTS_DIR; };
</span><span class="cx">                 BC14E4D8120E02D000826C0C /* GCController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCController.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -280,6 +283,8 @@
</span><span class="cx">                 08FB7795FE84155DC02AAC07 /* TestRunner */ = {
</span><span class="cx">                         isa = PBXGroup;
</span><span class="cx">                         children = (
</span><ins>+                                841CC00D181185BF0042E9B6 /* Options.cpp */,
+                                841CC00E181185BF0042E9B6 /* Options.h */,
</ins><span class="cx">                                 BC9192021333E4CD003011DC /* cg */,
</span><span class="cx">                                 BC7933FE118F7C74005EA8E2 /* mac */,
</span><span class="cx">                                 5322FB4113FDA0CD0041ABCC /* CyclicRedundancyCheck.cpp */,
</span><span class="lines">@@ -637,6 +642,7 @@
</span><span class="cx">                                 E132AA3A17CD5F1000611DF0 /* WebKitTestRunnerDraggingInfo.mm in Sources */,
</span><span class="cx">                                 3164C8F015D1ADA100EF1FE0 /* WebNotificationProvider.cpp in Sources */,
</span><span class="cx">                                 4429FC5F1627089600F66D8B /* WorkQueueManager.cpp in Sources */,
</span><ins>+                                841CC00F181185BF0042E9B6 /* Options.cpp in Sources */,
</ins><span class="cx">                         );
</span><span class="cx">                         runOnlyForDeploymentPostprocessing = 0;
</span><span class="cx">                 };
</span></span></pre>
</div>
</div>

</body>
</html>