Diff
Modified: trunk/Tools/ChangeLog (142642 => 142643)
--- trunk/Tools/ChangeLog 2013-02-12 18:49:38 UTC (rev 142642)
+++ trunk/Tools/ChangeLog 2013-02-12 18:50:43 UTC (rev 142643)
@@ -1,3 +1,42 @@
+2013-02-12 Jochen Eisinger <[email protected]>
+
+ [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:
+
2013-02-12 Jessie Berlin <[email protected]>
Rollout r142618, it broke all the Mac builds.
Modified: trunk/Tools/DumpRenderTree/DumpRenderTree.gypi (142642 => 142643)
--- trunk/Tools/DumpRenderTree/DumpRenderTree.gypi 2013-02-12 18:49:38 UTC (rev 142642)
+++ trunk/Tools/DumpRenderTree/DumpRenderTree.gypi 2013-02-12 18:50:43 UTC (rev 142643)
@@ -79,6 +79,7 @@
'chromium/TestRunner/src/MockWebRTCPeerConnectionHandler.h',
'chromium/TestRunner/src/SpellCheckClient.cpp',
'chromium/TestRunner/src/SpellCheckClient.h',
+ 'chromium/TestRunner/src/TestCommon.cpp',
'chromium/TestRunner/src/TestCommon.h',
'chromium/TestRunner/src/TestInterfaces.cpp',
'chromium/TestRunner/src/TestInterfaces.h',
Modified: trunk/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestDelegate.h (142642 => 142643)
--- trunk/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestDelegate.h 2013-02-12 18:49:38 UTC (rev 142642)
+++ trunk/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestDelegate.h 2013-02-12 18:50:43 UTC (rev 142643)
@@ -39,6 +39,7 @@
namespace WebKit {
class WebDeviceOrientation;
class WebGamepads;
+class WebHistoryItem;
struct WebRect;
struct WebURLError;
}
@@ -113,6 +114,7 @@
virtual void reload() { }
virtual void loadURLForFrame(const WebKit::WebURL&, const std::string&) { }
virtual bool allowExternalPages() { return false; }
+ virtual void captureHistoryForWindow(size_t windowIndex, WebKit::WebVector<WebKit::WebHistoryItem>* history, size_t* currentEntryIndex) { }
};
}
Modified: trunk/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestProxy.h (142642 => 142643)
--- trunk/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestProxy.h 2013-02-12 18:49:38 UTC (rev 142642)
+++ trunk/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestProxy.h 2013-02-12 18:50:43 UTC (rev 142643)
@@ -94,6 +94,8 @@
void setPaintRect(const WebKit::WebRect&);
WebKit::WebRect paintRect() const;
+ std::string captureTree(bool debugRenderTree);
+
void setLogConsoleOutput(bool enabled);
protected:
Modified: trunk/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestRunner.h (142642 => 142643)
--- trunk/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestRunner.h 2013-02-12 18:49:38 UTC (rev 142642)
+++ trunk/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestRunner.h 2013-02-12 18:50:43 UTC (rev 142643)
@@ -40,14 +40,10 @@
class WebTestRunner {
public:
- virtual bool shouldDumpAsText() const = 0;
- virtual bool shouldGeneratePixelResults() const = 0;
- virtual bool shouldDumpChildFrameScrollPositions() const = 0;
- virtual bool shouldDumpChildFramesAsText() const = 0;
+ virtual bool shouldGeneratePixelResults() = 0;
virtual bool shouldDumpAsAudio() const = 0;
virtual const WebKit::WebArrayBufferView* audioData() const = 0;
virtual WebKit::WebPermissionClient* webPermissions() const = 0;
- virtual bool shouldDumpBackForwardList() const = 0;
virtual bool shouldDumpSelectionRect() const = 0;
virtual bool testRepaint() const = 0;
virtual bool sweepHorizontally() const = 0;
Copied: trunk/Tools/DumpRenderTree/chromium/TestRunner/src/TestCommon.cpp (from rev 142642, trunk/Tools/DumpRenderTree/chromium/TestRunner/src/TestCommon.h) (0 => 142643)
--- trunk/Tools/DumpRenderTree/chromium/TestRunner/src/TestCommon.cpp (rev 0)
+++ trunk/Tools/DumpRenderTree/chromium/TestRunner/src/TestCommon.cpp 2013-02-12 18:50:43 UTC (rev 142643)
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2013 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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 THE COPYRIGHT
+ * OWNER 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 "config.h"
+#include "TestCommon.h"
+
+using namespace std;
+
+namespace WebTestRunner {
+
+namespace {
+
+const char layoutTestsPattern[] = "/LayoutTests/";
+const string::size_type layoutTestsPatternSize = sizeof(layoutTestsPattern) - 1;
+const char fileUrlPattern[] = "file:/";
+const char fileTestPrefix[] = "(file test):";
+const char dataUrlPattern[] = "data:";
+const string::size_type dataUrlPatternSize = sizeof(dataUrlPattern) - 1;
+
+}
+
+string normalizeLayoutTestURL(const string& url)
+{
+ string result = url;
+ size_t pos;
+ if (!url.find(fileUrlPattern) && ((pos = url.find(layoutTestsPattern)) != string::npos)) {
+ // adjust file URLs to match upstream results.
+ result.replace(0, pos + layoutTestsPatternSize, fileTestPrefix);
+ } else if (!url.find(dataUrlPattern)) {
+ // URL-escape data URLs to match results upstream.
+ string path = url.substr(dataUrlPatternSize);
+ result.replace(dataUrlPatternSize, url.length(), path);
+ }
+ return result;
+}
+
+}
Modified: trunk/Tools/DumpRenderTree/chromium/TestRunner/src/TestCommon.h (142642 => 142643)
--- trunk/Tools/DumpRenderTree/chromium/TestRunner/src/TestCommon.h 2013-02-12 18:49:38 UTC (rev 142642)
+++ trunk/Tools/DumpRenderTree/chromium/TestRunner/src/TestCommon.h 2013-02-12 18:50:43 UTC (rev 142643)
@@ -34,13 +34,20 @@
#include <base/compiler_specific.h>
#include <public/WebCommon.h>
#include <stdio.h>
+#include <string>
#if defined(WIN32)
#define snprintf(str, size, ...) _snprintf_s(str, size, size, __VA_ARGS__)
#endif
+namespace WebTestRunner {
+
inline bool isASCIIAlpha(char ch) { return (ch | 0x20) >= 'a' && (ch | 0x20) <= 'z'; }
inline bool isNotASCIIAlpha(char ch) { return !isASCIIAlpha(ch); }
+std::string normalizeLayoutTestURL(const std::string& url);
+
+}
+
#endif // TestCommon_h
Modified: trunk/Tools/DumpRenderTree/chromium/TestRunner/src/TestRunner.cpp (142642 => 142643)
--- trunk/Tools/DumpRenderTree/chromium/TestRunner/src/TestRunner.cpp 2013-02-12 18:49:38 UTC (rev 142642)
+++ trunk/Tools/DumpRenderTree/chromium/TestRunner/src/TestRunner.cpp 2013-02-12 18:50:43 UTC (rev 142643)
@@ -34,6 +34,7 @@
#include "TestRunner.h"
#include "WebBindings.h"
+#include "WebDataSource.h"
#include "WebDeviceOrientation.h"
#include "WebDocument.h"
#include "WebElement.h"
@@ -55,6 +56,7 @@
#include <memory>
#include <public/WebData.h>
#include <public/WebPoint.h>
+#include <public/WebURLResponse.h>
#if defined(__linux__) || defined(ANDROID)
#include "linux/WebFontRendering.h"
@@ -425,8 +427,22 @@
return m_dumpEditingCallbacks;
}
-bool TestRunner::shouldDumpAsText() const
+void TestRunner::checkResponseMimeType()
{
+ // Text output: the test page can request different types of output
+ // which we handle here.
+ if (!m_dumpAsText) {
+ string mimeType = m_webView->mainFrame()->dataSource()->response().mimeType().utf8();
+ if (mimeType == "text/plain") {
+ m_dumpAsText = true;
+ m_generatePixelResults = false;
+ }
+ }
+}
+
+bool TestRunner::shouldDumpAsText()
+{
+ checkResponseMimeType();
return m_dumpAsText;
}
@@ -435,8 +451,9 @@
m_dumpAsText = value;
}
-bool TestRunner::shouldGeneratePixelResults() const
+bool TestRunner::shouldGeneratePixelResults()
{
+ checkResponseMimeType();
return m_generatePixelResults;
}
Modified: trunk/Tools/DumpRenderTree/chromium/TestRunner/src/TestRunner.h (142642 => 142643)
--- trunk/Tools/DumpRenderTree/chromium/TestRunner/src/TestRunner.h 2013-02-12 18:49:38 UTC (rev 142642)
+++ trunk/Tools/DumpRenderTree/chromium/TestRunner/src/TestRunner.h 2013-02-12 18:50:43 UTC (rev 142643)
@@ -71,20 +71,20 @@
void setTestIsRunning(bool);
// WebTestRunner implementation.
- virtual bool shouldDumpAsText() const OVERRIDE;
- virtual bool shouldGeneratePixelResults() const OVERRIDE;
- virtual bool shouldDumpChildFrameScrollPositions() const OVERRIDE;
- virtual bool shouldDumpChildFramesAsText() const OVERRIDE;
+ virtual bool shouldGeneratePixelResults() OVERRIDE;
virtual bool shouldDumpAsAudio() const OVERRIDE;
virtual const WebKit::WebArrayBufferView* audioData() const OVERRIDE;
virtual WebKit::WebPermissionClient* webPermissions() const OVERRIDE;
- virtual bool shouldDumpBackForwardList() const OVERRIDE;
virtual bool shouldDumpSelectionRect() const OVERRIDE;
virtual bool testRepaint() const OVERRIDE;
virtual bool sweepHorizontally() const OVERRIDE;
virtual bool isPrinting() const OVERRIDE;
// Methods used by WebTestProxyBase.
+ bool shouldDumpAsText();
+ bool shouldDumpBackForwardList() const;
+ bool shouldDumpChildFrameScrollPositions() const;
+ bool shouldDumpChildFramesAsText() const;
void showDevTools();
void setShouldDumpAsText(bool);
void setShouldGeneratePixelResults(bool);
@@ -486,6 +486,7 @@
///////////////////////////////////////////////////////////////////////////
// Internal helpers
+ void checkResponseMimeType();
void completeNotifyDone(bool isTimeout);
class NotifyDoneTimedOutTask: public WebMethodTask<TestRunner> {
public:
Modified: trunk/Tools/DumpRenderTree/chromium/TestRunner/src/WebPermissions.cpp (142642 => 142643)
--- trunk/Tools/DumpRenderTree/chromium/TestRunner/src/WebPermissions.cpp 2013-02-12 18:49:38 UTC (rev 142642)
+++ trunk/Tools/DumpRenderTree/chromium/TestRunner/src/WebPermissions.cpp 2013-02-12 18:50:43 UTC (rev 142643)
@@ -31,6 +31,7 @@
#include "config.h"
#include "WebPermissions.h"
+#include "TestCommon.h"
#include "WebTestDelegate.h"
#include <public/WebCString.h>
#include <public/WebURL.h>
@@ -39,32 +40,6 @@
namespace WebTestRunner {
-namespace {
-
-const char layoutTestsPattern[] = "/LayoutTests/";
-const string::size_type layoutTestsPatternSize = sizeof(layoutTestsPattern) - 1;
-const char fileUrlPattern[] = "file:/";
-const char fileTestPrefix[] = "(file test):";
-const char dataUrlPattern[] = "data:";
-const string::size_type dataUrlPatternSize = sizeof(dataUrlPattern) - 1;
-
-string normalizeLayoutTestURL(const string& url)
-{
- string result = url;
- size_t pos;
- if (!url.find(fileUrlPattern) && ((pos = url.find(layoutTestsPattern)) != string::npos)) {
- // adjust file URLs to match upstream results.
- result.replace(0, pos + layoutTestsPatternSize, fileTestPrefix);
- } else if (!url.find(dataUrlPattern)) {
- // URL-escape data URLs to match results upstream.
- string path = url.substr(dataUrlPatternSize);
- result.replace(dataUrlPatternSize, url.length(), path);
- }
- return result;
-}
-
-}
-
WebPermissions::WebPermissions()
: m_delegate(0)
{
Modified: trunk/Tools/DumpRenderTree/chromium/TestRunner/src/WebTestProxy.cpp (142642 => 142643)
--- trunk/Tools/DumpRenderTree/chromium/TestRunner/src/WebTestProxy.cpp 2013-02-12 18:49:38 UTC (rev 142642)
+++ trunk/Tools/DumpRenderTree/chromium/TestRunner/src/WebTestProxy.cpp 2013-02-12 18:50:43 UTC (rev 142643)
@@ -43,17 +43,21 @@
#include "WebCachedURLRequest.h"
#include "WebConsoleMessage.h"
#include "WebDataSource.h"
+#include "WebDocument.h"
#include "WebElement.h"
#include "WebFrame.h"
+#include "WebHistoryItem.h"
#include "WebNode.h"
#include "WebPluginParams.h"
#include "WebPrintParams.h"
#include "WebRange.h"
+#include "WebScriptController.h"
#include "WebTestDelegate.h"
#include "WebTestInterfaces.h"
#include "WebTestRunner.h"
#include "WebUserMediaClientMock.h"
#include "WebView.h"
+#include <cctype>
#include <public/WebCString.h>
#include <public/WebURLError.h>
#include <public/WebURLRequest.h>
@@ -254,8 +258,158 @@
return illegalString;
}
+string dumpDocumentText(WebFrame* frame)
+{
+ // We use the document element's text instead of the body text here because
+ // not all documents have a body, such as XML documents.
+ WebElement documentElement = frame->document().documentElement();
+ if (documentElement.isNull())
+ return string();
+ return documentElement.innerText().utf8();
}
+string dumpFramesAsText(WebFrame* frame, bool recursive)
+{
+ string result;
+
+ // Add header for all but the main frame. Skip empty frames.
+ if (frame->parent() && !frame->document().documentElement().isNull()) {
+ result.append("\n--------\nFrame: '");
+ result.append(frame->uniqueName().utf8().data());
+ result.append("'\n--------\n");
+ }
+
+ result.append(dumpDocumentText(frame));
+ result.append("\n");
+
+ if (recursive) {
+ for (WebFrame* child = frame->firstChild(); child; child = child->nextSibling())
+ result.append(dumpFramesAsText(child, recursive));
+ }
+
+ return result;
+}
+
+string dumpFramesAsPrintedText(WebFrame* frame, bool recursive)
+{
+ string result;
+
+ // Cannot do printed format for anything other than HTML
+ if (!frame->document().isHTMLDocument())
+ return string();
+
+ // Add header for all but the main frame. Skip empty frames.
+ if (frame->parent() && !frame->document().documentElement().isNull()) {
+ result.append("\n--------\nFrame: '");
+ result.append(frame->uniqueName().utf8().data());
+ result.append("'\n--------\n");
+ }
+
+ result.append(frame->renderTreeAsText(WebFrame::RenderAsTextPrinting).utf8());
+ result.append("\n");
+
+ if (recursive) {
+ for (WebFrame* child = frame->firstChild(); child; child = child->nextSibling())
+ result.append(dumpFramesAsPrintedText(child, recursive));
+ }
+
+ return result;
+}
+
+string dumpFrameScrollPosition(WebFrame* frame, bool recursive)
+{
+ string result;
+ WebSize offset = frame->scrollOffset();
+ if (offset.width > 0 || offset.height > 0) {
+ if (frame->parent())
+ result = string("frame '") + frame->uniqueName().utf8().data() + "' ";
+ char data[100];
+ snprintf(data, sizeof(data), "scrolled to %d,%d\n", offset.width, offset.height);
+ result += data;
+ }
+
+ if (!recursive)
+ return result;
+ for (WebFrame* child = frame->firstChild(); child; child = child->nextSibling())
+ result += dumpFrameScrollPosition(child, recursive);
+ return result;
+}
+
+struct ToLower {
+ char16 operator()(char16 c) { return tolower(c); }
+};
+
+// Returns True if item1 < item2.
+bool HistoryItemCompareLess(const WebHistoryItem& item1, const WebHistoryItem& item2)
+{
+ string16 target1 = item1.target();
+ string16 target2 = item2.target();
+ std::transform(target1.begin(), target1.end(), target1.begin(), ToLower());
+ std::transform(target2.begin(), target2.end(), target2.begin(), ToLower());
+ return target1 < target2;
+}
+
+string dumpHistoryItem(const WebHistoryItem& item, int indent, bool isCurrent)
+{
+ string result;
+
+ if (isCurrent) {
+ result.append("curr->");
+ result.append(indent - 6, ' '); // 6 == "curr->".length()
+ } else
+ result.append(indent, ' ');
+
+ string url = ""
+ result.append(url);
+ if (!item.target().isEmpty()) {
+ result.append(" (in frame \"");
+ result.append(item.target().utf8());
+ result.append("\")");
+ }
+ if (item.isTargetItem())
+ result.append(" **nav target**");
+ result.append("\n");
+
+ const WebVector<WebHistoryItem>& children = item.children();
+ if (!children.isEmpty()) {
+ // Must sort to eliminate arbitrary result ordering which defeats
+ // reproducible testing.
+ // FIXME: WebVector should probably just be a std::vector!!
+ std::vector<WebHistoryItem> sortedChildren;
+ for (size_t i = 0; i < children.size(); ++i)
+ sortedChildren.push_back(children[i]);
+ std::sort(sortedChildren.begin(), sortedChildren.end(), HistoryItemCompareLess);
+ for (size_t i = 0; i < sortedChildren.size(); ++i)
+ result += dumpHistoryItem(sortedChildren[i], indent + 4, false);
+ }
+
+ return result;
+}
+
+void dumpBackForwardList(const WebVector<WebHistoryItem>& history, size_t currentEntryIndex, string& result)
+{
+ result.append("\n============== Back Forward List ==============\n");
+ for (int index = 0; index < history.size(); ++index)
+ result.append(dumpHistoryItem(history[index], 8, index == currentEntryIndex));
+ result.append("===============================================\n");
+}
+
+string dumpAllBackForwardLists(WebTestDelegate* delegate)
+{
+ string result;
+ unsigned windowCount = delegate->windowCount();
+ fprintf(stderr, "windowCount = %d\n", windowCount);
+ for (unsigned i = 0; i < windowCount; ++i) {
+ size_t currentEntryIndex = 0;
+ WebVector<WebHistoryItem> history;
+ delegate->captureHistoryForWindow(i, &history, ¤tEntryIndex);
+ dumpBackForwardList(history, currentEntryIndex, result);
+ }
+ return result;
+}
+
+}
+
WebTestProxyBase::WebTestProxyBase()
: m_testInterfaces(0)
, m_delegate(0)
@@ -301,6 +455,34 @@
return m_paintRect;
}
+string WebTestProxyBase::captureTree(bool debugRenderTree)
+{
+ WebScriptController::flushConsoleMessages();
+
+ bool shouldDumpAsText = m_testInterfaces->testRunner()->shouldDumpAsText();
+ bool shouldDumpAsPrinted = m_testInterfaces->testRunner()->isPrinting();
+ WebFrame* frame = m_testInterfaces->webView()->mainFrame();
+ string dataUtf8;
+ if (shouldDumpAsText) {
+ bool recursive = m_testInterfaces->testRunner()->shouldDumpChildFramesAsText();
+ dataUtf8 = shouldDumpAsPrinted ? dumpFramesAsPrintedText(frame, recursive) : dumpFramesAsText(frame, recursive);
+ } else {
+ bool recursive = m_testInterfaces->testRunner()->shouldDumpChildFrameScrollPositions();
+ WebFrame::RenderAsTextControls renderTextBehavior = WebFrame::RenderAsTextNormal;
+ if (shouldDumpAsPrinted)
+ renderTextBehavior |= WebFrame::RenderAsTextPrinting;
+ if (debugRenderTree)
+ renderTextBehavior |= WebFrame::RenderAsTextDebug;
+ dataUtf8 = frame->renderTreeAsText(renderTextBehavior).utf8();
+ dataUtf8 += dumpFrameScrollPosition(frame, recursive);
+ }
+
+ if (m_testInterfaces->testRunner()->shouldDumpBackForwardList())
+ dataUtf8 += dumpAllBackForwardLists(m_delegate);
+
+ return dataUtf8;
+}
+
void WebTestProxyBase::setLogConsoleOutput(bool enabled)
{
m_logConsoleOutput = enabled;
Modified: trunk/Tools/DumpRenderTree/chromium/TestShell.cpp (142642 => 142643)
--- trunk/Tools/DumpRenderTree/chromium/TestShell.cpp 2013-02-12 18:49:38 UTC (rev 142642)
+++ trunk/Tools/DumpRenderTree/chromium/TestShell.cpp 2013-02-12 18:50:43 UTC (rev 142643)
@@ -44,7 +44,6 @@
#include "WebIDBFactory.h"
#include "WebTestingSupport.h"
#include "WebRuntimeFeatures.h"
-#include "WebScriptController.h"
#include "WebSettings.h"
#include "WebTestProxy.h"
#include "WebTestRunner.h"
@@ -392,182 +391,14 @@
testFinished(webViewHost());
}
-static string dumpDocumentText(WebFrame* frame)
-{
- // We use the document element's text instead of the body text here because
- // not all documents have a body, such as XML documents.
- WebElement documentElement = frame->document().documentElement();
- if (documentElement.isNull())
- return string();
- return documentElement.innerText().utf8();
-}
-
-static string dumpFramesAsText(WebFrame* frame, bool recursive)
-{
- string result;
-
- // Add header for all but the main frame. Skip empty frames.
- if (frame->parent() && !frame->document().documentElement().isNull()) {
- result.append("\n--------\nFrame: '");
- result.append(frame->uniqueName().utf8().data());
- result.append("'\n--------\n");
- }
-
- result.append(dumpDocumentText(frame));
- result.append("\n");
-
- if (recursive) {
- for (WebFrame* child = frame->firstChild(); child; child = child->nextSibling())
- result.append(dumpFramesAsText(child, recursive));
- }
-
- return result;
-}
-
-static string dumpFramesAsPrintedText(WebFrame* frame, bool recursive)
-{
- string result;
-
- // Cannot do printed format for anything other than HTML
- if (!frame->document().isHTMLDocument())
- return string();
-
- // Add header for all but the main frame. Skip empty frames.
- if (frame->parent() && !frame->document().documentElement().isNull()) {
- result.append("\n--------\nFrame: '");
- result.append(frame->uniqueName().utf8().data());
- result.append("'\n--------\n");
- }
-
- result.append(frame->renderTreeAsText(WebFrame::RenderAsTextPrinting).utf8());
- result.append("\n");
-
- if (recursive) {
- for (WebFrame* child = frame->firstChild(); child; child = child->nextSibling())
- result.append(dumpFramesAsPrintedText(child, recursive));
- }
-
- return result;
-}
-
-static void dumpFrameScrollPosition(WebFrame* frame, bool recursive)
-{
- WebSize offset = frame->scrollOffset();
- if (offset.width > 0 || offset.height > 0) {
- if (frame->parent())
- printf("frame '%s' ", frame->uniqueName().utf8().data());
- printf("scrolled to %d,%d\n", offset.width, offset.height);
- }
-
- if (!recursive)
- return;
- for (WebFrame* child = frame->firstChild(); child; child = child->nextSibling())
- dumpFrameScrollPosition(child, recursive);
-}
-
-struct ToLower {
- char16 operator()(char16 c) { return tolower(c); }
-};
-
-// FIXME: Eliminate std::transform(), std::vector, and std::sort().
-
-// Returns True if item1 < item2.
-static bool HistoryItemCompareLess(const WebHistoryItem& item1, const WebHistoryItem& item2)
-{
- string16 target1 = item1.target();
- string16 target2 = item2.target();
- std::transform(target1.begin(), target1.end(), target1.begin(), ToLower());
- std::transform(target2.begin(), target2.end(), target2.begin(), ToLower());
- return target1 < target2;
-}
-
-static string normalizeLayoutTestURLInternal(const string& url)
-{
- string result = url;
- size_t pos;
- if (!url.find(fileUrlPattern) && ((pos = url.find(layoutTestsPattern)) != string::npos)) {
- // adjust file URLs to match upstream results.
- result.replace(0, pos + layoutTestsPatternSize, fileTestPrefix);
- } else if (!url.find(dataUrlPattern)) {
- // URL-escape data URLs to match results upstream.
- string path = url.substr(dataUrlPatternSize);
- result.replace(dataUrlPatternSize, url.length(), path);
- }
- return result;
-}
-
-static string dumpHistoryItem(const WebHistoryItem& item, int indent, bool isCurrent)
-{
- string result;
-
- if (isCurrent) {
- result.append("curr->");
- result.append(indent - 6, ' '); // 6 == "curr->".length()
- } else
- result.append(indent, ' ');
-
- string url = ""
- result.append(url);
- if (!item.target().isEmpty()) {
- result.append(" (in frame \"");
- result.append(item.target().utf8());
- result.append("\")");
- }
- if (item.isTargetItem())
- result.append(" **nav target**");
- result.append("\n");
-
- const WebVector<WebHistoryItem>& children = item.children();
- if (!children.isEmpty()) {
- // Must sort to eliminate arbitrary result ordering which defeats
- // reproducible testing.
- // FIXME: WebVector should probably just be a std::vector!!
- std::vector<WebHistoryItem> sortedChildren;
- for (size_t i = 0; i < children.size(); ++i)
- sortedChildren.push_back(children[i]);
- std::sort(sortedChildren.begin(), sortedChildren.end(), HistoryItemCompareLess);
- for (size_t i = 0; i < sortedChildren.size(); ++i)
- result += dumpHistoryItem(sortedChildren[i], indent + 4, false);
- }
-
- return result;
-}
-
-static void dumpBackForwardList(const TestNavigationController& navigationController, string& result)
-{
- result.append("\n============== Back Forward List ==============\n");
- for (int index = 0; index < navigationController.entryCount(); ++index) {
- int currentIndex = navigationController.lastCommittedEntryIndex();
- WebHistoryItem historyItem = navigationController.entryAtIndex(index)->contentState();
- if (historyItem.isNull()) {
- historyItem.initialize();
- historyItem.setURLString(navigationController.entryAtIndex(index)->URL().spec().utf16());
- }
- result.append(dumpHistoryItem(historyItem, 8, index == currentIndex));
- }
- result.append("===============================================\n");
-}
-
-string TestShell::dumpAllBackForwardLists()
-{
- string result;
- for (unsigned i = 0; i < m_windowList.size(); ++i)
- dumpBackForwardList(*m_windowList[i]->navigationController(), result);
- return result;
-}
-
void TestShell::dump()
{
- WebScriptController::flushConsoleMessages();
-
// Dump the requested representation.
WebFrame* frame = m_webView->mainFrame();
if (!frame)
return;
- bool shouldDumpAsText = m_testInterfaces->testRunner()->shouldDumpAsText();
bool shouldDumpAsAudio = m_testInterfaces->testRunner()->shouldDumpAsAudio();
bool shouldGeneratePixelResults = m_testInterfaces->testRunner()->shouldGeneratePixelResults();
- bool shouldDumpAsPrinted = m_testInterfaces->testRunner()->isPrinting();
bool dumpedAnything = false;
if (shouldDumpAsAudio) {
@@ -584,33 +415,9 @@
if (m_params.dumpTree) {
dumpedAnything = true;
m_printer.handleTextHeader();
- // Text output: the test page can request different types of output
- // which we handle here.
- if (!shouldDumpAsText) {
- // Plain text pages should be dumped as text
- string mimeType = frame->dataSource()->response().mimeType().utf8();
- if (mimeType == "text/plain") {
- shouldDumpAsText = true;
- shouldGeneratePixelResults = false;
- }
- }
- if (shouldDumpAsText) {
- bool recursive = m_testInterfaces->testRunner()->shouldDumpChildFramesAsText();
- string dataUtf8 = shouldDumpAsPrinted ? dumpFramesAsPrintedText(frame, recursive) : dumpFramesAsText(frame, recursive);
- if (fwrite(dataUtf8.c_str(), 1, dataUtf8.size(), stdout) != dataUtf8.size())
- FATAL("Short write to stdout, disk full?\n");
- } else {
- WebFrame::RenderAsTextControls renderTextBehavior = WebFrame::RenderAsTextNormal;
- if (shouldDumpAsPrinted)
- renderTextBehavior |= WebFrame::RenderAsTextPrinting;
- if (m_params.debugRenderTree)
- renderTextBehavior |= WebFrame::RenderAsTextDebug;
- printf("%s", frame->renderTreeAsText(renderTextBehavior).utf8().data());
- bool recursive = m_testInterfaces->testRunner()->shouldDumpChildFrameScrollPositions();
- dumpFrameScrollPosition(frame, recursive);
- }
- if (m_testInterfaces->testRunner()->shouldDumpBackForwardList())
- printf("%s", dumpAllBackForwardLists().c_str());
+ string dataUtf8 = m_webViewHost->proxy()->captureTree(m_params.debugRenderTree);
+ if (fwrite(dataUtf8.c_str(), 1, dataUtf8.size(), stdout) != dataUtf8.size())
+ FATAL("Short write to stdout, disk full?\n");
}
if (dumpedAnything && m_params.printSeparators)
m_printer.handleTextFooter();
@@ -810,3 +617,24 @@
{
return m_windowList.size();
}
+
+void TestShell::captureHistoryForWindow(size_t windowIndex, WebVector<WebHistoryItem>* history, size_t* currentEntryIndex)
+{
+ ASSERT(history);
+ ASSERT(currentEntryIndex);
+ if (windowIndex >= m_windowList.size())
+ return;
+ TestNavigationController& navigationController = *m_windowList[windowIndex]->navigationController();
+ size_t entryCount = navigationController.entryCount();
+ WebVector<WebHistoryItem> result(entryCount);
+ *currentEntryIndex = navigationController.lastCommittedEntryIndex();
+ for (size_t index = 0; index < entryCount; ++index) {
+ WebHistoryItem historyItem = navigationController.entryAtIndex(index)->contentState();
+ if (historyItem.isNull()) {
+ historyItem.initialize();
+ historyItem.setURLString(navigationController.entryAtIndex(index)->URL().spec().utf16());
+ }
+ result[index] = historyItem;
+ }
+ history->swap(result);
+}
Modified: trunk/Tools/DumpRenderTree/chromium/TestShell.h (142642 => 142643)
--- trunk/Tools/DumpRenderTree/chromium/TestShell.h 2013-02-12 18:49:38 UTC (rev 142642)
+++ trunk/Tools/DumpRenderTree/chromium/TestShell.h 2013-02-12 18:50:43 UTC (rev 142643)
@@ -165,6 +165,7 @@
void closeWindow(WebViewHost*);
void closeRemainingWindows();
int windowCount();
+ void captureHistoryForWindow(size_t windowIndex, WebKit::WebVector<WebKit::WebHistoryItem>*, size_t* currentEntryIndex);
static void resizeWindowForTest(WebViewHost*, const WebKit::WebURL&);
void showDevTools();
Modified: trunk/Tools/DumpRenderTree/chromium/WebViewHost.cpp (142642 => 142643)
--- trunk/Tools/DumpRenderTree/chromium/WebViewHost.cpp 2013-02-12 18:49:38 UTC (rev 142642)
+++ trunk/Tools/DumpRenderTree/chromium/WebViewHost.cpp 2013-02-12 18:50:43 UTC (rev 142643)
@@ -923,6 +923,11 @@
return m_shell->allowExternalPages();
}
+void WebViewHost::captureHistoryForWindow(size_t windowIndex, WebVector<WebHistoryItem>* history, size_t* currentEntryIndex)
+{
+ m_shell->captureHistoryForWindow(windowIndex, history, currentEntryIndex);
+}
+
// Public functions -----------------------------------------------------------
WebViewHost::WebViewHost(TestShell* shell)
Modified: trunk/Tools/DumpRenderTree/chromium/WebViewHost.h (142642 => 142643)
--- trunk/Tools/DumpRenderTree/chromium/WebViewHost.h 2013-02-12 18:49:38 UTC (rev 142642)
+++ trunk/Tools/DumpRenderTree/chromium/WebViewHost.h 2013-02-12 18:50:43 UTC (rev 142643)
@@ -170,6 +170,7 @@
virtual void reload() OVERRIDE;
virtual void loadURLForFrame(const WebKit::WebURL&, const std::string& frameName) OVERRIDE;
virtual bool allowExternalPages() OVERRIDE;
+ virtual void captureHistoryForWindow(size_t windowIndex, WebKit::WebVector<WebKit::WebHistoryItem>*, size_t* currentEntryIndex) OVERRIDE;
// NavigationHost
virtual bool navigate(const TestNavigationEntry&, bool reload);