diff options
author | shreyasv <shreyasv@chromium.org> | 2016-03-16 13:58:56 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-16 21:00:50 +0000 |
commit | 4caf5d6fb5d3ab9e8d53db06350cc7a45a6f3fa0 (patch) | |
tree | f4489d52e39b7b6426ca17ffe2f655229689ee70 /ios/web/web_state | |
parent | 376c69d2c253569a9404c750cdd2b0a93eebedac (diff) | |
download | chromium_src-4caf5d6fb5d3ab9e8d53db06350cc7a45a6f3fa0.zip chromium_src-4caf5d6fb5d3ab9e8d53db06350cc7a45a6f3fa0.tar.gz chromium_src-4caf5d6fb5d3ab9e8d53db06350cc7a45a6f3fa0.tar.bz2 |
Removing CRWUISimpleWebViewController
No longer needed.
BUG=579697
Review URL: https://codereview.chromium.org/1804273002
Cr-Commit-Position: refs/heads/master@{#381539}
Diffstat (limited to 'ios/web/web_state')
3 files changed, 0 insertions, 238 deletions
diff --git a/ios/web/web_state/ui/crw_ui_simple_web_view_controller.h b/ios/web/web_state/ui/crw_ui_simple_web_view_controller.h deleted file mode 100644 index 036eb52..0000000 --- a/ios/web/web_state/ui/crw_ui_simple_web_view_controller.h +++ /dev/null @@ -1,21 +0,0 @@ -// 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_UI_SIMPLE_WEB_VIEW_CONTROLLER_H_ -#define IOS_WEB_WEB_STATE_UI_CRW_UI_SIMPLE_WEB_VIEW_CONTROLLER_H_ - -#import <UIKit/UIKit.h> - -#import "ios/web/web_state/ui/crw_simple_web_view_controller.h" - -// A CRWSimpleWebViewController implentation backed by an UIWebView. -@interface CRWUISimpleWebViewController : NSObject<CRWSimpleWebViewController> - -// Designated initializer. Initializes a new view controller backed by a -// UIWebView. -- (instancetype)initWithUIWebView:(UIWebView*)webView; - -@end - -#endif // IOS_WEB_WEB_STATE_UI_CRW_UI_SIMPLE_WEB_VIEW_CONTROLLER_H_ diff --git a/ios/web/web_state/ui/crw_ui_simple_web_view_controller.mm b/ios/web/web_state/ui/crw_ui_simple_web_view_controller.mm deleted file mode 100644 index 7d12883..0000000 --- a/ios/web/web_state/ui/crw_ui_simple_web_view_controller.mm +++ /dev/null @@ -1,106 +0,0 @@ -// 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_ui_simple_web_view_controller.h" - -#include "base/ios/weak_nsobject.h" -#import "base/logging.h" -#import "base/mac/scoped_nsobject.h" - -@interface CRWUISimpleWebViewController () <UIWebViewDelegate> -@end - -@implementation CRWUISimpleWebViewController { - base::scoped_nsobject<UIWebView> _webView; - base::WeakNSProtocol<id<CRWSimpleWebViewControllerDelegate>> _delegate; -} - -- (instancetype)initWithUIWebView:(UIWebView*)webView { - self = [super init]; - if (self) { - DCHECK(webView); - _webView.reset([webView retain]); - [_webView setDelegate:self]; - } - return self; -} - -- (void)dealloc { - [_webView setDelegate:nil]; - [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 stringByEvaluatingJavaScriptFromString:@"document.title"]; -} - -- (void)loadRequest:(NSURLRequest*)request { - [_webView loadRequest:request]; -} - -- (void)loadHTMLString:(NSString*)html baseURL:(NSURL*)baseURL { - [_webView loadHTMLString:html baseURL:baseURL]; -} - -- (void)setDelegate:(id<CRWSimpleWebViewControllerDelegate>)delegate { - _delegate.reset(delegate); -} - -- (id<CRWSimpleWebViewControllerDelegate>)delegate { - return _delegate.get(); -} - -- (void)loadPDFAtFilePath:(NSString*)filePath { - DCHECK([[NSFileManager defaultManager] fileExistsAtPath:filePath]); - NSData* data = [NSData dataWithContentsOfFile:filePath]; - [_webView loadData:data - MIMEType:@"application/pdf" - textEncodingName:@"utf-8" - baseURL:[NSURL URLWithString:@""]]; -} - -- (void)evaluateJavaScript:(NSString*)script - stringResultHandler:(web::JavaScriptCompletion)handler { - web::EvaluateJavaScript(_webView, script, handler); -} - -#pragma mark - -#pragma mark UIWebViewDelegateMethods - -- (BOOL)webView:(UIWebView*)webView - shouldStartLoadWithRequest:(NSURLRequest*)request - navigationType:(UIWebViewNavigationType)navigationType { - if ([_delegate respondsToSelector:@selector(simpleWebViewController: - shouldStartLoadWithRequest:)]) { - return [_delegate simpleWebViewController:self - shouldStartLoadWithRequest:request]; - } - // By default all loads are allowed. - return YES; -} - -- (void)webViewDidFinishLoad:(UIWebView*)webView { - if (![_delegate respondsToSelector:@selector(simpleWebViewController: - titleMayHaveChanged:)]) { - return; - } - [_delegate simpleWebViewController:self titleMayHaveChanged:self.title]; -} - -@end diff --git a/ios/web/web_state/ui/crw_ui_simple_web_view_controller_unittest.mm b/ios/web/web_state/ui/crw_ui_simple_web_view_controller_unittest.mm deleted file mode 100644 index 02adc98..0000000 --- a/ios/web/web_state/ui/crw_ui_simple_web_view_controller_unittest.mm +++ /dev/null @@ -1,111 +0,0 @@ -// 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_ui_simple_web_view_controller.h" - -#import <UIKit/UIKit.h> - -#import "base/mac/scoped_nsobject.h" -#import "base/test/ios/wait_util.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "testing/gtest_mac.h" -#include "testing/platform_test.h" -#import "third_party/ocmock/OCMock/OCMock.h" -#include "third_party/ocmock/gtest_support.h" - -class CRWUISimpleWebViewControllerTest : public PlatformTest { - protected: - void SetUp() override { - mock_web_view_.reset( - [[OCMockObject niceMockForClass:[UIWebView class]] retain]); - simple_web_view_controller_.reset([[CRWUISimpleWebViewController alloc] - initWithUIWebView:mock_web_view_]); - } - base::scoped_nsobject<id> mock_web_view_; - base::scoped_nsobject<CRWUISimpleWebViewController> - simple_web_view_controller_; -}; - -// Tests to make sure a CRWUISimpleWebViewController correctly sets the backing -// UIWebView and its delegate. -TEST_F(CRWUISimpleWebViewControllerTest, Basic) { - EXPECT_EQ(mock_web_view_.get(), [simple_web_view_controller_ view]); -} - -// Tests that CRWUISimpleWebViewController can correctly retrieve the title from -// the underlying UIWebView. -// TODO(shreyasv): Revisit this test if mock HTTP server works for unit tests. -TEST_F(CRWUISimpleWebViewControllerTest, Title) { - [[[mock_web_view_ stub] andReturn:@"Steven Wilson"] - stringByEvaluatingJavaScriptFromString:@"document.title"]; - EXPECT_NSEQ(@"Steven Wilson", [simple_web_view_controller_ title]); -} - -// Tests that CRWUISimpleWebViewController correctly reloads from the underlying -// UIWebView. -TEST_F(CRWUISimpleWebViewControllerTest, Reload) { - [[mock_web_view_ expect] reload]; - [simple_web_view_controller_ reload]; - EXPECT_OCMOCK_VERIFY(mock_web_view_); -} - -// Tests that CRWUISimpleWebViewController correctly returns the WebView's -// scroll view. -TEST_F(CRWUISimpleWebViewControllerTest, ScrollView) { - base::scoped_nsobject<UIScrollView> scrollView([[UIScrollView alloc] init]); - [[[mock_web_view_ stub] andReturn:scrollView] scrollView]; - EXPECT_EQ(scrollView, [simple_web_view_controller_ scrollView]); -} - -// Tests that CRWUISimpleWebViewController correctly loads a request from the -// underlying UIWebView. -TEST_F(CRWUISimpleWebViewControllerTest, LoadRequest) { - NSURLRequest* request = - [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com"]]; - [[mock_web_view_ expect] loadRequest:request]; - [simple_web_view_controller_ loadRequest:request]; - EXPECT_OCMOCK_VERIFY(mock_web_view_); -} - -// Tests that CRWUISimpleWebViewControllerDelegate is correctly informed of a -// load request. -TEST_F(CRWUISimpleWebViewControllerTest, ShouldStartLoad) { - base::scoped_nsobject<id> mockDelegate([[OCMockObject - niceMockForProtocol:@protocol(CRWSimpleWebViewControllerDelegate)] - retain]); - NSURLRequest* request = - [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com"]]; - [[mockDelegate expect] simpleWebViewController:simple_web_view_controller_ - shouldStartLoadWithRequest:request]; - - // Simulate a UIWebViewDelegate callback. - [static_cast<id<UIWebViewDelegate>>(simple_web_view_controller_.get()) - webView:mock_web_view_ - shouldStartLoadWithRequest:request - navigationType:UIWebViewNavigationTypeOther]; - - EXPECT_OCMOCK_VERIFY(mock_web_view_); -} - -// Tests correct JavaScript evaluation. -TEST_F(CRWUISimpleWebViewControllerTest, JavaScriptEvaluation) { - NSString* const kTestScript = @"script"; - NSString* const kTestResult = @"result"; - [[[mock_web_view_ stub] andReturn:kTestResult] - stringByEvaluatingJavaScriptFromString:kTestScript]; - - __block bool evaluation_completed = false; - id completion_handler = ^(NSString* result, NSError* error) { - evaluation_completed = true; - EXPECT_NSEQ(kTestResult, result); - EXPECT_EQ(nil, error); - }; - [simple_web_view_controller_ evaluateJavaScript:kTestScript - stringResultHandler:completion_handler]; - base::test::ios::WaitUntilCondition(^bool() { - return evaluation_completed; - }); - - EXPECT_OCMOCK_VERIFY(mock_web_view_); -} |