Commit a3a9a49f authored by michaeldo's avatar michaeldo Committed by Commit bot

Remove SimpleWebViewController.

Remove SimpleWebViewController as it was used as an abstraction
when both WKWebView and UIWebView were used simulatenously.
WKWebView can now be used directly.

BUG=593897

Review URL: https://codereview.chromium.org/1829493003

Cr-Commit-Position: refs/heads/master@{#383816}
parent e180e0b9
......@@ -216,7 +216,6 @@ source_set("web") {
"web_state/ui/crw_context_menu_provider.h",
"web_state/ui/crw_context_menu_provider.mm",
"web_state/ui/crw_generic_content_view.mm",
"web_state/ui/crw_simple_web_view_controller.h",
"web_state/ui/crw_static_file_web_view.h",
"web_state/ui/crw_static_file_web_view.mm",
"web_state/ui/crw_swipe_recognizer_provider.h",
......@@ -230,8 +229,6 @@ source_set("web") {
"web_state/ui/crw_web_view_content_view.mm",
"web_state/ui/crw_wk_script_message_router.h",
"web_state/ui/crw_wk_script_message_router.mm",
"web_state/ui/crw_wk_simple_web_view_controller.h",
"web_state/ui/crw_wk_simple_web_view_controller.mm",
"web_state/ui/crw_wk_web_view_web_controller.h",
"web_state/ui/crw_wk_web_view_web_controller.mm",
"web_state/ui/web_view_js_utils.h",
......@@ -425,7 +422,6 @@ test("ios_web_unittests") {
"web_state/ui/crw_web_controller_observer_unittest.mm",
"web_state/ui/crw_web_controller_unittest.mm",
"web_state/ui/crw_wk_script_message_router_unittest.mm",
"web_state/ui/crw_wk_simple_web_view_controller_unittest.mm",
"web_state/ui/web_view_js_utils_unittest.mm",
"web_state/ui/wk_back_forward_list_item_holder_unittest.mm",
"web_state/ui/wk_web_view_configuration_provider_unittest.mm",
......
......@@ -5,15 +5,12 @@
#ifndef IOS_WEB_INTERSTITIALS_HTML_WEB_INTERSTITIAL_IMPL_H_
#define IOS_WEB_INTERSTITIALS_HTML_WEB_INTERSTITIAL_IMPL_H_
#import <UIKit/UIKit.h>
#import <WebKit/WebKit.h>
#include "base/mac/scoped_nsobject.h"
#include "base/memory/scoped_ptr.h"
#include "ios/web/interstitials/web_interstitial_impl.h"
@protocol CRWSimpleWebViewController;
@protocol CRWSimpleWebViewControllerDelegate;
namespace web {
class HtmlWebInterstitialDelegate;
......@@ -46,13 +43,12 @@ class HtmlWebInterstitialImpl : public WebInterstitialImpl {
private:
// The HTML interstitial delegate.
scoped_ptr<HtmlWebInterstitialDelegate> delegate_;
// The |web_view_controller_|'s delegate. Used to forward JavaScript commands
// The |web_view_|'s delegate. Used to forward JavaScript commands
// resulting from user interaction with the interstitial content.
base::scoped_nsprotocol<id<CRWSimpleWebViewControllerDelegate>>
web_view_controller_delegate_;
// The CRWSimpleWebViewController that contains the web view used to show the
// content. View needs to be resized by the caller.
base::scoped_nsprotocol<id<CRWSimpleWebViewController>> web_view_controller_;
base::scoped_nsprotocol<id<WKNavigationDelegate>> web_view_delegate_;
// The web view used to show the content. View needs to be resized by the
// caller.
base::scoped_nsobject<WKWebView> web_view_;
// The CRWContentView used to display |web_view_controller_|'s view.
base::scoped_nsobject<CRWContentView> content_view_;
};
......
......@@ -11,24 +11,24 @@
#include "ios/web/interstitials/web_interstitial_facade_delegate.h"
#include "ios/web/public/interstitials/web_interstitial_delegate.h"
#include "ios/web/public/web_state/ui/crw_web_view_content_view.h"
#import "ios/web/web_state/ui/crw_simple_web_view_controller.h"
#import "ios/web/public/web_view_creation_util.h"
#import "ios/web/web_state/ui/web_view_js_utils.h"
#include "ios/web/web_state/web_state_impl.h"
#import "ios/web/web_state/web_view_internal_creation_util.h"
#import "net/base/mac/url_conversions.h"
#include "ui/gfx/geometry/size.h"
// The delegate of the simple web view controller that is used to display the
// HTML content. It intercepts JavaScript-triggered commands and forwards them
// The delegate of the web view that is used to display the HTML content.
// It intercepts JavaScript-triggered commands and forwards them
// to the interstitial.
@interface CRWWebInterstitialImplCRWSimpleWebViewDelegate
: NSObject<CRWSimpleWebViewControllerDelegate>
// Initializes a CRWWebInterstitialImplCRWSimpleWebViewDelegate which will
// forward JavaScript commands from its CRWSimpleWebView to |interstitial|.
@interface CRWWebInterstitialImplWKWebViewDelegate
: NSObject<WKNavigationDelegate>
// Initializes a CRWWebInterstitialImplWKWebViewDelegate which will
// forward JavaScript commands from its WKWebView to |interstitial|.
- (instancetype)initWithInterstitial:
(web::HtmlWebInterstitialImpl*)interstitial;
@end
@implementation CRWWebInterstitialImplCRWSimpleWebViewDelegate {
@implementation CRWWebInterstitialImplWKWebViewDelegate {
web::HtmlWebInterstitialImpl* _interstitial;
}
......@@ -40,8 +40,7 @@
return self;
}
- (BOOL)simpleWebViewController:(id<CRWSimpleWebViewController>)controller
shouldStartLoadWithRequest:(NSURLRequest*)request {
- (BOOL)shouldStartLoadWithRequest:(NSURLRequest*)request {
NSString* requestString = [[request URL] absoluteString];
// If the request is a JavaScript-triggered command, parse it and forward the
// command to |interstitial_|.
......@@ -55,6 +54,18 @@
return YES;
}
#pragma mark -
#pragma mark WKNavigationDelegate methods
- (void)webView:(WKWebView*)webView
decidePolicyForNavigationAction:(WKNavigationAction*)navigationAction
decisionHandler:
(void (^)(WKNavigationActionPolicy))decisionHandler {
decisionHandler([self shouldStartLoadWithRequest:navigationAction.request]
? WKNavigationActionPolicyAllow
: WKNavigationActionPolicyCancel);
}
@end
#pragma mark -
......@@ -95,21 +106,18 @@ CRWContentView* HtmlWebInterstitialImpl::GetContentView() const {
void HtmlWebInterstitialImpl::PrepareForDisplay() {
if (!content_view_) {
web_view_controller_delegate_.reset(
[[CRWWebInterstitialImplCRWSimpleWebViewDelegate alloc]
initWithInterstitial:this]);
web_view_controller_.reset(web::CreateSimpleWebViewController(
CGRectZero, GetWebStateImpl()->GetBrowserState()));
[web_view_controller_ setDelegate:web_view_controller_delegate_];
[[web_view_controller_ view]
setAutoresizingMask:(UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight)];
web_view_delegate_.reset([[CRWWebInterstitialImplWKWebViewDelegate alloc]
initWithInterstitial:this]);
web_view_.reset(
web::CreateWKWebView(CGRectZero, GetWebStateImpl()->GetBrowserState()));
[web_view_ setNavigationDelegate:web_view_delegate_];
[web_view_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight)];
NSString* html = base::SysUTF8ToNSString(delegate_->GetHtmlContents());
[web_view_controller_ loadHTMLString:html
baseURL:net::NSURLWithGURL(GetUrl())];
[web_view_ loadHTMLString:html baseURL:net::NSURLWithGURL(GetUrl())];
content_view_.reset([[CRWWebViewContentView alloc]
initWithWebView:[web_view_controller_ view]
scrollView:[web_view_controller_ scrollView]]);
initWithWebView:web_view_
scrollView:[web_view_ scrollView]]);
}
}
......@@ -120,8 +128,7 @@ WebInterstitialDelegate* HtmlWebInterstitialImpl::GetDelegate() const {
void HtmlWebInterstitialImpl::EvaluateJavaScript(
NSString* script,
JavaScriptCompletion completionHandler) {
[web_view_controller_ evaluateJavaScript:script
stringResultHandler:completionHandler];
web::EvaluateJavaScript(web_view_, script, completionHandler);
}
} // namespace web
......@@ -252,7 +252,6 @@
'web_state/ui/crw_context_menu_provider.h',
'web_state/ui/crw_context_menu_provider.mm',
'web_state/ui/crw_generic_content_view.mm',
'web_state/ui/crw_simple_web_view_controller.h',
'web_state/ui/crw_static_file_web_view.h',
'web_state/ui/crw_static_file_web_view.mm',
'web_state/ui/crw_swipe_recognizer_provider.h',
......@@ -266,8 +265,6 @@
'web_state/ui/crw_web_view_content_view.mm',
'web_state/ui/crw_wk_script_message_router.h',
'web_state/ui/crw_wk_script_message_router.mm',
'web_state/ui/crw_wk_simple_web_view_controller.h',
'web_state/ui/crw_wk_simple_web_view_controller.mm',
'web_state/ui/crw_wk_web_view_web_controller.h',
'web_state/ui/crw_wk_web_view_web_controller.mm',
'web_state/ui/web_view_js_utils.h',
......
......@@ -71,7 +71,6 @@
'web_state/ui/crw_web_controller_observer_unittest.mm',
'web_state/ui/crw_web_controller_unittest.mm',
'web_state/ui/crw_wk_script_message_router_unittest.mm',
'web_state/ui/crw_wk_simple_web_view_controller_unittest.mm',
'web_state/ui/web_view_js_utils_unittest.mm',
'web_state/ui/wk_back_forward_list_item_holder_unittest.mm',
'web_state/ui/wk_web_view_configuration_provider_unittest.mm',
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_WEB_WEB_STATE_UI_CRW_SIMPLE_WEB_VIEW_CONTROLLER_H_
#define IOS_WEB_WEB_STATE_UI_CRW_SIMPLE_WEB_VIEW_CONTROLLER_H_
#import <UIKit/UIKit.h>
#import "ios/web/web_state/ui/web_view_js_utils.h"
@protocol CRWSimpleWebViewControllerDelegate;
#pragma mark -
#pragma mark Web View Protocol
// An abstraction for interacting with a web view without having to know if it's
// a UIWebView or a WKWebView internally.
@protocol CRWSimpleWebViewController<NSObject>
// The page title, meant for display to the user. Will return nil if not
// available.
@property(nonatomic, readonly) NSString* title;
// The web view associated with this controller.
@property(nonatomic, readonly) UIView* view;
// The web view's scroll view.
@property(nonatomic, readonly) UIScrollView* scrollView;
// The delegate that recieves page lifecycle callbacks
@property(nonatomic, weak) id<CRWSimpleWebViewControllerDelegate> delegate;
// Reloads any displayed data to ensure the view is up to date.
- (void)reload;
// Loads a request in the WebView.
- (void)loadRequest:(NSURLRequest*)request;
// Loads an HTML document in the web view. |baseURL| is a URL that is used to
// resolve relative URLs within the document.
- (void)loadHTMLString:(NSString*)html baseURL:(NSURL*)baseURL;
// Loads a PDF file from the application sandbox. A file must exist at
// |filePath|.
- (void)loadPDFAtFilePath:(NSString*)filePath;
// Evaluates the supplied JavaScript in the web view. Calls |completionHandler|
// with results of the evaluation. The |completionHandler| can be nil.
- (void)evaluateJavaScript:(NSString*)script
stringResultHandler:(web::JavaScriptCompletion)handler;
@end
#pragma mark -
#pragma mark Delegate Protocol
// CRWSimpleWebViewController delegate protocol for subscribing to page
// lifecycle events.
@protocol CRWSimpleWebViewControllerDelegate<NSObject>
@optional
// Called to decide if the CRWSimpleWebViewController should load a request.
- (BOOL)simpleWebViewController:
(id<CRWSimpleWebViewController>)simpleWebViewController
shouldStartLoadWithRequest:(NSURLRequest*)request;
// Called when the title changes. Can be called with nil value for |title|.
// Note: This call is not accurate all the time for the UIWebView case. The
// delegate method is not guaranteed to be called even if the title has changed.
// Clients should structure their code around it.
- (void)simpleWebViewController:
(id<CRWSimpleWebViewController>)simpleWebViewController
titleMayHaveChanged:(NSString*)title;
@end
#endif // IOS_WEB_WEB_STATE_UI_CRW_SIMPLE_WEB_VIEW_CONTROLLER_H_
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_WEB_WEB_STATE_UI_CRW_WK_SIMPLE_WEB_VIEW_CONTROLLER_H_
#define IOS_WEB_WEB_STATE_UI_CRW_WK_SIMPLE_WEB_VIEW_CONTROLLER_H_
#import <WebKit/WebKit.h>
#import "ios/web/web_state/ui/crw_simple_web_view_controller.h"
// A CRWSimpleWebViewController implentation backed by a WKWebView.
@interface CRWWKSimpleWebViewController : NSObject<CRWSimpleWebViewController>
// Creates a new view controller backed by a WKWebView.
- (instancetype)initWithWKWebView:(WKWebView*)webView;
@end
#endif // IOS_WEB_WEB_STATE_UI_CRW_WK_SIMPLE_WEB_VIEW_CONTROLLER_H_
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/web/web_state/ui/crw_wk_simple_web_view_controller.h"
#include "base/ios/ios_util.h"
#include "base/ios/weak_nsobject.h"
#include "base/logging.h"
#import "base/mac/scoped_nsobject.h"
@interface CRWWKSimpleWebViewController () <WKNavigationDelegate>
// Consults the delegate to decide whether a load request should be started.
- (BOOL)shouldStartLoadWithRequest:(NSURLRequest*)request;
@end
@implementation CRWWKSimpleWebViewController {
base::scoped_nsobject<WKWebView> _webView;
base::WeakNSProtocol<id<CRWSimpleWebViewControllerDelegate>> _delegate;
}
- (instancetype)initWithWKWebView:(WKWebView*)webView {
self = [super init];
if (self) {
DCHECK(webView);
_webView.reset([webView retain]);
[_webView setNavigationDelegate:self];
[_webView addObserver:self forKeyPath:@"title" options:0 context:NULL];
}
return self;
}
- (void)dealloc {
[_webView removeObserver:self forKeyPath:@"title"];
[super dealloc];
}
#pragma mark -
#pragma mark CRWSimpleWebView implementation
- (void)reload {
[_webView reload];
}
- (UIView*)view {
return _webView.get();
}
- (UIScrollView*)scrollView {
return [_webView scrollView];
}
- (NSString*)title {
return [_webView title];
}
- (void)loadRequest:(NSURLRequest*)request {
[_webView loadRequest:request];
}
- (void)loadHTMLString:(NSString*)html baseURL:(NSURL*)baseURL {
[_webView loadHTMLString:html baseURL:baseURL];
}
- (void)loadPDFAtFilePath:(NSString*)filePath {
if (!base::ios::IsRunningOnIOS9OrLater()) {
// WKWebView on iOS 8 can't load local files, so just bail.
NOTIMPLEMENTED();
return;
}
DCHECK([[NSFileManager defaultManager] fileExistsAtPath:filePath]);
NSURL* fileURL = [NSURL fileURLWithPath:filePath];
DCHECK(fileURL);
[_webView loadFileURL:fileURL allowingReadAccessToURL:fileURL];
}
- (void)setDelegate:(id<CRWSimpleWebViewControllerDelegate>)delegate {
_delegate.reset(delegate);
}
- (id<CRWSimpleWebViewControllerDelegate>)delegate {
return _delegate.get();
}
- (void)evaluateJavaScript:(NSString*)script
stringResultHandler:(web::JavaScriptCompletion)handler {
web::EvaluateJavaScript(_webView, script, handler);
}
#pragma mark -
#pragma mark KVO callback
- (void)observeValueForKeyPath:(NSString*)keyPath
ofObject:(id)object
change:(NSDictionary*)change
context:(void*)context {
DCHECK([keyPath isEqualToString:@"title"]);
if ([_delegate respondsToSelector:@selector(simpleWebViewController:
titleMayHaveChanged:)]) {
[_delegate simpleWebViewController:self titleMayHaveChanged:[self title]];
}
}
#pragma mark -
#pragma mark Delegate forwarding methods
- (BOOL)shouldStartLoadWithRequest:(NSURLRequest*)request {
if ([_delegate respondsToSelector:@selector(simpleWebViewController:
shouldStartLoadWithRequest:)]) {
return [_delegate simpleWebViewController:self
shouldStartLoadWithRequest:request];
}
// By default all loads are allowed.
return YES;
}
#pragma mark -
#pragma mark WKNavigationDelegate methods
- (void)webView:(WKWebView*)webView
decidePolicyForNavigationAction:(WKNavigationAction*)navigationAction
decisionHandler:
(void (^)(WKNavigationActionPolicy))decisionHandler {
decisionHandler([self shouldStartLoadWithRequest:navigationAction.request]
? WKNavigationActionPolicyAllow
: WKNavigationActionPolicyCancel);
}
@end
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/web/web_state/ui/crw_wk_simple_web_view_controller.h"
#import <UIKit/UIKit.h>
#import <WebKit/WebKit.h>
#import "base/mac/scoped_nsobject.h"
#import "base/test/ios/wait_util.h"
#include "ios/web/public/test/test_browser_state.h"
#import "ios/web/public/test/test_web_client.h"
#import "ios/web/public/web_view_creation_util.h"
#import "ios/web/test/web_test.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/gtest_mac.h"
#import "third_party/ocmock/OCMock/OCMock.h"
#include "third_party/ocmock/gtest_support.h"
namespace {
// A test fixture for testing CRWWKSimpleWebViewController.
class CRWWKSimpleWebViewControllerTest : public web::WebTest {
protected:
void SetUp() override {
web::WebTest::SetUp();
mock_web_view_.reset(
[[OCMockObject niceMockForClass:[WKWebView class]] retain]);
web_view_controller_.reset([[CRWWKSimpleWebViewController alloc]
initWithWKWebView:mock_web_view_]);
mock_delegate_.reset([[OCMockObject
mockForProtocol:@protocol(CRWSimpleWebViewControllerDelegate)] retain]);
[web_view_controller_ setDelegate:mock_delegate_];
}
// Tests that |shouldStartLoadWithRequest:| decision by the delegate is
// respected by the CRWSWKimpleWebViewController.
void TestShouldStartLoadRespected(BOOL expected_decision) {
NSURLRequest* request = [NSURLRequest requestWithURL:
[NSURL URLWithString:@"http://google.com"]];
base::scoped_nsobject<WKNavigationAction> navigation_action(
[[OCMockObject mockForClass:[WKNavigationAction class]] retain]);
[[[static_cast<OCMockObject*>(navigation_action.get()) stub]
andReturn:request] request];
[[[mock_delegate_ expect] andReturnValue:OCMOCK_VALUE(expected_decision)]
simpleWebViewController:web_view_controller_
shouldStartLoadWithRequest:request];
__block BOOL decision_handler_block_was_called = NO;
id decision_handler_block = ^void(WKNavigationActionPolicy policy) {
decision_handler_block_was_called = YES;
WKNavigationActionPolicy expected_policy = expected_decision ?
WKNavigationActionPolicyAllow : WKNavigationActionPolicyCancel;
EXPECT_EQ(expected_policy , policy);
};
[static_cast<id<WKNavigationDelegate>>(web_view_controller_.get())
webView:mock_web_view_
decidePolicyForNavigationAction:navigation_action
decisionHandler:decision_handler_block];
EXPECT_TRUE(decision_handler_block_was_called);
}
base::scoped_nsobject<id> mock_web_view_;
base::scoped_nsobject<id> mock_delegate_;
base::scoped_nsobject<CRWWKSimpleWebViewController> web_view_controller_;
};
// Tests to make sure a CRWWKSimpleWebViewController correctly sets the backing
// WKWebView.
TEST_F(CRWWKSimpleWebViewControllerTest, View) {
EXPECT_EQ(mock_web_view_.get(), [web_view_controller_ view]);
}
// Tests to make sure a CRWWKSimpleWebViewController correctly sets the backing
// WKWebView's navigation delegate
TEST_F(CRWWKSimpleWebViewControllerTest, Delegate) {
base::scoped_nsobject<WKWebView> web_view(
web::CreateWKWebView(CGRectZero, GetBrowserState()));
ASSERT_TRUE(web_view);
web_view_controller_.reset([[CRWWKSimpleWebViewController alloc]
initWithWKWebView:web_view]);
EXPECT_EQ(static_cast<id<WKNavigationDelegate>>(web_view_controller_.get()),
[web_view navigationDelegate]);
}
// Tests that CRWWKSimpleWebViewController can correctly retrieve the title from
// the underlying WKWebView.
TEST_F(CRWWKSimpleWebViewControllerTest, Title) {
[[[mock_web_view_ stub] andReturn:@"The Rolling Stones"] title];
EXPECT_NSEQ(@"The Rolling Stones", [web_view_controller_ title]);
}
// Tests that CRWWKSimpleWebViewController correctly reloads from the underlying
// WKWebView.
TEST_F(CRWWKSimpleWebViewControllerTest, Reload) {
[static_cast<WKWebView*>([mock_web_view_ expect]) reload];
[web_view_controller_ reload];
EXPECT_OCMOCK_VERIFY(mock_web_view_);
}
// Tests that CRWWKSimpleWebViewController correctly returns the web view's
// scroll view.
TEST_F(CRWWKSimpleWebViewControllerTest, ScrollView) {
base::scoped_nsobject<UIScrollView> scroll_view([[UIScrollView alloc] init]);
[[[mock_web_view_ stub] andReturn:scroll_view] scrollView];
EXPECT_EQ(scroll_view, [web_view_controller_ scrollView]);
}
// Tests that CRWWKSimpleWebViewControllerTest correctly loads a request from
// the underlying WKWebView.
TEST_F(CRWWKSimpleWebViewControllerTest, LoadRequest) {
NSURLRequest* request =
[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com"]];
[static_cast<WKWebView*>([mock_web_view_ expect]) loadRequest:request];
[web_view_controller_ loadRequest:request];
EXPECT_OCMOCK_VERIFY(mock_web_view_);
}
// Tests that CRWWKSimpleWebViewControllerTest correctly loads a html request
// from the underlying WKWebView.
TEST_F(CRWWKSimpleWebViewControllerTest, LoadHTMLString) {
NSURL* base_url = [NSURL URLWithString:@"http://google.com"];
NSString* html_string = @"<html>Some html</html>";
[static_cast<WKWebView*>([mock_web_view_ expect]) loadHTMLString:html_string
baseURL:base_url];
[web_view_controller_ loadHTMLString:html_string baseURL:base_url];
EXPECT_OCMOCK_VERIFY(mock_web_view_);
}
// Tests that CRWWKSimpleWebViewControllerTest correctly calls
// |shouldStartLoadWithRequest:| on the delegate when a navigation delegate
// callback is recieved.
// TODO(shreyasv): Revisit this test if mockHTTPServer is moved to
// ios_web_unittests.
TEST_F(CRWWKSimpleWebViewControllerTest, ShouldStartLoad) {
NSURLRequest* request = [NSURLRequest requestWithURL:
[NSURL URLWithString:@"http://google.com"]];
base::scoped_nsobject<WKNavigationAction> navigation_action(
[[OCMockObject mockForClass:[WKNavigationAction class]] retain]);
[[[static_cast<OCMockObject*>(navigation_action.get()) stub]
andReturn:request] request];
[[mock_delegate_ expect] simpleWebViewController:web_view_controller_
shouldStartLoadWithRequest:request];
[static_cast<id<WKNavigationDelegate>>(web_view_controller_.get())
webView:mock_web_view_
decidePolicyForNavigationAction:navigation_action
decisionHandler:^void(WKNavigationActionPolicy){}];
EXPECT_OCMOCK_VERIFY(mock_delegate_);
}
// Tests that |shouldStartLoadWithRequest:| YES decision by the delegate is
// respected by the CRWSWKimpleWebViewController
TEST_F(CRWWKSimpleWebViewControllerTest, ShouldStartLoadRespectedYes) {
TestShouldStartLoadRespected(YES);
}
// Tests that |shouldStartLoadWithRequest:| NO decision by the delegate is
// respected by the CRWSWKimpleWebViewController
TEST_F(CRWWKSimpleWebViewControllerTest, ShouldStartLoadRespectedNo) {
TestShouldStartLoadRespected(NO);
}
// Tests that |titleMayHaveChanged:| is correctly called on the delegate.
TEST_F(CRWWKSimpleWebViewControllerTest, TitleMayHaveChanged) {
base::scoped_nsobject<WKWebView> web_view(
web::CreateWKWebView(CGRectZero, GetBrowserState()));
base::scoped_nsobject<WKWebView> mock_web_view(
[[OCMockObject partialMockForObject:web_view] retain]);
web_view_controller_.reset(
[[CRWWKSimpleWebViewController alloc] initWithWKWebView:mock_web_view]);
[web_view_controller_ setDelegate:mock_delegate_];
[[mock_delegate_ expect] simpleWebViewController:web_view_controller_
titleMayHaveChanged:@"John Mayer"];
// Simulate a KVO callback.
[web_view willChangeValueForKey:@"title"];
[[[static_cast<OCMockObject*>(mock_web_view.get()) stub]
andReturn:@"John Mayer"] title];
[web_view didChangeValueForKey:@"title"];
EXPECT_OCMOCK_VERIFY(mock_delegate_);
}
// Tests correct JavaScript evaluation.
TEST_F(CRWWKSimpleWebViewControllerTest, JavaScriptEvaluation) {
NSString* const kTestResult = @"result";
NSError* const test_error = [NSError errorWithDomain:@"" code:0 userInfo:nil];
id run_completion_handler = ^(NSInvocation* invocation) {
void(^completionHandler)(id, NSError*);
[invocation getArgument:&completionHandler atIndex:3];
completionHandler(kTestResult, test_error);
};
NSString* const kTestScript = @"script";
[[[mock_web_view_ stub] andDo:run_completion_handler]
evaluateJavaScript:kTestScript completionHandler:[OCMArg isNotNil]];
__block bool evaluation_completed = false;
id completion_handler = ^(NSString* result, NSError* error) {
evaluation_completed = true;
EXPECT_NSEQ(kTestResult, result);
EXPECT_NSEQ(test_error, error);
};
[web_view_controller_ evaluateJavaScript:kTestScript
stringResultHandler:completion_handler];
base::test::ios::WaitUntilCondition(^bool() {
return evaluation_completed;
});
EXPECT_OCMOCK_VERIFY(mock_web_view_);
}
} // namespace
......@@ -7,7 +7,6 @@
#import <UIKit/UIKit.h>
@protocol CRWSimpleWebViewController;
@class WKWebView;
@class WKWebViewConfiguration;
......@@ -51,12 +50,6 @@ WKWebView* CreateWKWebView(CGRect frame,
// crbug.com/480507
NSUInteger GetActiveWKWebViewsCount();
// Returns a CRWSimpleWebViewController for managing/showing a web view.
// Note: Callers are responsible for releasing the CRWSimpleWebViewController.
id<CRWSimpleWebViewController> CreateSimpleWebViewController(
CGRect frame,
BrowserState* browser_state);
#if !defined(NDEBUG)
// Returns true if the creation of web views using alloc, init has been allowed
// by the embedder.
......
......@@ -18,7 +18,6 @@
#import "ios/web/public/web_view_counter.h"
#import "ios/web/public/web_view_creation_util.h"
#import "ios/web/weak_nsobject_counter.h"
#import "ios/web/web_state/ui/crw_wk_simple_web_view_controller.h"
#import "ios/web/web_state/ui/wk_web_view_configuration_provider.h"
#import "ios/web/web_view_counter_impl.h"
......@@ -182,15 +181,6 @@ NSUInteger GetActiveWKWebViewsCount() {
#endif
}
id<CRWSimpleWebViewController> CreateSimpleWebViewController(
CGRect frame,
BrowserState* browser_state) {
DCHECK(web::BrowsingDataPartition::IsSynchronized());
base::scoped_nsobject<WKWebView> web_view(
web::CreateWKWebView(frame, browser_state));
return [[CRWWKSimpleWebViewController alloc] initWithWKWebView:web_view];
}
#if !defined(NDEBUG)
bool IsWebViewAllocInitAllowed() {
static dispatch_once_t once_token = 0;
......
......@@ -16,7 +16,6 @@
#include "ios/web/public/test/test_web_thread.h"
#import "ios/web/public/web_view_creation_util.h"
#import "ios/web/test/web_test.h"
#import "ios/web/web_state/ui/crw_simple_web_view_controller.h"
#import "ios/web/web_state/ui/crw_static_file_web_view.h"
#import "ios/web/web_state/ui/wk_web_view_configuration_provider.h"
#include "testing/gmock/include/gmock/gmock.h"
......@@ -140,14 +139,5 @@ TEST_F(WebViewCreationUtilsTest, GetActiveWKWebViewsCount) {
#endif // defined(NDEBUG)
// Tests web::CreateSimpleWebViewController returns a CRWSimpleWebViewController
// instance with a web view.
TEST_F(WebViewCreationUtilsTest, CreateSimpleWebViewController) {
base::scoped_nsprotocol<id<CRWSimpleWebViewController>>
simpleWebViewController(
CreateSimpleWebViewController(CGRectZero, GetBrowserState()));
EXPECT_TRUE([simpleWebViewController view]);
}
} // namespace
} // namespace web
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment