Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: ios/clean/chrome/browser/ui/toolbar/toolbar_mediator_unittest.mm

Issue 2908623004: [ios clean] Toolbar displays total number of tabs. (Closed)
Patch Set: Minor comment changes. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/clean/chrome/browser/ui/toolbar/toolbar_mediator.h" 5 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_mediator.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "ios/chrome/browser/web_state_list/fake_web_state_list_delegate.h"
9 #include "ios/chrome/browser/web_state_list/web_state_list.h"
10 #import "ios/chrome/browser/web_state_list/web_state_list_observer_bridge.h"
8 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_consumer.h" 11 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_consumer.h"
9 #import "ios/shared/chrome/browser/ui/toolbar/toolbar_test_util.h" 12 #import "ios/shared/chrome/browser/ui/toolbar/toolbar_test_util.h"
10 #import "ios/web/public/test/fakes/test_navigation_manager.h" 13 #import "ios/web/public/test/fakes/test_navigation_manager.h"
11 #import "ios/web/public/test/fakes/test_web_state.h" 14 #import "ios/web/public/test/fakes/test_web_state.h"
12 #import "ios/web/public/web_state/web_state_observer_bridge.h" 15 #import "ios/web/public/web_state/web_state_observer_bridge.h"
13 #include "testing/platform_test.h" 16 #include "testing/platform_test.h"
14 #import "third_party/ocmock/OCMock/OCMock.h" 17 #import "third_party/ocmock/OCMock/OCMock.h"
15 #include "third_party/ocmock/gtest_support.h" 18 #include "third_party/ocmock/gtest_support.h"
16 19
17 #if !defined(__has_feature) || !__has_feature(objc_arc) 20 #if !defined(__has_feature) || !__has_feature(objc_arc)
18 #error "This file requires ARC support." 21 #error "This file requires ARC support."
19 #endif 22 #endif
20 23
21 @interface TestToolbarMediator : ToolbarMediator<CRWWebStateObserver> 24 @interface TestToolbarMediator
25 : ToolbarMediator<CRWWebStateObserver, WebStateListObserving>
22 @end 26 @end
23 27
24 @implementation TestToolbarMediator 28 @implementation TestToolbarMediator
25 @end 29 @end
26 30
27 namespace { 31 namespace {
28 32
33 static const int kNumberOfWebStates = 3;
29 static const char kTestUrl[] = "http://www.chromium.org"; 34 static const char kTestUrl[] = "http://www.chromium.org";
30 35
31 class ToolbarMediatorTest : public PlatformTest { 36 class ToolbarMediatorTest : public PlatformTest {
32 public: 37 public:
33 ToolbarMediatorTest() { 38 ToolbarMediatorTest() {
34 std::unique_ptr<ToolbarTestNavigationManager> navigation_manager = 39 std::unique_ptr<ToolbarTestNavigationManager> navigation_manager =
35 base::MakeUnique<ToolbarTestNavigationManager>(); 40 base::MakeUnique<ToolbarTestNavigationManager>();
36 navigation_manager_ = navigation_manager.get(); 41 navigation_manager_ = navigation_manager.get();
37 test_web_state_.SetNavigationManager(std::move(navigation_manager)); 42 test_web_state_.SetNavigationManager(std::move(navigation_manager));
38 test_web_state_.SetLoading(true); 43 test_web_state_.SetLoading(true);
39 mediator_ = [[TestToolbarMediator alloc] init]; 44 mediator_ = [[TestToolbarMediator alloc] init];
40 consumer_ = OCMProtocolMock(@protocol(ToolbarConsumer)); 45 consumer_ = OCMProtocolMock(@protocol(ToolbarConsumer));
41 } 46 }
47 // Explicitly dissconnect the mediator so there won't be any WebStateList
marq (ping after 24h) 2017/05/29 11:04:37 typo: disconnect newline before this comment?
sczs 2017/05/30 00:18:21 Done.
48 // observers when web_state_list_ gets dealloc.
49 ~ToolbarMediatorTest() override { [mediator_ disconnect]; }
marq (ping after 24h) 2017/05/29 11:04:37 I think we only use one-liner method implementatio
sczs 2017/05/30 00:18:21 Done.
marq (ping after 24h) 2017/05/30 09:47:03 Not done?
sczs 2017/05/30 18:14:12 I was pretty sure I had made this change. Now I re
42 50
43 protected: 51 protected:
52 void SetUpWebStateList() {
53 web_state_list_ = base::MakeUnique<WebStateList>(&web_state_list_delegate_);
54 for (int i = 0; i < kNumberOfWebStates; i++) {
55 InsertWebState(i);
56 }
57 }
58
59 void InsertWebState(int index) {
60 auto web_state = base::MakeUnique<web::TestWebState>();
61 GURL url("http://test/" + std::to_string(index));
62 web_state->SetCurrentURL(url);
63 web_state_list_->InsertWebState(index, std::move(web_state));
64 }
65
44 TestToolbarMediator* mediator_; 66 TestToolbarMediator* mediator_;
45 ToolbarTestWebState test_web_state_; 67 ToolbarTestWebState test_web_state_;
46 ToolbarTestNavigationManager* navigation_manager_; 68 ToolbarTestNavigationManager* navigation_manager_;
69 std::unique_ptr<WebStateList> web_state_list_;
70 FakeWebStateListDelegate web_state_list_delegate_;
47 id consumer_; 71 id consumer_;
48 }; 72 };
49 73
50 // Test no setup is being done on the Toolbar if there's no Webstate. 74 // Test no setup is being done on the Toolbar if there's no Webstate.
51 TEST_F(ToolbarMediatorTest, TestToolbarSetupWithNoWebstate) { 75 TEST_F(ToolbarMediatorTest, TestToolbarSetupWithNoWebstate) {
52 mediator_.consumer = consumer_; 76 mediator_.consumer = consumer_;
53 77
54 [[consumer_ reject] setCanGoForward:NO]; 78 [[consumer_ reject] setCanGoForward:NO];
55 [[consumer_ reject] setCanGoBack:NO]; 79 [[consumer_ reject] setCanGoBack:NO];
56 [[consumer_ reject] setIsLoading:YES]; 80 [[consumer_ reject] setIsLoading:YES];
57 } 81 }
58 82
59 // Test no setup is being done on the Toolbar if there's no consumer. 83 // Test no setup is being done on the Toolbar if there's no consumer.
60 TEST_F(ToolbarMediatorTest, TestToolbarSetupWithNoConsumer) { 84 TEST_F(ToolbarMediatorTest, TestToolbarSetupWithNoConsumer) {
61 mediator_.webState = &test_web_state_; 85 mediator_.webState = &test_web_state_;
62 86
63 [[consumer_ reject] setCanGoForward:NO]; 87 [[consumer_ reject] setCanGoForward:NO];
64 [[consumer_ reject] setCanGoBack:NO]; 88 [[consumer_ reject] setCanGoBack:NO];
65 [[consumer_ reject] setIsLoading:YES]; 89 [[consumer_ reject] setIsLoading:YES];
66 } 90 }
67 91
92 // Test no WebstateList related setup is being done on the Toolbar if there's no
93 // WebstateList.
94 TEST_F(ToolbarMediatorTest, TestToolbarSetupWithNoWebstateList) {
95 mediator_.consumer = consumer_;
96 mediator_.webState = &test_web_state_;
97
98 [[[consumer_ reject] ignoringNonObjectArgs] setNumberOfTabs:0];
99 }
100
68 // Test the Toolbar Setup gets called when the mediator's WebState and Consumer 101 // Test the Toolbar Setup gets called when the mediator's WebState and Consumer
69 // have been set. 102 // have been set.
70 TEST_F(ToolbarMediatorTest, TestToolbarSetup) { 103 TEST_F(ToolbarMediatorTest, TestToolbarSetup) {
71 mediator_.webState = &test_web_state_; 104 mediator_.webState = &test_web_state_;
72 mediator_.consumer = consumer_; 105 mediator_.consumer = consumer_;
73 106
74 [[consumer_ verify] setCanGoForward:NO]; 107 [[consumer_ verify] setCanGoForward:NO];
75 [[consumer_ verify] setCanGoBack:NO]; 108 [[consumer_ verify] setCanGoBack:NO];
76 [[consumer_ verify] setIsLoading:YES]; 109 [[consumer_ verify] setIsLoading:YES];
77 } 110 }
78 111
79 // Test the Toolbar Setup gets called when the mediator's WebState and Consumer 112 // Test the Toolbar Setup gets called when the mediator's WebState and Consumer
80 // have been set in reverse order. 113 // have been set in reverse order.
81 TEST_F(ToolbarMediatorTest, TestToolbarSetupReverse) { 114 TEST_F(ToolbarMediatorTest, TestToolbarSetupReverse) {
82 mediator_.consumer = consumer_; 115 mediator_.consumer = consumer_;
83 mediator_.webState = &test_web_state_; 116 mediator_.webState = &test_web_state_;
84 117
85 [[consumer_ verify] setCanGoForward:NO]; 118 [[consumer_ verify] setCanGoForward:NO];
86 [[consumer_ verify] setCanGoBack:NO]; 119 [[consumer_ verify] setCanGoBack:NO];
87 [[consumer_ verify] setIsLoading:YES]; 120 [[consumer_ verify] setIsLoading:YES];
88 } 121 }
89 122
123 // Test the WebstateList related setup gets called when the mediator's WebState
124 // and Consumer have been set.
125 TEST_F(ToolbarMediatorTest, TestWebstateListRelatedSetup) {
126 SetUpWebStateList();
127 mediator_.webStateList = web_state_list_.get();
128 mediator_.consumer = consumer_;
129
130 [[consumer_ verify] setNumberOfTabs:3];
131 }
132
133 // Test the WebstateList related setup gets called when the mediator's WebState
134 // and Consumer have been set in reverse order.
135 TEST_F(ToolbarMediatorTest, TestWebstateListRelatedSetupReverse) {
136 mediator_.consumer = consumer_;
137 SetUpWebStateList();
138 mediator_.webStateList = web_state_list_.get();
139
140 [[consumer_ verify] setNumberOfTabs:3];
141 }
142
90 // Test the Toolbar is updated when the Webstate observer method DidStartLoading 143 // Test the Toolbar is updated when the Webstate observer method DidStartLoading
91 // is triggered by SetLoading. 144 // is triggered by SetLoading.
92 TEST_F(ToolbarMediatorTest, TestDidStartLoading) { 145 TEST_F(ToolbarMediatorTest, TestDidStartLoading) {
93 // Change the default loading state to false so we can verify the Webstate 146 // Change the default loading state to false to verify the Webstate
94 // callback with true. 147 // callback with true.
95 test_web_state_.SetLoading(false); 148 test_web_state_.SetLoading(false);
96 mediator_.webState = &test_web_state_; 149 mediator_.webState = &test_web_state_;
97 mediator_.consumer = consumer_; 150 mediator_.consumer = consumer_;
98 151
99 test_web_state_.SetLoading(true); 152 test_web_state_.SetLoading(true);
100 [[consumer_ verify] setIsLoading:YES]; 153 [[consumer_ verify] setIsLoading:YES];
101 } 154 }
102 155
103 // Test the Toolbar is updated when the Webstate observer method DidStopLoading 156 // Test the Toolbar is updated when the Webstate observer method DidStopLoading
(...skipping 25 matching lines...) Expand all
129 // Test the Toolbar is updated when the Webstate observer method 182 // Test the Toolbar is updated when the Webstate observer method
130 // didChangeLoadingProgress is called. 183 // didChangeLoadingProgress is called.
131 TEST_F(ToolbarMediatorTest, TestLoadingProgress) { 184 TEST_F(ToolbarMediatorTest, TestLoadingProgress) {
132 mediator_.webState = &test_web_state_; 185 mediator_.webState = &test_web_state_;
133 mediator_.consumer = consumer_; 186 mediator_.consumer = consumer_;
134 187
135 [mediator_ webState:mediator_.webState didChangeLoadingProgress:0.42]; 188 [mediator_ webState:mediator_.webState didChangeLoadingProgress:0.42];
136 [[consumer_ verify] setLoadingProgress:0.42]; 189 [[consumer_ verify] setLoadingProgress:0.42];
137 } 190 }
138 191
192 // Test that increasing the number of Webstates will update the consumer with
193 // the right value.
194 TEST_F(ToolbarMediatorTest, TestIncreaseNumberOfWebstates) {
195 SetUpWebStateList();
196 mediator_.webStateList = web_state_list_.get();
197 mediator_.consumer = consumer_;
198
199 InsertWebState(3);
marq (ping after 24h) 2017/05/29 11:04:37 Mild nit: if for some reason kNumberOfWebStates is
sczs 2017/05/30 00:18:21 Done.
200 [[consumer_ verify] setNumberOfTabs:kNumberOfWebStates + 1];
201 }
202
203 // Test that decreasing the number of Webstates will update the consumer with
204 // the right value.
205 TEST_F(ToolbarMediatorTest, TestDecreaseNumberOfWebstates) {
206 SetUpWebStateList();
207 mediator_.webStateList = web_state_list_.get();
208 mediator_.consumer = consumer_;
209
210 web_state_list_->DetachWebStateAt(0);
211 [[consumer_ verify] setNumberOfTabs:kNumberOfWebStates - 1];
212 }
213
139 } // namespace 214 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698