OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2010 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 "PlatformUtilities.h" | |
28 #include "PlatformWebView.h" | |
29 #include "Test.h" | |
30 #include <WebKit2/WKRetainPtr.h> | |
31 | |
32 namespace TestWebKitAPI { | |
33 | |
34 static bool test1Done; | |
35 | |
36 struct State { | |
37 State() | |
38 : didDecidePolicyForNavigationAction(false) | |
39 , didStartProvisionalLoadForFrame(false) | |
40 , didCommitLoadForFrame(false) | |
41 { | |
42 } | |
43 | |
44 bool didDecidePolicyForNavigationAction; | |
45 bool didStartProvisionalLoadForFrame; | |
46 bool didCommitLoadForFrame; | |
47 }; | |
48 | |
49 static void didStartProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, WK
TypeRef userData, const void* clientInfo) | |
50 { | |
51 State* state = reinterpret_cast<State*>(const_cast<void*>(clientInfo)); | |
52 EXPECT_TRUE(state->didDecidePolicyForNavigationAction); | |
53 EXPECT_FALSE(state->didCommitLoadForFrame); | |
54 | |
55 // The commited URL should be null. | |
56 EXPECT_NULL(WKFrameCopyURL(frame)); | |
57 | |
58 EXPECT_FALSE(state->didStartProvisionalLoadForFrame); | |
59 | |
60 state->didStartProvisionalLoadForFrame = true; | |
61 } | |
62 | |
63 static void didCommitLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef us
erData, const void* clientInfo) | |
64 { | |
65 State* state = reinterpret_cast<State*>(const_cast<void*>(clientInfo)); | |
66 EXPECT_TRUE(state->didDecidePolicyForNavigationAction); | |
67 EXPECT_TRUE(state->didStartProvisionalLoadForFrame); | |
68 | |
69 // The provisional URL should be null. | |
70 EXPECT_NULL(WKFrameCopyProvisionalURL(frame)); | |
71 | |
72 state->didCommitLoadForFrame = true; | |
73 } | |
74 | |
75 static void didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef us
erData, const void* clientInfo) | |
76 { | |
77 State* state = reinterpret_cast<State*>(const_cast<void*>(clientInfo)); | |
78 EXPECT_TRUE(state->didDecidePolicyForNavigationAction); | |
79 EXPECT_TRUE(state->didStartProvisionalLoadForFrame); | |
80 EXPECT_TRUE(state->didCommitLoadForFrame); | |
81 | |
82 // The provisional URL should be null. | |
83 EXPECT_NULL(WKFrameCopyProvisionalURL(frame)); | |
84 | |
85 test1Done = true; | |
86 } | |
87 | |
88 static void decidePolicyForNavigationAction(WKPageRef page, WKFrameRef frame, WK
FrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButt
on mouseButton, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTy
peRef userData, const void* clientInfo) | |
89 { | |
90 State* state = reinterpret_cast<State*>(const_cast<void*>(clientInfo)); | |
91 EXPECT_FALSE(state->didStartProvisionalLoadForFrame); | |
92 EXPECT_FALSE(state->didCommitLoadForFrame); | |
93 EXPECT_TRUE(mouseButton == kWKEventMouseButtonNoButton); | |
94 | |
95 state->didDecidePolicyForNavigationAction = true; | |
96 | |
97 WKFramePolicyListenerUse(listener); | |
98 } | |
99 | |
100 static void decidePolicyForNewWindowAction(WKPageRef page, WKFrameRef frame, WKF
rameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButto
n mouseButton, WKURLRequestRef request, WKStringRef frameName, WKFramePolicyList
enerRef listener, WKTypeRef userData, const void* clientInfo) | |
101 { | |
102 EXPECT_TRUE(mouseButton == kWKEventMouseButtonNoButton); | |
103 WKFramePolicyListenerUse(listener); | |
104 } | |
105 | |
106 static void decidePolicyForResponse(WKPageRef page, WKFrameRef frame, WKURLRespo
nseRef response, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKT
ypeRef userData, const void* clientInfo) | |
107 { | |
108 WKFramePolicyListenerUse(listener); | |
109 } | |
110 | |
111 TEST(WebKit2, PageLoadBasic) | |
112 { | |
113 State state; | |
114 | |
115 WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate()); | |
116 PlatformWebView webView(context.get()); | |
117 | |
118 WKPageLoaderClient loaderClient; | |
119 memset(&loaderClient, 0, sizeof(loaderClient)); | |
120 | |
121 loaderClient.version = 0; | |
122 loaderClient.clientInfo = &state; | |
123 loaderClient.didStartProvisionalLoadForFrame = didStartProvisionalLoadForFra
me; | |
124 loaderClient.didCommitLoadForFrame = didCommitLoadForFrame; | |
125 loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; | |
126 WKPageSetPageLoaderClient(webView.page(), &loaderClient); | |
127 | |
128 WKPagePolicyClient policyClient; | |
129 memset(&policyClient, 0, sizeof(policyClient)); | |
130 | |
131 policyClient.version = 0; | |
132 policyClient.clientInfo = &state; | |
133 policyClient.decidePolicyForNavigationAction = decidePolicyForNavigationActi
on; | |
134 policyClient.decidePolicyForNewWindowAction = decidePolicyForNewWindowAction
; | |
135 policyClient.decidePolicyForResponse = decidePolicyForResponse; | |
136 WKPageSetPagePolicyClient(webView.page(), &policyClient); | |
137 | |
138 // Before loading anything, the active url should be null | |
139 EXPECT_NULL(WKPageCopyActiveURL(webView.page())); | |
140 | |
141 WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("simple", "htm
l")); | |
142 WKPageLoadURL(webView.page(), url.get()); | |
143 | |
144 // But immediately after starting a load, the active url should reflect the
request | |
145 WKRetainPtr<WKURLRef> activeUrl = adoptWK(WKPageCopyActiveURL(webView.page()
)); | |
146 ASSERT_NOT_NULL(activeUrl.get()); | |
147 EXPECT_TRUE(WKURLIsEqual(activeUrl.get(), url.get())); | |
148 | |
149 Util::run(&test1Done); | |
150 } | |
151 | |
152 } // namespace TestWebKitAPI | |
OLD | NEW |