OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/distilled_content_store.h" | 5 #include "components/dom_distiller/core/distilled_content_store.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 page->set_url(entry.pages(i).url()); | 46 page->set_url(entry.pages(i).url()); |
47 page->set_html("<div>" + entry.pages(i).url() + "</div>"); | 47 page->set_html("<div>" + entry.pages(i).url() + "</div>"); |
48 } | 48 } |
49 return article; | 49 return article; |
50 } | 50 } |
51 | 51 |
52 } // namespace | 52 } // namespace |
53 | 53 |
54 class InMemoryContentStoreTest : public testing::Test { | 54 class InMemoryContentStoreTest : public testing::Test { |
55 public: | 55 public: |
56 void OnLoadCallback(bool success, scoped_ptr<DistilledArticleProto> proto) { | 56 void OnLoadCallback(bool success, |
| 57 std::unique_ptr<DistilledArticleProto> proto) { |
57 load_success_ = success; | 58 load_success_ = success; |
58 loaded_proto_ = std::move(proto); | 59 loaded_proto_ = std::move(proto); |
59 } | 60 } |
60 | 61 |
61 void OnSaveCallback(bool success) { save_success_ = success; } | 62 void OnSaveCallback(bool success) { save_success_ = success; } |
62 | 63 |
63 protected: | 64 protected: |
64 // testing::Test implementation: | 65 // testing::Test implementation: |
65 void SetUp() override { | 66 void SetUp() override { |
66 store_.reset(new InMemoryContentStore(kDefaultMaxNumCachedEntries)); | 67 store_.reset(new InMemoryContentStore(kDefaultMaxNumCachedEntries)); |
67 save_success_ = false; | 68 save_success_ = false; |
68 load_success_ = false; | 69 load_success_ = false; |
69 loaded_proto_.reset(); | 70 loaded_proto_.reset(); |
70 } | 71 } |
71 | 72 |
72 scoped_ptr<InMemoryContentStore> store_; | 73 std::unique_ptr<InMemoryContentStore> store_; |
73 bool save_success_; | 74 bool save_success_; |
74 bool load_success_; | 75 bool load_success_; |
75 scoped_ptr<DistilledArticleProto> loaded_proto_; | 76 std::unique_ptr<DistilledArticleProto> loaded_proto_; |
76 }; | 77 }; |
77 | 78 |
78 // Tests whether saving and then loading a single article works as expected. | 79 // Tests whether saving and then loading a single article works as expected. |
79 TEST_F(InMemoryContentStoreTest, SaveAndLoadSingleArticle) { | 80 TEST_F(InMemoryContentStoreTest, SaveAndLoadSingleArticle) { |
80 base::MessageLoop loop; | 81 base::MessageLoop loop; |
81 const ArticleEntry entry = CreateEntry("test-id", "url1", "url2", "url3"); | 82 const ArticleEntry entry = CreateEntry("test-id", "url1", "url2", "url3"); |
82 const DistilledArticleProto stored_proto = | 83 const DistilledArticleProto stored_proto = |
83 CreateDistilledArticleForEntry(entry); | 84 CreateDistilledArticleForEntry(entry); |
84 store_->SaveContent(entry, | 85 store_->SaveContent(entry, |
85 stored_proto, | 86 stored_proto, |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 | 328 |
328 // Looking up the first entry by URL should fail when it is not in the cache. | 329 // Looking up the first entry by URL should fail when it is not in the cache. |
329 store_->LoadContent(first_entry_lookup, | 330 store_->LoadContent(first_entry_lookup, |
330 base::Bind(&InMemoryContentStoreTest::OnLoadCallback, | 331 base::Bind(&InMemoryContentStoreTest::OnLoadCallback, |
331 base::Unretained(this))); | 332 base::Unretained(this))); |
332 base::MessageLoop::current()->RunUntilIdle(); | 333 base::MessageLoop::current()->RunUntilIdle(); |
333 EXPECT_FALSE(load_success_); | 334 EXPECT_FALSE(load_success_); |
334 } | 335 } |
335 | 336 |
336 } // namespace dom_distiller | 337 } // namespace dom_distiller |
OLD | NEW |