| 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/web_state/ui/crw_web_controller.h" | 5 #import "ios/web/web_state/ui/crw_web_controller.h" |
| 6 | 6 |
| 7 #import <UIKit/UIKit.h> | 7 #import <UIKit/UIKit.h> |
| 8 #import <WebKit/WebKit.h> | 8 #import <WebKit/WebKit.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 | 328 |
| 329 virtual void TearDown() override { | 329 virtual void TearDown() override { |
| 330 EXPECT_OCMOCK_VERIFY(mockDelegate_); | 330 EXPECT_OCMOCK_VERIFY(mockDelegate_); |
| 331 EXPECT_OCMOCK_VERIFY(mockChildWebController_.get()); | 331 EXPECT_OCMOCK_VERIFY(mockChildWebController_.get()); |
| 332 EXPECT_OCMOCK_VERIFY(mockWebView_); | 332 EXPECT_OCMOCK_VERIFY(mockWebView_); |
| 333 [WebTestT::webController_ resetInjectedWebViewContentView]; | 333 [WebTestT::webController_ resetInjectedWebViewContentView]; |
| 334 [WebTestT::webController_ setDelegate:nil]; | 334 [WebTestT::webController_ setDelegate:nil]; |
| 335 WebTestT::TearDown(); | 335 WebTestT::TearDown(); |
| 336 } | 336 } |
| 337 | 337 |
| 338 // The value for web view OCMock objects to expect for |-setFrame:|. |
| 339 CGRect ExpectedWebViewFrame() const { |
| 340 CGSize containerViewSize = [UIScreen mainScreen].bounds.size; |
| 341 containerViewSize.height -= |
| 342 CGRectGetHeight([UIApplication sharedApplication].statusBarFrame); |
| 343 return {CGPointZero, containerViewSize}; |
| 344 } |
| 345 |
| 338 // Creates WebView mock. | 346 // Creates WebView mock. |
| 339 virtual UIView* CreateMockWebView() const = 0; | 347 virtual UIView* CreateMockWebView() const = 0; |
| 340 | 348 |
| 341 // Simulates a load request delegate call from the web view. | 349 // Simulates a load request delegate call from the web view. |
| 342 virtual void SimulateLoadRequest(NSURLRequest* request) const = 0; | 350 virtual void SimulateLoadRequest(NSURLRequest* request) const = 0; |
| 343 | 351 |
| 344 base::scoped_nsobject<UIScrollView> mockScrollView_; | 352 base::scoped_nsobject<UIScrollView> mockScrollView_; |
| 345 base::scoped_nsobject<id> mockWebView_; | 353 base::scoped_nsobject<id> mockWebView_; |
| 346 base::scoped_nsobject<id> mockDelegate_; | 354 base::scoped_nsobject<id> mockDelegate_; |
| 347 base::scoped_nsobject<id> mockChildWebController_; | 355 base::scoped_nsobject<id> mockChildWebController_; |
| 348 }; | 356 }; |
| 349 | 357 |
| 350 class CRWUIWebViewWebControllerTest | 358 class CRWUIWebViewWebControllerTest |
| 351 : public WebControllerTest<web::WebTestWithUIWebViewWebController> { | 359 : public WebControllerTest<web::WebTestWithUIWebViewWebController> { |
| 352 protected: | 360 protected: |
| 353 UIView* CreateMockWebView() const override { | 361 UIView* CreateMockWebView() const override { |
| 354 id result = [[OCMockObject mockForClass:[UIWebView class]] retain]; | 362 id result = [[OCMockObject mockForClass:[UIWebView class]] retain]; |
| 355 [[[result stub] andReturn:nil] request]; | 363 [[[result stub] andReturn:nil] request]; |
| 356 [[result stub] setDelegate:OCMOCK_ANY]; // Called by resetInjectedWebView | 364 [[result stub] setDelegate:OCMOCK_ANY]; // Called by resetInjectedWebView |
| 365 [[result stub] setFrame:ExpectedWebViewFrame()]; |
| 357 // Stub out the injection process. | 366 // Stub out the injection process. |
| 358 [[[result stub] andReturn:@"object"] | 367 [[[result stub] andReturn:@"object"] |
| 359 stringByEvaluatingJavaScriptFromString: | 368 stringByEvaluatingJavaScriptFromString: |
| 360 @"try { typeof __gCrWeb; } catch (e) { 'undefined'; }"]; | 369 @"try { typeof __gCrWeb; } catch (e) { 'undefined'; }"]; |
| 361 [[[result stub] andReturn:@"object"] | 370 [[[result stub] andReturn:@"object"] |
| 362 stringByEvaluatingJavaScriptFromString:@"try { typeof " | 371 stringByEvaluatingJavaScriptFromString:@"try { typeof " |
| 363 @"__gCrWeb.windowIdObject; } " | 372 @"__gCrWeb.windowIdObject; } " |
| 364 @"catch (e) { 'undefined'; }"]; | 373 @"catch (e) { 'undefined'; }"]; |
| 365 return result; | 374 return result; |
| 366 } | 375 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 381 WebControllerTest<web::WebTestWithWKWebViewWebController>::SetUp(); | 390 WebControllerTest<web::WebTestWithWKWebViewWebController>::SetUp(); |
| 382 } | 391 } |
| 383 UIView* CreateMockWebView() const override { | 392 UIView* CreateMockWebView() const override { |
| 384 id result = [[OCMockObject mockForClass:[WKWebView class]] retain]; | 393 id result = [[OCMockObject mockForClass:[WKWebView class]] retain]; |
| 385 | 394 |
| 386 // Called by resetInjectedWebView | 395 // Called by resetInjectedWebView |
| 387 [[result stub] backForwardList]; | 396 [[result stub] backForwardList]; |
| 388 [[[result stub] andReturn:[NSURL URLWithString:kTestURLString]] URL]; | 397 [[[result stub] andReturn:[NSURL URLWithString:kTestURLString]] URL]; |
| 389 [[result stub] setNavigationDelegate:OCMOCK_ANY]; | 398 [[result stub] setNavigationDelegate:OCMOCK_ANY]; |
| 390 [[result stub] setUIDelegate:OCMOCK_ANY]; | 399 [[result stub] setUIDelegate:OCMOCK_ANY]; |
| 400 [[result stub] setFrame:ExpectedWebViewFrame()]; |
| 391 [[result stub] addObserver:webController_ | 401 [[result stub] addObserver:webController_ |
| 392 forKeyPath:OCMOCK_ANY | 402 forKeyPath:OCMOCK_ANY |
| 393 options:0 | 403 options:0 |
| 394 context:nullptr]; | 404 context:nullptr]; |
| 395 [[result stub] addObserver:OCMOCK_ANY | 405 [[result stub] addObserver:OCMOCK_ANY |
| 396 forKeyPath:@"scrollView.backgroundColor" | 406 forKeyPath:@"scrollView.backgroundColor" |
| 397 options:0 | 407 options:0 |
| 398 context:nullptr]; | 408 context:nullptr]; |
| 399 | 409 |
| 400 [[result stub] removeObserver:webController_ forKeyPath:OCMOCK_ANY]; | 410 [[result stub] removeObserver:webController_ forKeyPath:OCMOCK_ANY]; |
| (...skipping 1150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1551 // https://bugs.webkit.org/show_bug.cgi?id=140203 | 1561 // https://bugs.webkit.org/show_bug.cgi?id=140203 |
| 1552 VLOG(1) << "Script has been flushed."; | 1562 VLOG(1) << "Script has been flushed."; |
| 1553 }]; | 1563 }]; |
| 1554 // -evaluateJavaScript:stringResultHandler: is asynchronous so JavaScript | 1564 // -evaluateJavaScript:stringResultHandler: is asynchronous so JavaScript |
| 1555 // evaluation will not happen until TearDown, which deallocates | 1565 // evaluation will not happen until TearDown, which deallocates |
| 1556 // CRWWebController, which in its turn will deallocate WKWebView to create a | 1566 // CRWWebController, which in its turn will deallocate WKWebView to create a |
| 1557 // crashy condition. | 1567 // crashy condition. |
| 1558 }; | 1568 }; |
| 1559 | 1569 |
| 1560 } // namespace | 1570 } // namespace |
| OLD | NEW |