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/chrome/browser/tabs/tab_model_list.h" |
| 6 |
| 7 #import "base/mac/scoped_nsobject.h" |
| 8 #include "base/memory/ptr_util.h" |
| 9 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
| 10 #import "ios/chrome/browser/sessions/test_session_service.h" |
| 11 #import "ios/chrome/browser/tabs/tab_model.h" |
| 12 #include "ios/web/public/test/test_web_thread_bundle.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "testing/platform_test.h" |
| 15 |
| 16 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 17 #error "This file requires ARC support." |
| 18 #endif |
| 19 |
| 20 class TabModelListTest : public PlatformTest { |
| 21 public: |
| 22 TabModelListTest() { |
| 23 TestChromeBrowserState::Builder test_cbs_builder; |
| 24 chrome_browser_state_ = test_cbs_builder.Build(); |
| 25 } |
| 26 |
| 27 TabModel* CreateTabModel() { |
| 28 return [[TabModel alloc] |
| 29 initWithSessionWindow:nil |
| 30 sessionService:[[TestSessionService alloc] init] |
| 31 browserState:chrome_browser_state_.get()]; |
| 32 } |
| 33 |
| 34 NSArray<TabModel*>* RegisteredTabModels() { |
| 35 return GetTabModelsForChromeBrowserState(chrome_browser_state_.get()); |
| 36 } |
| 37 |
| 38 private: |
| 39 web::TestWebThreadBundle thread_bundle_; |
| 40 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; |
| 41 |
| 42 DISALLOW_COPY_AND_ASSIGN(TabModelListTest); |
| 43 }; |
| 44 |
| 45 TEST_F(TabModelListTest, RegisterAndUnregister) { |
| 46 EXPECT_EQ([RegisteredTabModels() count], 0u); |
| 47 |
| 48 TabModel* tab_model = CreateTabModel(); |
| 49 EXPECT_EQ([RegisteredTabModels() count], 1u); |
| 50 EXPECT_NE([RegisteredTabModels() indexOfObject:tab_model], |
| 51 static_cast<NSUInteger>(NSNotFound)); |
| 52 |
| 53 [tab_model browserStateDestroyed]; |
| 54 |
| 55 EXPECT_EQ([RegisteredTabModels() count], 0u); |
| 56 } |
| 57 |
| 58 TEST_F(TabModelListTest, SupportsMultipleTabModel) { |
| 59 EXPECT_EQ([RegisteredTabModels() count], 0u); |
| 60 |
| 61 TabModel* tab_model1 = CreateTabModel(); |
| 62 EXPECT_EQ([RegisteredTabModels() count], 1u); |
| 63 EXPECT_NE([RegisteredTabModels() indexOfObject:tab_model1], |
| 64 static_cast<NSUInteger>(NSNotFound)); |
| 65 |
| 66 TabModel* tab_model2 = CreateTabModel(); |
| 67 EXPECT_EQ([RegisteredTabModels() count], 2u); |
| 68 EXPECT_NE([RegisteredTabModels() indexOfObject:tab_model2], |
| 69 static_cast<NSUInteger>(NSNotFound)); |
| 70 |
| 71 [tab_model1 browserStateDestroyed]; |
| 72 [tab_model2 browserStateDestroyed]; |
| 73 |
| 74 EXPECT_EQ([RegisteredTabModels() count], 0u); |
| 75 } |
OLD | NEW |