| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/chrome/browser/ui/ntp/new_tab_page_controller.h" | 5 #import "ios/chrome/browser/ui/ntp/new_tab_page_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "components/bookmarks/test/bookmark_test_helpers.h" | 11 #include "components/bookmarks/test/bookmark_test_helpers.h" |
| 12 #include "components/prefs/testing_pref_service.h" | 12 #include "components/prefs/testing_pref_service.h" |
| 13 #include "components/search_engines/template_url_service.h" | 13 #include "components/search_engines/template_url_service.h" |
| 14 #include "components/sessions/core/tab_restore_service.h" | 14 #include "components/sessions/core/tab_restore_service.h" |
| 15 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" | 15 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" |
| 16 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" | 16 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
| 17 #include "ios/chrome/browser/chrome_url_constants.h" | 17 #include "ios/chrome/browser/chrome_url_constants.h" |
| 18 #include "ios/chrome/browser/search_engines/template_url_service_factory.h" | 18 #include "ios/chrome/browser/search_engines/template_url_service_factory.h" |
| 19 #include "ios/chrome/browser/sessions/ios_chrome_tab_restore_service_factory.h" | 19 #include "ios/chrome/browser/sessions/ios_chrome_tab_restore_service_factory.h" |
| 20 #import "ios/chrome/browser/sessions/test_session_service.h" |
| 21 #import "ios/chrome/browser/tabs/tab_model.h" |
| 20 #import "ios/chrome/browser/ui/ntp/new_tab_page_view.h" | 22 #import "ios/chrome/browser/ui/ntp/new_tab_page_view.h" |
| 21 #include "ios/chrome/browser/ui/ui_util.h" | 23 #include "ios/chrome/browser/ui/ui_util.h" |
| 22 #include "ios/chrome/test/block_cleanup_test.h" | 24 #include "ios/chrome/test/block_cleanup_test.h" |
| 23 #include "ios/chrome/test/ios_chrome_scoped_testing_local_state.h" | 25 #include "ios/chrome/test/ios_chrome_scoped_testing_local_state.h" |
| 24 #include "ios/chrome/test/testing_application_context.h" | 26 #include "ios/chrome/test/testing_application_context.h" |
| 25 #include "ios/web/public/test/test_web_thread_bundle.h" | 27 #include "ios/web/public/test/test_web_thread_bundle.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #include "testing/gtest_mac.h" | 29 #include "testing/gtest_mac.h" |
| 28 #import "third_party/ocmock/OCMock/OCMock.h" | 30 #import "third_party/ocmock/OCMock/OCMock.h" |
| 29 #import "third_party/ocmock/gtest_support.h" | 31 #import "third_party/ocmock/gtest_support.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 ios::TemplateURLServiceFactory::GetForBrowserState( | 82 ios::TemplateURLServiceFactory::GetForBrowserState( |
| 81 chrome_browser_state_.get()); | 83 chrome_browser_state_.get()); |
| 82 template_url_service->Load(); | 84 template_url_service->Load(); |
| 83 | 85 |
| 84 chrome_browser_state_->CreateBookmarkModel(true); | 86 chrome_browser_state_->CreateBookmarkModel(true); |
| 85 bookmarks::test::WaitForBookmarkModelToLoad( | 87 bookmarks::test::WaitForBookmarkModelToLoad( |
| 86 ios::BookmarkModelFactory::GetForBrowserState( | 88 ios::BookmarkModelFactory::GetForBrowserState( |
| 87 chrome_browser_state_.get())); | 89 chrome_browser_state_.get())); |
| 88 GURL url(kChromeUINewTabURL); | 90 GURL url(kChromeUINewTabURL); |
| 89 parentViewController_ = [[UIViewController alloc] init]; | 91 parentViewController_ = [[UIViewController alloc] init]; |
| 92 tabModel_ = [[TabModel alloc] |
| 93 initWithSessionWindow:nil |
| 94 sessionService:[[TestSessionService alloc] init] |
| 95 browserState:chrome_browser_state_.get()]; |
| 90 controller_ = | 96 controller_ = |
| 91 [[NewTabPageController alloc] initWithUrl:url | 97 [[NewTabPageController alloc] initWithUrl:url |
| 92 loader:nil | 98 loader:nil |
| 93 focuser:nil | 99 focuser:nil |
| 94 ntpObserver:nil | 100 ntpObserver:nil |
| 95 browserState:chrome_browser_state_.get() | 101 browserState:chrome_browser_state_.get() |
| 96 colorCache:nil | 102 colorCache:nil |
| 97 webToolbarDelegate:nil | 103 webToolbarDelegate:nil |
| 98 tabModel:nil | 104 tabModel:tabModel_ |
| 99 parentViewController:parentViewController_]; | 105 parentViewController:parentViewController_]; |
| 100 | 106 |
| 101 incognitoController_ = [[NewTabPageController alloc] | 107 incognitoController_ = [[NewTabPageController alloc] |
| 102 initWithUrl:url | 108 initWithUrl:url |
| 103 loader:nil | 109 loader:nil |
| 104 focuser:nil | 110 focuser:nil |
| 105 ntpObserver:nil | 111 ntpObserver:nil |
| 106 browserState:chrome_browser_state_ | 112 browserState:chrome_browser_state_ |
| 107 ->GetOffTheRecordChromeBrowserState() | 113 ->GetOffTheRecordChromeBrowserState() |
| 108 colorCache:nil | 114 colorCache:nil |
| 109 webToolbarDelegate:nil | 115 webToolbarDelegate:nil |
| 110 tabModel:nil | 116 tabModel:nil |
| 111 parentViewController:parentViewController_]; | 117 parentViewController:parentViewController_]; |
| 112 }; | 118 }; |
| 113 | 119 |
| 114 void TearDown() override { | 120 void TearDown() override { |
| 115 incognitoController_ = nil; | 121 incognitoController_ = nil; |
| 116 controller_ = nil; | 122 controller_ = nil; |
| 117 parentViewController_ = nil; | 123 parentViewController_ = nil; |
| 124 [tabModel_ browserStateDestroyed]; |
| 125 tabModel_ = nil; |
| 118 | 126 |
| 119 // There may be blocks released below that have weak references to |profile| | 127 // There may be blocks released below that have weak references to |profile| |
| 120 // owned by chrome_browser_state_. Ensure BlockCleanupTest::TearDown() is | 128 // owned by chrome_browser_state_. Ensure BlockCleanupTest::TearDown() is |
| 121 // called before |chrome_browser_state_| is reset. | 129 // called before |chrome_browser_state_| is reset. |
| 122 BlockCleanupTest::TearDown(); | 130 BlockCleanupTest::TearDown(); |
| 123 chrome_browser_state_.reset(); | 131 chrome_browser_state_.reset(); |
| 124 } | 132 } |
| 125 | 133 |
| 126 web::TestWebThreadBundle thread_bundle_; | 134 web::TestWebThreadBundle thread_bundle_; |
| 127 IOSChromeScopedTestingLocalState local_state_; | 135 IOSChromeScopedTestingLocalState local_state_; |
| 128 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; | 136 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; |
| 137 TabModel* tabModel_; |
| 129 UIViewController* parentViewController_; | 138 UIViewController* parentViewController_; |
| 130 NewTabPageController* controller_; | 139 NewTabPageController* controller_; |
| 131 NewTabPageController* incognitoController_; | 140 NewTabPageController* incognitoController_; |
| 132 }; | 141 }; |
| 133 | 142 |
| 134 TEST_F(NewTabPageControllerTest, NewTabBarItemDidChange) { | 143 TEST_F(NewTabPageControllerTest, NewTabBarItemDidChange) { |
| 135 // Switching the selected index in the NewTabPageBar should cause | 144 // Switching the selected index in the NewTabPageBar should cause |
| 136 // newTabBarItemDidChange to get called. | 145 // newTabBarItemDidChange to get called. |
| 137 NewTabPageBar* bar = [[controller_ ntpView] tabBar]; | 146 NewTabPageBar* bar = [[controller_ ntpView] tabBar]; |
| 138 NSUInteger bookmarkIndex = 0; | 147 NSUInteger bookmarkIndex = 0; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 EXPECT_EQ("open_tabs", | 222 EXPECT_EQ("open_tabs", |
| 214 NewTabPage::FragmentFromIdentifier(NewTabPage::kOpenTabsPanel)); | 223 NewTabPage::FragmentFromIdentifier(NewTabPage::kOpenTabsPanel)); |
| 215 EXPECT_EQ("", NewTabPage::FragmentFromIdentifier(NewTabPage::kNone)); | 224 EXPECT_EQ("", NewTabPage::FragmentFromIdentifier(NewTabPage::kNone)); |
| 216 EXPECT_EQ(NewTabPage::kBookmarksPanel, | 225 EXPECT_EQ(NewTabPage::kBookmarksPanel, |
| 217 NewTabPage::IdentifierFromFragment("bookmarks")); | 226 NewTabPage::IdentifierFromFragment("bookmarks")); |
| 218 EXPECT_EQ(NewTabPage::kNone, NewTabPage::IdentifierFromFragment("garbage")); | 227 EXPECT_EQ(NewTabPage::kNone, NewTabPage::IdentifierFromFragment("garbage")); |
| 219 EXPECT_EQ(NewTabPage::kNone, NewTabPage::IdentifierFromFragment("")); | 228 EXPECT_EQ(NewTabPage::kNone, NewTabPage::IdentifierFromFragment("")); |
| 220 } | 229 } |
| 221 | 230 |
| 222 } // anonymous namespace | 231 } // anonymous namespace |
| OLD | NEW |