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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "components/dom_distiller/core/article_distillation_update.h" | 10 #include "components/dom_distiller/core/article_distillation_update.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 ArticleEntry entry; | 70 ArticleEntry entry; |
71 entry.set_entry_id(entry_id_); | 71 entry.set_entry_id(entry_id_); |
72 ArticleEntryPage* page0 = entry.add_pages(); | 72 ArticleEntryPage* page0 = entry.add_pages(); |
73 ArticleEntryPage* page1 = entry.add_pages(); | 73 ArticleEntryPage* page1 = entry.add_pages(); |
74 page0->set_url(page_0_url_.spec()); | 74 page0->set_url(page_0_url_.spec()); |
75 page1->set_url(page_1_url_.spec()); | 75 page1->set_url(page_1_url_.spec()); |
76 return entry; | 76 return entry; |
77 } | 77 } |
78 | 78 |
79 protected: | 79 protected: |
80 scoped_ptr<base::MessageLoop> message_loop_; | 80 std::unique_ptr<base::MessageLoop> message_loop_; |
81 std::string entry_id_; | 81 std::string entry_id_; |
82 GURL page_0_url_; | 82 GURL page_0_url_; |
83 GURL page_1_url_; | 83 GURL page_1_url_; |
84 }; | 84 }; |
85 | 85 |
86 TEST_F(DomDistillerTaskTrackerTest, TestHasEntryId) { | 86 TEST_F(DomDistillerTaskTrackerTest, TestHasEntryId) { |
87 MockDistillerFactory distiller_factory; | 87 MockDistillerFactory distiller_factory; |
88 TestCancelCallback cancel_callback; | 88 TestCancelCallback cancel_callback; |
89 TaskTracker task_tracker( | 89 TaskTracker task_tracker( |
90 GetDefaultEntry(), cancel_callback.GetCallback(), NULL); | 90 GetDefaultEntry(), cancel_callback.GetCallback(), NULL); |
(...skipping 12 matching lines...) Expand all Loading... |
103 } | 103 } |
104 | 104 |
105 TEST_F(DomDistillerTaskTrackerTest, TestViewerCancelled) { | 105 TEST_F(DomDistillerTaskTrackerTest, TestViewerCancelled) { |
106 MockDistillerFactory distiller_factory; | 106 MockDistillerFactory distiller_factory; |
107 TestCancelCallback cancel_callback; | 107 TestCancelCallback cancel_callback; |
108 TaskTracker task_tracker( | 108 TaskTracker task_tracker( |
109 GetDefaultEntry(), cancel_callback.GetCallback(), NULL); | 109 GetDefaultEntry(), cancel_callback.GetCallback(), NULL); |
110 | 110 |
111 FakeViewRequestDelegate viewer_delegate; | 111 FakeViewRequestDelegate viewer_delegate; |
112 FakeViewRequestDelegate viewer_delegate2; | 112 FakeViewRequestDelegate viewer_delegate2; |
113 scoped_ptr<ViewerHandle> handle(task_tracker.AddViewer(&viewer_delegate)); | 113 std::unique_ptr<ViewerHandle> handle( |
114 scoped_ptr<ViewerHandle> handle2(task_tracker.AddViewer(&viewer_delegate2)); | 114 task_tracker.AddViewer(&viewer_delegate)); |
| 115 std::unique_ptr<ViewerHandle> handle2( |
| 116 task_tracker.AddViewer(&viewer_delegate2)); |
115 | 117 |
116 EXPECT_FALSE(cancel_callback.Cancelled()); | 118 EXPECT_FALSE(cancel_callback.Cancelled()); |
117 handle.reset(); | 119 handle.reset(); |
118 EXPECT_FALSE(cancel_callback.Cancelled()); | 120 EXPECT_FALSE(cancel_callback.Cancelled()); |
119 handle2.reset(); | 121 handle2.reset(); |
120 EXPECT_TRUE(cancel_callback.Cancelled()); | 122 EXPECT_TRUE(cancel_callback.Cancelled()); |
121 } | 123 } |
122 | 124 |
123 TEST_F(DomDistillerTaskTrackerTest, TestViewerCancelledWithSaveRequest) { | 125 TEST_F(DomDistillerTaskTrackerTest, TestViewerCancelledWithSaveRequest) { |
124 MockDistillerFactory distiller_factory; | 126 MockDistillerFactory distiller_factory; |
125 TestCancelCallback cancel_callback; | 127 TestCancelCallback cancel_callback; |
126 TaskTracker task_tracker( | 128 TaskTracker task_tracker( |
127 GetDefaultEntry(), cancel_callback.GetCallback(), NULL); | 129 GetDefaultEntry(), cancel_callback.GetCallback(), NULL); |
128 | 130 |
129 FakeViewRequestDelegate viewer_delegate; | 131 FakeViewRequestDelegate viewer_delegate; |
130 scoped_ptr<ViewerHandle> handle(task_tracker.AddViewer(&viewer_delegate)); | 132 std::unique_ptr<ViewerHandle> handle( |
| 133 task_tracker.AddViewer(&viewer_delegate)); |
131 EXPECT_FALSE(cancel_callback.Cancelled()); | 134 EXPECT_FALSE(cancel_callback.Cancelled()); |
132 | 135 |
133 MockSaveCallback save_callback; | 136 MockSaveCallback save_callback; |
134 task_tracker.AddSaveCallback( | 137 task_tracker.AddSaveCallback( |
135 base::Bind(&MockSaveCallback::Save, base::Unretained(&save_callback))); | 138 base::Bind(&MockSaveCallback::Save, base::Unretained(&save_callback))); |
136 handle.reset(); | 139 handle.reset(); |
137 | 140 |
138 // Since there is a pending save request, the task shouldn't be cancelled. | 141 // Since there is a pending save request, the task shouldn't be cancelled. |
139 EXPECT_FALSE(cancel_callback.Cancelled()); | 142 EXPECT_FALSE(cancel_callback.Cancelled()); |
140 } | 143 } |
141 | 144 |
142 TEST_F(DomDistillerTaskTrackerTest, TestViewerNotifiedOnDistillationComplete) { | 145 TEST_F(DomDistillerTaskTrackerTest, TestViewerNotifiedOnDistillationComplete) { |
143 MockDistillerFactory distiller_factory; | 146 MockDistillerFactory distiller_factory; |
144 FakeDistiller* distiller = new FakeDistiller(true); | 147 FakeDistiller* distiller = new FakeDistiller(true); |
145 EXPECT_CALL(distiller_factory, CreateDistillerImpl()) | 148 EXPECT_CALL(distiller_factory, CreateDistillerImpl()) |
146 .WillOnce(Return(distiller)); | 149 .WillOnce(Return(distiller)); |
147 TestCancelCallback cancel_callback; | 150 TestCancelCallback cancel_callback; |
148 TaskTracker task_tracker( | 151 TaskTracker task_tracker( |
149 GetDefaultEntry(), cancel_callback.GetCallback(), NULL); | 152 GetDefaultEntry(), cancel_callback.GetCallback(), NULL); |
150 | 153 |
151 FakeViewRequestDelegate viewer_delegate; | 154 FakeViewRequestDelegate viewer_delegate; |
152 scoped_ptr<ViewerHandle> handle(task_tracker.AddViewer(&viewer_delegate)); | 155 std::unique_ptr<ViewerHandle> handle( |
| 156 task_tracker.AddViewer(&viewer_delegate)); |
153 base::RunLoop().RunUntilIdle(); | 157 base::RunLoop().RunUntilIdle(); |
154 | 158 |
155 EXPECT_CALL(viewer_delegate, OnArticleReady(_)); | 159 EXPECT_CALL(viewer_delegate, OnArticleReady(_)); |
156 | 160 |
157 task_tracker.StartDistiller(&distiller_factory, scoped_ptr<DistillerPage>()); | 161 task_tracker.StartDistiller(&distiller_factory, |
| 162 std::unique_ptr<DistillerPage>()); |
158 base::RunLoop().RunUntilIdle(); | 163 base::RunLoop().RunUntilIdle(); |
159 | 164 |
160 EXPECT_FALSE(cancel_callback.Cancelled()); | 165 EXPECT_FALSE(cancel_callback.Cancelled()); |
161 } | 166 } |
162 | 167 |
163 TEST_F(DomDistillerTaskTrackerTest, TestDistillerFails) { | 168 TEST_F(DomDistillerTaskTrackerTest, TestDistillerFails) { |
164 MockDistillerFactory distiller_factory; | 169 MockDistillerFactory distiller_factory; |
165 FakeDistiller* distiller = new FakeDistiller(false); | 170 FakeDistiller* distiller = new FakeDistiller(false); |
166 EXPECT_CALL(distiller_factory, CreateDistillerImpl()) | 171 EXPECT_CALL(distiller_factory, CreateDistillerImpl()) |
167 .WillOnce(Return(distiller)); | 172 .WillOnce(Return(distiller)); |
168 | 173 |
169 TestCancelCallback cancel_callback; | 174 TestCancelCallback cancel_callback; |
170 TaskTracker task_tracker( | 175 TaskTracker task_tracker( |
171 GetDefaultEntry(), cancel_callback.GetCallback(), NULL); | 176 GetDefaultEntry(), cancel_callback.GetCallback(), NULL); |
172 | 177 |
173 FakeViewRequestDelegate viewer_delegate; | 178 FakeViewRequestDelegate viewer_delegate; |
174 scoped_ptr<ViewerHandle> handle(task_tracker.AddViewer(&viewer_delegate)); | 179 std::unique_ptr<ViewerHandle> handle( |
| 180 task_tracker.AddViewer(&viewer_delegate)); |
175 base::RunLoop().RunUntilIdle(); | 181 base::RunLoop().RunUntilIdle(); |
176 | 182 |
177 EXPECT_CALL(viewer_delegate, OnArticleReady(_)); | 183 EXPECT_CALL(viewer_delegate, OnArticleReady(_)); |
178 | 184 |
179 task_tracker.StartDistiller(&distiller_factory, scoped_ptr<DistillerPage>()); | 185 task_tracker.StartDistiller(&distiller_factory, |
| 186 std::unique_ptr<DistillerPage>()); |
180 distiller->RunDistillerCallback( | 187 distiller->RunDistillerCallback( |
181 scoped_ptr<DistilledArticleProto>(new DistilledArticleProto)); | 188 std::unique_ptr<DistilledArticleProto>(new DistilledArticleProto)); |
182 base::RunLoop().RunUntilIdle(); | 189 base::RunLoop().RunUntilIdle(); |
183 | 190 |
184 EXPECT_FALSE(cancel_callback.Cancelled()); | 191 EXPECT_FALSE(cancel_callback.Cancelled()); |
185 } | 192 } |
186 | 193 |
187 TEST_F(DomDistillerTaskTrackerTest, | 194 TEST_F(DomDistillerTaskTrackerTest, |
188 TestSaveCallbackCalledOnDistillationComplete) { | 195 TestSaveCallbackCalledOnDistillationComplete) { |
189 MockDistillerFactory distiller_factory; | 196 MockDistillerFactory distiller_factory; |
190 FakeDistiller* distiller = new FakeDistiller(true); | 197 FakeDistiller* distiller = new FakeDistiller(true); |
191 EXPECT_CALL(distiller_factory, CreateDistillerImpl()) | 198 EXPECT_CALL(distiller_factory, CreateDistillerImpl()) |
192 .WillOnce(Return(distiller)); | 199 .WillOnce(Return(distiller)); |
193 TestCancelCallback cancel_callback; | 200 TestCancelCallback cancel_callback; |
194 TaskTracker task_tracker( | 201 TaskTracker task_tracker( |
195 GetDefaultEntry(), cancel_callback.GetCallback(), NULL); | 202 GetDefaultEntry(), cancel_callback.GetCallback(), NULL); |
196 | 203 |
197 MockSaveCallback save_callback; | 204 MockSaveCallback save_callback; |
198 task_tracker.AddSaveCallback( | 205 task_tracker.AddSaveCallback( |
199 base::Bind(&MockSaveCallback::Save, base::Unretained(&save_callback))); | 206 base::Bind(&MockSaveCallback::Save, base::Unretained(&save_callback))); |
200 base::RunLoop().RunUntilIdle(); | 207 base::RunLoop().RunUntilIdle(); |
201 | 208 |
202 EXPECT_CALL(save_callback, Save(_, _, _)); | 209 EXPECT_CALL(save_callback, Save(_, _, _)); |
203 | 210 |
204 task_tracker.StartDistiller(&distiller_factory, scoped_ptr<DistillerPage>()); | 211 task_tracker.StartDistiller(&distiller_factory, |
| 212 std::unique_ptr<DistillerPage>()); |
205 base::RunLoop().RunUntilIdle(); | 213 base::RunLoop().RunUntilIdle(); |
206 | 214 |
207 EXPECT_TRUE(cancel_callback.Cancelled()); | 215 EXPECT_TRUE(cancel_callback.Cancelled()); |
208 } | 216 } |
209 | 217 |
210 DistilledArticleProto CreateDistilledArticleForEntry( | 218 DistilledArticleProto CreateDistilledArticleForEntry( |
211 const ArticleEntry& entry) { | 219 const ArticleEntry& entry) { |
212 DistilledArticleProto article; | 220 DistilledArticleProto article; |
213 for (int i = 0; i < entry.pages_size(); ++i) { | 221 for (int i = 0; i < entry.pages_size(); ++i) { |
214 DistilledPageProto* page = article.add_pages(); | 222 DistilledPageProto* page = article.add_pages(); |
215 page->set_url(entry.pages(i).url()); | 223 page->set_url(entry.pages(i).url()); |
216 page->set_html("<div>" + entry.pages(i).url() + "</div>"); | 224 page->set_html("<div>" + entry.pages(i).url() + "</div>"); |
217 } | 225 } |
218 return article; | 226 return article; |
219 } | 227 } |
220 | 228 |
221 TEST_F(DomDistillerTaskTrackerTest, TestBlobFetcher) { | 229 TEST_F(DomDistillerTaskTrackerTest, TestBlobFetcher) { |
222 ArticleEntry entry_with_blob = GetDefaultEntry(); | 230 ArticleEntry entry_with_blob = GetDefaultEntry(); |
223 DistilledArticleProto stored_distilled_article = | 231 DistilledArticleProto stored_distilled_article = |
224 CreateDistilledArticleForEntry(entry_with_blob); | 232 CreateDistilledArticleForEntry(entry_with_blob); |
225 InMemoryContentStore content_store(kDefaultMaxNumCachedEntries); | 233 InMemoryContentStore content_store(kDefaultMaxNumCachedEntries); |
226 content_store.InjectContent(entry_with_blob, stored_distilled_article); | 234 content_store.InjectContent(entry_with_blob, stored_distilled_article); |
227 TestCancelCallback cancel_callback; | 235 TestCancelCallback cancel_callback; |
228 | 236 |
229 TaskTracker task_tracker( | 237 TaskTracker task_tracker( |
230 entry_with_blob, cancel_callback.GetCallback(), &content_store); | 238 entry_with_blob, cancel_callback.GetCallback(), &content_store); |
231 | 239 |
232 FakeViewRequestDelegate viewer_delegate; | 240 FakeViewRequestDelegate viewer_delegate; |
233 scoped_ptr<ViewerHandle> handle(task_tracker.AddViewer(&viewer_delegate)); | 241 std::unique_ptr<ViewerHandle> handle( |
| 242 task_tracker.AddViewer(&viewer_delegate)); |
234 base::RunLoop().RunUntilIdle(); | 243 base::RunLoop().RunUntilIdle(); |
235 | 244 |
236 const DistilledArticleProto* distilled_article; | 245 const DistilledArticleProto* distilled_article; |
237 | 246 |
238 EXPECT_CALL(viewer_delegate, OnArticleReady(_)) | 247 EXPECT_CALL(viewer_delegate, OnArticleReady(_)) |
239 .WillOnce(testing::SaveArg<0>(&distilled_article)); | 248 .WillOnce(testing::SaveArg<0>(&distilled_article)); |
240 | 249 |
241 task_tracker.StartBlobFetcher(); | 250 task_tracker.StartBlobFetcher(); |
242 base::RunLoop().RunUntilIdle(); | 251 base::RunLoop().RunUntilIdle(); |
243 | 252 |
(...skipping 12 matching lines...) Expand all Loading... |
256 ArticleEntry entry_with_blob = GetDefaultEntry(); | 265 ArticleEntry entry_with_blob = GetDefaultEntry(); |
257 DistilledArticleProto stored_distilled_article = | 266 DistilledArticleProto stored_distilled_article = |
258 CreateDistilledArticleForEntry(entry_with_blob); | 267 CreateDistilledArticleForEntry(entry_with_blob); |
259 InMemoryContentStore content_store(kDefaultMaxNumCachedEntries); | 268 InMemoryContentStore content_store(kDefaultMaxNumCachedEntries); |
260 content_store.InjectContent(entry_with_blob, stored_distilled_article); | 269 content_store.InjectContent(entry_with_blob, stored_distilled_article); |
261 TestCancelCallback cancel_callback; | 270 TestCancelCallback cancel_callback; |
262 TaskTracker task_tracker( | 271 TaskTracker task_tracker( |
263 entry_with_blob, cancel_callback.GetCallback(), &content_store); | 272 entry_with_blob, cancel_callback.GetCallback(), &content_store); |
264 | 273 |
265 FakeViewRequestDelegate viewer_delegate; | 274 FakeViewRequestDelegate viewer_delegate; |
266 scoped_ptr<ViewerHandle> handle(task_tracker.AddViewer(&viewer_delegate)); | 275 std::unique_ptr<ViewerHandle> handle( |
| 276 task_tracker.AddViewer(&viewer_delegate)); |
267 base::RunLoop().RunUntilIdle(); | 277 base::RunLoop().RunUntilIdle(); |
268 | 278 |
269 DistilledArticleProto distilled_article; | 279 DistilledArticleProto distilled_article; |
270 | 280 |
271 EXPECT_CALL(viewer_delegate, OnArticleReady(_)) | 281 EXPECT_CALL(viewer_delegate, OnArticleReady(_)) |
272 .WillOnce(testing::SaveArgPointee<0>(&distilled_article)); | 282 .WillOnce(testing::SaveArgPointee<0>(&distilled_article)); |
273 bool distiller_destroyed = false; | 283 bool distiller_destroyed = false; |
274 EXPECT_CALL(*distiller, Die()) | 284 EXPECT_CALL(*distiller, Die()) |
275 .WillOnce(testing::Assign(&distiller_destroyed, true)); | 285 .WillOnce(testing::Assign(&distiller_destroyed, true)); |
276 | 286 |
277 task_tracker.StartDistiller(&distiller_factory, scoped_ptr<DistillerPage>()); | 287 task_tracker.StartDistiller(&distiller_factory, |
| 288 std::unique_ptr<DistillerPage>()); |
278 task_tracker.StartBlobFetcher(); | 289 task_tracker.StartBlobFetcher(); |
279 base::RunLoop().RunUntilIdle(); | 290 base::RunLoop().RunUntilIdle(); |
280 | 291 |
281 testing::Mock::VerifyAndClearExpectations(&viewer_delegate); | 292 testing::Mock::VerifyAndClearExpectations(&viewer_delegate); |
282 EXPECT_EQ(stored_distilled_article.SerializeAsString(), | 293 EXPECT_EQ(stored_distilled_article.SerializeAsString(), |
283 distilled_article.SerializeAsString()); | 294 distilled_article.SerializeAsString()); |
284 | 295 |
285 EXPECT_TRUE(distiller_destroyed); | 296 EXPECT_TRUE(distiller_destroyed); |
286 EXPECT_FALSE(cancel_callback.Cancelled()); | 297 EXPECT_FALSE(cancel_callback.Cancelled()); |
287 base::RunLoop().RunUntilIdle(); | 298 base::RunLoop().RunUntilIdle(); |
288 } | 299 } |
289 | 300 |
290 TEST_F(DomDistillerTaskTrackerTest, TestBlobFetcherWithoutBlob) { | 301 TEST_F(DomDistillerTaskTrackerTest, TestBlobFetcherWithoutBlob) { |
291 MockDistillerFactory distiller_factory; | 302 MockDistillerFactory distiller_factory; |
292 FakeDistiller* distiller = new FakeDistiller(false); | 303 FakeDistiller* distiller = new FakeDistiller(false); |
293 EXPECT_CALL(distiller_factory, CreateDistillerImpl()) | 304 EXPECT_CALL(distiller_factory, CreateDistillerImpl()) |
294 .WillOnce(Return(distiller)); | 305 .WillOnce(Return(distiller)); |
295 | 306 |
296 ArticleEntry entry(GetDefaultEntry()); | 307 ArticleEntry entry(GetDefaultEntry()); |
297 InMemoryContentStore content_store(kDefaultMaxNumCachedEntries); | 308 InMemoryContentStore content_store(kDefaultMaxNumCachedEntries); |
298 scoped_ptr<DistilledArticleProto> distilled_article( | 309 std::unique_ptr<DistilledArticleProto> distilled_article( |
299 new DistilledArticleProto(CreateDistilledArticleForEntry(entry))); | 310 new DistilledArticleProto(CreateDistilledArticleForEntry(entry))); |
300 | 311 |
301 TestCancelCallback cancel_callback; | 312 TestCancelCallback cancel_callback; |
302 TaskTracker task_tracker( | 313 TaskTracker task_tracker( |
303 GetDefaultEntry(), cancel_callback.GetCallback(), &content_store); | 314 GetDefaultEntry(), cancel_callback.GetCallback(), &content_store); |
304 | 315 |
305 FakeViewRequestDelegate viewer_delegate; | 316 FakeViewRequestDelegate viewer_delegate; |
306 scoped_ptr<ViewerHandle> handle(task_tracker.AddViewer(&viewer_delegate)); | 317 std::unique_ptr<ViewerHandle> handle( |
| 318 task_tracker.AddViewer(&viewer_delegate)); |
307 base::RunLoop().RunUntilIdle(); | 319 base::RunLoop().RunUntilIdle(); |
308 | 320 |
309 task_tracker.StartBlobFetcher(); | 321 task_tracker.StartBlobFetcher(); |
310 task_tracker.StartDistiller(&distiller_factory, scoped_ptr<DistillerPage>()); | 322 task_tracker.StartDistiller(&distiller_factory, |
| 323 std::unique_ptr<DistillerPage>()); |
311 | 324 |
312 // OnArticleReady shouldn't be called until distillation finishes (i.e. the | 325 // OnArticleReady shouldn't be called until distillation finishes (i.e. the |
313 // blob fetcher shouldn't return distilled content). | 326 // blob fetcher shouldn't return distilled content). |
314 EXPECT_CALL(viewer_delegate, OnArticleReady(_)).Times(0); | 327 EXPECT_CALL(viewer_delegate, OnArticleReady(_)).Times(0); |
315 base::RunLoop().RunUntilIdle(); | 328 base::RunLoop().RunUntilIdle(); |
316 | 329 |
317 EXPECT_CALL(viewer_delegate, OnArticleReady(_)); | 330 EXPECT_CALL(viewer_delegate, OnArticleReady(_)); |
318 distiller->RunDistillerCallback(std::move(distilled_article)); | 331 distiller->RunDistillerCallback(std::move(distilled_article)); |
319 base::RunLoop().RunUntilIdle(); | 332 base::RunLoop().RunUntilIdle(); |
320 | 333 |
321 EXPECT_FALSE(cancel_callback.Cancelled()); | 334 EXPECT_FALSE(cancel_callback.Cancelled()); |
322 } | 335 } |
323 | 336 |
324 TEST_F(DomDistillerTaskTrackerTest, TestDistillerFailsFirst) { | 337 TEST_F(DomDistillerTaskTrackerTest, TestDistillerFailsFirst) { |
325 MockDistillerFactory distiller_factory; | 338 MockDistillerFactory distiller_factory; |
326 FakeDistiller* distiller = new FakeDistiller(false); | 339 FakeDistiller* distiller = new FakeDistiller(false); |
327 EXPECT_CALL(distiller_factory, CreateDistillerImpl()) | 340 EXPECT_CALL(distiller_factory, CreateDistillerImpl()) |
328 .WillOnce(Return(distiller)); | 341 .WillOnce(Return(distiller)); |
329 | 342 |
330 ArticleEntry entry(GetDefaultEntry()); | 343 ArticleEntry entry(GetDefaultEntry()); |
331 MockContentStore content_store; | 344 MockContentStore content_store; |
332 | 345 |
333 TestCancelCallback cancel_callback; | 346 TestCancelCallback cancel_callback; |
334 TaskTracker task_tracker( | 347 TaskTracker task_tracker( |
335 GetDefaultEntry(), cancel_callback.GetCallback(), &content_store); | 348 GetDefaultEntry(), cancel_callback.GetCallback(), &content_store); |
336 | 349 |
337 FakeViewRequestDelegate viewer_delegate; | 350 FakeViewRequestDelegate viewer_delegate; |
338 scoped_ptr<ViewerHandle> handle(task_tracker.AddViewer(&viewer_delegate)); | 351 std::unique_ptr<ViewerHandle> handle( |
| 352 task_tracker.AddViewer(&viewer_delegate)); |
339 | 353 |
340 DistilledContentStore::LoadCallback content_store_load_callback; | 354 DistilledContentStore::LoadCallback content_store_load_callback; |
341 EXPECT_CALL(content_store, LoadContent(_, _)) | 355 EXPECT_CALL(content_store, LoadContent(_, _)) |
342 .WillOnce(testing::SaveArg<1>(&content_store_load_callback)); | 356 .WillOnce(testing::SaveArg<1>(&content_store_load_callback)); |
343 | 357 |
344 task_tracker.StartDistiller(&distiller_factory, scoped_ptr<DistillerPage>()); | 358 task_tracker.StartDistiller(&distiller_factory, |
| 359 std::unique_ptr<DistillerPage>()); |
345 task_tracker.StartBlobFetcher(); | 360 task_tracker.StartBlobFetcher(); |
346 | 361 |
347 EXPECT_CALL(viewer_delegate, OnArticleReady(_)).Times(0); | 362 EXPECT_CALL(viewer_delegate, OnArticleReady(_)).Times(0); |
348 distiller->RunDistillerCallback( | 363 distiller->RunDistillerCallback( |
349 scoped_ptr<DistilledArticleProto>(new DistilledArticleProto)); | 364 std::unique_ptr<DistilledArticleProto>(new DistilledArticleProto)); |
350 base::RunLoop().RunUntilIdle(); | 365 base::RunLoop().RunUntilIdle(); |
351 | 366 |
352 EXPECT_CALL(viewer_delegate, OnArticleReady(_)); | 367 EXPECT_CALL(viewer_delegate, OnArticleReady(_)); |
353 content_store_load_callback.Run( | 368 content_store_load_callback.Run( |
354 true, | 369 true, std::unique_ptr<DistilledArticleProto>(new DistilledArticleProto( |
355 scoped_ptr<DistilledArticleProto>( | 370 CreateDistilledArticleForEntry(entry)))); |
356 new DistilledArticleProto(CreateDistilledArticleForEntry(entry)))); | |
357 base::RunLoop().RunUntilIdle(); | 371 base::RunLoop().RunUntilIdle(); |
358 | 372 |
359 EXPECT_FALSE(cancel_callback.Cancelled()); | 373 EXPECT_FALSE(cancel_callback.Cancelled()); |
360 } | 374 } |
361 | 375 |
362 TEST_F(DomDistillerTaskTrackerTest, ContentIsSaved) { | 376 TEST_F(DomDistillerTaskTrackerTest, ContentIsSaved) { |
363 MockDistillerFactory distiller_factory; | 377 MockDistillerFactory distiller_factory; |
364 FakeDistiller* distiller = new FakeDistiller(false); | 378 FakeDistiller* distiller = new FakeDistiller(false); |
365 EXPECT_CALL(distiller_factory, CreateDistillerImpl()) | 379 EXPECT_CALL(distiller_factory, CreateDistillerImpl()) |
366 .WillOnce(Return(distiller)); | 380 .WillOnce(Return(distiller)); |
367 | 381 |
368 ArticleEntry entry(GetDefaultEntry()); | 382 ArticleEntry entry(GetDefaultEntry()); |
369 DistilledArticleProto distilled_article = | 383 DistilledArticleProto distilled_article = |
370 CreateDistilledArticleForEntry(entry); | 384 CreateDistilledArticleForEntry(entry); |
371 | 385 |
372 MockContentStore content_store; | 386 MockContentStore content_store; |
373 TestCancelCallback cancel_callback; | 387 TestCancelCallback cancel_callback; |
374 TaskTracker task_tracker( | 388 TaskTracker task_tracker( |
375 GetDefaultEntry(), cancel_callback.GetCallback(), &content_store); | 389 GetDefaultEntry(), cancel_callback.GetCallback(), &content_store); |
376 | 390 |
377 FakeViewRequestDelegate viewer_delegate; | 391 FakeViewRequestDelegate viewer_delegate; |
378 scoped_ptr<ViewerHandle> handle(task_tracker.AddViewer(&viewer_delegate)); | 392 std::unique_ptr<ViewerHandle> handle( |
| 393 task_tracker.AddViewer(&viewer_delegate)); |
379 | 394 |
380 DistilledArticleProto stored_distilled_article; | 395 DistilledArticleProto stored_distilled_article; |
381 DistilledContentStore::LoadCallback content_store_load_callback; | 396 DistilledContentStore::LoadCallback content_store_load_callback; |
382 EXPECT_CALL(content_store, SaveContent(_, _, _)) | 397 EXPECT_CALL(content_store, SaveContent(_, _, _)) |
383 .WillOnce(testing::SaveArg<1>(&stored_distilled_article)); | 398 .WillOnce(testing::SaveArg<1>(&stored_distilled_article)); |
384 | 399 |
385 task_tracker.StartDistiller(&distiller_factory, scoped_ptr<DistillerPage>()); | 400 task_tracker.StartDistiller(&distiller_factory, |
| 401 std::unique_ptr<DistillerPage>()); |
386 | 402 |
387 EXPECT_CALL(viewer_delegate, OnArticleReady(_)); | 403 EXPECT_CALL(viewer_delegate, OnArticleReady(_)); |
388 distiller->RunDistillerCallback(scoped_ptr<DistilledArticleProto>( | 404 distiller->RunDistillerCallback(std::unique_ptr<DistilledArticleProto>( |
389 new DistilledArticleProto(distilled_article))); | 405 new DistilledArticleProto(distilled_article))); |
390 base::RunLoop().RunUntilIdle(); | 406 base::RunLoop().RunUntilIdle(); |
391 | 407 |
392 ASSERT_EQ(stored_distilled_article.SerializeAsString(), | 408 ASSERT_EQ(stored_distilled_article.SerializeAsString(), |
393 distilled_article.SerializeAsString()); | 409 distilled_article.SerializeAsString()); |
394 EXPECT_FALSE(cancel_callback.Cancelled()); | 410 EXPECT_FALSE(cancel_callback.Cancelled()); |
395 } | 411 } |
396 | 412 |
397 } // namespace test | 413 } // namespace test |
398 } // namespace dom_distiller | 414 } // namespace dom_distiller |
OLD | NEW |