OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_view_controll
er.h" |
| 6 |
| 7 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_consumer.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #import "testing/gtest_mac.h" |
| 10 #include "testing/platform_test.h" |
| 11 #include "third_party/ocmock/gtest_support.h" |
| 12 |
| 13 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 14 #error "This file requires ARC support." |
| 15 #endif |
| 16 |
| 17 @interface TestTabCollectionViewController : TabCollectionViewController |
| 18 @property(nonatomic, readwrite) NSMutableArray<TabCollectionItem*>* items; |
| 19 @end |
| 20 |
| 21 @implementation TestTabCollectionViewController |
| 22 @dynamic items; |
| 23 @end |
| 24 |
| 25 class TabCollectionViewControllerTest : public PlatformTest { |
| 26 public: |
| 27 TabCollectionViewControllerTest() { |
| 28 view_controller_ = [[TestTabCollectionViewController alloc] init]; |
| 29 TabCollectionItem* item0 = [[TabCollectionItem alloc] init]; |
| 30 item0.title = @"Item0"; |
| 31 TabCollectionItem* item1 = [[TabCollectionItem alloc] init]; |
| 32 item1.title = @"Item1"; |
| 33 view_controller_.items = [@[ item0, item1 ] mutableCopy]; |
| 34 } |
| 35 |
| 36 protected: |
| 37 TestTabCollectionViewController* view_controller_; |
| 38 }; |
| 39 |
| 40 // Tests that an item is inserted. |
| 41 TEST_F(TabCollectionViewControllerTest, TestInsertItem) { |
| 42 [view_controller_ insertItem:[[TabCollectionItem alloc] init] atIndex:0]; |
| 43 EXPECT_EQ(3, static_cast<int>(view_controller_.items.count)); |
| 44 } |
| 45 |
| 46 // Tests that an item is deleted. |
| 47 TEST_F(TabCollectionViewControllerTest, TestDeleteItem) { |
| 48 [view_controller_ deleteItemAtIndex:0]; |
| 49 EXPECT_EQ(1, static_cast<int>(view_controller_.items.count)); |
| 50 } |
| 51 |
| 52 // Tests that an item is moved. |
| 53 TEST_F(TabCollectionViewControllerTest, TestMoveItem) { |
| 54 [view_controller_ moveItemFromIndex:0 toIndex:1]; |
| 55 EXPECT_NSEQ(@"Item1", view_controller_.items[0].title); |
| 56 } |
| 57 |
| 58 // Tests that an item is replaced. |
| 59 TEST_F(TabCollectionViewControllerTest, TestReplaceItem) { |
| 60 TabCollectionItem* item = [[TabCollectionItem alloc] init]; |
| 61 item.title = @"NewItem"; |
| 62 [view_controller_ replaceItemAtIndex:0 withItem:item]; |
| 63 EXPECT_NSEQ(@"NewItem", view_controller_.items[0].title); |
| 64 } |
| 65 |
| 66 // Tests that items are initialized. |
| 67 TEST_F(TabCollectionViewControllerTest, TestInitializeItems) { |
| 68 TabCollectionItem* item = [[TabCollectionItem alloc] init]; |
| 69 item.title = @"NewItem"; |
| 70 [view_controller_ initializeItems:@[ item ]]; |
| 71 EXPECT_NSEQ(@"NewItem", view_controller_.items[0].title); |
| 72 } |
OLD | NEW |