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
3 // found in the LICENSE file.
5 #include "base/logging.h"
6 #include "base/mac/scoped_nsobject.h"
7 #import "ios/chrome/browser/ui/native_content_controller.h"
8 #include "testing/gtest/include/gtest/gtest.h"
13 TEST(NativeContentControllerTest, TestInitWithURL) {
14 GURL url("http://foo.bar.com");
15 base::scoped_nsobject<NativeContentController> controller(
16 [[NativeContentController alloc] initWithURL:url]);
17 EXPECT_EQ(url, controller.get().url);
19 // There is no default view without a nib.
20 EXPECT_EQ(nil, controller.get().view);
23 TEST(NativeContentControllerTest, TestInitWithEmptyNibNameAndURL) {
24 GURL url("http://foo.bar.com");
25 base::scoped_nsobject<NativeContentController> controller(
26 [[NativeContentController alloc] initWithNibName:nil url:url]);
27 EXPECT_EQ(url, controller.get().url);
29 // There is no default view without a nib.
30 EXPECT_EQ(nil, controller.get().view);
33 TEST(NativeContentControllerTest, TestInitWithNibAndURL) {
34 GURL url("http://foo.bar.com");
35 NSString* nibName = @"native_content_controller_test";
36 base::scoped_nsobject<NativeContentController> controller(
37 [[NativeContentController alloc] initWithNibName:nibName url:url]);
38 EXPECT_EQ(url, controller.get().url);
40 // Check that view is loaded from nib.
41 EXPECT_NE(nil, controller.get().view);
42 UIView* view = controller.get().view;
43 EXPECT_EQ(1u, view.subviews.count);
44 EXPECT_NE(nil, [view.subviews firstObject]);
45 UILabel* label = [view.subviews firstObject];
46 EXPECT_TRUE([label isKindOfClass:[UILabel class]]);
47 EXPECT_TRUE([label.text isEqualToString:@"test pass"]);