Changeset 62032 in webkit
- Timestamp:
- Jun 28, 2010 1:22:22 PM (14 years ago)
- Location:
- trunk/WebKitTools
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebKitTools/ChangeLog
r62024 r62032 1 2010-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 1 30 2010-06-28 Robert Hogan <robert@webkit.org> 2 31 -
trunk/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp
r61906 r62032 29 29 #include <WebKit2/WKBundle.h> 30 30 #include <WebKit2/WKBundlePage.h> 31 #include <WebKit2/WKRetainPtr.h> 32 #include <WebKit2/WKStringCF.h> 33 #include <WebKit2/WebKit2.h> 34 #include <wtf/RetainPtr.h> 31 35 32 36 namespace WTR { … … 73 77 } 74 78 79 void 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 75 87 void InjectedBundle::didCreatePage(WKBundlePageRef page) 76 88 { … … 85 97 void InjectedBundle::didRecieveMessage(WKStringRef message) 86 98 { 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()); 87 110 } 88 111 -
trunk/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.h
r61906 r62032 33 33 #include <wtf/RefPtr.h> 34 34 35 #include <sstream> 36 35 37 namespace WTR { 36 38 … … 44 46 void initialize(WKBundleRef); 45 47 48 void done(); 49 46 50 LayoutTestController* layoutTestController() { return m_layoutTestController.get(); } 51 52 std::ostringstream& os() { return m_outputStream; } 47 53 48 54 private: … … 62 68 63 69 RefPtr<LayoutTestController> m_layoutTestController; 70 71 std::ostringstream m_outputStream; 64 72 }; 65 73 -
trunk/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp
r61906 r62032 27 27 28 28 #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> 29 36 30 37 namespace WTR { … … 108 115 } 109 116 117 static 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 110 130 void InjectedBundlePage::didFinishLoadForFrame(WKBundleFrameRef frame) 111 131 { 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(); 112 140 } 113 141 114 142 void InjectedBundlePage::didFailLoadWithErrorForFrame(WKBundleFrameRef frame) 115 143 { 144 if (!WKBundleFrameIsMainFrame(frame)) 145 return; 146 147 InjectedBundle::shared().done(); 116 148 } 117 149 -
trunk/WebKitTools/WebKitTestRunner/TestInvocation.cpp
r61902 r62032 29 29 #include "TestController.h" 30 30 #include <WebKit2/WKContextPrivate.h> 31 #include <WebKit2/WKPagePrivate.h>32 31 #include <WebKit2/WKRetainPtr.h> 33 32 #include <WebKit2/WKStringCF.h> 34 33 #include <WebKit2/WKURLCF.h> 34 #include <wtf/Vector.h> 35 35 #include <wtf/RetainPtr.h> 36 36 … … 50 50 } 51 51 52 static 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 52 65 TestInvocation::TestInvocation(const char* pathOrURL) 53 66 : m_url(AdoptWK, createWKURL(pathOrURL)) 54 67 , m_mainWebView(0) 55 , m_loadDone(false) 56 , m_renderTreeFetchDone(false) 57 , m_failed(false) 68 , m_gotInitialResponse(false) 69 , m_gotFinalMessage(false) 58 70 { 59 71 } … … 69 81 initializeMainWebView(); 70 82 83 WKRetainPtr<WKStringRef> message(AdoptWK, WKStringCreateWithCFString(CFSTR("InitialPageCreated"))); 84 WKContextPostMessageToInjectedBundle(m_context.get(), message.get()); 85 86 runUntil(m_gotInitialResponse); 87 71 88 WKPageLoadURL(m_mainWebView->page(), m_url.get()); 72 runUntil(m_loadDone);73 89 74 if (m_failed) 75 return; 76 77 WKPageRenderTreeExternalRepresentation(m_mainWebView->page(), this, renderTreeExternalRepresentationFunction, renderTreeExternalRepresentationDisposeFunction); 78 runUntil(m_renderTreeFetchDone); 90 runUntil(m_gotFinalMessage); 79 91 } 80 92 … … 94 106 void TestInvocation::initializeMainWebView() 95 107 { 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())); 99 109 100 WK PageLoaderClient loaderClient = {110 WKContextInjectedBundleClient injectedBundlePathClient = { 101 111 0, 102 112 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 117 114 }; 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()); 119 119 } 120 120 121 void TestInvocation::didStartProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, const void* clientInfo) 121 // WKContextInjectedBundleClient functions 122 123 void TestInvocation::_didRecieveMessageFromInjectedBundle(WKContextRef context, WKStringRef message, const void *clientInfo) 122 124 { 125 static_cast<TestInvocation*>(const_cast<void*>(clientInfo))->didRecieveMessageFromInjectedBundle(message); 123 126 } 124 127 125 void TestInvocation::didRec eiveServerRedirectForProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, const void* clientInfo)128 void TestInvocation::didRecieveMessageFromInjectedBundle(WKStringRef message) 126 129 { 127 } 130 RetainPtr<CFStringRef> cfMessage(AdoptCF, WKStringCopyCFString(0, message)); 131 if (CFEqual(cfMessage.get(), CFSTR("InitialPageCreatedAck"))) { 132 m_gotInitialResponse = true; 133 return; 134 } 128 135 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); 135 137 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; 175 140 } 176 141 -
trunk/WebKitTools/WebKitTestRunner/TestInvocation.h
r61902 r62032 48 48 static void runUntil(bool& done); 49 49 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); 61 53 62 54 WKStringRef injectedBundlePath(); 63 55 64 56 WKRetainPtr<WKURLRef> m_url; 57 WKRetainPtr<WKContextRef> m_context; 58 WKRetainPtr<WKPageNamespaceRef> m_pageNamespace; 65 59 PlatformWebView* m_mainWebView; 66 60 67 61 // Invocation state 68 bool m_loadDone; 69 bool m_renderTreeFetchDone; 70 bool m_failed; 62 bool m_gotInitialResponse; 63 bool m_gotFinalMessage; 71 64 }; 72 65
Note: See TracChangeset
for help on using the changeset viewer.