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/tab_coordinator.h" |
| 6 |
| 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/run_loop.h" |
| 9 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
| 10 #import "ios/clean/chrome/browser/ui/tab/tab_container_view_controller.h" |
| 11 #import "ios/shared/chrome/browser/ui/browser_list/browser.h" |
| 12 #import "ios/shared/chrome/browser/ui/coordinators/browser_coordinator+internal.
h" |
| 13 #import "ios/shared/chrome/browser/ui/toolbar/toolbar_test_util.h" |
| 14 #include "ios/web/public/test/test_web_thread.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "testing/platform_test.h" |
| 17 |
| 18 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 19 #error "This file requires ARC support." |
| 20 #endif |
| 21 |
| 22 namespace { |
| 23 |
| 24 class TabCoordinatorTest : public PlatformTest { |
| 25 protected: |
| 26 TabCoordinatorTest() |
| 27 : loop_(base::MessageLoop::TYPE_IO), |
| 28 ui_thread_(web::WebThread::UI, &loop_) { |
| 29 // Store the initial setting. |
| 30 initial_setting_ = [[NSUserDefaults standardUserDefaults] |
| 31 objectForKey:@"EnableBottomToolbar"]; |
| 32 |
| 33 // Initialize the browser. |
| 34 TestChromeBrowserState::Builder builder; |
| 35 chrome_browser_state_ = builder.Build(); |
| 36 browser_ = base::MakeUnique<Browser>(chrome_browser_state_.get()); |
| 37 |
| 38 // Initialize the web state. |
| 39 navigation_manager_ = base::MakeUnique<ToolbarTestNavigationManager>(); |
| 40 web_state_.SetNavigationManager(std::move(navigation_manager_)); |
| 41 |
| 42 // Initialize the coordinator. |
| 43 coordinator_ = [[TabCoordinator alloc] init]; |
| 44 coordinator_.browser = browser_.get(); |
| 45 coordinator_.webState = &web_state_; |
| 46 } |
| 47 ~TabCoordinatorTest() override { |
| 48 // Restore the initial setting. |
| 49 [[NSUserDefaults standardUserDefaults] setObject:initial_setting_ |
| 50 forKey:@"EnableBottomToolbar"]; |
| 51 } |
| 52 void TearDown() override { |
| 53 if (coordinator_.started) { |
| 54 [coordinator_ stop]; |
| 55 } |
| 56 coordinator_ = nil; |
| 57 } |
| 58 TabCoordinator* GetCoordinator() { return coordinator_; } |
| 59 |
| 60 protected: |
| 61 TabCoordinator* coordinator_; |
| 62 |
| 63 private: |
| 64 id initial_setting_; |
| 65 base::MessageLoop loop_; |
| 66 web::TestWebThread ui_thread_; |
| 67 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; |
| 68 std::unique_ptr<Browser> browser_; |
| 69 ToolbarTestWebState web_state_; |
| 70 std::unique_ptr<ToolbarTestNavigationManager> navigation_manager_; |
| 71 }; |
| 72 |
| 73 } // namespace |
| 74 |
| 75 TEST_F(TabCoordinatorTest, DefaultToolbar) { |
| 76 [[NSUserDefaults standardUserDefaults] setObject:@"" |
| 77 forKey:@"EnableBottomToolbar"]; |
| 78 [coordinator_ start]; |
| 79 EXPECT_EQ([TopToolbarTabViewController class], |
| 80 [coordinator_.viewController class]); |
| 81 } |
| 82 |
| 83 TEST_F(TabCoordinatorTest, TopToolbar) { |
| 84 [[NSUserDefaults standardUserDefaults] setObject:@"Disabled" |
| 85 forKey:@"EnableBottomToolbar"]; |
| 86 [GetCoordinator() start]; |
| 87 EXPECT_EQ([TopToolbarTabViewController class], |
| 88 [GetCoordinator().viewController class]); |
| 89 } |
| 90 |
| 91 TEST_F(TabCoordinatorTest, BottomToolbar) { |
| 92 [[NSUserDefaults standardUserDefaults] setObject:@"Enabled" |
| 93 forKey:@"EnableBottomToolbar"]; |
| 94 [GetCoordinator() start]; |
| 95 EXPECT_EQ([BottomToolbarTabViewController class], |
| 96 [GetCoordinator().viewController class]); |
| 97 } |
OLD | NEW |