OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "ios/web/test/web_test.h" | 5 #import "ios/web/test/web_test.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/memory/ptr_util.h" |
10 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
11 #import "base/test/ios/wait_util.h" | 12 #import "base/test/ios/wait_util.h" |
12 #import "ios/testing/ocmock_complex_type_helper.h" | 13 #import "ios/testing/ocmock_complex_type_helper.h" |
13 #import "ios/web/navigation/crw_session_controller.h" | 14 #import "ios/web/navigation/crw_session_controller.h" |
14 #include "ios/web/public/active_state_manager.h" | 15 #include "ios/web/public/active_state_manager.h" |
15 #include "ios/web/public/referrer.h" | 16 #include "ios/web/public/referrer.h" |
16 #import "ios/web/public/web_state/ui/crw_web_delegate.h" | 17 #import "ios/web/public/web_state/ui/crw_web_delegate.h" |
17 #import "ios/web/web_state/ui/crw_wk_web_view_web_controller.h" | 18 #import "ios/web/web_state/ui/crw_wk_web_view_web_controller.h" |
18 #import "ios/web/web_state/web_state_impl.h" | 19 #import "ios/web/web_state/web_state_impl.h" |
19 #include "third_party/ocmock/OCMock/OCMock.h" | 20 #include "third_party/ocmock/OCMock/OCMock.h" |
20 | 21 |
21 // Helper Mock to stub out API with C++ objects in arguments. | 22 // Helper Mock to stub out API with C++ objects in arguments. |
22 @interface WebDelegateMock : OCMockComplexTypeHelper | 23 @interface WebDelegateMock : OCMockComplexTypeHelper |
23 @end | 24 @end |
24 | 25 |
25 @implementation WebDelegateMock | 26 @implementation WebDelegateMock |
26 // Stub implementation always returns YES. | 27 // Stub implementation always returns YES. |
27 - (BOOL)webController:(CRWWebController*)webController | 28 - (BOOL)webController:(CRWWebController*)webController |
28 shouldOpenURL:(const GURL&)url | 29 shouldOpenURL:(const GURL&)url |
29 mainDocumentURL:(const GURL&)mainDocumentURL | 30 mainDocumentURL:(const GURL&)mainDocumentURL |
30 linkClicked:(BOOL)linkClicked { | 31 linkClicked:(BOOL)linkClicked { |
31 return YES; | 32 return YES; |
32 } | 33 } |
33 @end | 34 @end |
34 | 35 |
35 namespace web { | 36 namespace web { |
36 | 37 |
37 #pragma mark - | 38 #pragma mark - |
38 | 39 |
39 WebTest::WebTest() : web_client_(make_scoped_ptr(new TestWebClient)) {} | 40 WebTest::WebTest() : web_client_(base::WrapUnique(new TestWebClient)) {} |
40 WebTest::~WebTest() {} | 41 WebTest::~WebTest() {} |
41 | 42 |
42 void WebTest::SetUp() { | 43 void WebTest::SetUp() { |
43 PlatformTest::SetUp(); | 44 PlatformTest::SetUp(); |
44 BrowserState::GetActiveStateManager(&browser_state_)->SetActive(true); | 45 BrowserState::GetActiveStateManager(&browser_state_)->SetActive(true); |
45 } | 46 } |
46 | 47 |
47 void WebTest::TearDown() { | 48 void WebTest::TearDown() { |
48 BrowserState::GetActiveStateManager(&browser_state_)->SetActive(false); | 49 BrowserState::GetActiveStateManager(&browser_state_)->SetActive(false); |
49 PlatformTest::TearDown(); | 50 PlatformTest::TearDown(); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 JSONObjectWithData:evaluationData | 213 JSONObjectWithData:evaluationData |
213 options:0 | 214 options:0 |
214 error:&error]; | 215 error:&error]; |
215 DCHECK(dictionary && !error); | 216 DCHECK(dictionary && !error); |
216 NSString* exception = [dictionary objectForKey:@"exception"]; | 217 NSString* exception = [dictionary objectForKey:@"exception"]; |
217 CHECK(!exception) << "Script error: " << [exception UTF8String]; | 218 CHECK(!exception) << "Script error: " << [exception UTF8String]; |
218 return [dictionary objectForKey:@"result"]; | 219 return [dictionary objectForKey:@"result"]; |
219 } | 220 } |
220 | 221 |
221 CRWWebController* WebTestWithWebController::CreateWebController() { | 222 CRWWebController* WebTestWithWebController::CreateWebController() { |
222 scoped_ptr<WebStateImpl> web_state_impl(new WebStateImpl(GetBrowserState())); | 223 std::unique_ptr<WebStateImpl> web_state_impl( |
| 224 new WebStateImpl(GetBrowserState())); |
223 return [[CRWWKWebViewWebController alloc] | 225 return [[CRWWKWebViewWebController alloc] |
224 initWithWebState:std::move(web_state_impl)]; | 226 initWithWebState:std::move(web_state_impl)]; |
225 } | 227 } |
226 | 228 |
227 void WebTestWithWebController::WillProcessTask( | 229 void WebTestWithWebController::WillProcessTask( |
228 const base::PendingTask& pending_task) { | 230 const base::PendingTask& pending_task) { |
229 // Nothing to do. | 231 // Nothing to do. |
230 } | 232 } |
231 | 233 |
232 void WebTestWithWebController::DidProcessTask( | 234 void WebTestWithWebController::DidProcessTask( |
(...skipping 13 matching lines...) Expand all Loading... |
246 } | 248 } |
247 return false; | 249 return false; |
248 } | 250 } |
249 | 251 |
250 NSString* WebTestWithWebController::CreateLoadCheck() { | 252 NSString* WebTestWithWebController::CreateLoadCheck() { |
251 return [NSString stringWithFormat:@"<p style=\"display: none;\">%d</p>", | 253 return [NSString stringWithFormat:@"<p style=\"display: none;\">%d</p>", |
252 s_html_load_count++]; | 254 s_html_load_count++]; |
253 } | 255 } |
254 | 256 |
255 } // namespace web | 257 } // namespace web |
OLD | NEW |