2 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "WebKitAgnosticTest.h"
29 #include <WebKit2/WKURLCF.h>
30 #include <wtf/RetainPtr.h>
32 @interface FrameLoadDelegate : NSObject {
36 - (id)initWithDidFinishLoadBoolean:(bool*)didFinishLoad;
40 @implementation FrameLoadDelegate
42 - (id)initWithDidFinishLoadBoolean:(bool*)didFinishLoad
48 _didFinishLoad = didFinishLoad;
52 - (void)webView:(WebView *)webView didFinishLoadForFrame:(WebFrame *)webFrame
54 *_didFinishLoad = true;
59 namespace TestWebKitAPI {
61 static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void* context)
63 *static_cast<bool*>(const_cast<void*>(context)) = true;
66 static void setPageLoaderClient(WKPageRef page, bool* didFinishLoad)
68 WKPageLoaderClient loaderClient;
69 memset(&loaderClient, 0, sizeof(loaderClient));
70 loaderClient.version = 0;
71 loaderClient.clientInfo = didFinishLoad;
72 loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
74 WKPageSetPageLoaderClient(page, &loaderClient);
77 WebKitAgnosticTest::WebKitAgnosticTest()
78 : viewFrame(NSMakeRect(0, 0, 800, 600))
79 , didFinishLoad(false)
83 void WebKitAgnosticTest::runWebKit1Test()
85 RetainPtr<WebView> webView(AdoptNS, [[WebView alloc] initWithFrame:viewFrame]);
86 RetainPtr<FrameLoadDelegate> delegate(AdoptNS, [[FrameLoadDelegate alloc] initWithDidFinishLoadBoolean:&didFinishLoad]);
87 [webView.get() setFrameLoadDelegate:delegate.get()];
88 initializeView(webView.get());
90 loadURL(webView.get(), url());
91 waitForLoadToFinish();
92 didLoadURL(webView.get());
95 void WebKitAgnosticTest::runWebKit2Test()
97 WKRetainPtr<WKContextRef> context = adoptWK(WKContextCreate());
98 RetainPtr<WKView> view(AdoptNS, [[WKView alloc] initWithFrame:viewFrame contextRef:context.get()]);
99 setPageLoaderClient([view.get() pageRef], &didFinishLoad);
100 initializeView(view.get());
102 loadURL(view.get(), url());
103 waitForLoadToFinish();
104 didLoadURL(view.get());
107 void WebKitAgnosticTest::loadURL(WebView *webView, NSURL *url)
109 EXPECT_FALSE(didFinishLoad);
110 [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:url]];
113 void WebKitAgnosticTest::loadURL(WKView *view, NSURL *url)
115 EXPECT_FALSE(didFinishLoad);
116 WKPageLoadURL([view pageRef], adoptWK(WKURLCreateWithCFURL((CFURLRef)url)).get());
119 void WebKitAgnosticTest::goBack(WebView *webView)
121 EXPECT_FALSE(didFinishLoad);
125 void WebKitAgnosticTest::goBack(WKView *view)
127 EXPECT_FALSE(didFinishLoad);
128 WKPageGoBack([view pageRef]);
131 void WebKitAgnosticTest::waitForLoadToFinish()
133 Util::run(&didFinishLoad);
134 didFinishLoad = false;
137 } // namespace TestWebKitAPI