OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/history/history_collection_view_controller.h" | 5 #import "ios/chrome/browser/ui/history/history_collection_view_controller.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #import "base/mac/scoped_nsobject.h" | |
10 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
11 #import "base/test/ios/wait_util.h" | 10 #import "base/test/ios/wait_util.h" |
12 #include "base/time/time.h" | 11 #include "base/time/time.h" |
13 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" | 12 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
14 #include "ios/chrome/browser/signin/authentication_service_factory.h" | 13 #include "ios/chrome/browser/signin/authentication_service_factory.h" |
15 #include "ios/chrome/browser/signin/authentication_service_fake.h" | 14 #include "ios/chrome/browser/signin/authentication_service_fake.h" |
16 #import "ios/chrome/browser/ui/history/history_entry.h" | 15 #import "ios/chrome/browser/ui/history/history_entry.h" |
17 #import "ios/chrome/browser/ui/history/history_service_facade.h" | 16 #import "ios/chrome/browser/ui/history/history_service_facade.h" |
18 #import "ios/chrome/browser/ui/history/history_service_facade_delegate.h" | 17 #import "ios/chrome/browser/ui/history/history_service_facade_delegate.h" |
19 #import "ios/chrome/browser/ui/url_loader.h" | 18 #import "ios/chrome/browser/ui/url_loader.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 ~HistoryCollectionViewControllerTest() override {} | 53 ~HistoryCollectionViewControllerTest() override {} |
55 | 54 |
56 void SetUp() override { | 55 void SetUp() override { |
57 BlockCleanupTest::SetUp(); | 56 BlockCleanupTest::SetUp(); |
58 DCHECK_CURRENTLY_ON(web::WebThread::UI); | 57 DCHECK_CURRENTLY_ON(web::WebThread::UI); |
59 TestChromeBrowserState::Builder builder; | 58 TestChromeBrowserState::Builder builder; |
60 builder.AddTestingFactory( | 59 builder.AddTestingFactory( |
61 AuthenticationServiceFactory::GetInstance(), | 60 AuthenticationServiceFactory::GetInstance(), |
62 AuthenticationServiceFake::CreateAuthenticationService); | 61 AuthenticationServiceFake::CreateAuthenticationService); |
63 mock_browser_state_ = builder.Build(); | 62 mock_browser_state_ = builder.Build(); |
64 mock_delegate_.reset([[OCMockObject | 63 mock_delegate_ = [OCMockObject |
65 niceMockForProtocol:@protocol(HistoryCollectionViewControllerDelegate)] | 64 niceMockForProtocol:@protocol(HistoryCollectionViewControllerDelegate)]; |
66 retain]); | 65 mock_url_loader_ = [OCMockObject niceMockForProtocol:@protocol(UrlLoader)]; |
67 mock_url_loader_.reset( | 66 history_collection_view_controller_ = |
68 [[OCMockObject niceMockForProtocol:@protocol(UrlLoader)] retain]); | |
69 history_collection_view_controller_.reset( | |
70 [[HistoryCollectionViewController alloc] | 67 [[HistoryCollectionViewController alloc] |
71 initWithLoader:mock_url_loader_ | 68 initWithLoader:mock_url_loader_ |
72 browserState:mock_browser_state_.get() | 69 browserState:mock_browser_state_.get() |
73 delegate:mock_delegate_]); | 70 delegate:mock_delegate_]; |
74 } | 71 } |
75 | 72 |
76 void TearDown() override { | 73 void TearDown() override { |
77 history_collection_view_controller_.reset(); | 74 history_collection_view_controller_ = nil; |
78 BlockCleanupTest::TearDown(); | 75 BlockCleanupTest::TearDown(); |
79 } | 76 } |
80 | 77 |
81 protected: | 78 protected: |
82 web::TestWebThreadBundle thread_bundle_; | 79 web::TestWebThreadBundle thread_bundle_; |
83 base::scoped_nsprotocol<id<UrlLoader>> mock_url_loader_; | 80 id<UrlLoader> mock_url_loader_; |
84 std::unique_ptr<TestChromeBrowserState> mock_browser_state_; | 81 std::unique_ptr<TestChromeBrowserState> mock_browser_state_; |
85 base::scoped_nsprotocol<id<HistoryCollectionViewControllerDelegate>> | 82 id<HistoryCollectionViewControllerDelegate> mock_delegate_; |
86 mock_delegate_; | 83 HistoryCollectionViewController* history_collection_view_controller_; |
87 base::scoped_nsobject<HistoryCollectionViewController> | |
88 history_collection_view_controller_; | |
89 bool privacy_settings_opened_; | 84 bool privacy_settings_opened_; |
90 DISALLOW_COPY_AND_ASSIGN(HistoryCollectionViewControllerTest); | 85 DISALLOW_COPY_AND_ASSIGN(HistoryCollectionViewControllerTest); |
91 }; | 86 }; |
92 | 87 |
93 // Tests that hasHistoryEntries property returns YES after entries have been | 88 // Tests that hasHistoryEntries property returns YES after entries have been |
94 // received. | 89 // received. |
95 TEST_F(HistoryCollectionViewControllerTest, HasHistoryEntries) { | 90 TEST_F(HistoryCollectionViewControllerTest, HasHistoryEntries) { |
96 GURL url_1("http://test1"); | 91 GURL url_1("http://test1"); |
97 HistoryServiceFacade::QueryResult query_result = | 92 HistoryServiceFacade::QueryResult query_result = |
98 QueryResultWithVisits({{url_1, base::Time::Now()}}); | 93 QueryResultWithVisits({{url_1, base::Time::Now()}}); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 [collection_view | 177 [collection_view |
183 selectItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:2] | 178 selectItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:2] |
184 animated:NO | 179 animated:NO |
185 scrollPosition:UICollectionViewScrollPositionNone]; | 180 scrollPosition:UICollectionViewScrollPositionNone]; |
186 [history_collection_view_controller_ deleteSelectedItemsFromHistory]; | 181 [history_collection_view_controller_ deleteSelectedItemsFromHistory]; |
187 | 182 |
188 // Expect only the header section to remain. | 183 // Expect only the header section to remain. |
189 EXPECT_EQ(1, [collection_view numberOfSections]); | 184 EXPECT_EQ(1, [collection_view numberOfSections]); |
190 EXPECT_EQ(1, [collection_view numberOfItemsInSection:0]); | 185 EXPECT_EQ(1, [collection_view numberOfItemsInSection:0]); |
191 } | 186 } |
OLD | NEW |