📄 dumprendertree.cpp
字号:
/* * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple 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: * * 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. * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "DumpRenderTree.h"#include "EditingDelegate.h"#include "FrameLoadDelegate.h"#include "LayoutTestController.h"#include "PixelDumpSupport.h"#include "PolicyDelegate.h"#include "ResourceLoadDelegate.h"#include "UIDelegate.h"#include "WorkQueueItem.h"#include "WorkQueue.h"#include <fcntl.h>#include <io.h>#include <math.h>#include <pthread.h>#include <shlwapi.h>#include <stdio.h>#include <string.h>#include <tchar.h>#include <wtf/RetainPtr.h>#include <wtf/Vector.h>#include <windows.h>#include <CFNetwork/CFURLCachePriv.h>#include <CoreFoundation/CoreFoundation.h>#include <JavaScriptCore/JavaScriptCore.h>#include <WebKit/ForEachCoClass.h>#include <WebKit/WebKit.h>using namespace std;#ifndef NDEBUGconst LPWSTR TestPluginDir = L"TestNetscapePlugin_Debug";#elseconst LPWSTR TestPluginDir = L"TestNetscapePlugin";#endifstatic LPCWSTR fontsEnvironmentVariable = L"WEBKIT_TESTFONTS";#define USE_MAC_FONTSconst LPCWSTR kDumpRenderTreeClassName = L"DumpRenderTreeWindow";static bool dumpTree = true;static bool dumpPixels;static bool dumpAllPixels;static bool printSeparators;static bool leakChecking = false;static bool threaded = false;static bool forceComplexText = false;static RetainPtr<CFStringRef> persistentUserStyleSheetLocation;volatile bool done;// This is the topmost frame that is loading, during a given load, or nil when no load is // in progress. Usually this is the same as the main frame, but not always. In the case// where a frameset is loaded, and then new content is loaded into one of the child frames,// that child frame is the "topmost frame that is loading".IWebFrame* topLoadingFrame; // !nil iff a load is in progressstatic COMPtr<IWebHistoryItem> prevTestBFItem; // current b/f item at the end of the previous testPolicyDelegate* policyDelegate; COMPtr<FrameLoadDelegate> sharedFrameLoadDelegate;COMPtr<UIDelegate> sharedUIDelegate;COMPtr<EditingDelegate> sharedEditingDelegate;COMPtr<ResourceLoadDelegate> sharedResourceLoadDelegate;IWebFrame* frame;HWND webViewWindow;LayoutTestController* gLayoutTestController = 0;CFRunLoopTimerRef waitToDumpWatchdog = 0; const unsigned maxViewWidth = 800;const unsigned maxViewHeight = 600;void setPersistentUserStyleSheetLocation(CFStringRef url){ persistentUserStyleSheetLocation = url;}wstring urlSuitableForTestResult(const wstring& url){ if (!url.c_str() || url.find(L"file://") == wstring::npos) return url; return PathFindFileNameW(url.c_str());}static LRESULT CALLBACK DumpRenderTreeWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){ switch (msg) { case WM_DESTROY: for (unsigned i = openWindows().size() - 1; i >= 0; --i) { if (openWindows()[i] == hWnd) { openWindows().remove(i); windowToWebViewMap().remove(hWnd); break; } } return 0; break; default: return DefWindowProc(hWnd, msg, wParam, lParam); }}static const wstring& exePath(){ static wstring path; static bool initialized; if (initialized) return path; initialized = true; TCHAR buffer[MAX_PATH]; GetModuleFileName(GetModuleHandle(0), buffer, ARRAYSIZE(buffer)); path = buffer; int lastSlash = path.rfind('\\'); if (lastSlash != -1 && lastSlash + 1 < path.length()) path = path.substr(0, lastSlash + 1); return path;}static const wstring& fontsPath(){ static wstring path; static bool initialized; if (initialized) return path; initialized = true; DWORD size = GetEnvironmentVariable(fontsEnvironmentVariable, 0, 0); Vector<TCHAR> buffer(size); if (GetEnvironmentVariable(fontsEnvironmentVariable, buffer.data(), buffer.size())) { path = buffer.data(); if (path[path.length() - 1] != '\\') path.append(L"\\"); return path; } path = exePath() + TEXT("DumpRenderTree.resources\\"); return path;}#ifdef DEBUG_WEBKIT_HAS_SUFFIX#define WEBKITDLL TEXT("WebKit_debug.dll")#else#define WEBKITDLL TEXT("WebKit.dll")#endifstatic void initialize(){ if (HMODULE webKitModule = LoadLibrary(WEBKITDLL)) if (FARPROC dllRegisterServer = GetProcAddress(webKitModule, "DllRegisterServer")) dllRegisterServer(); // Init COM OleInitialize(0); static LPCTSTR fontsToInstall[] = { TEXT("AHEM____.ttf"), TEXT("Apple Chancery.ttf"), TEXT("Courier Bold.ttf"), TEXT("Courier.ttf"), TEXT("Helvetica Bold Oblique.ttf"), TEXT("Helvetica Bold.ttf"), TEXT("Helvetica Oblique.ttf"), TEXT("Helvetica.ttf"), TEXT("Helvetica Neue Bold Italic.ttf"), TEXT("Helvetica Neue Bold.ttf"), TEXT("Helvetica Neue Condensed Black.ttf"), TEXT("Helvetica Neue Condensed Bold.ttf"), TEXT("Helvetica Neue Italic.ttf"), TEXT("Helvetica Neue Light Italic.ttf"), TEXT("Helvetica Neue Light.ttf"), TEXT("Helvetica Neue UltraLight Italic.ttf"), TEXT("Helvetica Neue UltraLight.ttf"), TEXT("Helvetica Neue.ttf"), TEXT("Lucida Grande.ttf"), TEXT("Lucida Grande Bold.ttf"), TEXT("Monaco.ttf"), TEXT("Papyrus.ttf"), TEXT("Times Bold Italic.ttf"), TEXT("Times Bold.ttf"), TEXT("Times Italic.ttf"), TEXT("Times Roman.ttf"), TEXT("WebKit Layout Tests.ttf"), TEXT("WebKitWeightWatcher100.ttf"), TEXT("WebKitWeightWatcher200.ttf"), TEXT("WebKitWeightWatcher300.ttf"), TEXT("WebKitWeightWatcher400.ttf"), TEXT("WebKitWeightWatcher500.ttf"), TEXT("WebKitWeightWatcher600.ttf"), TEXT("WebKitWeightWatcher700.ttf"), TEXT("WebKitWeightWatcher800.ttf"), TEXT("WebKitWeightWatcher900.ttf") }; wstring resourcesPath = fontsPath(); COMPtr<IWebTextRenderer> textRenderer; if (SUCCEEDED(CoCreateInstance(CLSID_WebTextRenderer, 0, CLSCTX_ALL, IID_IWebTextRenderer, (void**)&textRenderer))) for (int i = 0; i < ARRAYSIZE(fontsToInstall); ++i) textRenderer->registerPrivateFont(wstring(resourcesPath + fontsToInstall[i]).c_str()); // Register a host window WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = DumpRenderTreeWndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = GetModuleHandle(0); wcex.hIcon = 0; wcex.hCursor = LoadCursor(0, IDC_ARROW); wcex.hbrBackground = 0; wcex.lpszMenuName = 0; wcex.lpszClassName = kDumpRenderTreeClassName; wcex.hIconSm = 0; RegisterClassEx(&wcex);}void displayWebView(){ ::InvalidateRect(webViewWindow, 0, TRUE); ::UpdateWindow(webViewWindow);}void dumpFrameScrollPosition(IWebFrame* frame){ if (!frame) return; COMPtr<IWebFramePrivate> framePrivate; if (FAILED(frame->QueryInterface(&framePrivate))) return; SIZE scrollPosition; if (FAILED(framePrivate->scrollOffset(&scrollPosition))) return; if (abs(scrollPosition.cx) > 0.00000001 || abs(scrollPosition.cy) > 0.00000001) { COMPtr<IWebFrame> parent; if (FAILED(frame->parentFrame(&parent))) return; if (parent) { BSTR name; if (FAILED(frame->name(&name))) return; printf("frame '%S' ", name ? name : L""); SysFreeString(name); } printf("scrolled to %.f,%.f\n", (double)scrollPosition.cx, (double)scrollPosition.cy); } if (::gLayoutTestController->dumpChildFrameScrollPositions()) { COMPtr<IEnumVARIANT> enumKids; if (FAILED(frame->childFrames(&enumKids))) return; VARIANT var; VariantInit(&var); while (enumKids->Next(1, &var, 0) == S_OK) { ASSERT(V_VT(&var) == VT_UNKNOWN); COMPtr<IWebFrame> framePtr; V_UNKNOWN(&var)->QueryInterface(IID_IWebFrame, (void**)&framePtr); dumpFrameScrollPosition(framePtr.get()); VariantClear(&var); } }}static wstring dumpFramesAsText(IWebFrame* frame){ if (!frame) return L""; COMPtr<IDOMDocument> document; if (FAILED(frame->DOMDocument(&document))) return L""; COMPtr<IDOMElement> documentElement; if (FAILED(document->documentElement(&documentElement))) return L""; wstring result; // Add header for all but the main frame. COMPtr<IWebFrame> parent; if (FAILED(frame->parentFrame(&parent))) return L""; if (parent) { BSTR name = L""; if (FAILED(frame->name(&name))) return L""; result.append(L"\n--------\nFrame: '"); result.append(name ? name : L"", SysStringLen(name)); result.append(L"'\n--------\n"); SysFreeString(name); } BSTR innerText = 0; COMPtr<IDOMElementPrivate> docPrivate; if (SUCCEEDED(documentElement->QueryInterface(&docPrivate))) docPrivate->innerText(&innerText); result.append(innerText ? innerText : L"", SysStringLen(innerText)); result.append(L"\n"); SysFreeString(innerText); if (::gLayoutTestController->dumpChildFramesAsText()) { COMPtr<IEnumVARIANT> enumKids; if (FAILED(frame->childFrames(&enumKids))) return L""; VARIANT var; VariantInit(&var); while (enumKids->Next(1, &var, 0) == S_OK) { ASSERT(V_VT(&var) == VT_UNKNOWN); COMPtr<IWebFrame> framePtr; V_UNKNOWN(&var)->QueryInterface(IID_IWebFrame, (void**)&framePtr); result.append(dumpFramesAsText(framePtr.get())); VariantClear(&var); } } return result;}static int compareHistoryItems(const void* item1, const void* item2){ COMPtr<IWebHistoryItemPrivate> itemA; if (FAILED((*(COMPtr<IUnknown>*)item1)->QueryInterface(&itemA))) return 0; COMPtr<IWebHistoryItemPrivate> itemB; if (FAILED((*(COMPtr<IUnknown>*)item2)->QueryInterface(&itemB))) return 0; BSTR targetA; if (FAILED(itemA->target(&targetA))) return 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -