| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2011 Apple Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | |
| 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | |
| 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | |
| 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | |
| 23 * THE POSSIBILITY OF SUCH DAMAGE. | |
| 24 */ | |
| 25 | |
| 26 #include "config.h" | |
| 27 #include "WebKitAgnosticTest.h" | |
| 28 | |
| 29 #include <WebKit2/WKURLCF.h> | |
| 30 #include <WebKit2/WKViewPrivate.h> | |
| 31 #include <wtf/RetainPtr.h> | |
| 32 | |
| 33 @interface FrameLoadDelegate : NSObject { | |
| 34 bool* _didFinishLoad; | |
| 35 } | |
| 36 | |
| 37 - (id)initWithDidFinishLoadBoolean:(bool*)didFinishLoad; | |
| 38 | |
| 39 @end | |
| 40 | |
| 41 @implementation FrameLoadDelegate | |
| 42 | |
| 43 - (id)initWithDidFinishLoadBoolean:(bool*)didFinishLoad | |
| 44 { | |
| 45 self = [super init]; | |
| 46 if (!self) | |
| 47 return nil; | |
| 48 | |
| 49 _didFinishLoad = didFinishLoad; | |
| 50 return self; | |
| 51 } | |
| 52 | |
| 53 - (void)webView:(WebView *)webView didFinishLoadForFrame:(WebFrame *)webFrame | |
| 54 { | |
| 55 *_didFinishLoad = true; | |
| 56 } | |
| 57 | |
| 58 @end | |
| 59 | |
| 60 namespace TestWebKitAPI { | |
| 61 | |
| 62 static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void*
context) | |
| 63 { | |
| 64 *static_cast<bool*>(const_cast<void*>(context)) = true; | |
| 65 } | |
| 66 | |
| 67 static void setPageLoaderClient(WKPageRef page, bool* didFinishLoad) | |
| 68 { | |
| 69 WKPageLoaderClient loaderClient; | |
| 70 memset(&loaderClient, 0, sizeof(loaderClient)); | |
| 71 loaderClient.version = 0; | |
| 72 loaderClient.clientInfo = didFinishLoad; | |
| 73 loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; | |
| 74 | |
| 75 WKPageSetPageLoaderClient(page, &loaderClient); | |
| 76 } | |
| 77 | |
| 78 WebKitAgnosticTest::WebKitAgnosticTest() | |
| 79 : viewFrame(NSMakeRect(0, 0, 800, 600)) | |
| 80 , didFinishLoad(false) | |
| 81 { | |
| 82 } | |
| 83 | |
| 84 void WebKitAgnosticTest::runWebKit1Test() | |
| 85 { | |
| 86 RetainPtr<WebView> webView(AdoptNS, [[WebView alloc] initWithFrame:viewFrame
]); | |
| 87 RetainPtr<FrameLoadDelegate> delegate(AdoptNS, [[FrameLoadDelegate alloc] in
itWithDidFinishLoadBoolean:&didFinishLoad]); | |
| 88 [webView.get() setFrameLoadDelegate:delegate.get()]; | |
| 89 initializeView(webView.get()); | |
| 90 | |
| 91 loadURL(webView.get(), url()); | |
| 92 waitForLoadToFinish(); | |
| 93 didLoadURL(webView.get()); | |
| 94 teardownView(webView.get()); | |
| 95 } | |
| 96 | |
| 97 void WebKitAgnosticTest::runWebKit2Test() | |
| 98 { | |
| 99 WKRetainPtr<WKContextRef> context = adoptWK(WKContextCreate()); | |
| 100 WKRetainPtr<WKPageGroupRef> pageGroup = adoptWK(WKPageGroupCreateWithIdentif
ier(Util::toWK("WebKitAgnosticTest").get())); | |
| 101 RetainPtr<WKView> view(AdoptNS, [[WKView alloc] initWithFrame:viewFrame cont
extRef:context.get() pageGroupRef:pageGroup.get()]); | |
| 102 setPageLoaderClient([view.get() pageRef], &didFinishLoad); | |
| 103 initializeView(view.get()); | |
| 104 | |
| 105 loadURL(view.get(), url()); | |
| 106 waitForLoadToFinish(); | |
| 107 didLoadURL(view.get()); | |
| 108 teardownView(view.get()); | |
| 109 } | |
| 110 | |
| 111 void WebKitAgnosticTest::loadURL(WebView *webView, NSURL *url) | |
| 112 { | |
| 113 EXPECT_FALSE(didFinishLoad); | |
| 114 [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:url]]; | |
| 115 } | |
| 116 | |
| 117 void WebKitAgnosticTest::loadURL(WKView *view, NSURL *url) | |
| 118 { | |
| 119 EXPECT_FALSE(didFinishLoad); | |
| 120 WKPageLoadURL([view pageRef], adoptWK(WKURLCreateWithCFURL((CFURLRef)url)).g
et()); | |
| 121 } | |
| 122 | |
| 123 void WebKitAgnosticTest::goBack(WebView *webView) | |
| 124 { | |
| 125 EXPECT_FALSE(didFinishLoad); | |
| 126 [webView goBack]; | |
| 127 } | |
| 128 | |
| 129 void WebKitAgnosticTest::goBack(WKView *view) | |
| 130 { | |
| 131 EXPECT_FALSE(didFinishLoad); | |
| 132 WKPageGoBack([view pageRef]); | |
| 133 } | |
| 134 | |
| 135 void WebKitAgnosticTest::waitForLoadToFinish() | |
| 136 { | |
| 137 Util::run(&didFinishLoad); | |
| 138 didFinishLoad = false; | |
| 139 } | |
| 140 | |
| 141 } // namespace TestWebKitAPI | |
| OLD | NEW |