| 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" | |
| 22 #import "ios/chrome/browser/ui/ntp/new_tab_page_view.h" | 20 #import "ios/chrome/browser/ui/ntp/new_tab_page_view.h" |
| 23 #include "ios/chrome/browser/ui/ui_util.h" | 21 #include "ios/chrome/browser/ui/ui_util.h" |
| 24 #include "ios/chrome/test/block_cleanup_test.h" | 22 #include "ios/chrome/test/block_cleanup_test.h" |
| 25 #include "ios/chrome/test/ios_chrome_scoped_testing_local_state.h" | 23 #include "ios/chrome/test/ios_chrome_scoped_testing_local_state.h" |
| 26 #include "ios/chrome/test/testing_application_context.h" | 24 #include "ios/chrome/test/testing_application_context.h" |
| 27 #include "ios/web/public/test/test_web_thread_bundle.h" | 25 #include "ios/web/public/test/test_web_thread_bundle.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 29 #include "testing/gtest_mac.h" | 27 #include "testing/gtest_mac.h" |
| 30 #import "third_party/ocmock/OCMock/OCMock.h" | 28 #import "third_party/ocmock/OCMock/OCMock.h" |
| 31 #import "third_party/ocmock/gtest_support.h" | 29 #import "third_party/ocmock/gtest_support.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 ios::TemplateURLServiceFactory::GetForBrowserState( | 80 ios::TemplateURLServiceFactory::GetForBrowserState( |
| 83 chrome_browser_state_.get()); | 81 chrome_browser_state_.get()); |
| 84 template_url_service->Load(); | 82 template_url_service->Load(); |
| 85 | 83 |
| 86 chrome_browser_state_->CreateBookmarkModel(true); | 84 chrome_browser_state_->CreateBookmarkModel(true); |
| 87 bookmarks::test::WaitForBookmarkModelToLoad( | 85 bookmarks::test::WaitForBookmarkModelToLoad( |
| 88 ios::BookmarkModelFactory::GetForBrowserState( | 86 ios::BookmarkModelFactory::GetForBrowserState( |
| 89 chrome_browser_state_.get())); | 87 chrome_browser_state_.get())); |
| 90 GURL url(kChromeUINewTabURL); | 88 GURL url(kChromeUINewTabURL); |
| 91 parentViewController_ = [[UIViewController alloc] init]; | 89 parentViewController_ = [[UIViewController alloc] init]; |
| 92 tabModel_ = [[TabModel alloc] | |
| 93 initWithSessionWindow:nil | |
| 94 sessionService:[[TestSessionService alloc] init] | |
| 95 browserState:chrome_browser_state_.get()]; | |
| 96 controller_ = | 90 controller_ = |
| 97 [[NewTabPageController alloc] initWithUrl:url | 91 [[NewTabPageController alloc] initWithUrl:url |
| 98 loader:nil | 92 loader:nil |
| 99 focuser:nil | 93 focuser:nil |
| 100 ntpObserver:nil | 94 ntpObserver:nil |
| 101 browserState:chrome_browser_state_.get() | 95 browserState:chrome_browser_state_.get() |
| 102 colorCache:nil | 96 colorCache:nil |
| 103 webToolbarDelegate:nil | 97 webToolbarDelegate:nil |
| 104 tabModel:tabModel_ | 98 tabModel:nil |
| 105 parentViewController:parentViewController_]; | 99 parentViewController:parentViewController_]; |
| 106 | 100 |
| 107 incognitoController_ = [[NewTabPageController alloc] | 101 incognitoController_ = [[NewTabPageController alloc] |
| 108 initWithUrl:url | 102 initWithUrl:url |
| 109 loader:nil | 103 loader:nil |
| 110 focuser:nil | 104 focuser:nil |
| 111 ntpObserver:nil | 105 ntpObserver:nil |
| 112 browserState:chrome_browser_state_ | 106 browserState:chrome_browser_state_ |
| 113 ->GetOffTheRecordChromeBrowserState() | 107 ->GetOffTheRecordChromeBrowserState() |
| 114 colorCache:nil | 108 colorCache:nil |
| 115 webToolbarDelegate:nil | 109 webToolbarDelegate:nil |
| 116 tabModel:nil | 110 tabModel:nil |
| 117 parentViewController:parentViewController_]; | 111 parentViewController:parentViewController_]; |
| 118 }; | 112 }; |
| 119 | 113 |
| 120 void TearDown() override { | 114 void TearDown() override { |
| 121 incognitoController_ = nil; | 115 incognitoController_ = nil; |
| 122 controller_ = nil; | 116 controller_ = nil; |
| 123 parentViewController_ = nil; | 117 parentViewController_ = nil; |
| 124 [tabModel_ browserStateDestroyed]; | |
| 125 tabModel_ = nil; | |
| 126 | 118 |
| 127 // There may be blocks released below that have weak references to |profile| | 119 // There may be blocks released below that have weak references to |profile| |
| 128 // owned by chrome_browser_state_. Ensure BlockCleanupTest::TearDown() is | 120 // owned by chrome_browser_state_. Ensure BlockCleanupTest::TearDown() is |
| 129 // called before |chrome_browser_state_| is reset. | 121 // called before |chrome_browser_state_| is reset. |
| 130 BlockCleanupTest::TearDown(); | 122 BlockCleanupTest::TearDown(); |
| 131 chrome_browser_state_.reset(); | 123 chrome_browser_state_.reset(); |
| 132 } | 124 } |
| 133 | 125 |
| 134 web::TestWebThreadBundle thread_bundle_; | 126 web::TestWebThreadBundle thread_bundle_; |
| 135 IOSChromeScopedTestingLocalState local_state_; | 127 IOSChromeScopedTestingLocalState local_state_; |
| 136 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; | 128 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; |
| 137 TabModel* tabModel_; | |
| 138 UIViewController* parentViewController_; | 129 UIViewController* parentViewController_; |
| 139 NewTabPageController* controller_; | 130 NewTabPageController* controller_; |
| 140 NewTabPageController* incognitoController_; | 131 NewTabPageController* incognitoController_; |
| 141 }; | 132 }; |
| 142 | 133 |
| 143 TEST_F(NewTabPageControllerTest, NewTabBarItemDidChange) { | 134 TEST_F(NewTabPageControllerTest, NewTabBarItemDidChange) { |
| 144 // Switching the selected index in the NewTabPageBar should cause | 135 // Switching the selected index in the NewTabPageBar should cause |
| 145 // newTabBarItemDidChange to get called. | 136 // newTabBarItemDidChange to get called. |
| 146 NewTabPageBar* bar = [[controller_ ntpView] tabBar]; | 137 NewTabPageBar* bar = [[controller_ ntpView] tabBar]; |
| 147 NSUInteger bookmarkIndex = 0; | 138 NSUInteger bookmarkIndex = 0; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 EXPECT_EQ("open_tabs", | 213 EXPECT_EQ("open_tabs", |
| 223 NewTabPage::FragmentFromIdentifier(NewTabPage::kOpenTabsPanel)); | 214 NewTabPage::FragmentFromIdentifier(NewTabPage::kOpenTabsPanel)); |
| 224 EXPECT_EQ("", NewTabPage::FragmentFromIdentifier(NewTabPage::kNone)); | 215 EXPECT_EQ("", NewTabPage::FragmentFromIdentifier(NewTabPage::kNone)); |
| 225 EXPECT_EQ(NewTabPage::kBookmarksPanel, | 216 EXPECT_EQ(NewTabPage::kBookmarksPanel, |
| 226 NewTabPage::IdentifierFromFragment("bookmarks")); | 217 NewTabPage::IdentifierFromFragment("bookmarks")); |
| 227 EXPECT_EQ(NewTabPage::kNone, NewTabPage::IdentifierFromFragment("garbage")); | 218 EXPECT_EQ(NewTabPage::kNone, NewTabPage::IdentifierFromFragment("garbage")); |
| 228 EXPECT_EQ(NewTabPage::kNone, NewTabPage::IdentifierFromFragment("")); | 219 EXPECT_EQ(NewTabPage::kNone, NewTabPage::IdentifierFromFragment("")); |
| 229 } | 220 } |
| 230 | 221 |
| 231 } // anonymous namespace | 222 } // anonymous namespace |
| OLD | NEW |