diff options
author | stkhapugin <stkhapugin@chromium.org> | 2015-06-25 02:21:16 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-25 09:22:22 +0000 |
commit | b4eca4c1c4f0d62f77d48a73341eb8d1fa752c77 (patch) | |
tree | 6ce76a74ae7bafefaeb34aaccf99b74d43f1c0ad /ios | |
parent | 85432b5cfa605b14fa5690a43432a1374ef2edef (diff) | |
download | chromium_src-b4eca4c1c4f0d62f77d48a73341eb8d1fa752c77.zip chromium_src-b4eca4c1c4f0d62f77d48a73341eb8d1fa752c77.tar.gz chromium_src-b4eca4c1c4f0d62f77d48a73341eb8d1fa752c77.tar.bz2 |
NativeContentController cleanup
Modernized native_content_controller.h to have a designated initializer,
hidden the ivars.
Updated implementation to support the designated initializer.
Added some simple unit tests for this class.
BUG=None
Review URL: https://codereview.chromium.org/1211533002
Cr-Commit-Position: refs/heads/master@{#336110}
Diffstat (limited to 'ios')
-rw-r--r-- | ios/chrome/browser/ui/native_content_controller.h | 23 | ||||
-rw-r--r-- | ios/chrome/browser/ui/native_content_controller.mm | 17 | ||||
-rw-r--r-- | ios/chrome/browser/ui/native_content_controller_test.xib | 27 | ||||
-rw-r--r-- | ios/chrome/browser/ui/native_content_controller_unittest.mm | 50 | ||||
-rw-r--r-- | ios/chrome/ios_chrome_tests.gyp | 4 |
5 files changed, 97 insertions, 24 deletions
diff --git a/ios/chrome/browser/ui/native_content_controller.h b/ios/chrome/browser/ui/native_content_controller.h index 3bca461f..18bdaaa 100644 --- a/ios/chrome/browser/ui/native_content_controller.h +++ b/ios/chrome/browser/ui/native_content_controller.h @@ -8,8 +8,8 @@ #import <Foundation/Foundation.h> #import "ios/web/public/web_state/ui/crw_native_content.h" -#include "url/gurl.h" +class GURL; @class UIView; // Abstract base class for controllers that implement the behavior for native @@ -17,30 +17,21 @@ // |view| from the view hierarchy when it is destroyed. Subclasses are // responsible for setting the view (usually through loading a nib) and the // page title. -@interface NativeContentController : NSObject<CRWNativeContent> { - @protected - UIView* _view; // Top-level view. - NSString* _title; - GURL _url; -} +@interface NativeContentController : NSObject<CRWNativeContent> +// Top-level view. @property(nonatomic, retain) IBOutlet UIView* view; @property(nonatomic, copy) NSString* title; @property(nonatomic, readonly, assign) const GURL& url; -// Initializer that attempts to load the nib specified in |nibName| for -// |url|, which may be nil. -- (instancetype)initWithNibName:(NSString*)nibName url:(const GURL&)url; +// Initializer that attempts to load the nib specified in |nibName|, which may +// be nil. The |url| is the url to be loaded. +- (instancetype)initWithNibName:(NSString*)nibName + url:(const GURL&)url NS_DESIGNATED_INITIALIZER; // Initializer with the |url| to be loaded. - (instancetype)initWithURL:(const GURL&)url; -// Called when memory is low and this is not the foreground tab. Release -// anything (such as views) that can be easily re-created to free up RAM. -// Subclasses that override this method should always call -// [super handleLowMemory]. -- (void)handleLowMemory; - @end #endif // IOS_CHROME_BROWSER_UI_NATIVE_CONTENT_CONTROLLER_H_ diff --git a/ios/chrome/browser/ui/native_content_controller.mm b/ios/chrome/browser/ui/native_content_controller.mm index 0d40cfc..0d30432 100644 --- a/ios/chrome/browser/ui/native_content_controller.mm +++ b/ios/chrome/browser/ui/native_content_controller.mm @@ -11,6 +11,7 @@ #include "base/mac/objc_property_releaser.h" @implementation NativeContentController { + GURL _url; base::mac::ObjCPropertyReleaser _propertyReleaser_NativeContentController; } @@ -23,20 +24,18 @@ if (self) { _propertyReleaser_NativeContentController.Init( self, [NativeContentController class]); - [base::mac::FrameworkBundle() loadNibNamed:nibName owner:self options:nil]; + if (nibName.length) { + [base::mac::FrameworkBundle() loadNibNamed:nibName + owner:self + options:nil]; + } _url = url; } return self; } - (instancetype)initWithURL:(const GURL&)url { - self = [super init]; - if (self) { - _propertyReleaser_NativeContentController.Init( - self, [NativeContentController class]); - _url = url; - } - return self; + return [self initWithNibName:nil url:url]; } - (void)dealloc { @@ -44,6 +43,8 @@ [super dealloc]; } +#pragma mark CRWNativeContent + - (void)handleLowMemory { // TODO(pinkerton): What should this do? Toss the view? } diff --git a/ios/chrome/browser/ui/native_content_controller_test.xib b/ios/chrome/browser/ui/native_content_controller_test.xib new file mode 100644 index 0000000..e868fe6 --- /dev/null +++ b/ios/chrome/browser/ui/native_content_controller_test.xib @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7702" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES"> + <dependencies> + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7701"/> + </dependencies> + <objects> + <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="NativeContentController"> + <connections> + <outlet property="view" destination="iN0-l3-epB" id="nc9-et-tHX"/> + </connections> + </placeholder> + <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> + <view contentMode="scaleToFill" id="iN0-l3-epB"> + <rect key="frame" x="0.0" y="0.0" width="600" height="600"/> + <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> + <subviews> + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="test pass" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="DgZ-eM-3WO"> + <rect key="frame" x="231" y="166" width="42" height="21"/> + <fontDescription key="fontDescription" type="system" pointSize="17"/> + <color key="textColor" cocoaTouchSystemColor="darkTextColor"/> + <nil key="highlightedColor"/> + </label> + </subviews> + <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> + </view> + </objects> +</document> diff --git a/ios/chrome/browser/ui/native_content_controller_unittest.mm b/ios/chrome/browser/ui/native_content_controller_unittest.mm new file mode 100644 index 0000000..707c0fd --- /dev/null +++ b/ios/chrome/browser/ui/native_content_controller_unittest.mm @@ -0,0 +1,50 @@ +// Copyright 2015 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. + +#include "base/logging.h" +#include "base/mac/scoped_nsobject.h" +#import "ios/chrome/browser/ui/native_content_controller.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "url/gurl.h" + +namespace { + +TEST(NativeContentControllerTest, TestInitWithURL) { + GURL url("http://foo.bar.com"); + base::scoped_nsobject<NativeContentController> controller( + [[NativeContentController alloc] initWithURL:url]); + EXPECT_EQ(url, controller.get().url); + + // There is no default view without a nib. + EXPECT_EQ(nil, controller.get().view); +} + +TEST(NativeContentControllerTest, TestInitWithEmptyNibNameAndURL) { + GURL url("http://foo.bar.com"); + base::scoped_nsobject<NativeContentController> controller( + [[NativeContentController alloc] initWithNibName:nil url:url]); + EXPECT_EQ(url, controller.get().url); + + // There is no default view without a nib. + EXPECT_EQ(nil, controller.get().view); +} + +TEST(NativeContentControllerTest, TestInitWithNibAndURL) { + GURL url("http://foo.bar.com"); + NSString* nibName = @"native_content_controller_test"; + base::scoped_nsobject<NativeContentController> controller( + [[NativeContentController alloc] initWithNibName:nibName url:url]); + EXPECT_EQ(url, controller.get().url); + + // Check that view is loaded from nib. + EXPECT_NE(nil, controller.get().view); + UIView* view = controller.get().view; + EXPECT_EQ(1u, view.subviews.count); + EXPECT_NE(nil, [view.subviews firstObject]); + UILabel* label = [view.subviews firstObject]; + EXPECT_TRUE([label isKindOfClass:[UILabel class]]); + EXPECT_TRUE([label.text isEqualToString:@"test pass"]); +} + +} // namespace diff --git a/ios/chrome/ios_chrome_tests.gyp b/ios/chrome/ios_chrome_tests.gyp index 4a23a08..4c14d68 100644 --- a/ios/chrome/ios_chrome_tests.gyp +++ b/ios/chrome/ios_chrome_tests.gyp @@ -26,6 +26,9 @@ 'ios_chrome.gyp:ios_chrome_common', 'ios_chrome_test_support', ], + 'mac_bundle_resources': [ + 'browser/ui/native_content_controller_test.xib' + ], 'sources': [ 'app/safe_mode_util_unittest.cc', 'browser/chrome_url_util_unittest.mm', @@ -44,6 +47,7 @@ 'browser/snapshots/snapshots_util_unittest.mm', 'browser/translate/translate_service_ios_unittest.cc', 'browser/ui/commands/set_up_for_testing_command_unittest.mm', + 'browser/ui/native_content_controller_unittest.mm', 'browser/ui/ui_util_unittest.mm', 'browser/ui/uikit_ui_util_unittest.mm', 'common/string_util_unittest.mm', |