OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h" | 5 #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h" |
6 | 6 |
7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "base/ios/ios_util.h" | 11 #include "base/ios/ios_util.h" |
12 #include "base/mac/scoped_nsobject.h" | |
13 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
14 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
15 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" | 14 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
16 #import "ios/chrome/browser/ui/toolbar/test_toolbar_model_ios.h" | 15 #import "ios/chrome/browser/ui/toolbar/test_toolbar_model_ios.h" |
17 #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller_private.h" | 16 #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller_private.h" |
18 #include "ios/chrome/browser/ui/ui_util.h" | 17 #include "ios/chrome/browser/ui/ui_util.h" |
19 #include "ios/chrome/test/block_cleanup_test.h" | 18 #include "ios/chrome/test/block_cleanup_test.h" |
20 #include "ios/web/public/test/test_web_thread_bundle.h" | 19 #include "ios/web/public/test/test_web_thread_bundle.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "testing/gtest_mac.h" | 21 #include "testing/gtest_mac.h" |
23 #import "third_party/ocmock/OCMock/OCMock.h" | 22 #import "third_party/ocmock/OCMock/OCMock.h" |
24 | 23 |
| 24 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 25 #error "This file requires ARC support." |
| 26 #endif |
| 27 |
25 @interface UIView (SubViewTesting) | 28 @interface UIView (SubViewTesting) |
26 - (NSMutableArray*)allSubviews; | 29 - (NSMutableArray*)allSubviews; |
27 @end | 30 @end |
28 | 31 |
29 @implementation UIView (SubViewTesting) | 32 @implementation UIView (SubViewTesting) |
30 - (NSMutableArray*)allSubviews { | 33 - (NSMutableArray*)allSubviews { |
31 NSMutableArray* views = [NSMutableArray array]; | 34 NSMutableArray* views = [NSMutableArray array]; |
32 [views addObject:self]; | 35 [views addObject:self]; |
33 for (UIView* subview in [self subviews]) { | 36 for (UIView* subview in [self subviews]) { |
34 [views addObjectsFromArray:[subview allSubviews]]; | 37 [views addObjectsFromArray:[subview allSubviews]]; |
(...skipping 27 matching lines...) Expand all Loading... |
62 // fine if a temporary variable is used. | 65 // fine if a temporary variable is used. |
63 ToolbarModelIOS* model_for_mock = toolbar_model_ios_.get(); | 66 ToolbarModelIOS* model_for_mock = toolbar_model_ios_.get(); |
64 id delegate = | 67 id delegate = |
65 [OCMockObject niceMockForProtocol:@protocol(WebToolbarDelegate)]; | 68 [OCMockObject niceMockForProtocol:@protocol(WebToolbarDelegate)]; |
66 [[[delegate stub] andReturnValue:OCMOCK_VALUE(model_for_mock)] | 69 [[[delegate stub] andReturnValue:OCMOCK_VALUE(model_for_mock)] |
67 toolbarModelIOS]; | 70 toolbarModelIOS]; |
68 | 71 |
69 id urlLoader = [OCMockObject niceMockForProtocol:@protocol(UrlLoader)]; | 72 id urlLoader = [OCMockObject niceMockForProtocol:@protocol(UrlLoader)]; |
70 | 73 |
71 // Create the WebToolbarController using the test objects. | 74 // Create the WebToolbarController using the test objects. |
72 web_toolbar_controller_.reset([[WebToolbarController alloc] | 75 web_toolbar_controller_ = [[WebToolbarController alloc] |
73 initWithDelegate:delegate | 76 initWithDelegate:delegate |
74 urlLoader:urlLoader | 77 urlLoader:urlLoader |
75 browserState:chrome_browser_state_.get() | 78 browserState:chrome_browser_state_.get() |
76 preloadProvider:nil]); | 79 preloadProvider:nil]; |
77 [web_toolbar_controller_ setUnitTesting:YES]; | 80 [web_toolbar_controller_ setUnitTesting:YES]; |
78 } | 81 } |
79 void TearDown() override { | 82 void TearDown() override { |
80 web_toolbar_controller_.reset(); | 83 web_toolbar_controller_ = nil; |
81 BlockCleanupTest::TearDown(); | 84 BlockCleanupTest::TearDown(); |
82 } | 85 } |
83 | 86 |
84 web::TestWebThreadBundle thread_bundle_; | 87 web::TestWebThreadBundle thread_bundle_; |
85 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; | 88 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; |
86 TestToolbarModel* toolbar_model_; // weak. Owned by toolbar_model_ios_. | 89 TestToolbarModel* toolbar_model_; // weak. Owned by toolbar_model_ios_. |
87 std::unique_ptr<TestToolbarModelIOS> toolbar_model_ios_; | 90 std::unique_ptr<TestToolbarModelIOS> toolbar_model_ios_; |
88 base::scoped_nsobject<WebToolbarController> web_toolbar_controller_; | 91 WebToolbarController* web_toolbar_controller_; |
89 }; | 92 }; |
90 | 93 |
91 TEST_F(WebToolbarControllerTest, TestUpdateToolbar_NavigationButtonsEnabled) { | 94 TEST_F(WebToolbarControllerTest, TestUpdateToolbar_NavigationButtonsEnabled) { |
92 EXPECT_FALSE([web_toolbar_controller_ isForwardButtonEnabled]); | 95 EXPECT_FALSE([web_toolbar_controller_ isForwardButtonEnabled]); |
93 EXPECT_FALSE([web_toolbar_controller_ isBackButtonEnabled]); | 96 EXPECT_FALSE([web_toolbar_controller_ isBackButtonEnabled]); |
94 toolbar_model_ios_->set_can_go_back(true); | 97 toolbar_model_ios_->set_can_go_back(true); |
95 toolbar_model_ios_->set_can_go_forward(true); | 98 toolbar_model_ios_->set_can_go_forward(true); |
96 [web_toolbar_controller_ updateToolbarState]; | 99 [web_toolbar_controller_ updateToolbarState]; |
97 EXPECT_TRUE([web_toolbar_controller_ isForwardButtonEnabled]); | 100 EXPECT_TRUE([web_toolbar_controller_ isForwardButtonEnabled]); |
98 EXPECT_TRUE([web_toolbar_controller_ isBackButtonEnabled]); | 101 EXPECT_TRUE([web_toolbar_controller_ isBackButtonEnabled]); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 CGRect initialRect = initialIt->second; | 215 CGRect initialRect = initialIt->second; |
213 CGRect layoutRect = postLayoutIt->second; | 216 CGRect layoutRect = postLayoutIt->second; |
214 EXPECT_EQ(initialRect.origin.x, layoutRect.origin.x); | 217 EXPECT_EQ(initialRect.origin.x, layoutRect.origin.x); |
215 EXPECT_EQ(initialRect.origin.y, layoutRect.origin.y); | 218 EXPECT_EQ(initialRect.origin.y, layoutRect.origin.y); |
216 EXPECT_EQ(initialRect.size.width, layoutRect.size.width); | 219 EXPECT_EQ(initialRect.size.width, layoutRect.size.width); |
217 EXPECT_EQ(initialRect.size.height, layoutRect.size.height); | 220 EXPECT_EQ(initialRect.size.height, layoutRect.size.height); |
218 initialIt++; | 221 initialIt++; |
219 } | 222 } |
220 } | 223 } |
221 } // namespace | 224 } // namespace |
OLD | NEW |