OLD | NEW |
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/tab_collection/tab_collection_mediator.h" | 5 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_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" | 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" | 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" | 10 #import "ios/chrome/browser/web_state_list/web_state_list_observer_bridge.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #if !defined(__has_feature) || !__has_feature(objc_arc) | 21 #if !defined(__has_feature) || !__has_feature(objc_arc) |
22 #error "This file requires ARC support." | 22 #error "This file requires ARC support." |
23 #endif | 23 #endif |
24 | 24 |
25 class TabCollectionMediatorTest : public PlatformTest { | 25 class TabCollectionMediatorTest : public PlatformTest { |
26 public: | 26 public: |
27 TabCollectionMediatorTest() { | 27 TabCollectionMediatorTest() { |
28 SetUpWebStateList(); | 28 SetUpWebStateList(); |
29 mediator_ = [[TabCollectionMediator alloc] init]; | 29 mediator_ = [[TabCollectionMediator alloc] init]; |
30 mediator_.webStateList = web_state_list_.get(); | 30 mediator_.webStateList = web_state_list_.get(); |
31 consumer_ = [OCMockObject mockForProtocol:@protocol(TabCollectionConsumer)]; | 31 consumer_ = OCMProtocolMock(@protocol(TabCollectionConsumer)); |
32 mediator_.consumer = consumer_; | 32 mediator_.consumer = consumer_; |
33 } | 33 } |
34 ~TabCollectionMediatorTest() override { [mediator_ disconnect]; } | 34 ~TabCollectionMediatorTest() override { [mediator_ disconnect]; } |
35 | 35 |
36 protected: | 36 protected: |
37 void SetUpWebStateList() { | 37 void SetUpWebStateList() { |
38 web_state_list_ = base::MakeUnique<WebStateList>(&web_state_list_delegate_); | 38 web_state_list_ = base::MakeUnique<WebStateList>(&web_state_list_delegate_); |
39 for (int i = 0; i < 3; i++) { | 39 for (int i = 0; i < 3; i++) { |
40 InsertWebState(i); | 40 InsertWebState(i); |
41 } | 41 } |
(...skipping 11 matching lines...) Expand all Loading... |
53 return static_cast<web::TestWebState*>( | 53 return static_cast<web::TestWebState*>( |
54 web_state_list_->GetWebStateAt(index)); | 54 web_state_list_->GetWebStateAt(index)); |
55 } | 55 } |
56 | 56 |
57 TabCollectionMediator* mediator_; | 57 TabCollectionMediator* mediator_; |
58 std::unique_ptr<WebStateList> web_state_list_; | 58 std::unique_ptr<WebStateList> web_state_list_; |
59 FakeWebStateListDelegate web_state_list_delegate_; | 59 FakeWebStateListDelegate web_state_list_delegate_; |
60 id consumer_; | 60 id consumer_; |
61 }; | 61 }; |
62 | 62 |
63 // Tests that -numberOfTabs returns the expected number of elements from | |
64 // web_state_list_. | |
65 TEST_F(TabCollectionMediatorTest, TestNumberOfTabs) { | |
66 EXPECT_EQ(3, [mediator_ numberOfTabs]); | |
67 } | |
68 | |
69 // Tests that -indexOfActiveTab returns the expected active_index from | |
70 // web_state_list_. | |
71 TEST_F(TabCollectionMediatorTest, TestActiveTabIndex) { | |
72 EXPECT_EQ(0, [mediator_ indexOfActiveTab]); | |
73 } | |
74 | |
75 // Tests that -titleAtIndex: returns the expected title from web_state_list_. | |
76 TEST_F(TabCollectionMediatorTest, TestTitleAtIndex) { | |
77 EXPECT_NSEQ(@"http://test/0", [mediator_ titleAtIndex:0]); | |
78 } | |
79 | |
80 // Tests that the consumer is notified of an insert into webStateList. | 63 // Tests that the consumer is notified of an insert into webStateList. |
81 TEST_F(TabCollectionMediatorTest, TestInsertWebState) { | 64 TEST_F(TabCollectionMediatorTest, TestInsertWebState) { |
82 [[consumer_ expect] insertItemAtIndex:2]; | |
83 InsertWebState(2); | 65 InsertWebState(2); |
84 EXPECT_OCMOCK_VERIFY(consumer_); | 66 [[consumer_ verify] insertItem:[OCMArg any] atIndex:2]; |
85 } | 67 } |
86 | 68 |
87 // Tests that the consumer is notified that a web state has been moved in | 69 // Tests that the consumer is notified that a web state has been moved in |
88 // webStateList. | 70 // webStateList. |
89 TEST_F(TabCollectionMediatorTest, TestMoveWebState) { | 71 TEST_F(TabCollectionMediatorTest, TestMoveWebState) { |
90 NSMutableIndexSet* indexes = [NSMutableIndexSet indexSet]; | |
91 [indexes addIndex:0]; | |
92 [indexes addIndex:1]; | |
93 [indexes addIndex:2]; | |
94 [[consumer_ expect] reloadItemsAtIndexes:indexes]; | |
95 web_state_list_->MoveWebStateAt(0, 2); | 72 web_state_list_->MoveWebStateAt(0, 2); |
96 EXPECT_OCMOCK_VERIFY(consumer_); | 73 [[consumer_ verify] moveItemFromIndex:0 toIndex:2]; |
97 } | 74 } |
98 | 75 |
99 // Tests that the consumer is notified that a web state has been replaced in | 76 // Tests that the consumer is notified that a web state has been replaced in |
100 // webStateList. | 77 // webStateList. |
101 TEST_F(TabCollectionMediatorTest, TestReplaceWebState) { | 78 TEST_F(TabCollectionMediatorTest, TestReplaceWebState) { |
102 NSIndexSet* indexes = [NSIndexSet indexSetWithIndex:1]; | |
103 [[consumer_ expect] reloadItemsAtIndexes:indexes]; | |
104 auto different_web_state = base::MakeUnique<web::TestWebState>(); | 79 auto different_web_state = base::MakeUnique<web::TestWebState>(); |
105 web_state_list_->ReplaceWebStateAt(1, std::move(different_web_state)); | 80 web_state_list_->ReplaceWebStateAt(1, std::move(different_web_state)); |
106 EXPECT_OCMOCK_VERIFY(consumer_); | 81 [[consumer_ verify] replaceItemAtIndex:1 withItem:[OCMArg any]]; |
107 } | 82 } |
108 | 83 |
109 // Tests that the consumer is notified that a web state has been deleted from | 84 // Tests that the consumer is notified that a web state has been deleted from |
110 // webStateList. | 85 // webStateList. |
111 TEST_F(TabCollectionMediatorTest, TestDetachWebState) { | 86 TEST_F(TabCollectionMediatorTest, TestDetachWebState) { |
112 [[consumer_ expect] deleteItemAtIndex:1]; | |
113 web_state_list_->CloseWebStateAt(1); | 87 web_state_list_->CloseWebStateAt(1); |
114 EXPECT_OCMOCK_VERIFY(consumer_); | 88 [[consumer_ verify] deleteItemAtIndex:1]; |
115 } | 89 } |
116 | 90 |
117 // Tests that the consumer is notified that the active web state has changed in | 91 // Tests that the consumer is notified that the active web state has changed in |
118 // webStateList. | 92 // webStateList. |
119 TEST_F(TabCollectionMediatorTest, TestChangeActiveWebState) { | 93 TEST_F(TabCollectionMediatorTest, TestChangeActiveWebState) { |
120 NSMutableIndexSet* indexes = [NSMutableIndexSet indexSet]; | |
121 [indexes addIndex:0]; | |
122 [indexes addIndex:2]; | |
123 [[consumer_ expect] reloadItemsAtIndexes:indexes]; | |
124 web_state_list_->ActivateWebStateAt(2); | 94 web_state_list_->ActivateWebStateAt(2); |
125 EXPECT_OCMOCK_VERIFY(consumer_); | 95 [[consumer_ verify] selectItemAtIndex:2]; |
126 } | 96 } |
OLD | NEW |