Changeset 62032 in webkit


Ignore:
Timestamp:
Jun 28, 2010 1:22:22 PM (14 years ago)
Author:
weinig@apple.com
Message:

Patch for https://bugs.webkit.org/show_bug.cgi?id=41299
Build up WebKitTestRunner output in the InjectedBundle

Reviewed by Anders Carlsson.

Simplify WebKitTestRunner by building up the output in the InjectedBundle
and sending it over postMessage when done, instead of using the async
WKPageRenderTreeExternalRepresentation.

  • WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:

(WTR::InjectedBundle::done):
(WTR::InjectedBundle::didRecieveMessage):

  • WebKitTestRunner/InjectedBundle/InjectedBundle.h:

(WTR::InjectedBundle::os):

  • WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp:

(WTR::WKStringToUTF8):
(WTR::InjectedBundlePage::didFinishLoadForFrame):
(WTR::InjectedBundlePage::didFailLoadWithErrorForFrame):

  • WebKitTestRunner/TestInvocation.cpp:

(WTR::WKStringToUTF8):
(WTR::TestInvocation::TestInvocation):
(WTR::TestInvocation::invoke):
(WTR::TestInvocation::initializeMainWebView):
(WTR::TestInvocation::_didRecieveMessageFromInjectedBundle):
(WTR::TestInvocation::didRecieveMessageFromInjectedBundle):

  • WebKitTestRunner/TestInvocation.h:
