Changeset 142643 in webkit


Ignore:
Timestamp:
Feb 12, 2013 10:50:43 AM (11 years ago)
Author:
jochen@chromium.org
Message:

[chromium] move text dump generation to TestRunner library
https://bugs.webkit.org/show_bug.cgi?id=109575

Reviewed by Adam Barth.

  • DumpRenderTree/DumpRenderTree.gypi:
  • DumpRenderTree/chromium/TestRunner/public/WebTestDelegate.h:

(WebKit):
(WebTestRunner::WebTestDelegate::captureHistoryForWindow):

  • DumpRenderTree/chromium/TestRunner/public/WebTestProxy.h:
  • DumpRenderTree/chromium/TestRunner/public/WebTestRunner.h:

(WebTestRunner):

  • DumpRenderTree/chromium/TestRunner/src/TestCommon.cpp: Copied from Tools/DumpRenderTree/chromium/TestRunner/src/TestCommon.h.

(WebTestRunner::normalizeLayoutTestURL):
(WebTestRunner):

  • DumpRenderTree/chromium/TestRunner/src/TestCommon.h:

(WebTestRunner):

  • DumpRenderTree/chromium/TestRunner/src/TestRunner.cpp:

(WebTestRunner::TestRunner::checkResponseMimeType):
(WebTestRunner):
(WebTestRunner::TestRunner::shouldDumpAsText):
(WebTestRunner::TestRunner::shouldGeneratePixelResults):

  • DumpRenderTree/chromium/TestRunner/src/TestRunner.h:

(TestRunner):

  • DumpRenderTree/chromium/TestRunner/src/WebPermissions.cpp:
  • DumpRenderTree/chromium/TestRunner/src/WebTestProxy.cpp:

(WebTestRunner::WebTestProxyBase::captureTree):
(WebTestRunner):

  • DumpRenderTree/chromium/TestShell.cpp:

(TestShell::dump):
(TestShell::captureHistoryForWindow):

  • DumpRenderTree/chromium/TestShell.h:

(TestShell):

  • DumpRenderTree/chromium/WebViewHost.cpp:

(WebViewHost::captureHistoryForWindow):

  • DumpRenderTree/chromium/WebViewHost.h:
