void dump()
{
    invalidateAnyPreviousWaitToDumpWatchdog();

    COMPtr<IWebDataSource> dataSource;
    if (SUCCEEDED(frame->dataSource(&dataSource))) {
        COMPtr<IWebURLResponse> response;
        if (SUCCEEDED(dataSource->response(&response)) && response) {
            BSTR mimeType;
            if (SUCCEEDED(response->MIMEType(&mimeType)))
                ::gLayoutTestController->setDumpAsText(::gLayoutTestController->dumpAsText() | !_tcscmp(mimeType, TEXT("text/plain")));
            SysFreeString(mimeType);
        }
    }

    BSTR resultString = 0;

    if (dumpTree) {
        if (::gLayoutTestController->dumpAsText()) {
            ::InvalidateRect(webViewWindow, 0, TRUE);
            ::SendMessage(webViewWindow, WM_PAINT, 0, 0);
            wstring result = dumpFramesAsText(frame);
            resultString = SysAllocStringLen(result.data(), result.size());
        } else {
            bool isSVGW3CTest = (gLayoutTestController->testPathOrURL().find("svg\\W3C-SVG-1.1") != string::npos);
            unsigned width;
            unsigned height;
            if (isSVGW3CTest) {
                width = 480;
                height = 360;
            } else {
                width = LayoutTestController::maxViewWidth;
                height = LayoutTestController::maxViewHeight;
            }

            ::SetWindowPos(webViewWindow, 0, 0, 0, width, height, SWP_NOMOVE);
            ::InvalidateRect(webViewWindow, 0, TRUE);
            ::SendMessage(webViewWindow, WM_PAINT, 0, 0);

            COMPtr<IWebFramePrivate> framePrivate;
            if (FAILED(frame->QueryInterface(&framePrivate)))
                goto fail;
            framePrivate->renderTreeAsExternalRepresentation(&resultString);
        }
        
        if (!resultString)
            printf("ERROR: nil result from %s", ::gLayoutTestController->dumpAsText() ? "IDOMElement::innerText" : "IFrameViewPrivate::renderTreeAsExternalRepresentation");
        else {
            unsigned stringLength = SysStringLen(resultString);
            int bufferSize = ::WideCharToMultiByte(CP_UTF8, 0, resultString, stringLength, 0, 0, 0, 0);
            char* buffer = (char*)malloc(bufferSize + 1);
            ::WideCharToMultiByte(CP_UTF8, 0, resultString, stringLength, buffer, bufferSize + 1, 0, 0);
            fwrite(buffer, 1, bufferSize, stdout);
            free(buffer);
            if (!::gLayoutTestController->dumpAsText())
                dumpFrameScrollPosition(frame);
        }
        if (::gLayoutTestController->dumpBackForwardList())
            dumpBackForwardListForAllWindows();
    }

    if (printSeparators) {
        puts("#EOF");   // terminate the content block
        fputs("#EOF\n", stderr);
        fflush(stdout);
        fflush(stderr);
    }

    if (dumpPixels) {
        if (!gLayoutTestController->dumpAsText() && !gLayoutTestController->dumpDOMAsWebArchive() && !gLayoutTestController->dumpSourceAsWebArchive())
            dumpWebViewAsPixelsAndCompareWithExpected(gLayoutTestController->expectedPixelHash());
    }

    printf("#EOF\n");   // terminate the (possibly empty) pixels block
    fflush(stdout);

fail:
    SysFreeString(resultString);
    // This will exit from our message loop.
    PostQuitMessage(0);
    done = true;
}
Exemple #2
0
void dump()
{
    invalidateAnyPreviousWaitToDumpWatchdog();

    COMPtr<IWebDataSource> dataSource;
    if (SUCCEEDED(frame->dataSource(&dataSource))) {
        COMPtr<IWebURLResponse> response;
        if (SUCCEEDED(dataSource->response(&response)) && response) {
            BSTR mimeType;
            if (SUCCEEDED(response->MIMEType(&mimeType)) && !_tcscmp(mimeType, TEXT("text/plain"))) {
                ::gTestRunner->setDumpAsText(true);
                ::gTestRunner->setGeneratePixelResults(false);
            }
            SysFreeString(mimeType);
        }
    }

    BSTR resultString = 0;

    if (dumpTree) {
        ::InvalidateRect(webViewWindow, 0, TRUE);
        ::SendMessage(webViewWindow, WM_PAINT, 0, 0);

        if (::gTestRunner->dumpAsText()) {
            wstring result = dumpFramesAsText(frame);
            resultString = SysAllocStringLen(result.data(), result.size());
        } else {
            COMPtr<IWebFramePrivate> framePrivate;
            if (FAILED(frame->QueryInterface(&framePrivate)))
                goto fail;
            framePrivate->renderTreeAsExternalRepresentation(gTestRunner->isPrinting(), &resultString);
        }
        
        if (!resultString)
            printf("ERROR: nil result from %s", ::gTestRunner->dumpAsText() ? "IDOMElement::innerText" : "IFrameViewPrivate::renderTreeAsExternalRepresentation");
        else {
            unsigned stringLength = SysStringLen(resultString);
            int bufferSize = ::WideCharToMultiByte(CP_UTF8, 0, resultString, stringLength, 0, 0, 0, 0);
            char* buffer = (char*)malloc(bufferSize + 1);
            ::WideCharToMultiByte(CP_UTF8, 0, resultString, stringLength, buffer, bufferSize + 1, 0, 0);
            fwrite(buffer, 1, bufferSize, stdout);
            free(buffer);
            if (!::gTestRunner->dumpAsText())
                dumpFrameScrollPosition(frame);
        }
        if (::gTestRunner->dumpBackForwardList())
            dumpBackForwardListForAllWindows();
    }

    if (printSeparators) {
        puts("#EOF");   // terminate the content block
        fputs("#EOF\n", stderr);
        fflush(stdout);
        fflush(stderr);
    }

    if (dumpPixelsForCurrentTest
     && gTestRunner->generatePixelResults()
     && !gTestRunner->dumpDOMAsWebArchive()
     && !gTestRunner->dumpSourceAsWebArchive())
        dumpWebViewAsPixelsAndCompareWithExpected(gTestRunner->expectedPixelHash());

    printf("#EOF\n");   // terminate the (possibly empty) pixels block
    fflush(stdout);

fail:
    SysFreeString(resultString);
    // This will exit from our message loop.
    PostQuitMessage(0);
    done = true;
}