Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(669)

Side by Side Diff: components/dom_distiller/core/task_tracker_unittest.cc

Issue 302163005: Change InMemoryContentStore to use MRUCache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated tests for expiry and fixed lint errors. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « components/dom_distiller/core/dom_distiller_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 10 matching lines...) Expand all
21 public: 21 public:
22 virtual ~FakeViewRequestDelegate() {} 22 virtual ~FakeViewRequestDelegate() {}
23 MOCK_METHOD1(OnArticleReady, 23 MOCK_METHOD1(OnArticleReady,
24 void(const DistilledArticleProto* article_proto)); 24 void(const DistilledArticleProto* article_proto));
25 MOCK_METHOD1(OnArticleUpdated, 25 MOCK_METHOD1(OnArticleUpdated,
26 void(ArticleDistillationUpdate article_update)); 26 void(ArticleDistillationUpdate article_update));
27 }; 27 };
28 28
29 class MockContentStore : public DistilledContentStore { 29 class MockContentStore : public DistilledContentStore {
30 public: 30 public:
31 MOCK_CONST_METHOD2(LoadContent, 31 MOCK_METHOD2(LoadContent,
32 void(const ArticleEntry& entry, LoadCallback callback)); 32 void(const ArticleEntry& entry, LoadCallback callback));
33 MOCK_METHOD3(SaveContent, 33 MOCK_METHOD3(SaveContent,
34 void(const ArticleEntry& entry, 34 void(const ArticleEntry& entry,
35 const DistilledArticleProto& proto, 35 const DistilledArticleProto& proto,
36 SaveCallback callback)); 36 SaveCallback callback));
37 }; 37 };
38 38
39 class TestCancelCallback { 39 class TestCancelCallback {
40 public: 40 public:
41 TestCancelCallback() : cancelled_(false) {} 41 TestCancelCallback() : cancelled_(false) {}
42 TaskTracker::CancelCallback GetCallback() { 42 TaskTracker::CancelCallback GetCallback() {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 page->set_url(entry.pages(i).url()); 191 page->set_url(entry.pages(i).url());
192 page->set_html("<div>" + entry.pages(i).url() + "</div>"); 192 page->set_html("<div>" + entry.pages(i).url() + "</div>");
193 } 193 }
194 return article; 194 return article;
195 } 195 }
196 196
197 TEST_F(DomDistillerTaskTrackerTest, TestBlobFetcher) { 197 TEST_F(DomDistillerTaskTrackerTest, TestBlobFetcher) {
198 ArticleEntry entry_with_blob = GetDefaultEntry(); 198 ArticleEntry entry_with_blob = GetDefaultEntry();
199 DistilledArticleProto stored_distilled_article = 199 DistilledArticleProto stored_distilled_article =
200 CreateDistilledArticleForEntry(entry_with_blob); 200 CreateDistilledArticleForEntry(entry_with_blob);
201 InMemoryContentStore content_store; 201 InMemoryContentStore content_store(kDefaultMaxNumCachedEntries);
202 content_store.InjectContent(entry_with_blob, stored_distilled_article); 202 content_store.InjectContent(entry_with_blob, stored_distilled_article);
203 TestCancelCallback cancel_callback; 203 TestCancelCallback cancel_callback;
204 204
205 TaskTracker task_tracker( 205 TaskTracker task_tracker(
206 entry_with_blob, cancel_callback.GetCallback(), &content_store); 206 entry_with_blob, cancel_callback.GetCallback(), &content_store);
207 207
208 FakeViewRequestDelegate viewer_delegate; 208 FakeViewRequestDelegate viewer_delegate;
209 scoped_ptr<ViewerHandle> handle(task_tracker.AddViewer(&viewer_delegate)); 209 scoped_ptr<ViewerHandle> handle(task_tracker.AddViewer(&viewer_delegate));
210 base::RunLoop().RunUntilIdle(); 210 base::RunLoop().RunUntilIdle();
211 211
(...skipping 13 matching lines...) Expand all
225 225
226 TEST_F(DomDistillerTaskTrackerTest, TestBlobFetcherFinishesFirst) { 226 TEST_F(DomDistillerTaskTrackerTest, TestBlobFetcherFinishesFirst) {
227 MockDistillerFactory distiller_factory; 227 MockDistillerFactory distiller_factory;
228 FakeDistiller* distiller = new FakeDistiller(false); 228 FakeDistiller* distiller = new FakeDistiller(false);
229 EXPECT_CALL(distiller_factory, CreateDistillerImpl()) 229 EXPECT_CALL(distiller_factory, CreateDistillerImpl())
230 .WillOnce(Return(distiller)); 230 .WillOnce(Return(distiller));
231 231
232 ArticleEntry entry_with_blob = GetDefaultEntry(); 232 ArticleEntry entry_with_blob = GetDefaultEntry();
233 DistilledArticleProto stored_distilled_article = 233 DistilledArticleProto stored_distilled_article =
234 CreateDistilledArticleForEntry(entry_with_blob); 234 CreateDistilledArticleForEntry(entry_with_blob);
235 InMemoryContentStore content_store; 235 InMemoryContentStore content_store(kDefaultMaxNumCachedEntries);
236 content_store.InjectContent(entry_with_blob, stored_distilled_article); 236 content_store.InjectContent(entry_with_blob, stored_distilled_article);
237 TestCancelCallback cancel_callback; 237 TestCancelCallback cancel_callback;
238 TaskTracker task_tracker( 238 TaskTracker task_tracker(
239 entry_with_blob, cancel_callback.GetCallback(), &content_store); 239 entry_with_blob, cancel_callback.GetCallback(), &content_store);
240 240
241 FakeViewRequestDelegate viewer_delegate; 241 FakeViewRequestDelegate viewer_delegate;
242 scoped_ptr<ViewerHandle> handle(task_tracker.AddViewer(&viewer_delegate)); 242 scoped_ptr<ViewerHandle> handle(task_tracker.AddViewer(&viewer_delegate));
243 base::RunLoop().RunUntilIdle(); 243 base::RunLoop().RunUntilIdle();
244 244
245 DistilledArticleProto distilled_article; 245 DistilledArticleProto distilled_article;
(...skipping 18 matching lines...) Expand all
264 base::RunLoop().RunUntilIdle(); 264 base::RunLoop().RunUntilIdle();
265 } 265 }
266 266
267 TEST_F(DomDistillerTaskTrackerTest, TestBlobFetcherWithoutBlob) { 267 TEST_F(DomDistillerTaskTrackerTest, TestBlobFetcherWithoutBlob) {
268 MockDistillerFactory distiller_factory; 268 MockDistillerFactory distiller_factory;
269 FakeDistiller* distiller = new FakeDistiller(false); 269 FakeDistiller* distiller = new FakeDistiller(false);
270 EXPECT_CALL(distiller_factory, CreateDistillerImpl()) 270 EXPECT_CALL(distiller_factory, CreateDistillerImpl())
271 .WillOnce(Return(distiller)); 271 .WillOnce(Return(distiller));
272 272
273 ArticleEntry entry(GetDefaultEntry()); 273 ArticleEntry entry(GetDefaultEntry());
274 InMemoryContentStore content_store; 274 InMemoryContentStore content_store(kDefaultMaxNumCachedEntries);
275 scoped_ptr<DistilledArticleProto> distilled_article( 275 scoped_ptr<DistilledArticleProto> distilled_article(
276 new DistilledArticleProto(CreateDistilledArticleForEntry(entry))); 276 new DistilledArticleProto(CreateDistilledArticleForEntry(entry)));
277 277
278 TestCancelCallback cancel_callback; 278 TestCancelCallback cancel_callback;
279 TaskTracker task_tracker( 279 TaskTracker task_tracker(
280 GetDefaultEntry(), cancel_callback.GetCallback(), &content_store); 280 GetDefaultEntry(), cancel_callback.GetCallback(), &content_store);
281 281
282 FakeViewRequestDelegate viewer_delegate; 282 FakeViewRequestDelegate viewer_delegate;
283 scoped_ptr<ViewerHandle> handle(task_tracker.AddViewer(&viewer_delegate)); 283 scoped_ptr<ViewerHandle> handle(task_tracker.AddViewer(&viewer_delegate));
284 base::RunLoop().RunUntilIdle(); 284 base::RunLoop().RunUntilIdle();
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 new DistilledArticleProto(distilled_article))); 369 new DistilledArticleProto(distilled_article)));
370 base::RunLoop().RunUntilIdle(); 370 base::RunLoop().RunUntilIdle();
371 371
372 ASSERT_EQ(stored_distilled_article.SerializeAsString(), 372 ASSERT_EQ(stored_distilled_article.SerializeAsString(),
373 distilled_article.SerializeAsString()); 373 distilled_article.SerializeAsString());
374 EXPECT_FALSE(cancel_callback.Cancelled()); 374 EXPECT_FALSE(cancel_callback.Cancelled());
375 } 375 }
376 376
377 } // namespace test 377 } // namespace test
378 } // namespace dom_distiller 378 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « components/dom_distiller/core/dom_distiller_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698