Index: ios/clean/chrome/browser/ui/tab/tab_coordinator_unittest.mm |
diff --git a/ios/clean/chrome/browser/ui/tab/tab_coordinator_unittest.mm b/ios/clean/chrome/browser/ui/tab/tab_coordinator_unittest.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..df2e69abf1d3c20f4a2964fa8f546f2a81625be9 |
--- /dev/null |
+++ b/ios/clean/chrome/browser/ui/tab/tab_coordinator_unittest.mm |
@@ -0,0 +1,97 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#import "ios/clean/chrome/browser/ui/tab/tab_coordinator.h" |
+ |
+#include "base/memory/ptr_util.h" |
+#include "base/run_loop.h" |
+#include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
+#import "ios/clean/chrome/browser/ui/tab/tab_container_view_controller.h" |
+#import "ios/shared/chrome/browser/ui/browser_list/browser.h" |
+#import "ios/shared/chrome/browser/ui/coordinators/browser_coordinator+internal.h" |
+#import "ios/shared/chrome/browser/ui/toolbar/toolbar_test_util.h" |
+#include "ios/web/public/test/test_web_thread.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "testing/platform_test.h" |
+ |
+#if !defined(__has_feature) || !__has_feature(objc_arc) |
+#error "This file requires ARC support." |
+#endif |
+ |
+namespace { |
+ |
+class TabCoordinatorTest : public PlatformTest { |
+ protected: |
+ TabCoordinatorTest() |
+ : loop_(base::MessageLoop::TYPE_IO), |
+ ui_thread_(web::WebThread::UI, &loop_) { |
+ // Store the initial setting. |
+ initial_setting_ = [[NSUserDefaults standardUserDefaults] |
+ objectForKey:@"EnableBottomToolbar"]; |
+ |
+ // Initialize the browser. |
+ TestChromeBrowserState::Builder builder; |
+ chrome_browser_state_ = builder.Build(); |
+ browser_ = base::MakeUnique<Browser>(chrome_browser_state_.get()); |
+ |
+ // Initialize the web state. |
+ navigation_manager_ = base::MakeUnique<ToolbarTestNavigationManager>(); |
+ web_state_.SetNavigationManager(std::move(navigation_manager_)); |
+ |
+ // Initialize the coordinator. |
+ coordinator_ = [[TabCoordinator alloc] init]; |
+ coordinator_.browser = browser_.get(); |
+ coordinator_.webState = &web_state_; |
+ } |
+ ~TabCoordinatorTest() override { |
+ // Restore the initial setting. |
+ [[NSUserDefaults standardUserDefaults] setObject:initial_setting_ |
+ forKey:@"EnableBottomToolbar"]; |
+ } |
+ void TearDown() override { |
+ if (coordinator_.started) { |
+ [coordinator_ stop]; |
+ } |
+ coordinator_ = nil; |
+ } |
+ TabCoordinator* GetCoordinator() { return coordinator_; } |
+ |
+ protected: |
+ TabCoordinator* coordinator_; |
+ |
+ private: |
+ id initial_setting_; |
+ base::MessageLoop loop_; |
+ web::TestWebThread ui_thread_; |
+ std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; |
+ std::unique_ptr<Browser> browser_; |
+ ToolbarTestWebState web_state_; |
+ std::unique_ptr<ToolbarTestNavigationManager> navigation_manager_; |
+}; |
+ |
+} // namespace |
+ |
+TEST_F(TabCoordinatorTest, DefaultToolbar) { |
+ [[NSUserDefaults standardUserDefaults] setObject:@"" |
+ forKey:@"EnableBottomToolbar"]; |
+ [coordinator_ start]; |
+ EXPECT_EQ([TopToolbarTabViewController class], |
+ [coordinator_.viewController class]); |
+} |
+ |
+TEST_F(TabCoordinatorTest, TopToolbar) { |
+ [[NSUserDefaults standardUserDefaults] setObject:@"Disabled" |
+ forKey:@"EnableBottomToolbar"]; |
+ [GetCoordinator() start]; |
+ EXPECT_EQ([TopToolbarTabViewController class], |
+ [GetCoordinator().viewController class]); |
+} |
+ |
+TEST_F(TabCoordinatorTest, BottomToolbar) { |
+ [[NSUserDefaults standardUserDefaults] setObject:@"Enabled" |
+ forKey:@"EnableBottomToolbar"]; |
+ [GetCoordinator() start]; |
+ EXPECT_EQ([BottomToolbarTabViewController class], |
+ [GetCoordinator().viewController class]); |
+} |