Chromium Code Reviews| 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_ = |
| 32 [OCMockObject niceMockForProtocol:@protocol(TabCollectionConsumer)]; | |
|
sczs
2017/05/18 16:11:02
nit: What about using OCMProtocolMock(@protocol(Ta
edchin
2017/05/18 17:30:26
Done.
| |
| 32 mediator_.consumer = consumer_; | 33 mediator_.consumer = consumer_; |
| 33 } | 34 } |
| 34 ~TabCollectionMediatorTest() override { [mediator_ disconnect]; } | 35 ~TabCollectionMediatorTest() override { [mediator_ disconnect]; } |
| 35 | 36 |
| 36 protected: | 37 protected: |
| 37 void SetUpWebStateList() { | 38 void SetUpWebStateList() { |
| 38 web_state_list_ = base::MakeUnique<WebStateList>(&web_state_list_delegate_); | 39 web_state_list_ = base::MakeUnique<WebStateList>(&web_state_list_delegate_); |
| 39 for (int i = 0; i < 3; i++) { | 40 for (int i = 0; i < 3; i++) { |
| 40 InsertWebState(i); | 41 InsertWebState(i); |
| 41 } | 42 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 53 return static_cast<web::TestWebState*>( | 54 return static_cast<web::TestWebState*>( |
| 54 web_state_list_->GetWebStateAt(index)); | 55 web_state_list_->GetWebStateAt(index)); |
| 55 } | 56 } |
| 56 | 57 |
| 57 TabCollectionMediator* mediator_; | 58 TabCollectionMediator* mediator_; |
| 58 std::unique_ptr<WebStateList> web_state_list_; | 59 std::unique_ptr<WebStateList> web_state_list_; |
| 59 FakeWebStateListDelegate web_state_list_delegate_; | 60 FakeWebStateListDelegate web_state_list_delegate_; |
| 60 id consumer_; | 61 id consumer_; |
| 61 }; | 62 }; |
| 62 | 63 |
| 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. | 64 // Tests that the consumer is notified of an insert into webStateList. |
| 81 TEST_F(TabCollectionMediatorTest, TestInsertWebState) { | 65 TEST_F(TabCollectionMediatorTest, TestInsertWebState) { |
| 82 [[consumer_ expect] insertItemAtIndex:2]; | |
| 83 InsertWebState(2); | 66 InsertWebState(2); |
| 84 EXPECT_OCMOCK_VERIFY(consumer_); | 67 [[consumer_ verify] insertItem:[OCMArg any] atIndex:2]; |
| 85 } | 68 } |
| 86 | 69 |
| 87 // Tests that the consumer is notified that a web state has been moved in | 70 // Tests that the consumer is notified that a web state has been moved in |
| 88 // webStateList. | 71 // webStateList. |
| 89 TEST_F(TabCollectionMediatorTest, TestMoveWebState) { | 72 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); | 73 web_state_list_->MoveWebStateAt(0, 2); |
| 96 EXPECT_OCMOCK_VERIFY(consumer_); | 74 [[consumer_ verify] moveItemFromIndex:0 toIndex:2]; |
| 97 } | 75 } |
| 98 | 76 |
| 99 // Tests that the consumer is notified that a web state has been replaced in | 77 // Tests that the consumer is notified that a web state has been replaced in |
| 100 // webStateList. | 78 // webStateList. |
| 101 TEST_F(TabCollectionMediatorTest, TestReplaceWebState) { | 79 TEST_F(TabCollectionMediatorTest, TestReplaceWebState) { |
| 102 NSIndexSet* indexes = [NSIndexSet indexSetWithIndex:1]; | |
| 103 [[consumer_ expect] reloadItemsAtIndexes:indexes]; | |
| 104 auto different_web_state = base::MakeUnique<web::TestWebState>(); | 80 auto different_web_state = base::MakeUnique<web::TestWebState>(); |
| 105 web_state_list_->ReplaceWebStateAt(1, std::move(different_web_state)); | 81 web_state_list_->ReplaceWebStateAt(1, std::move(different_web_state)); |
| 106 EXPECT_OCMOCK_VERIFY(consumer_); | 82 [[consumer_ verify] replaceItemAtIndex:1 withItem:[OCMArg any]]; |
| 107 } | 83 } |
| 108 | 84 |
| 109 // Tests that the consumer is notified that a web state has been deleted from | 85 // Tests that the consumer is notified that a web state has been deleted from |
| 110 // webStateList. | 86 // webStateList. |
| 111 TEST_F(TabCollectionMediatorTest, TestDetachWebState) { | 87 TEST_F(TabCollectionMediatorTest, TestDetachWebState) { |
| 112 [[consumer_ expect] deleteItemAtIndex:1]; | |
| 113 web_state_list_->CloseWebStateAt(1); | 88 web_state_list_->CloseWebStateAt(1); |
| 114 EXPECT_OCMOCK_VERIFY(consumer_); | 89 [[consumer_ verify] deleteItemAtIndex:1]; |
| 115 } | 90 } |
| 116 | 91 |
| 117 // Tests that the consumer is notified that the active web state has changed in | 92 // Tests that the consumer is notified that the active web state has changed in |
| 118 // webStateList. | 93 // webStateList. |
| 119 TEST_F(TabCollectionMediatorTest, TestChangeActiveWebState) { | 94 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); | 95 web_state_list_->ActivateWebStateAt(2); |
| 125 EXPECT_OCMOCK_VERIFY(consumer_); | 96 [[consumer_ verify] selectItemAtIndex:2]; |
| 126 } | 97 } |
| OLD | NEW |