Location:
trunk/Tools
Files:
14 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r142637 r142643  
     12013-02-12  Jochen Eisinger  <jochen@chromium.org>
     2
     3        [chromium] move text dump generation to TestRunner library
     4        https://bugs.webkit.org/show_bug.cgi?id=109575
     5
     6        Reviewed by Adam Barth.
     7
     8        * DumpRenderTree/DumpRenderTree.gypi:
     9        * DumpRenderTree/chromium/TestRunner/public/WebTestDelegate.h:
     10        (WebKit):
     11        (WebTestRunner::WebTestDelegate::captureHistoryForWindow):
     12        * DumpRenderTree/chromium/TestRunner/public/WebTestProxy.h:
     13        * DumpRenderTree/chromium/TestRunner/public/WebTestRunner.h:
     14        (WebTestRunner):
     15        * DumpRenderTree/chromium/TestRunner/src/TestCommon.cpp: Copied from Tools/DumpRenderTree/chromium/TestRunner/src/TestCommon.h.
     16        (WebTestRunner::normalizeLayoutTestURL):
     17        (WebTestRunner):
     18        * DumpRenderTree/chromium/TestRunner/src/TestCommon.h:
     19        (WebTestRunner):
     20        * DumpRenderTree/chromium/TestRunner/src/TestRunner.cpp:
     21        (WebTestRunner::TestRunner::checkResponseMimeType):
     22        (WebTestRunner):
     23        (WebTestRunner::TestRunner::shouldDumpAsText):
     24        (WebTestRunner::TestRunner::shouldGeneratePixelResults):
     25        * DumpRenderTree/chromium/TestRunner/src/TestRunner.h:
     26        (TestRunner):
     27        * DumpRenderTree/chromium/TestRunner/src/WebPermissions.cpp:
     28        * DumpRenderTree/chromium/TestRunner/src/WebTestProxy.cpp:
     29        (WebTestRunner::WebTestProxyBase::captureTree):
     30        (WebTestRunner):
     31        * DumpRenderTree/chromium/TestShell.cpp:
     32        (TestShell::dump):
     33        (TestShell::captureHistoryForWindow):
     34        * DumpRenderTree/chromium/TestShell.h:
     35        (TestShell):
     36        * DumpRenderTree/chromium/WebViewHost.cpp:
     37        (WebViewHost::captureHistoryForWindow):
     38        * DumpRenderTree/chromium/WebViewHost.h:
     39
    1402013-02-12  Jessie Berlin  <jberlin@apple.com>
    241
  • trunk/Tools/DumpRenderTree/DumpRenderTree.gypi

    r142593 r142643  
    8080            'chromium/TestRunner/src/SpellCheckClient.cpp',
    8181            'chromium/TestRunner/src/SpellCheckClient.h',
     82            'chromium/TestRunner/src/TestCommon.cpp',
    8283            'chromium/TestRunner/src/TestCommon.h',
    8384            'chromium/TestRunner/src/TestInterfaces.cpp',
  • trunk/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestDelegate.h

    r142549 r142643  
    4040class WebDeviceOrientation;
    4141class WebGamepads;
     42class WebHistoryItem;
    4243struct WebRect;
    4344struct WebURLError;
     
    114115    virtual void loadURLForFrame(const WebKit::WebURL&, const std::string&) { }
    115116    virtual bool allowExternalPages() { return false; }
     117    virtual void captureHistoryForWindow(size_t windowIndex, WebKit::WebVector<WebKit::WebHistoryItem>* history, size_t* currentEntryIndex) { }
    116118};
    117119
  • trunk/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestProxy.h

    r142593 r142643  
    9494    void setPaintRect(const WebKit::WebRect&);
    9595    WebKit::WebRect paintRect() const;
     96
     97    std::string captureTree(bool debugRenderTree);
    9698
    9799    void setLogConsoleOutput(bool enabled);
  • trunk/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestRunner.h

    r142370 r142643  
    4141class WebTestRunner {
    4242public:
    43     virtual bool shouldDumpAsText() const = 0;
    44     virtual bool shouldGeneratePixelResults() const = 0;
    45     virtual bool shouldDumpChildFrameScrollPositions() const = 0;
    46     virtual bool shouldDumpChildFramesAsText() const = 0;
     43    virtual bool shouldGeneratePixelResults() = 0;
    4744    virtual bool shouldDumpAsAudio() const = 0;
    4845    virtual const WebKit::WebArrayBufferView* audioData() const = 0;
    4946    virtual WebKit::WebPermissionClient* webPermissions() const = 0;
    50     virtual bool shouldDumpBackForwardList() const = 0;
    5147    virtual bool shouldDumpSelectionRect() const = 0;
    5248    virtual bool testRepaint() const = 0;
  • trunk/Tools/DumpRenderTree/chromium/TestRunner/src/TestCommon.cpp

    r142642 r142643  
    2929 */
    3030
    31 #ifndef TestCommon_h
    32 #define TestCommon_h
     31#include "config.h"
     32#include "TestCommon.h"
    3333
    34 #include <base/compiler_specific.h>
    35 #include <public/WebCommon.h>
    36 #include <stdio.h>
     34using namespace std;
    3735
    38 #if defined(WIN32)
    39 #define snprintf(str, size, ...) _snprintf_s(str, size, size, __VA_ARGS__)
    40 #endif
     36namespace WebTestRunner {
    4137
    42 inline bool isASCIIAlpha(char ch) { return (ch | 0x20) >= 'a' && (ch | 0x20) <= 'z'; }
     38namespace {
    4339
    44 inline bool isNotASCIIAlpha(char ch) { return !isASCIIAlpha(ch); }
     40const char layoutTestsPattern[] = "/LayoutTests/";
     41const string::size_type layoutTestsPatternSize = sizeof(layoutTestsPattern) - 1;
     42const char fileUrlPattern[] = "file:/";
     43const char fileTestPrefix[] = "(file test):";
     44const char dataUrlPattern[] = "data:";
     45const string::size_type dataUrlPatternSize = sizeof(dataUrlPattern) - 1;
    4546
    46 #endif // TestCommon_h
     47}
     48
     49string normalizeLayoutTestURL(const string& url)
     50{
     51    string result = url;
     52    size_t pos;
     53    if (!url.find(fileUrlPattern) && ((pos = url.find(layoutTestsPattern)) != string::npos)) {
     54        // adjust file URLs to match upstream results.
     55        result.replace(0, pos + layoutTestsPatternSize, fileTestPrefix);
     56    } else if (!url.find(dataUrlPattern)) {
     57        // URL-escape data URLs to match results upstream.
     58        string path = url.substr(dataUrlPatternSize);
     59        result.replace(dataUrlPatternSize, url.length(), path);
     60    }
     61    return result;
     62}
     63
     64}
  • trunk/Tools/DumpRenderTree/chromium/TestRunner/src/TestCommon.h

    r142237 r142643  
    3535#include <public/WebCommon.h>
    3636#include <stdio.h>
     37#include <string>
    3738
    3839#if defined(WIN32)
     
    4041#endif
    4142
     43namespace WebTestRunner {
     44
    4245inline bool isASCIIAlpha(char ch) { return (ch | 0x20) >= 'a' && (ch | 0x20) <= 'z'; }
    4346
    4447inline bool isNotASCIIAlpha(char ch) { return !isASCIIAlpha(ch); }
    4548
     49std::string normalizeLayoutTestURL(const std::string& url);
     50
     51}
     52
    4653#endif // TestCommon_h
  • trunk/Tools/DumpRenderTree/chromium/TestRunner/src/TestRunner.cpp

    r142582 r142643  
    3535
    3636#include "WebBindings.h"
     37#include "WebDataSource.h"
    3738#include "WebDeviceOrientation.h"
    3839#include "WebDocument.h"
     
    5657#include <public/WebData.h>
    5758#include <public/WebPoint.h>
     59#include <public/WebURLResponse.h>
    5860
    5961#if defined(__linux__) || defined(ANDROID)
     
    426428}
    427429
    428 bool TestRunner::shouldDumpAsText() const
    429 {
     430void TestRunner::checkResponseMimeType()
     431{
     432    // Text output: the test page can request different types of output
     433    // which we handle here.
     434    if (!m_dumpAsText) {
     435        string mimeType = m_webView->mainFrame()->dataSource()->response().mimeType().utf8();
     436        if (mimeType == "text/plain") {
     437            m_dumpAsText = true;
     438            m_generatePixelResults = false;
     439        }
     440    }
     441}
     442
     443bool TestRunner::shouldDumpAsText()
     444{
     445    checkResponseMimeType();
    430446    return m_dumpAsText;
    431447}
     
    436452}
    437453
    438 bool TestRunner::shouldGeneratePixelResults() const
    439 {
     454bool TestRunner::shouldGeneratePixelResults()
     455{
     456    checkResponseMimeType();
    440457    return m_generatePixelResults;
    441458}
  • trunk/Tools/DumpRenderTree/chromium/TestRunner/src/TestRunner.h

    r142549 r142643  
    7272
    7373    // WebTestRunner implementation.
    74     virtual bool shouldDumpAsText() const OVERRIDE;
    75     virtual bool shouldGeneratePixelResults() const OVERRIDE;
    76     virtual bool shouldDumpChildFrameScrollPositions() const OVERRIDE;
    77     virtual bool shouldDumpChildFramesAsText() const OVERRIDE;
     74    virtual bool shouldGeneratePixelResults() OVERRIDE;
    7875    virtual bool shouldDumpAsAudio() const OVERRIDE;
    7976    virtual const WebKit::WebArrayBufferView* audioData() const OVERRIDE;
    8077    virtual WebKit::WebPermissionClient* webPermissions() const OVERRIDE;
    81     virtual bool shouldDumpBackForwardList() const OVERRIDE;
    8278    virtual bool shouldDumpSelectionRect() const OVERRIDE;
    8379    virtual bool testRepaint() const OVERRIDE;
     
    8682
    8783    // Methods used by WebTestProxyBase.
     84    bool shouldDumpAsText();
     85    bool shouldDumpBackForwardList() const;
     86    bool shouldDumpChildFrameScrollPositions() const;
     87    bool shouldDumpChildFramesAsText() const;
    8888    void showDevTools();
    8989    void setShouldDumpAsText(bool);
     
    487487    ///////////////////////////////////////////////////////////////////////////
    488488    // Internal helpers
     489    void checkResponseMimeType();
    489490    void completeNotifyDone(bool isTimeout);
    490491    class NotifyDoneTimedOutTask: public WebMethodTask<TestRunner> {
  • trunk/Tools/DumpRenderTree/chromium/TestRunner/src/WebPermissions.cpp

    r142253 r142643  
    3232#include "WebPermissions.h"
    3333
     34#include "TestCommon.h"
    3435#include "WebTestDelegate.h"
    3536#include <public/WebCString.h>
     
    3940
    4041namespace WebTestRunner {
    41 
    42 namespace {
    43 
    44 const char layoutTestsPattern[] = "/LayoutTests/";
    45 const string::size_type layoutTestsPatternSize = sizeof(layoutTestsPattern) - 1;
    46 const char fileUrlPattern[] = "file:/";
    47 const char fileTestPrefix[] = "(file test):";
    48 const char dataUrlPattern[] = "data:";
    49 const string::size_type dataUrlPatternSize = sizeof(dataUrlPattern) - 1;
    50 
    51 string normalizeLayoutTestURL(const string& url)
    52 {
    53     string result = url;
    54     size_t pos;
    55     if (!url.find(fileUrlPattern) && ((pos = url.find(layoutTestsPattern)) != string::npos)) {
    56         // adjust file URLs to match upstream results.
    57         result.replace(0, pos + layoutTestsPatternSize, fileTestPrefix);
    58     } else if (!url.find(dataUrlPattern)) {
    59         // URL-escape data URLs to match results upstream.
    60         string path = url.substr(dataUrlPatternSize);
    61         result.replace(dataUrlPatternSize, url.length(), path);
    62     }
    63     return result;
    64 }
    65 
    66 }
    6742
    6843WebPermissions::WebPermissions()
  • trunk/Tools/DumpRenderTree/chromium/TestRunner/src/WebTestProxy.cpp

    r142593 r142643  
    4444#include "WebConsoleMessage.h"
    4545#include "WebDataSource.h"
     46#include "WebDocument.h"
    4647#include "WebElement.h"
    4748#include "WebFrame.h"
     49#include "WebHistoryItem.h"
    4850#include "WebNode.h"
    4951#include "WebPluginParams.h"
    5052#include "WebPrintParams.h"
    5153#include "WebRange.h"
     54#include "WebScriptController.h"
    5255#include "WebTestDelegate.h"
    5356#include "WebTestInterfaces.h"
     
    5558#include "WebUserMediaClientMock.h"
    5659#include "WebView.h"
     60#include <cctype>
    5761#include <public/WebCString.h>
    5862#include <public/WebURLError.h>
     
    255259}
    256260
     261string dumpDocumentText(WebFrame* frame)
     262{
     263    // We use the document element's text instead of the body text here because
     264    // not all documents have a body, such as XML documents.
     265    WebElement documentElement = frame->document().documentElement();
     266    if (documentElement.isNull())
     267        return string();
     268    return documentElement.innerText().utf8();
     269}
     270
     271string dumpFramesAsText(WebFrame* frame, bool recursive)
     272{
     273    string result;
     274
     275    // Add header for all but the main frame. Skip empty frames.
     276    if (frame->parent() && !frame->document().documentElement().isNull()) {
     277        result.append("\n--------\nFrame: '");
     278        result.append(frame->uniqueName().utf8().data());
     279        result.append("'\n--------\n");
     280    }
     281
     282    result.append(dumpDocumentText(frame));
     283    result.append("\n");
     284
     285    if (recursive) {
     286        for (WebFrame* child = frame->firstChild(); child; child = child->nextSibling())
     287            result.append(dumpFramesAsText(child, recursive));
     288    }
     289
     290    return result;
     291}
     292
     293string dumpFramesAsPrintedText(WebFrame* frame, bool recursive)
     294{
     295    string result;
     296
     297    // Cannot do printed format for anything other than HTML
     298    if (!frame->document().isHTMLDocument())
     299        return string();
     300
     301    // Add header for all but the main frame. Skip empty frames.
     302    if (frame->parent() && !frame->document().documentElement().isNull()) {
     303        result.append("\n--------\nFrame: '");
     304        result.append(frame->uniqueName().utf8().data());
     305        result.append("'\n--------\n");
     306    }
     307
     308    result.append(frame->renderTreeAsText(WebFrame::RenderAsTextPrinting).utf8());
     309    result.append("\n");
     310
     311    if (recursive) {
     312        for (WebFrame* child = frame->firstChild(); child; child = child->nextSibling())
     313            result.append(dumpFramesAsPrintedText(child, recursive));
     314    }
     315
     316    return result;
     317}
     318
     319string dumpFrameScrollPosition(WebFrame* frame, bool recursive)
     320{
     321    string result;
     322    WebSize offset = frame->scrollOffset();
     323    if (offset.width > 0 || offset.height > 0) {
     324        if (frame->parent())
     325            result = string("frame '") + frame->uniqueName().utf8().data() + "' ";
     326        char data[100];
     327        snprintf(data, sizeof(data), "scrolled to %d,%d\n", offset.width, offset.height);
     328        result += data;
     329    }
     330
     331    if (!recursive)
     332        return result;
     333    for (WebFrame* child = frame->firstChild(); child; child = child->nextSibling())
     334        result += dumpFrameScrollPosition(child, recursive);
     335    return result;
     336}
     337
     338struct ToLower {
     339    char16 operator()(char16 c) { return tolower(c); }
     340};
     341
     342// Returns True if item1 < item2.
     343bool HistoryItemCompareLess(const WebHistoryItem& item1, const WebHistoryItem& item2)
     344{
     345    string16 target1 = item1.target();
     346    string16 target2 = item2.target();
     347    std::transform(target1.begin(), target1.end(), target1.begin(), ToLower());
     348    std::transform(target2.begin(), target2.end(), target2.begin(), ToLower());
     349    return target1 < target2;
     350}
     351
     352string dumpHistoryItem(const WebHistoryItem& item, int indent, bool isCurrent)
     353{
     354    string result;
     355
     356    if (isCurrent) {
     357        result.append("curr->");
     358        result.append(indent - 6, ' '); // 6 == "curr->".length()
     359    } else
     360        result.append(indent, ' ');
     361
     362    string url = normalizeLayoutTestURL(item.urlString().utf8());
     363    result.append(url);
     364    if (!item.target().isEmpty()) {
     365        result.append(" (in frame \"");
     366        result.append(item.target().utf8());
     367        result.append("\")");
     368    }
     369    if (item.isTargetItem())
     370        result.append("  **nav target**");
     371    result.append("\n");
     372
     373    const WebVector<WebHistoryItem>& children = item.children();
     374    if (!children.isEmpty()) {
     375        // Must sort to eliminate arbitrary result ordering which defeats
     376        // reproducible testing.
     377        // FIXME: WebVector should probably just be a std::vector!!
     378        std::vector<WebHistoryItem> sortedChildren;
     379        for (size_t i = 0; i < children.size(); ++i)
     380            sortedChildren.push_back(children[i]);
     381        std::sort(sortedChildren.begin(), sortedChildren.end(), HistoryItemCompareLess);
     382        for (size_t i = 0; i < sortedChildren.size(); ++i)
     383            result += dumpHistoryItem(sortedChildren[i], indent + 4, false);
     384    }
     385
     386    return result;
     387}
     388
     389void dumpBackForwardList(const WebVector<WebHistoryItem>& history, size_t currentEntryIndex, string& result)
     390{
     391    result.append("\n============== Back Forward List ==============\n");
     392    for (int index = 0; index < history.size(); ++index)
     393        result.append(dumpHistoryItem(history[index], 8, index == currentEntryIndex));
     394    result.append("===============================================\n");
     395}
     396
     397string dumpAllBackForwardLists(WebTestDelegate* delegate)
     398{
     399    string result;
     400    unsigned windowCount = delegate->windowCount();
     401    fprintf(stderr, "windowCount = %d\n", windowCount);
     402    for (unsigned i = 0; i < windowCount; ++i) {
     403        size_t currentEntryIndex = 0;
     404        WebVector<WebHistoryItem> history;
     405        delegate->captureHistoryForWindow(i, &history, &currentEntryIndex);
     406        dumpBackForwardList(history, currentEntryIndex, result);
     407    }
     408    return result;
     409}
     410
    257411}
    258412
     
    300454{
    301455    return m_paintRect;
     456}
     457
     458string WebTestProxyBase::captureTree(bool debugRenderTree)
     459{
     460    WebScriptController::flushConsoleMessages();
     461
     462    bool shouldDumpAsText = m_testInterfaces->testRunner()->shouldDumpAsText();
     463    bool shouldDumpAsPrinted = m_testInterfaces->testRunner()->isPrinting();
     464    WebFrame* frame = m_testInterfaces->webView()->mainFrame();
     465    string dataUtf8;
     466    if (shouldDumpAsText) {
     467        bool recursive = m_testInterfaces->testRunner()->shouldDumpChildFramesAsText();
     468        dataUtf8 = shouldDumpAsPrinted ? dumpFramesAsPrintedText(frame, recursive) : dumpFramesAsText(frame, recursive);
     469    } else {
     470        bool recursive = m_testInterfaces->testRunner()->shouldDumpChildFrameScrollPositions();
     471        WebFrame::RenderAsTextControls renderTextBehavior = WebFrame::RenderAsTextNormal;
     472        if (shouldDumpAsPrinted)
     473            renderTextBehavior |= WebFrame::RenderAsTextPrinting;
     474        if (debugRenderTree)
     475            renderTextBehavior |= WebFrame::RenderAsTextDebug;
     476        dataUtf8 = frame->renderTreeAsText(renderTextBehavior).utf8();
     477        dataUtf8 += dumpFrameScrollPosition(frame, recursive);
     478    }
     479
     480    if (m_testInterfaces->testRunner()->shouldDumpBackForwardList())
     481        dataUtf8 += dumpAllBackForwardLists(m_delegate);
     482
     483    return dataUtf8;
    302484}
    303485
  • trunk/Tools/DumpRenderTree/chromium/TestShell.cpp

    r142593 r142643  
    4545#include "WebTestingSupport.h"
    4646#include "WebRuntimeFeatures.h"
    47 #include "WebScriptController.h"
    4847#include "WebSettings.h"
    4948#include "WebTestProxy.h"
     
    393392}
    394393
    395 static string dumpDocumentText(WebFrame* frame)
    396 {
    397     // We use the document element's text instead of the body text here because
    398     // not all documents have a body, such as XML documents.
    399     WebElement documentElement = frame->document().documentElement();
    400     if (documentElement.isNull())
    401         return string();
    402     return documentElement.innerText().utf8();
    403 }
    404 
    405 static string dumpFramesAsText(WebFrame* frame, bool recursive)
    406 {
    407     string result;
    408 
    409     // Add header for all but the main frame. Skip empty frames.
    410     if (frame->parent() && !frame->document().documentElement().isNull()) {
    411         result.append("\n--------\nFrame: '");
    412         result.append(frame->uniqueName().utf8().data());
    413         result.append("'\n--------\n");
    414     }
    415 
    416     result.append(dumpDocumentText(frame));
    417     result.append("\n");
    418 
    419     if (recursive) {
    420         for (WebFrame* child = frame->firstChild(); child; child = child->nextSibling())
    421             result.append(dumpFramesAsText(child, recursive));
    422     }
    423 
    424     return result;
    425 }
    426 
    427 static string dumpFramesAsPrintedText(WebFrame* frame, bool recursive)
    428 {
    429     string result;
    430 
    431     // Cannot do printed format for anything other than HTML
    432     if (!frame->document().isHTMLDocument())
    433         return string();
    434 
    435     // Add header for all but the main frame. Skip empty frames.
    436     if (frame->parent() && !frame->document().documentElement().isNull()) {
    437         result.append("\n--------\nFrame: '");
    438         result.append(frame->uniqueName().utf8().data());
    439         result.append("'\n--------\n");
    440     }
    441 
    442     result.append(frame->renderTreeAsText(WebFrame::RenderAsTextPrinting).utf8());
    443     result.append("\n");
    444 
    445     if (recursive) {
    446         for (WebFrame* child = frame->firstChild(); child; child = child->nextSibling())
    447             result.append(dumpFramesAsPrintedText(child, recursive));
    448     }
    449 
    450     return result;
    451 }
    452 
    453 static void dumpFrameScrollPosition(WebFrame* frame, bool recursive)
    454 {
    455     WebSize offset = frame->scrollOffset();
    456     if (offset.width > 0 || offset.height > 0) {
    457         if (frame->parent())
    458             printf("frame '%s' ", frame->uniqueName().utf8().data());
    459         printf("scrolled to %d,%d\n", offset.width, offset.height);
    460     }
    461 
    462     if (!recursive)
    463         return;
    464     for (WebFrame* child = frame->firstChild(); child; child = child->nextSibling())
    465         dumpFrameScrollPosition(child, recursive);
    466 }
    467 
    468 struct ToLower {
    469     char16 operator()(char16 c) { return tolower(c); }
    470 };
    471 
    472 // FIXME: Eliminate std::transform(), std::vector, and std::sort().
    473 
    474 // Returns True if item1 < item2.
    475 static bool HistoryItemCompareLess(const WebHistoryItem& item1, const WebHistoryItem& item2)
    476 {
    477     string16 target1 = item1.target();
    478     string16 target2 = item2.target();
    479     std::transform(target1.begin(), target1.end(), target1.begin(), ToLower());
    480     std::transform(target2.begin(), target2.end(), target2.begin(), ToLower());
    481     return target1 < target2;
    482 }
    483 
    484 static string normalizeLayoutTestURLInternal(const string& url)
    485 {
    486     string result = url;
    487     size_t pos;
    488     if (!url.find(fileUrlPattern) && ((pos = url.find(layoutTestsPattern)) != string::npos)) {
    489         // adjust file URLs to match upstream results.
    490         result.replace(0, pos + layoutTestsPatternSize, fileTestPrefix);
    491     } else if (!url.find(dataUrlPattern)) {
    492         // URL-escape data URLs to match results upstream.
    493         string path = url.substr(dataUrlPatternSize);
    494         result.replace(dataUrlPatternSize, url.length(), path);
    495     }
    496     return result;
    497 }
    498 
    499 static string dumpHistoryItem(const WebHistoryItem& item, int indent, bool isCurrent)
    500 {
    501     string result;
    502 
    503     if (isCurrent) {
    504         result.append("curr->");
    505         result.append(indent - 6, ' '); // 6 == "curr->".length()
    506     } else
    507         result.append(indent, ' ');
    508 
    509     string url = normalizeLayoutTestURLInternal(item.urlString().utf8());
    510     result.append(url);
    511     if (!item.target().isEmpty()) {
    512         result.append(" (in frame \"");
    513         result.append(item.target().utf8());
    514         result.append("\")");
    515     }
    516     if (item.isTargetItem())
    517         result.append("  **nav target**");
    518     result.append("\n");
    519 
    520     const WebVector<WebHistoryItem>& children = item.children();
    521     if (!children.isEmpty()) {
    522         // Must sort to eliminate arbitrary result ordering which defeats
    523         // reproducible testing.
    524         // FIXME: WebVector should probably just be a std::vector!!
    525         std::vector<WebHistoryItem> sortedChildren;
    526         for (size_t i = 0; i < children.size(); ++i)
    527             sortedChildren.push_back(children[i]);
    528         std::sort(sortedChildren.begin(), sortedChildren.end(), HistoryItemCompareLess);
    529         for (size_t i = 0; i < sortedChildren.size(); ++i)
    530             result += dumpHistoryItem(sortedChildren[i], indent + 4, false);
    531     }
    532 
    533     return result;
    534 }
    535 
    536 static void dumpBackForwardList(const TestNavigationController& navigationController, string& result)
    537 {
    538     result.append("\n============== Back Forward List ==============\n");
    539     for (int index = 0; index < navigationController.entryCount(); ++index) {
    540         int currentIndex = navigationController.lastCommittedEntryIndex();
    541         WebHistoryItem historyItem = navigationController.entryAtIndex(index)->contentState();
    542         if (historyItem.isNull()) {
    543             historyItem.initialize();
    544             historyItem.setURLString(navigationController.entryAtIndex(index)->URL().spec().utf16());
    545         }
    546         result.append(dumpHistoryItem(historyItem, 8, index == currentIndex));
    547     }
    548     result.append("===============================================\n");
    549 }
    550 
    551 string TestShell::dumpAllBackForwardLists()
    552 {
    553     string result;
    554     for (unsigned i = 0; i < m_windowList.size(); ++i)
    555         dumpBackForwardList(*m_windowList[i]->navigationController(), result);
    556     return result;
    557 }
    558 
    559394void TestShell::dump()
    560395{
    561     WebScriptController::flushConsoleMessages();
    562 
    563396    // Dump the requested representation.
    564397    WebFrame* frame = m_webView->mainFrame();
    565398    if (!frame)
    566399        return;
    567     bool shouldDumpAsText = m_testInterfaces->testRunner()->shouldDumpAsText();
    568400    bool shouldDumpAsAudio = m_testInterfaces->testRunner()->shouldDumpAsAudio();
    569401    bool shouldGeneratePixelResults = m_testInterfaces->testRunner()->shouldGeneratePixelResults();
    570     bool shouldDumpAsPrinted = m_testInterfaces->testRunner()->isPrinting();
    571402    bool dumpedAnything = false;
    572403
     
    585416        dumpedAnything = true;
    586417        m_printer.handleTextHeader();
    587         // Text output: the test page can request different types of output
    588         // which we handle here.
    589         if (!shouldDumpAsText) {
    590             // Plain text pages should be dumped as text
    591             string mimeType = frame->dataSource()->response().mimeType().utf8();
    592             if (mimeType == "text/plain") {
    593                 shouldDumpAsText = true;
    594                 shouldGeneratePixelResults = false;
    595             }
    596         }
    597         if (shouldDumpAsText) {
    598             bool recursive = m_testInterfaces->testRunner()->shouldDumpChildFramesAsText();
    599             string dataUtf8 = shouldDumpAsPrinted ? dumpFramesAsPrintedText(frame, recursive) : dumpFramesAsText(frame, recursive);
    600             if (fwrite(dataUtf8.c_str(), 1, dataUtf8.size(), stdout) != dataUtf8.size())
    601                 FATAL("Short write to stdout, disk full?\n");
    602         } else {
    603           WebFrame::RenderAsTextControls renderTextBehavior = WebFrame::RenderAsTextNormal;
    604             if (shouldDumpAsPrinted)
    605                 renderTextBehavior |= WebFrame::RenderAsTextPrinting;
    606             if (m_params.debugRenderTree)
    607                 renderTextBehavior |= WebFrame::RenderAsTextDebug;
    608             printf("%s", frame->renderTreeAsText(renderTextBehavior).utf8().data());
    609             bool recursive = m_testInterfaces->testRunner()->shouldDumpChildFrameScrollPositions();
    610             dumpFrameScrollPosition(frame, recursive);
    611         }
    612         if (m_testInterfaces->testRunner()->shouldDumpBackForwardList())
    613             printf("%s", dumpAllBackForwardLists().c_str());
     418        string dataUtf8 = m_webViewHost->proxy()->captureTree(m_params.debugRenderTree);
     419        if (fwrite(dataUtf8.c_str(), 1, dataUtf8.size(), stdout) != dataUtf8.size())
     420            FATAL("Short write to stdout, disk full?\n");
    614421    }
    615422    if (dumpedAnything && m_params.printSeparators)
     
    811618    return m_windowList.size();
    812619}
     620
     621void TestShell::captureHistoryForWindow(size_t windowIndex, WebVector<WebHistoryItem>* history, size_t* currentEntryIndex)
     622{
     623    ASSERT(history);
     624    ASSERT(currentEntryIndex);
     625    if (windowIndex >= m_windowList.size())
     626        return;
     627    TestNavigationController& navigationController = *m_windowList[windowIndex]->navigationController();
     628    size_t entryCount = navigationController.entryCount();
     629    WebVector<WebHistoryItem> result(entryCount);
     630    *currentEntryIndex = navigationController.lastCommittedEntryIndex();
     631    for (size_t index = 0; index < entryCount; ++index) {
     632        WebHistoryItem historyItem = navigationController.entryAtIndex(index)->contentState();
     633        if (historyItem.isNull()) {
     634            historyItem.initialize();
     635            historyItem.setURLString(navigationController.entryAtIndex(index)->URL().spec().utf16());
     636        }
     637        result[index] = historyItem;
     638    }
     639    history->swap(result);
     640}
  • trunk/Tools/DumpRenderTree/chromium/TestShell.h

    r142593 r142643  
    166166    void closeRemainingWindows();
    167167    int windowCount();
     168    void captureHistoryForWindow(size_t windowIndex, WebKit::WebVector<WebKit::WebHistoryItem>*, size_t* currentEntryIndex);
    168169    static void resizeWindowForTest(WebViewHost*, const WebKit::WebURL&);
    169170
  • trunk/Tools/DumpRenderTree/chromium/WebViewHost.cpp

    r142593 r142643  
    924924}
    925925
     926void WebViewHost::captureHistoryForWindow(size_t windowIndex, WebVector<WebHistoryItem>* history, size_t* currentEntryIndex)
     927{
     928    m_shell->captureHistoryForWindow(windowIndex, history, currentEntryIndex);
     929}
     930
    926931// Public functions -----------------------------------------------------------
    927932
  • trunk/Tools/DumpRenderTree/chromium/WebViewHost.h

    r142593 r142643  
    171171    virtual void loadURLForFrame(const WebKit::WebURL&, const std::string& frameName) OVERRIDE;
    172172    virtual bool allowExternalPages() OVERRIDE;
     173    virtual void captureHistoryForWindow(size_t windowIndex, WebKit::WebVector<WebKit::WebHistoryItem>*, size_t* currentEntryIndex) OVERRIDE;
    173174
    174175    // NavigationHost
Note: See TracChangeset for help on using the changeset viewer.