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