Location:
trunk/WebKitTools
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r62024 r62032  
     12010-06-28  Sam Weinig  <sam@webkit.org>
     2
     3        Reviewed by Anders Carlsson.
     4
     5        Patch for https://bugs.webkit.org/show_bug.cgi?id=41299
     6        Build up WebKitTestRunner output in the InjectedBundle
     7
     8        Simplify WebKitTestRunner by building up the output in the InjectedBundle
     9        and sending it over postMessage when done, instead of using the async
     10        WKPageRenderTreeExternalRepresentation.
     11
     12        * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
     13        (WTR::InjectedBundle::done):
     14        (WTR::InjectedBundle::didRecieveMessage):
     15        * WebKitTestRunner/InjectedBundle/InjectedBundle.h:
     16        (WTR::InjectedBundle::os):
     17        * WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp:
     18        (WTR::WKStringToUTF8):
     19        (WTR::InjectedBundlePage::didFinishLoadForFrame):
     20        (WTR::InjectedBundlePage::didFailLoadWithErrorForFrame):
     21        * WebKitTestRunner/TestInvocation.cpp:
     22        (WTR::WKStringToUTF8):
     23        (WTR::TestInvocation::TestInvocation):
     24        (WTR::TestInvocation::invoke):
     25        (WTR::TestInvocation::initializeMainWebView):
     26        (WTR::TestInvocation::_didRecieveMessageFromInjectedBundle):
     27        (WTR::TestInvocation::didRecieveMessageFromInjectedBundle):
     28        * WebKitTestRunner/TestInvocation.h:
     29
    1302010-06-28  Robert Hogan  <robert@webkit.org>
    231
  • trunk/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp

    r61906 r62032  
    2929#include <WebKit2/WKBundle.h>
    3030#include <WebKit2/WKBundlePage.h>
     31#include <WebKit2/WKRetainPtr.h>
     32#include <WebKit2/WKStringCF.h>
     33#include <WebKit2/WebKit2.h>
     34#include <wtf/RetainPtr.h>
    3135
    3236namespace WTR {
     
    7377}
    7478
     79void InjectedBundle::done()
     80{
     81    std::string output = m_outputStream.str();
     82    RetainPtr<CFStringRef> outputCFString(AdoptCF, CFStringCreateWithCString(0, output.c_str(), kCFStringEncodingUTF8));
     83    WKRetainPtr<WKStringRef> doneMessage(AdoptWK, WKStringCreateWithCFString(outputCFString.get()));
     84    WKBundlePostMessage(m_bundle, doneMessage.get());
     85}
     86
    7587void InjectedBundle::didCreatePage(WKBundlePageRef page)
    7688{
     
    8597void InjectedBundle::didRecieveMessage(WKStringRef message)
    8698{
     99    CFStringRef cfMessage = WKStringCopyCFString(0, message);
     100    if (CFEqual(cfMessage, CFSTR("InitialPageCreated"))) {
     101        if (m_pages.size() == 1) {
     102            WKRetainPtr<WKStringRef> ackMessage(AdoptWK, WKStringCreateWithCFString(CFSTR("InitialPageCreatedAck")));
     103            WKBundlePostMessage(m_bundle, ackMessage.get());
     104            return;
     105        }
     106    }
     107
     108    WKRetainPtr<WKStringRef> errorMessage(AdoptWK, WKStringCreateWithCFString(CFSTR("Error")));
     109    WKBundlePostMessage(m_bundle, errorMessage.get());
    87110}
    88111
  • trunk/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.h

    r61906 r62032  
    3333#include <wtf/RefPtr.h>
    3434
     35#include <sstream>
     36
    3537namespace WTR {
    3638
     
    4446    void initialize(WKBundleRef);
    4547
     48    void done();
     49
    4650    LayoutTestController* layoutTestController() { return m_layoutTestController.get(); }
     51
     52    std::ostringstream& os() { return m_outputStream; }
    4753
    4854private:
     
    6268
    6369    RefPtr<LayoutTestController> m_layoutTestController;
     70
     71    std::ostringstream m_outputStream;
    6472};
    6573
  • trunk/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp

    r61906 r62032  
    2727
    2828#include "InjectedBundle.h"
     29#include <WebKit2/WKBundleFrame.h>
     30#include <WebKit2/WKBundlePagePrivate.h>
     31#include <WebKit2/WKRetainPtr.h>
     32#include <WebKit2/WKString.h>
     33#include <WebKit2/WKStringCF.h>
     34#include <wtf/RetainPtr.h>
     35#include <wtf/Vector.h>
    2936
    3037namespace WTR {
     
    108115}
    109116
     117static std::auto_ptr<Vector<char> > WKStringToUTF8(WKStringRef wkStringRef)
     118{
     119    RetainPtr<CFStringRef> cfString(AdoptCF, WKStringCopyCFString(0, wkStringRef));
     120    CFIndex bufferLength = CFStringGetMaximumSizeForEncoding(CFStringGetLength(cfString.get()), kCFStringEncodingUTF8) + 1;
     121    std::auto_ptr<Vector<char> > buffer(new Vector<char>(bufferLength));
     122    if (!CFStringGetCString(cfString.get(), buffer->data(), bufferLength, kCFStringEncodingUTF8)) {
     123        buffer->shrink(1);
     124        (*buffer)[0] = 0;
     125    } else
     126        buffer->shrink(strlen(buffer->data()) + 1);
     127    return buffer;
     128}
     129
    110130void InjectedBundlePage::didFinishLoadForFrame(WKBundleFrameRef frame)
    111131{
     132    if (!WKBundleFrameIsMainFrame(frame))
     133        return;
     134
     135    WKRetainPtr<WKStringRef> externalRepresentation(AdoptWK, WKBundlePageCopyRenderTreeExternalRepresentation(m_page));
     136    std::auto_ptr<Vector<char> > utf8String = WKStringToUTF8(externalRepresentation.get());
     137
     138    InjectedBundle::shared().os() << utf8String->data();
     139    InjectedBundle::shared().done();
    112140}
    113141
    114142void InjectedBundlePage::didFailLoadWithErrorForFrame(WKBundleFrameRef frame)
    115143{
     144    if (!WKBundleFrameIsMainFrame(frame))
     145        return;
     146
     147    InjectedBundle::shared().done();
    116148}
    117149
  • trunk/WebKitTools/WebKitTestRunner/TestInvocation.cpp

    r61902 r62032  
    2929#include "TestController.h"
    3030#include <WebKit2/WKContextPrivate.h>
    31 #include <WebKit2/WKPagePrivate.h>
    3231#include <WebKit2/WKRetainPtr.h>
    3332#include <WebKit2/WKStringCF.h>
    3433#include <WebKit2/WKURLCF.h>
     34#include <wtf/Vector.h>
    3535#include <wtf/RetainPtr.h>
    3636
     
    5050}
    5151
     52static std::auto_ptr<Vector<char> > WKStringToUTF8(WKStringRef wkStringRef)
     53{
     54    RetainPtr<CFStringRef> cfString(AdoptCF, WKStringCopyCFString(0, wkStringRef));
     55    CFIndex bufferLength = CFStringGetMaximumSizeForEncoding(CFStringGetLength(cfString.get()), kCFStringEncodingUTF8) + 1;
     56    std::auto_ptr<Vector<char> > buffer(new Vector<char>(bufferLength));
     57    if (!CFStringGetCString(cfString.get(), buffer->data(), bufferLength, kCFStringEncodingUTF8)) {
     58        buffer->shrink(1);
     59        (*buffer)[0] = 0;
     60    } else
     61        buffer->shrink(strlen(buffer->data()) + 1);
     62    return buffer;
     63}
     64
    5265TestInvocation::TestInvocation(const char* pathOrURL)
    5366    : m_url(AdoptWK, createWKURL(pathOrURL))
    5467    , m_mainWebView(0)
    55     , m_loadDone(false)
    56     , m_renderTreeFetchDone(false)
    57     , m_failed(false)
     68    , m_gotInitialResponse(false)
     69    , m_gotFinalMessage(false)
    5870{
    5971}
     
    6981    initializeMainWebView();
    7082
     83    WKRetainPtr<WKStringRef> message(AdoptWK, WKStringCreateWithCFString(CFSTR("InitialPageCreated")));
     84    WKContextPostMessageToInjectedBundle(m_context.get(), message.get());
     85
     86    runUntil(m_gotInitialResponse);
     87 
    7188    WKPageLoadURL(m_mainWebView->page(), m_url.get());
    72     runUntil(m_loadDone);
    7389
    74     if (m_failed)
    75         return;
    76 
    77     WKPageRenderTreeExternalRepresentation(m_mainWebView->page(), this, renderTreeExternalRepresentationFunction, renderTreeExternalRepresentationDisposeFunction);
    78     runUntil(m_renderTreeFetchDone);
     90    runUntil(m_gotFinalMessage);
    7991}
    8092
     
    94106void TestInvocation::initializeMainWebView()
    95107{
    96     WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreateWithInjectedBundlePath(TestController::shared().injectedBundlePath()));
    97     WKRetainPtr<WKPageNamespaceRef> pageNamespace(AdoptWK, WKPageNamespaceCreate(context.get()));
    98     m_mainWebView = new PlatformWebView(pageNamespace.get());
     108    m_context.adopt(WKContextCreateWithInjectedBundlePath(TestController::shared().injectedBundlePath()));
    99109
    100     WKPageLoaderClient loaderClient = {
     110    WKContextInjectedBundleClient injectedBundlePathClient = {
    101111        0,
    102112        this,
    103         didStartProvisionalLoadForFrame,
    104         didReceiveServerRedirectForProvisionalLoadForFrame,
    105         didFailProvisionalLoadWithErrorForFrame,
    106         didCommitLoadForFrame,
    107         didFinishLoadForFrame,
    108         didFailLoadForFrame,
    109         0,
    110         0,
    111         0,
    112         0,
    113         0,
    114         0,
    115         0,
    116         0
     113        _didRecieveMessageFromInjectedBundle
    117114    };
    118     WKPageSetPageLoaderClient(m_mainWebView->page(), &loaderClient);
     115    WKContextSetInjectedBundleClient(m_context.get(), &injectedBundlePathClient);
     116
     117    m_pageNamespace.adopt(WKPageNamespaceCreate(m_context.get()));
     118    m_mainWebView = new PlatformWebView(m_pageNamespace.get());
    119119}
    120120
    121 void TestInvocation::didStartProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, const void* clientInfo)
     121// WKContextInjectedBundleClient functions
     122
     123void TestInvocation::_didRecieveMessageFromInjectedBundle(WKContextRef context, WKStringRef message, const void *clientInfo)
    122124{
     125    static_cast<TestInvocation*>(const_cast<void*>(clientInfo))->didRecieveMessageFromInjectedBundle(message);
    123126}
    124127
    125 void TestInvocation::didReceiveServerRedirectForProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, const void* clientInfo)
     128void TestInvocation::didRecieveMessageFromInjectedBundle(WKStringRef message)
    126129{
    127 }
     130    RetainPtr<CFStringRef> cfMessage(AdoptCF, WKStringCopyCFString(0, message));
     131    if (CFEqual(cfMessage.get(), CFSTR("InitialPageCreatedAck"))) {
     132        m_gotInitialResponse = true;
     133        return;
     134    }
    128135
    129 void TestInvocation::didFailProvisionalLoadWithErrorForFrame(WKPageRef page, WKFrameRef frame, const void* clientInfo)
    130 {
    131     TestInvocation* self = reinterpret_cast<TestInvocation*>(const_cast<void*>(clientInfo));
    132     self->m_loadDone = true;
    133     self->m_failed = true;
    134 }
     136    std::auto_ptr<Vector<char> > utf8Message = WKStringToUTF8(message);
    135137
    136 void TestInvocation::didCommitLoadForFrame(WKPageRef page, WKFrameRef frame, const void* clientInfo)
    137 {
    138 }
    139 
    140 void TestInvocation::didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, const void* clientInfo)
    141 {
    142     TestInvocation* self = reinterpret_cast<TestInvocation*>(const_cast<void*>(clientInfo));
    143     self->m_loadDone = true;
    144 }
    145 
    146 void TestInvocation::didFailLoadForFrame(WKPageRef page, WKFrameRef frame, const void* clientInfo)
    147 {
    148     TestInvocation* self = reinterpret_cast<TestInvocation*>(const_cast<void*>(clientInfo));
    149 
    150     self->m_loadDone = true;
    151     self->m_failed = true;
    152 }
    153 
    154 void TestInvocation::renderTreeExternalRepresentationFunction(WKStringRef wkResult, void* context)
    155 {
    156     TestInvocation* self = reinterpret_cast<TestInvocation*>(context);
    157 
    158     RetainPtr<CFStringRef> result(AdoptCF, WKStringCopyCFString(0, wkResult));
    159     CFIndex bufferLength = CFStringGetMaximumSizeForEncoding(CFStringGetLength(result.get()), kCFStringEncodingUTF8) + 1;
    160     char* buffer = (char*)malloc(bufferLength);
    161     CFStringGetCString(result.get(), buffer, bufferLength, kCFStringEncodingUTF8);
    162 
    163     self->dump(buffer);
    164     free(buffer);
    165 
    166     self->m_renderTreeFetchDone = true;
    167 }
    168 
    169 void TestInvocation::renderTreeExternalRepresentationDisposeFunction(void* context)
    170 {
    171     TestInvocation* self = reinterpret_cast<TestInvocation*>(context);
    172 
    173     self->m_renderTreeFetchDone = true;
    174     self->m_failed = true;
     138    dump(utf8Message->data());
     139    m_gotFinalMessage = true;
    175140}
    176141
  • trunk/WebKitTools/WebKitTestRunner/TestInvocation.h

    r61902 r62032  
    4848    static void runUntil(bool& done);
    4949
    50     // PageLoaderClient
    51     static void didStartProvisionalLoadForFrame(WKPageRef page, WKFrameRef, const void*);
    52     static void didReceiveServerRedirectForProvisionalLoadForFrame(WKPageRef, WKFrameRef, const void*);
    53     static void didFailProvisionalLoadWithErrorForFrame(WKPageRef, WKFrameRef, const void*);
    54     static void didCommitLoadForFrame(WKPageRef, WKFrameRef, const void*);
    55     static void didFinishLoadForFrame(WKPageRef, WKFrameRef, const void*);
    56     static void didFailLoadForFrame(WKPageRef, WKFrameRef, const void*);
    57 
    58     // RenderTreeExternalRepresentation callbacks
    59     static void renderTreeExternalRepresentationFunction(WKStringRef, void*);
    60     static void renderTreeExternalRepresentationDisposeFunction(void*);
     50    // WKContextInjectedBundleClient
     51    static void _didRecieveMessageFromInjectedBundle(WKContextRef context, WKStringRef message, const void*);
     52    void didRecieveMessageFromInjectedBundle(WKStringRef message);
    6153
    6254    WKStringRef injectedBundlePath();
    6355
    6456    WKRetainPtr<WKURLRef> m_url;
     57    WKRetainPtr<WKContextRef> m_context;
     58    WKRetainPtr<WKPageNamespaceRef> m_pageNamespace;
    6559    PlatformWebView* m_mainWebView;
    6660
    6761    // Invocation state
    68     bool m_loadDone;
    69     bool m_renderTreeFetchDone;
    70     bool m_failed;
     62    bool m_gotInitialResponse;
     63    bool m_gotFinalMessage;
    7164};
    7265
Note: See TracChangeset for help on using the changeset viewer.