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 #import "config.h" | |
27 #import "Test.h" | |
28 | |
29 #import <WebKit2/WKBrowsingContextController.h> | |
30 #import <WebKit2/WKBrowsingContextGroup.h> | |
31 #import <WebKit2/WKBrowsingContextLoadDelegate.h> | |
32 #import <WebKit2/WKProcessGroup.h> | |
33 #import <WebKit2/WKRetainPtr.h> | |
34 #import <WebKit2/WKView.h> | |
35 | |
36 #import "PlatformUtilities.h" | |
37 | |
38 namespace { | |
39 | |
40 class WKBrowsingContextLoadDelegateTest : public ::testing::Test { | |
41 public: | |
42 WKProcessGroup *processGroup; | |
43 WKBrowsingContextGroup *browsingContextGroup; | |
44 WKView *view; | |
45 | |
46 WKBrowsingContextLoadDelegateTest() | |
47 : processGroup(nil) | |
48 , browsingContextGroup(nil) | |
49 , view(nil) | |
50 { | |
51 } | |
52 | |
53 virtual void SetUp() | |
54 { | |
55 processGroup = [[WKProcessGroup alloc] init]; | |
56 browsingContextGroup = [[WKBrowsingContextGroup alloc] initWithIdentifie
r:@"TestIdentifier"]; | |
57 view = [[WKView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) processG
roup:processGroup browsingContextGroup:browsingContextGroup]; | |
58 } | |
59 | |
60 virtual void TearDown() | |
61 { | |
62 [view release]; | |
63 [browsingContextGroup release]; | |
64 [processGroup release]; | |
65 } | |
66 }; | |
67 | |
68 } // namespace | |
69 | |
70 @interface SimpleLoadDelegate : NSObject <WKBrowsingContextLoadDelegate> | |
71 { | |
72 bool* _simpleLoadDone; | |
73 } | |
74 | |
75 - (id)initWithFlag:(bool*)flag; | |
76 | |
77 @end | |
78 | |
79 @implementation SimpleLoadDelegate | |
80 | |
81 - (id)initWithFlag:(bool*)flag | |
82 { | |
83 self = [super init]; | |
84 if (!self) | |
85 return nil; | |
86 | |
87 _simpleLoadDone = flag; | |
88 return self; | |
89 } | |
90 | |
91 - (void)browsingContextControllerDidFinishLoad:(WKBrowsingContextController *)se
nder | |
92 { | |
93 *_simpleLoadDone = true; | |
94 } | |
95 | |
96 @end | |
97 | |
98 TEST_F(WKBrowsingContextLoadDelegateTest, Empty) | |
99 { | |
100 // Just make sure the setup/tear down works. | |
101 } | |
102 | |
103 TEST_F(WKBrowsingContextLoadDelegateTest, SimpleLoad) | |
104 { | |
105 bool simpleLoadDone = false; | |
106 | |
107 // Add the load delegate. | |
108 SimpleLoadDelegate *loadDelegate = [[SimpleLoadDelegate alloc] initWithFlag:
&simpleLoadDone]; | |
109 view.browsingContextController.loadDelegate = loadDelegate; | |
110 | |
111 // Load the file. | |
112 NSURL *nsURL = [[NSBundle mainBundle] URLForResource:@"simple" withExtension
:@"html" subdirectory:@"TestWebKitAPI.resources"]; | |
113 [view.browsingContextController loadFileURL:nsURL restrictToFilesWithin:nil]
; | |
114 | |
115 // Wait for the load to finish. | |
116 TestWebKitAPI::Util::run(&simpleLoadDone); | |
117 | |
118 // Tear down the delegate. | |
119 view.browsingContextController.loadDelegate = nil; | |
120 [loadDelegate release]; | |
121 } | |
122 | |
123 TEST_F(WKBrowsingContextLoadDelegateTest, SimpleLoadOfHTMLString) | |
124 { | |
125 bool simpleLoadDone = false; | |
126 | |
127 // Add the load delegate. | |
128 SimpleLoadDelegate *loadDelegate = [[SimpleLoadDelegate alloc] initWithFlag:
&simpleLoadDone]; | |
129 view.browsingContextController.loadDelegate = loadDelegate; | |
130 | |
131 // Load the HTML string. | |
132 [view.browsingContextController loadHTMLString:@"<html><body>Simple HTML Str
ing</body></html>" baseURL:[NSURL URLWithString:@"about:blank"]]; | |
133 | |
134 // Wait for the load to finish. | |
135 TestWebKitAPI::Util::run(&simpleLoadDone); | |
136 | |
137 // Tear down the delegate. | |
138 view.browsingContextController.loadDelegate = nil; | |
139 [loadDelegate release]; | |
140 } | |
141 | |
142 TEST_F(WKBrowsingContextLoadDelegateTest, SimpleLoadOfHTMLString_NilBaseURL) | |
143 { | |
144 bool simpleLoadDone = false; | |
145 | |
146 // Add the load delegate. | |
147 SimpleLoadDelegate *loadDelegate = [[SimpleLoadDelegate alloc] initWithFlag:
&simpleLoadDone]; | |
148 view.browsingContextController.loadDelegate = loadDelegate; | |
149 | |
150 // Load the HTML string, pass nil as the baseURL. | |
151 [view.browsingContextController loadHTMLString:@"<html><body>Simple HTML Str
ing</body></html>" baseURL:nil]; | |
152 | |
153 // Wait for the load to finish. | |
154 TestWebKitAPI::Util::run(&simpleLoadDone); | |
155 | |
156 // Tear down the delegate. | |
157 view.browsingContextController.loadDelegate = nil; | |
158 [loadDelegate release]; | |
159 } | |
160 | |
161 TEST_F(WKBrowsingContextLoadDelegateTest, SimpleLoadOfHTMLString_NilHTMLStringAn
dBaseURL) | |
162 { | |
163 bool simpleLoadDone = false; | |
164 | |
165 // Add the load delegate. | |
166 SimpleLoadDelegate *loadDelegate = [[SimpleLoadDelegate alloc] initWithFlag:
&simpleLoadDone]; | |
167 view.browsingContextController.loadDelegate = loadDelegate; | |
168 | |
169 // Load the HTML string (as nil). | |
170 [view.browsingContextController loadHTMLString:nil baseURL:nil]; | |
171 | |
172 // Wait for the load to finish. | |
173 TestWebKitAPI::Util::run(&simpleLoadDone); | |
174 | |
175 // Tear down the delegate. | |
176 view.browsingContextController.loadDelegate = nil; | |
177 [loadDelegate release]; | |
178 } | |
179 | |
180 @interface SimpleLoadFailDelegate : NSObject <WKBrowsingContextLoadDelegate> | |
181 { | |
182 bool* _simpleLoadFailDone; | |
183 } | |
184 | |
185 - (id)initWithFlag:(bool*)flag; | |
186 | |
187 @end | |
188 | |
189 @implementation SimpleLoadFailDelegate | |
190 | |
191 - (id)initWithFlag:(bool*)flag | |
192 { | |
193 self = [super init]; | |
194 if (!self) | |
195 return nil; | |
196 | |
197 _simpleLoadFailDone = flag; | |
198 return self; | |
199 } | |
200 | |
201 - (void)browsingContextControllerDidFailProvisionalLoad:(WKBrowsingContextContro
ller *)sender withError:(NSError *)error | |
202 { | |
203 EXPECT_EQ(-1100, error.code); | |
204 EXPECT_WK_STREQ(NSURLErrorDomain, error.domain); | |
205 | |
206 *_simpleLoadFailDone = true; | |
207 } | |
208 | |
209 @end | |
210 | |
211 TEST_F(WKBrowsingContextLoadDelegateTest, SimpleLoadFail) | |
212 { | |
213 bool simpleLoadFailDone = false; | |
214 | |
215 // Add the load delegate. | |
216 SimpleLoadFailDelegate *loadDelegate = [[SimpleLoadFailDelegate alloc] initW
ithFlag:&simpleLoadFailDone]; | |
217 view.browsingContextController.loadDelegate = loadDelegate; | |
218 | |
219 // Load a non-existent file. | |
220 NSURL *nsURL = [NSURL URLWithString:@"file:///does-not-exist.html"]; | |
221 [view.browsingContextController loadFileURL:nsURL restrictToFilesWithin:nil]
; | |
222 | |
223 // Wait for the load to fail. | |
224 TestWebKitAPI::Util::run(&simpleLoadFailDone); | |
225 | |
226 // Tear down the delegate. | |
227 view.browsingContextController.loadDelegate = nil; | |
228 [loadDelegate release]; | |
229 } | |
OLD | NEW |