| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/mac/scoped_nsobject.h" | |
| 7 #import "ios/chrome/browser/ui/native_content_controller.h" | 6 #import "ios/chrome/browser/ui/native_content_controller.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "url/gurl.h" | 8 #include "url/gurl.h" |
| 10 | 9 |
| 10 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 11 #error "This file requires ARC support." |
| 12 #endif |
| 13 |
| 11 namespace { | 14 namespace { |
| 12 | 15 |
| 13 TEST(NativeContentControllerTest, TestInitWithURL) { | 16 TEST(NativeContentControllerTest, TestInitWithURL) { |
| 14 GURL url("http://foo.bar.com"); | 17 GURL url("http://foo.bar.com"); |
| 15 base::scoped_nsobject<NativeContentController> controller( | 18 NativeContentController* controller = |
| 16 [[NativeContentController alloc] initWithURL:url]); | 19 [[NativeContentController alloc] initWithURL:url]; |
| 17 EXPECT_EQ(url, controller.get().url); | 20 EXPECT_EQ(url, controller.url); |
| 18 | 21 |
| 19 // There is no default view without a nib. | 22 // There is no default view without a nib. |
| 20 EXPECT_EQ(nil, controller.get().view); | 23 EXPECT_EQ(nil, controller.view); |
| 21 } | 24 } |
| 22 | 25 |
| 23 TEST(NativeContentControllerTest, TestInitWithEmptyNibNameAndURL) { | 26 TEST(NativeContentControllerTest, TestInitWithEmptyNibNameAndURL) { |
| 24 GURL url("http://foo.bar.com"); | 27 GURL url("http://foo.bar.com"); |
| 25 base::scoped_nsobject<NativeContentController> controller( | 28 NativeContentController* controller = |
| 26 [[NativeContentController alloc] initWithNibName:nil url:url]); | 29 [[NativeContentController alloc] initWithNibName:nil url:url]; |
| 27 EXPECT_EQ(url, controller.get().url); | 30 EXPECT_EQ(url, controller.url); |
| 28 | 31 |
| 29 // There is no default view without a nib. | 32 // There is no default view without a nib. |
| 30 EXPECT_EQ(nil, controller.get().view); | 33 EXPECT_EQ(nil, controller.view); |
| 31 } | 34 } |
| 32 | 35 |
| 33 TEST(NativeContentControllerTest, TestInitWithNibAndURL) { | 36 TEST(NativeContentControllerTest, TestInitWithNibAndURL) { |
| 34 GURL url("http://foo.bar.com"); | 37 GURL url("http://foo.bar.com"); |
| 35 NSString* nibName = @"native_content_controller_test"; | 38 NSString* nibName = @"native_content_controller_test"; |
| 36 base::scoped_nsobject<NativeContentController> controller( | 39 NativeContentController* controller = |
| 37 [[NativeContentController alloc] initWithNibName:nibName url:url]); | 40 [[NativeContentController alloc] initWithNibName:nibName url:url]; |
| 38 EXPECT_EQ(url, controller.get().url); | 41 EXPECT_EQ(url, controller.url); |
| 39 | 42 |
| 40 // Check that view is loaded from nib. | 43 // Check that view is loaded from nib. |
| 41 EXPECT_NE(nil, controller.get().view); | 44 EXPECT_NE(nil, controller.view); |
| 42 UIView* view = controller.get().view; | 45 UIView* view = controller.view; |
| 43 EXPECT_EQ(1u, view.subviews.count); | 46 EXPECT_EQ(1u, view.subviews.count); |
| 44 EXPECT_NE(nil, [view.subviews firstObject]); | 47 EXPECT_NE(nil, [view.subviews firstObject]); |
| 45 UILabel* label = [view.subviews firstObject]; | 48 UILabel* label = [view.subviews firstObject]; |
| 46 EXPECT_TRUE([label isKindOfClass:[UILabel class]]); | 49 EXPECT_TRUE([label isKindOfClass:[UILabel class]]); |
| 47 EXPECT_TRUE([label.text isEqualToString:@"test pass"]); | 50 EXPECT_TRUE([label.text isEqualToString:@"test pass"]); |
| 48 } | 51 } |
| 49 | 52 |
| 50 } // namespace | 53 } // namespace |
| OLD | NEW |