Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(266)

Unified Diff: ios/chrome/browser/ui/settings/settings_navigation_controller_unittest.mm

Issue 2587023002: Upstream Chrome on iOS source code [8/11]. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/settings/settings_navigation_controller_unittest.mm
diff --git a/ios/chrome/browser/ui/settings/settings_navigation_controller_unittest.mm b/ios/chrome/browser/ui/settings/settings_navigation_controller_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..7a41d6f6c33f90f990cf298d2682ac9b0304b335
--- /dev/null
+++ b/ios/chrome/browser/ui/settings/settings_navigation_controller_unittest.mm
@@ -0,0 +1,170 @@
+// Copyright 2013 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/chrome/browser/ui/settings/settings_navigation_controller.h"
+
+#import <Foundation/Foundation.h>
+
+#include <memory>
+
+#include "base/mac/scoped_nsautorelease_pool.h"
+#include "base/mac/scoped_nsobject.h"
+#include "base/memory/ptr_util.h"
+#include "components/search_engines/template_url_service.h"
+#include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
+#include "ios/chrome/browser/browser_state/test_chrome_browser_state_manager.h"
+#include "ios/chrome/browser/search_engines/template_url_service_factory.h"
+#include "ios/chrome/browser/signin/authentication_service.h"
+#include "ios/chrome/browser/signin/authentication_service_factory.h"
+#include "ios/chrome/browser/signin/authentication_service_fake.h"
+#include "ios/chrome/browser/sync/sync_setup_service.h"
+#include "ios/chrome/browser/sync/sync_setup_service_factory.h"
+#include "ios/chrome/test/testing_application_context.h"
+#include "ios/web/public/test/test_web_thread_bundle.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/gtest_mac.h"
+#include "testing/platform_test.h"
+#import "third_party/ocmock/OCMock/OCMock.h"
+#include "third_party/ocmock/gtest_support.h"
+
+namespace {
+
+NSString* const kSpdyProxyEnabled = @"SpdyProxyEnabled";
+
+using testing::ReturnRef;
+
+class SettingsNavigationControllerTest : public PlatformTest {
+ protected:
+ SettingsNavigationControllerTest()
+ : browser_state_manager_(base::FilePath()) {}
+
+ void SetUp() override {
+ PlatformTest::SetUp();
+ TestingApplicationContext::GetGlobal()->SetChromeBrowserStateManager(
+ &browser_state_manager_);
+
+ TestChromeBrowserState::Builder test_cbs_builder;
+ test_cbs_builder.AddTestingFactory(
+ AuthenticationServiceFactory::GetInstance(),
+ &AuthenticationServiceFake::CreateAuthenticationService);
+ test_cbs_builder.AddTestingFactory(
+ ios::TemplateURLServiceFactory::GetInstance(),
+ ios::TemplateURLServiceFactory::GetDefaultFactory());
+ chrome_browser_state_ = test_cbs_builder.Build();
+
+ mockDelegate_.reset([[OCMockObject
+ niceMockForProtocol:@protocol(SettingsNavigationControllerDelegate)]
+ retain]);
+
+ TemplateURLService* template_url_service =
+ ios::TemplateURLServiceFactory::GetForBrowserState(
+ chrome_browser_state_.get());
+ template_url_service->Load();
+
+ NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
+ initialValueForSpdyProxyEnabled_.reset(
+ [[defaults stringForKey:kSpdyProxyEnabled] copy]);
+ [defaults setObject:@"Disabled" forKey:kSpdyProxyEnabled];
+ };
+
+ void TearDown() override {
+ if (initialValueForSpdyProxyEnabled_) {
+ [[NSUserDefaults standardUserDefaults]
+ setObject:initialValueForSpdyProxyEnabled_.get()
+ forKey:kSpdyProxyEnabled];
+ } else {
+ [[NSUserDefaults standardUserDefaults]
+ removeObjectForKey:kSpdyProxyEnabled];
+ }
+ TestingApplicationContext::GetGlobal()->SetChromeBrowserStateManager(
+ nullptr);
+ PlatformTest::TearDown();
+ }
+
+ web::TestWebThreadBundle threadBundle_;
+ TestChromeBrowserStateManager browser_state_manager_;
+ std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
+ base::mac::ScopedNSAutoreleasePool pool;
+ base::scoped_nsprotocol<id> mockDelegate_;
+ base::scoped_nsobject<NSString> initialValueForSpdyProxyEnabled_;
+};
+
+// When navigation stack has more than one view controller,
+// -popViewControllerAnimated: successfully removes the top view controller.
+TEST_F(SettingsNavigationControllerTest, PopController) {
+ base::scoped_nsobject<SettingsNavigationController> settingsController(
+ [SettingsNavigationController
+ newSettingsMainControllerWithMainBrowserState:chrome_browser_state_
+ .get()
+ currentBrowserState:chrome_browser_state_
+ .get()
+ delegate:nil]);
+ base::scoped_nsobject<UIViewController> viewController(
+ [[UIViewController alloc] initWithNibName:nil bundle:nil]);
+ [settingsController pushViewController:viewController animated:NO];
+ EXPECT_EQ(2U, [[settingsController viewControllers] count]);
+
+ UIViewController* poppedViewController =
+ [settingsController popViewControllerAnimated:NO];
+ EXPECT_NSEQ(viewController, poppedViewController);
+ EXPECT_EQ(1U, [[settingsController viewControllers] count]);
+}
+
+// When the navigation stack has only one view controller,
+// -popViewControllerAnimated: returns false.
+TEST_F(SettingsNavigationControllerTest, DontPopRootController) {
+ base::scoped_nsobject<SettingsNavigationController> settingsController(
+ [SettingsNavigationController
+ newSettingsMainControllerWithMainBrowserState:chrome_browser_state_
+ .get()
+ currentBrowserState:chrome_browser_state_
+ .get()
+ delegate:nil]);
+ EXPECT_EQ(1U, [[settingsController viewControllers] count]);
+
+ EXPECT_FALSE([settingsController popViewControllerAnimated:NO]);
+}
+
+// When the settings navigation stack has more than one view controller, calling
+// -popViewControllerOrCloseSettingsAnimated: pops the top view controller to
+// reveal the view controller underneath.
+TEST_F(SettingsNavigationControllerTest,
+ PopWhenNavigationStackSizeIsGreaterThanOne) {
+ base::scoped_nsobject<SettingsNavigationController> settingsController(
+ [SettingsNavigationController
+ newSettingsMainControllerWithMainBrowserState:chrome_browser_state_
+ .get()
+ currentBrowserState:chrome_browser_state_
+ .get()
+ delegate:mockDelegate_]);
+ base::scoped_nsobject<UIViewController> viewController(
+ [[UIViewController alloc] initWithNibName:nil bundle:nil]);
+ [settingsController pushViewController:viewController animated:NO];
+ EXPECT_EQ(2U, [[settingsController viewControllers] count]);
+ [[mockDelegate_ reject] closeSettings];
+ [settingsController popViewControllerOrCloseSettingsAnimated:NO];
+ EXPECT_EQ(1U, [[settingsController viewControllers] count]);
+ EXPECT_OCMOCK_VERIFY(mockDelegate_);
+}
+
+// When the settings navigation stack only has one view controller, calling
+// -popViewControllerOrCloseSettingsAnimated: calls -closeSettings on the
+// delegate.
+TEST_F(SettingsNavigationControllerTest,
+ CloseSettingsWhenNavigationStackSizeIsOne) {
+ base::scoped_nsobject<SettingsNavigationController> settingsController(
+ [SettingsNavigationController
+ newSettingsMainControllerWithMainBrowserState:chrome_browser_state_
+ .get()
+ currentBrowserState:chrome_browser_state_
+ .get()
+ delegate:mockDelegate_]);
+ EXPECT_EQ(1U, [[settingsController viewControllers] count]);
+ [[mockDelegate_ expect] closeSettings];
+ [settingsController popViewControllerOrCloseSettingsAnimated:NO];
+ EXPECT_OCMOCK_VERIFY(mockDelegate_);
+}
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698