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 #include "ios/chrome/browser/ui/history/history_service_facade.h" | 5 #include "ios/chrome/browser/ui/history/history_service_facade.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #import "base/mac/scoped_nsobject.h" | |
10 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
11 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
12 #include "components/history/core/browser/history_service.h" | 11 #include "components/history/core/browser/history_service.h" |
13 #include "components/history/core/browser/history_service_observer.h" | 12 #include "components/history/core/browser/history_service_observer.h" |
14 #include "components/keyed_service/core/service_access_type.h" | 13 #include "components/keyed_service/core/service_access_type.h" |
15 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" | 14 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
16 #include "ios/chrome/browser/history/history_service_factory.h" | 15 #include "ios/chrome/browser/history/history_service_factory.h" |
17 #import "ios/chrome/browser/ui/history/history_entry.h" | 16 #import "ios/chrome/browser/ui/history/history_entry.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 #include "ios/web/public/test/test_web_thread.h" | 18 #include "ios/web/public/test/test_web_thread.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 HistoryServiceFacadeTest() {} | 98 HistoryServiceFacadeTest() {} |
100 ~HistoryServiceFacadeTest() override {} | 99 ~HistoryServiceFacadeTest() override {} |
101 | 100 |
102 void SetUp() override { | 101 void SetUp() override { |
103 DCHECK_CURRENTLY_ON(web::WebThread::UI); | 102 DCHECK_CURRENTLY_ON(web::WebThread::UI); |
104 TestChromeBrowserState::Builder builder; | 103 TestChromeBrowserState::Builder builder; |
105 browser_state_ = builder.Build(); | 104 browser_state_ = builder.Build(); |
106 bool success = browser_state_->CreateHistoryService(true); | 105 bool success = browser_state_->CreateHistoryService(true); |
107 EXPECT_TRUE(success); | 106 EXPECT_TRUE(success); |
108 | 107 |
109 mock_delegate_.reset([[MockHistoryServiceFacadeDelegate alloc] init]); | 108 mock_delegate_ = [[MockHistoryServiceFacadeDelegate alloc] init]; |
110 history_service_facade_.reset( | 109 history_service_facade_.reset( |
111 new HistoryServiceFacade(browser_state_.get(), mock_delegate_)); | 110 new HistoryServiceFacade(browser_state_.get(), mock_delegate_)); |
112 } | 111 } |
113 | 112 |
114 // Cycles the runloop until the condition is met (up to 10 seconds). | 113 // Cycles the runloop until the condition is met (up to 10 seconds). |
115 typedef base::Callback<bool(void)> WaitCondition; | 114 typedef base::Callback<bool(void)> WaitCondition; |
116 bool WaitUntilLoop(WaitCondition condition) { | 115 bool WaitUntilLoop(WaitCondition condition) { |
117 DCHECK_CURRENTLY_ON(web::WebThread::UI); | 116 DCHECK_CURRENTLY_ON(web::WebThread::UI); |
118 base::Time maxDate = base::Time::Now() + base::TimeDelta::FromSeconds(10); | 117 base::Time maxDate = base::Time::Now() + base::TimeDelta::FromSeconds(10); |
119 while (!condition.Run()) { | 118 while (!condition.Run()) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 // Verify that the | 168 // Verify that the |
170 // historyServiceFacade:shouldShowNoticeAboutOtherFormsOfBrowsingHistory | 169 // historyServiceFacade:shouldShowNoticeAboutOtherFormsOfBrowsingHistory |
171 // delegate callback was called. | 170 // delegate callback was called. |
172 bool VerifyOtherHistoryCallback() { | 171 bool VerifyOtherHistoryCallback() { |
173 return [mock_delegate_ didReceiveOtherBrowsingHistoryCallback]; | 172 return [mock_delegate_ didReceiveOtherBrowsingHistoryCallback]; |
174 } | 173 } |
175 | 174 |
176 protected: | 175 protected: |
177 web::TestWebThreadBundle thread_bundle_; | 176 web::TestWebThreadBundle thread_bundle_; |
178 std::unique_ptr<TestChromeBrowserState> browser_state_; | 177 std::unique_ptr<TestChromeBrowserState> browser_state_; |
179 base::scoped_nsobject<MockHistoryServiceFacadeDelegate> mock_delegate_; | 178 MockHistoryServiceFacadeDelegate* mock_delegate_; |
180 std::unique_ptr<HistoryServiceFacade> history_service_facade_; | 179 std::unique_ptr<HistoryServiceFacade> history_service_facade_; |
181 GURL visited_url_; | 180 GURL visited_url_; |
182 base::Time visited_time_; | 181 base::Time visited_time_; |
183 DISALLOW_COPY_AND_ASSIGN(HistoryServiceFacadeTest); | 182 DISALLOW_COPY_AND_ASSIGN(HistoryServiceFacadeTest); |
184 }; | 183 }; |
185 | 184 |
186 // Tests that invoking QueryHistory results in the delegate receiving an added | 185 // Tests that invoking QueryHistory results in the delegate receiving an added |
187 // history entry. | 186 // history entry. |
188 TEST_F(HistoryServiceFacadeTest, TestQueryHistory) { | 187 TEST_F(HistoryServiceFacadeTest, TestQueryHistory) { |
189 GURL url("http://www.testurl.com"); | 188 GURL url("http://www.testurl.com"); |
(...skipping 24 matching lines...) Expand all Loading... |
214 | 213 |
215 // Tests that invoking QueryOtherFormsOfBrowsingHistory completes with callback | 214 // Tests that invoking QueryOtherFormsOfBrowsingHistory completes with callback |
216 // to delegate method | 215 // to delegate method |
217 // historyServiceFacade:shouldShowNoticeAboutOtherFormsOfBrowsingHistory:. | 216 // historyServiceFacade:shouldShowNoticeAboutOtherFormsOfBrowsingHistory:. |
218 TEST_F(HistoryServiceFacadeTest, TestQueryOtherFormsOfBrowsingHistory) { | 217 TEST_F(HistoryServiceFacadeTest, TestQueryOtherFormsOfBrowsingHistory) { |
219 history_service_facade_->QueryOtherFormsOfBrowsingHistory(); | 218 history_service_facade_->QueryOtherFormsOfBrowsingHistory(); |
220 EXPECT_TRUE(WaitUntilLoop( | 219 EXPECT_TRUE(WaitUntilLoop( |
221 base::Bind(&HistoryServiceFacadeTest::VerifyOtherHistoryCallback, | 220 base::Bind(&HistoryServiceFacadeTest::VerifyOtherHistoryCallback, |
222 base::Unretained(this)))); | 221 base::Unretained(this)))); |
223 } | 222 } |
OLD | NEW |