OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/dom_distiller/core/task_tracker.h" | 5 #include "components/dom_distiller/core/task_tracker.h" |
6 | 6 |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "components/dom_distiller/core/article_distillation_update.h" | 8 #include "components/dom_distiller/core/article_distillation_update.h" |
9 #include "components/dom_distiller/core/article_entry.h" | 9 #include "components/dom_distiller/core/article_entry.h" |
10 #include "components/dom_distiller/core/distilled_content_store.h" | 10 #include "components/dom_distiller/core/distilled_content_store.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 TestCancelCallback cancel_callback; | 145 TestCancelCallback cancel_callback; |
146 TaskTracker task_tracker( | 146 TaskTracker task_tracker( |
147 GetDefaultEntry(), cancel_callback.GetCallback(), NULL); | 147 GetDefaultEntry(), cancel_callback.GetCallback(), NULL); |
148 | 148 |
149 FakeViewRequestDelegate viewer_delegate; | 149 FakeViewRequestDelegate viewer_delegate; |
150 scoped_ptr<ViewerHandle> handle(task_tracker.AddViewer(&viewer_delegate)); | 150 scoped_ptr<ViewerHandle> handle(task_tracker.AddViewer(&viewer_delegate)); |
151 base::RunLoop().RunUntilIdle(); | 151 base::RunLoop().RunUntilIdle(); |
152 | 152 |
153 EXPECT_CALL(viewer_delegate, OnArticleReady(_)); | 153 EXPECT_CALL(viewer_delegate, OnArticleReady(_)); |
154 | 154 |
155 task_tracker.StartDistiller(&distiller_factory); | 155 task_tracker.StartDistiller(&distiller_factory, |
| 156 scoped_ptr<DistillerPage>().Pass()); |
156 base::RunLoop().RunUntilIdle(); | 157 base::RunLoop().RunUntilIdle(); |
157 | 158 |
158 EXPECT_FALSE(cancel_callback.Cancelled()); | 159 EXPECT_FALSE(cancel_callback.Cancelled()); |
159 } | 160 } |
160 | 161 |
161 TEST_F(DomDistillerTaskTrackerTest, | 162 TEST_F(DomDistillerTaskTrackerTest, |
162 TestSaveCallbackCalledOnDistillationComplete) { | 163 TestSaveCallbackCalledOnDistillationComplete) { |
163 MockDistillerFactory distiller_factory; | 164 MockDistillerFactory distiller_factory; |
164 FakeDistiller* distiller = new FakeDistiller(true); | 165 FakeDistiller* distiller = new FakeDistiller(true); |
165 EXPECT_CALL(distiller_factory, CreateDistillerImpl()) | 166 EXPECT_CALL(distiller_factory, CreateDistillerImpl()) |
166 .WillOnce(Return(distiller)); | 167 .WillOnce(Return(distiller)); |
167 TestCancelCallback cancel_callback; | 168 TestCancelCallback cancel_callback; |
168 TaskTracker task_tracker( | 169 TaskTracker task_tracker( |
169 GetDefaultEntry(), cancel_callback.GetCallback(), NULL); | 170 GetDefaultEntry(), cancel_callback.GetCallback(), NULL); |
170 | 171 |
171 MockSaveCallback save_callback; | 172 MockSaveCallback save_callback; |
172 task_tracker.AddSaveCallback( | 173 task_tracker.AddSaveCallback( |
173 base::Bind(&MockSaveCallback::Save, base::Unretained(&save_callback))); | 174 base::Bind(&MockSaveCallback::Save, base::Unretained(&save_callback))); |
174 base::RunLoop().RunUntilIdle(); | 175 base::RunLoop().RunUntilIdle(); |
175 | 176 |
176 EXPECT_CALL(save_callback, Save(_, _, _)); | 177 EXPECT_CALL(save_callback, Save(_, _, _)); |
177 | 178 |
178 task_tracker.StartDistiller(&distiller_factory); | 179 task_tracker.StartDistiller(&distiller_factory, |
| 180 scoped_ptr<DistillerPage>().Pass()); |
179 base::RunLoop().RunUntilIdle(); | 181 base::RunLoop().RunUntilIdle(); |
180 | 182 |
181 EXPECT_TRUE(cancel_callback.Cancelled()); | 183 EXPECT_TRUE(cancel_callback.Cancelled()); |
182 } | 184 } |
183 | 185 |
184 DistilledArticleProto CreateDistilledArticleForEntry( | 186 DistilledArticleProto CreateDistilledArticleForEntry( |
185 const ArticleEntry& entry) { | 187 const ArticleEntry& entry) { |
186 DistilledArticleProto article; | 188 DistilledArticleProto article; |
187 for (int i = 0; i < entry.pages_size(); ++i) { | 189 for (int i = 0; i < entry.pages_size(); ++i) { |
188 DistilledPageProto* page = article.add_pages(); | 190 DistilledPageProto* page = article.add_pages(); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 base::RunLoop().RunUntilIdle(); | 243 base::RunLoop().RunUntilIdle(); |
242 | 244 |
243 DistilledArticleProto distilled_article; | 245 DistilledArticleProto distilled_article; |
244 | 246 |
245 EXPECT_CALL(viewer_delegate, OnArticleReady(_)) | 247 EXPECT_CALL(viewer_delegate, OnArticleReady(_)) |
246 .WillOnce(testing::SaveArgPointee<0>(&distilled_article)); | 248 .WillOnce(testing::SaveArgPointee<0>(&distilled_article)); |
247 bool distiller_destroyed = false; | 249 bool distiller_destroyed = false; |
248 EXPECT_CALL(*distiller, Die()) | 250 EXPECT_CALL(*distiller, Die()) |
249 .WillOnce(testing::Assign(&distiller_destroyed, true)); | 251 .WillOnce(testing::Assign(&distiller_destroyed, true)); |
250 | 252 |
251 task_tracker.StartDistiller(&distiller_factory); | 253 task_tracker.StartDistiller(&distiller_factory, |
| 254 scoped_ptr<DistillerPage>().Pass()); |
252 task_tracker.StartBlobFetcher(); | 255 task_tracker.StartBlobFetcher(); |
253 base::RunLoop().RunUntilIdle(); | 256 base::RunLoop().RunUntilIdle(); |
254 | 257 |
255 testing::Mock::VerifyAndClearExpectations(&viewer_delegate); | 258 testing::Mock::VerifyAndClearExpectations(&viewer_delegate); |
256 EXPECT_EQ(stored_distilled_article.SerializeAsString(), | 259 EXPECT_EQ(stored_distilled_article.SerializeAsString(), |
257 distilled_article.SerializeAsString()); | 260 distilled_article.SerializeAsString()); |
258 | 261 |
259 EXPECT_TRUE(distiller_destroyed); | 262 EXPECT_TRUE(distiller_destroyed); |
260 EXPECT_FALSE(cancel_callback.Cancelled()); | 263 EXPECT_FALSE(cancel_callback.Cancelled()); |
261 base::RunLoop().RunUntilIdle(); | 264 base::RunLoop().RunUntilIdle(); |
(...skipping 12 matching lines...) Expand all Loading... |
274 | 277 |
275 TestCancelCallback cancel_callback; | 278 TestCancelCallback cancel_callback; |
276 TaskTracker task_tracker( | 279 TaskTracker task_tracker( |
277 GetDefaultEntry(), cancel_callback.GetCallback(), &content_store); | 280 GetDefaultEntry(), cancel_callback.GetCallback(), &content_store); |
278 | 281 |
279 FakeViewRequestDelegate viewer_delegate; | 282 FakeViewRequestDelegate viewer_delegate; |
280 scoped_ptr<ViewerHandle> handle(task_tracker.AddViewer(&viewer_delegate)); | 283 scoped_ptr<ViewerHandle> handle(task_tracker.AddViewer(&viewer_delegate)); |
281 base::RunLoop().RunUntilIdle(); | 284 base::RunLoop().RunUntilIdle(); |
282 | 285 |
283 task_tracker.StartBlobFetcher(); | 286 task_tracker.StartBlobFetcher(); |
284 task_tracker.StartDistiller(&distiller_factory); | 287 task_tracker.StartDistiller(&distiller_factory, |
| 288 scoped_ptr<DistillerPage>().Pass()); |
285 | 289 |
286 // OnArticleReady shouldn't be called until distillation finishes (i.e. the | 290 // OnArticleReady shouldn't be called until distillation finishes (i.e. the |
287 // blob fetcher shouldn't return distilled content). | 291 // blob fetcher shouldn't return distilled content). |
288 EXPECT_CALL(viewer_delegate, OnArticleReady(_)).Times(0); | 292 EXPECT_CALL(viewer_delegate, OnArticleReady(_)).Times(0); |
289 base::RunLoop().RunUntilIdle(); | 293 base::RunLoop().RunUntilIdle(); |
290 | 294 |
291 EXPECT_CALL(viewer_delegate, OnArticleReady(_)); | 295 EXPECT_CALL(viewer_delegate, OnArticleReady(_)); |
292 distiller->RunDistillerCallback(distilled_article.Pass()); | 296 distiller->RunDistillerCallback(distilled_article.Pass()); |
293 base::RunLoop().RunUntilIdle(); | 297 base::RunLoop().RunUntilIdle(); |
294 | 298 |
(...skipping 10 matching lines...) Expand all Loading... |
305 MockContentStore content_store; | 309 MockContentStore content_store; |
306 | 310 |
307 TestCancelCallback cancel_callback; | 311 TestCancelCallback cancel_callback; |
308 TaskTracker task_tracker( | 312 TaskTracker task_tracker( |
309 GetDefaultEntry(), cancel_callback.GetCallback(), &content_store); | 313 GetDefaultEntry(), cancel_callback.GetCallback(), &content_store); |
310 | 314 |
311 FakeViewRequestDelegate viewer_delegate; | 315 FakeViewRequestDelegate viewer_delegate; |
312 scoped_ptr<ViewerHandle> handle(task_tracker.AddViewer(&viewer_delegate)); | 316 scoped_ptr<ViewerHandle> handle(task_tracker.AddViewer(&viewer_delegate)); |
313 | 317 |
314 DistilledContentStore::LoadCallback content_store_load_callback; | 318 DistilledContentStore::LoadCallback content_store_load_callback; |
315 EXPECT_CALL(content_store, LoadContent(_, _)).WillOnce( | 319 EXPECT_CALL(content_store, LoadContent(_, _)) |
316 testing::SaveArg<1>(&content_store_load_callback)); | 320 .WillOnce(testing::SaveArg<1>(&content_store_load_callback)); |
317 | 321 |
318 task_tracker.StartDistiller(&distiller_factory); | 322 task_tracker.StartDistiller(&distiller_factory, |
| 323 scoped_ptr<DistillerPage>().Pass()); |
319 task_tracker.StartBlobFetcher(); | 324 task_tracker.StartBlobFetcher(); |
320 | 325 |
321 EXPECT_CALL(viewer_delegate, OnArticleReady(_)).Times(0); | 326 EXPECT_CALL(viewer_delegate, OnArticleReady(_)).Times(0); |
322 distiller->RunDistillerCallback( | 327 distiller->RunDistillerCallback( |
323 scoped_ptr<DistilledArticleProto>(new DistilledArticleProto)); | 328 scoped_ptr<DistilledArticleProto>(new DistilledArticleProto)); |
324 base::RunLoop().RunUntilIdle(); | 329 base::RunLoop().RunUntilIdle(); |
325 | 330 |
326 EXPECT_CALL(viewer_delegate, OnArticleReady(_)); | 331 EXPECT_CALL(viewer_delegate, OnArticleReady(_)); |
327 content_store_load_callback.Run( | 332 content_store_load_callback.Run( |
328 true, | 333 true, |
(...skipping 20 matching lines...) Expand all Loading... |
349 GetDefaultEntry(), cancel_callback.GetCallback(), &content_store); | 354 GetDefaultEntry(), cancel_callback.GetCallback(), &content_store); |
350 | 355 |
351 FakeViewRequestDelegate viewer_delegate; | 356 FakeViewRequestDelegate viewer_delegate; |
352 scoped_ptr<ViewerHandle> handle(task_tracker.AddViewer(&viewer_delegate)); | 357 scoped_ptr<ViewerHandle> handle(task_tracker.AddViewer(&viewer_delegate)); |
353 | 358 |
354 DistilledArticleProto stored_distilled_article; | 359 DistilledArticleProto stored_distilled_article; |
355 DistilledContentStore::LoadCallback content_store_load_callback; | 360 DistilledContentStore::LoadCallback content_store_load_callback; |
356 EXPECT_CALL(content_store, SaveContent(_, _, _)) | 361 EXPECT_CALL(content_store, SaveContent(_, _, _)) |
357 .WillOnce(testing::SaveArg<1>(&stored_distilled_article)); | 362 .WillOnce(testing::SaveArg<1>(&stored_distilled_article)); |
358 | 363 |
359 task_tracker.StartDistiller(&distiller_factory); | 364 task_tracker.StartDistiller(&distiller_factory, |
| 365 scoped_ptr<DistillerPage>().Pass()); |
360 | 366 |
361 EXPECT_CALL(viewer_delegate, OnArticleReady(_)); | 367 EXPECT_CALL(viewer_delegate, OnArticleReady(_)); |
362 distiller->RunDistillerCallback(scoped_ptr<DistilledArticleProto>( | 368 distiller->RunDistillerCallback(scoped_ptr<DistilledArticleProto>( |
363 new DistilledArticleProto(distilled_article))); | 369 new DistilledArticleProto(distilled_article))); |
364 base::RunLoop().RunUntilIdle(); | 370 base::RunLoop().RunUntilIdle(); |
365 | 371 |
366 ASSERT_EQ(stored_distilled_article.SerializeAsString(), | 372 ASSERT_EQ(stored_distilled_article.SerializeAsString(), |
367 distilled_article.SerializeAsString()); | 373 distilled_article.SerializeAsString()); |
368 EXPECT_FALSE(cancel_callback.Cancelled()); | 374 EXPECT_FALSE(cancel_callback.Cancelled()); |
369 } | 375 } |
370 | 376 |
371 } // namespace test | 377 } // namespace test |
372 } // namespace dom_distiller | 378 } // namespace dom_distiller |
OLD | NEW |