| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 // 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. |
| 80 TEST_F(InMemoryContentStoreTest, SaveAndLoadSingleArticle) { | 80 TEST_F(InMemoryContentStoreTest, SaveAndLoadSingleArticle) { |
| 81 base::MessageLoop loop; | 81 base::MessageLoop loop; |
| 82 const ArticleEntry entry = CreateEntry("test-id", "url1", "url2", "url3"); | 82 const ArticleEntry entry = CreateEntry("test-id", "url1", "url2", "url3"); |
| 83 const DistilledArticleProto stored_proto = | 83 const DistilledArticleProto stored_proto = |
| 84 CreateDistilledArticleForEntry(entry); | 84 CreateDistilledArticleForEntry(entry); |
| 85 store_->SaveContent(entry, | 85 store_->SaveContent(entry, |
| 86 stored_proto, | 86 stored_proto, |
| 87 base::Bind(&InMemoryContentStoreTest::OnSaveCallback, | 87 base::Bind(&InMemoryContentStoreTest::OnSaveCallback, |
| 88 base::Unretained(this))); | 88 base::Unretained(this))); |
| 89 base::MessageLoop::current()->RunUntilIdle(); | 89 base::RunLoop().RunUntilIdle(); |
| 90 EXPECT_TRUE(save_success_); | 90 EXPECT_TRUE(save_success_); |
| 91 save_success_ = false; | 91 save_success_ = false; |
| 92 | 92 |
| 93 store_->LoadContent(entry, | 93 store_->LoadContent(entry, |
| 94 base::Bind(&InMemoryContentStoreTest::OnLoadCallback, | 94 base::Bind(&InMemoryContentStoreTest::OnLoadCallback, |
| 95 base::Unretained(this))); | 95 base::Unretained(this))); |
| 96 base::MessageLoop::current()->RunUntilIdle(); | 96 base::RunLoop().RunUntilIdle(); |
| 97 EXPECT_TRUE(load_success_); | 97 EXPECT_TRUE(load_success_); |
| 98 EXPECT_EQ(stored_proto.SerializeAsString(), | 98 EXPECT_EQ(stored_proto.SerializeAsString(), |
| 99 loaded_proto_->SerializeAsString()); | 99 loaded_proto_->SerializeAsString()); |
| 100 } | 100 } |
| 101 | 101 |
| 102 // Tests that loading articles which have never been stored, yields a callback | 102 // Tests that loading articles which have never been stored, yields a callback |
| 103 // where success is false. | 103 // where success is false. |
| 104 TEST_F(InMemoryContentStoreTest, LoadNonExistentArticle) { | 104 TEST_F(InMemoryContentStoreTest, LoadNonExistentArticle) { |
| 105 base::MessageLoop loop; | 105 base::MessageLoop loop; |
| 106 const ArticleEntry entry = CreateEntry("bogus-id", "url1", "url2", "url3"); | 106 const ArticleEntry entry = CreateEntry("bogus-id", "url1", "url2", "url3"); |
| 107 store_->LoadContent(entry, | 107 store_->LoadContent(entry, |
| 108 base::Bind(&InMemoryContentStoreTest::OnLoadCallback, | 108 base::Bind(&InMemoryContentStoreTest::OnLoadCallback, |
| 109 base::Unretained(this))); | 109 base::Unretained(this))); |
| 110 base::MessageLoop::current()->RunUntilIdle(); | 110 base::RunLoop().RunUntilIdle(); |
| 111 EXPECT_FALSE(load_success_); | 111 EXPECT_FALSE(load_success_); |
| 112 } | 112 } |
| 113 | 113 |
| 114 // Verifies that content store can store multiple articles, and that ordering | 114 // Verifies that content store can store multiple articles, and that ordering |
| 115 // of save and store does not matter when the total number of articles does not | 115 // of save and store does not matter when the total number of articles does not |
| 116 // exceed |kDefaultMaxNumCachedEntries|. | 116 // exceed |kDefaultMaxNumCachedEntries|. |
| 117 TEST_F(InMemoryContentStoreTest, SaveAndLoadMultipleArticles) { | 117 TEST_F(InMemoryContentStoreTest, SaveAndLoadMultipleArticles) { |
| 118 base::MessageLoop loop; | 118 base::MessageLoop loop; |
| 119 // Store first article. | 119 // Store first article. |
| 120 const ArticleEntry first_entry = CreateEntry("first", "url1", "url2", "url3"); | 120 const ArticleEntry first_entry = CreateEntry("first", "url1", "url2", "url3"); |
| 121 const DistilledArticleProto first_stored_proto = | 121 const DistilledArticleProto first_stored_proto = |
| 122 CreateDistilledArticleForEntry(first_entry); | 122 CreateDistilledArticleForEntry(first_entry); |
| 123 store_->SaveContent(first_entry, | 123 store_->SaveContent(first_entry, |
| 124 first_stored_proto, | 124 first_stored_proto, |
| 125 base::Bind(&InMemoryContentStoreTest::OnSaveCallback, | 125 base::Bind(&InMemoryContentStoreTest::OnSaveCallback, |
| 126 base::Unretained(this))); | 126 base::Unretained(this))); |
| 127 base::MessageLoop::current()->RunUntilIdle(); | 127 base::RunLoop().RunUntilIdle(); |
| 128 EXPECT_TRUE(save_success_); | 128 EXPECT_TRUE(save_success_); |
| 129 save_success_ = false; | 129 save_success_ = false; |
| 130 | 130 |
| 131 // Store second article. | 131 // Store second article. |
| 132 const ArticleEntry second_entry = | 132 const ArticleEntry second_entry = |
| 133 CreateEntry("second", "url4", "url5", "url6"); | 133 CreateEntry("second", "url4", "url5", "url6"); |
| 134 const DistilledArticleProto second_stored_proto = | 134 const DistilledArticleProto second_stored_proto = |
| 135 CreateDistilledArticleForEntry(second_entry); | 135 CreateDistilledArticleForEntry(second_entry); |
| 136 store_->SaveContent(second_entry, | 136 store_->SaveContent(second_entry, |
| 137 second_stored_proto, | 137 second_stored_proto, |
| 138 base::Bind(&InMemoryContentStoreTest::OnSaveCallback, | 138 base::Bind(&InMemoryContentStoreTest::OnSaveCallback, |
| 139 base::Unretained(this))); | 139 base::Unretained(this))); |
| 140 base::MessageLoop::current()->RunUntilIdle(); | 140 base::RunLoop().RunUntilIdle(); |
| 141 EXPECT_TRUE(save_success_); | 141 EXPECT_TRUE(save_success_); |
| 142 save_success_ = false; | 142 save_success_ = false; |
| 143 | 143 |
| 144 // Load second article. | 144 // Load second article. |
| 145 store_->LoadContent(second_entry, | 145 store_->LoadContent(second_entry, |
| 146 base::Bind(&InMemoryContentStoreTest::OnLoadCallback, | 146 base::Bind(&InMemoryContentStoreTest::OnLoadCallback, |
| 147 base::Unretained(this))); | 147 base::Unretained(this))); |
| 148 base::MessageLoop::current()->RunUntilIdle(); | 148 base::RunLoop().RunUntilIdle(); |
| 149 EXPECT_TRUE(load_success_); | 149 EXPECT_TRUE(load_success_); |
| 150 load_success_ = false; | 150 load_success_ = false; |
| 151 EXPECT_EQ(second_stored_proto.SerializeAsString(), | 151 EXPECT_EQ(second_stored_proto.SerializeAsString(), |
| 152 loaded_proto_->SerializeAsString()); | 152 loaded_proto_->SerializeAsString()); |
| 153 loaded_proto_.reset(); | 153 loaded_proto_.reset(); |
| 154 | 154 |
| 155 // Load first article. | 155 // Load first article. |
| 156 store_->LoadContent(first_entry, | 156 store_->LoadContent(first_entry, |
| 157 base::Bind(&InMemoryContentStoreTest::OnLoadCallback, | 157 base::Bind(&InMemoryContentStoreTest::OnLoadCallback, |
| 158 base::Unretained(this))); | 158 base::Unretained(this))); |
| 159 base::MessageLoop::current()->RunUntilIdle(); | 159 base::RunLoop().RunUntilIdle(); |
| 160 EXPECT_TRUE(load_success_); | 160 EXPECT_TRUE(load_success_); |
| 161 EXPECT_EQ(first_stored_proto.SerializeAsString(), | 161 EXPECT_EQ(first_stored_proto.SerializeAsString(), |
| 162 loaded_proto_->SerializeAsString()); | 162 loaded_proto_->SerializeAsString()); |
| 163 } | 163 } |
| 164 | 164 |
| 165 // Verifies that the content store does not store unlimited number of articles, | 165 // Verifies that the content store does not store unlimited number of articles, |
| 166 // but expires the oldest ones when the limit for number of articles is reached. | 166 // but expires the oldest ones when the limit for number of articles is reached. |
| 167 TEST_F(InMemoryContentStoreTest, SaveAndLoadMoreThanMaxArticles) { | 167 TEST_F(InMemoryContentStoreTest, SaveAndLoadMoreThanMaxArticles) { |
| 168 base::MessageLoop loop; | 168 base::MessageLoop loop; |
| 169 | 169 |
| 170 // Create a new store with only |kMaxNumArticles| articles as the limit. | 170 // Create a new store with only |kMaxNumArticles| articles as the limit. |
| 171 const int kMaxNumArticles = 3; | 171 const int kMaxNumArticles = 3; |
| 172 store_.reset(new InMemoryContentStore(kMaxNumArticles)); | 172 store_.reset(new InMemoryContentStore(kMaxNumArticles)); |
| 173 | 173 |
| 174 // Store first article. | 174 // Store first article. |
| 175 const ArticleEntry first_entry = CreateEntry("first", "url1", "url2", "url3"); | 175 const ArticleEntry first_entry = CreateEntry("first", "url1", "url2", "url3"); |
| 176 const DistilledArticleProto first_stored_proto = | 176 const DistilledArticleProto first_stored_proto = |
| 177 CreateDistilledArticleForEntry(first_entry); | 177 CreateDistilledArticleForEntry(first_entry); |
| 178 store_->SaveContent(first_entry, | 178 store_->SaveContent(first_entry, |
| 179 first_stored_proto, | 179 first_stored_proto, |
| 180 base::Bind(&InMemoryContentStoreTest::OnSaveCallback, | 180 base::Bind(&InMemoryContentStoreTest::OnSaveCallback, |
| 181 base::Unretained(this))); | 181 base::Unretained(this))); |
| 182 base::MessageLoop::current()->RunUntilIdle(); | 182 base::RunLoop().RunUntilIdle(); |
| 183 EXPECT_TRUE(save_success_); | 183 EXPECT_TRUE(save_success_); |
| 184 save_success_ = false; | 184 save_success_ = false; |
| 185 | 185 |
| 186 // Store second article. | 186 // Store second article. |
| 187 const ArticleEntry second_entry = | 187 const ArticleEntry second_entry = |
| 188 CreateEntry("second", "url4", "url5", "url6"); | 188 CreateEntry("second", "url4", "url5", "url6"); |
| 189 const DistilledArticleProto second_stored_proto = | 189 const DistilledArticleProto second_stored_proto = |
| 190 CreateDistilledArticleForEntry(second_entry); | 190 CreateDistilledArticleForEntry(second_entry); |
| 191 store_->SaveContent(second_entry, | 191 store_->SaveContent(second_entry, |
| 192 second_stored_proto, | 192 second_stored_proto, |
| 193 base::Bind(&InMemoryContentStoreTest::OnSaveCallback, | 193 base::Bind(&InMemoryContentStoreTest::OnSaveCallback, |
| 194 base::Unretained(this))); | 194 base::Unretained(this))); |
| 195 base::MessageLoop::current()->RunUntilIdle(); | 195 base::RunLoop().RunUntilIdle(); |
| 196 EXPECT_TRUE(save_success_); | 196 EXPECT_TRUE(save_success_); |
| 197 save_success_ = false; | 197 save_success_ = false; |
| 198 | 198 |
| 199 // Store third article. | 199 // Store third article. |
| 200 const ArticleEntry third_entry = CreateEntry("third", "url7", "url8", "url9"); | 200 const ArticleEntry third_entry = CreateEntry("third", "url7", "url8", "url9"); |
| 201 const DistilledArticleProto third_stored_proto = | 201 const DistilledArticleProto third_stored_proto = |
| 202 CreateDistilledArticleForEntry(third_entry); | 202 CreateDistilledArticleForEntry(third_entry); |
| 203 store_->SaveContent(third_entry, | 203 store_->SaveContent(third_entry, |
| 204 third_stored_proto, | 204 third_stored_proto, |
| 205 base::Bind(&InMemoryContentStoreTest::OnSaveCallback, | 205 base::Bind(&InMemoryContentStoreTest::OnSaveCallback, |
| 206 base::Unretained(this))); | 206 base::Unretained(this))); |
| 207 base::MessageLoop::current()->RunUntilIdle(); | 207 base::RunLoop().RunUntilIdle(); |
| 208 EXPECT_TRUE(save_success_); | 208 EXPECT_TRUE(save_success_); |
| 209 save_success_ = false; | 209 save_success_ = false; |
| 210 | 210 |
| 211 // Load first article. This will make the first article the most recent | 211 // Load first article. This will make the first article the most recent |
| 212 // accessed article. | 212 // accessed article. |
| 213 store_->LoadContent(first_entry, | 213 store_->LoadContent(first_entry, |
| 214 base::Bind(&InMemoryContentStoreTest::OnLoadCallback, | 214 base::Bind(&InMemoryContentStoreTest::OnLoadCallback, |
| 215 base::Unretained(this))); | 215 base::Unretained(this))); |
| 216 base::MessageLoop::current()->RunUntilIdle(); | 216 base::RunLoop().RunUntilIdle(); |
| 217 EXPECT_TRUE(load_success_); | 217 EXPECT_TRUE(load_success_); |
| 218 load_success_ = false; | 218 load_success_ = false; |
| 219 EXPECT_EQ(first_stored_proto.SerializeAsString(), | 219 EXPECT_EQ(first_stored_proto.SerializeAsString(), |
| 220 loaded_proto_->SerializeAsString()); | 220 loaded_proto_->SerializeAsString()); |
| 221 loaded_proto_.reset(); | 221 loaded_proto_.reset(); |
| 222 | 222 |
| 223 // Store fourth article. | 223 // Store fourth article. |
| 224 const ArticleEntry fourth_entry = | 224 const ArticleEntry fourth_entry = |
| 225 CreateEntry("fourth", "url10", "url11", "url12"); | 225 CreateEntry("fourth", "url10", "url11", "url12"); |
| 226 const DistilledArticleProto fourth_stored_proto = | 226 const DistilledArticleProto fourth_stored_proto = |
| 227 CreateDistilledArticleForEntry(fourth_entry); | 227 CreateDistilledArticleForEntry(fourth_entry); |
| 228 store_->SaveContent(fourth_entry, | 228 store_->SaveContent(fourth_entry, |
| 229 fourth_stored_proto, | 229 fourth_stored_proto, |
| 230 base::Bind(&InMemoryContentStoreTest::OnSaveCallback, | 230 base::Bind(&InMemoryContentStoreTest::OnSaveCallback, |
| 231 base::Unretained(this))); | 231 base::Unretained(this))); |
| 232 base::MessageLoop::current()->RunUntilIdle(); | 232 base::RunLoop().RunUntilIdle(); |
| 233 EXPECT_TRUE(save_success_); | 233 EXPECT_TRUE(save_success_); |
| 234 save_success_ = false; | 234 save_success_ = false; |
| 235 | 235 |
| 236 // Load second article, which by now is the oldest accessed article, since | 236 // Load second article, which by now is the oldest accessed article, since |
| 237 // the first article has been loaded once. | 237 // the first article has been loaded once. |
| 238 store_->LoadContent(second_entry, | 238 store_->LoadContent(second_entry, |
| 239 base::Bind(&InMemoryContentStoreTest::OnLoadCallback, | 239 base::Bind(&InMemoryContentStoreTest::OnLoadCallback, |
| 240 base::Unretained(this))); | 240 base::Unretained(this))); |
| 241 base::MessageLoop::current()->RunUntilIdle(); | 241 base::RunLoop().RunUntilIdle(); |
| 242 // Since the store can only contain |kMaxNumArticles| entries, this load | 242 // Since the store can only contain |kMaxNumArticles| entries, this load |
| 243 // should fail. | 243 // should fail. |
| 244 EXPECT_FALSE(load_success_); | 244 EXPECT_FALSE(load_success_); |
| 245 } | 245 } |
| 246 | 246 |
| 247 // Tests whether saving and then loading a single article works as expected. | 247 // Tests whether saving and then loading a single article works as expected. |
| 248 TEST_F(InMemoryContentStoreTest, LookupArticleByURL) { | 248 TEST_F(InMemoryContentStoreTest, LookupArticleByURL) { |
| 249 base::MessageLoop loop; | 249 base::MessageLoop loop; |
| 250 const ArticleEntry entry = CreateEntry("test-id", "url1", "url2", "url3"); | 250 const ArticleEntry entry = CreateEntry("test-id", "url1", "url2", "url3"); |
| 251 const DistilledArticleProto stored_proto = | 251 const DistilledArticleProto stored_proto = |
| 252 CreateDistilledArticleForEntry(entry); | 252 CreateDistilledArticleForEntry(entry); |
| 253 store_->SaveContent(entry, | 253 store_->SaveContent(entry, |
| 254 stored_proto, | 254 stored_proto, |
| 255 base::Bind(&InMemoryContentStoreTest::OnSaveCallback, | 255 base::Bind(&InMemoryContentStoreTest::OnSaveCallback, |
| 256 base::Unretained(this))); | 256 base::Unretained(this))); |
| 257 base::MessageLoop::current()->RunUntilIdle(); | 257 base::RunLoop().RunUntilIdle(); |
| 258 EXPECT_TRUE(save_success_); | 258 EXPECT_TRUE(save_success_); |
| 259 save_success_ = false; | 259 save_success_ = false; |
| 260 | 260 |
| 261 // Create an entry where the entry ID does not match, but the first URL does. | 261 // Create an entry where the entry ID does not match, but the first URL does. |
| 262 const ArticleEntry lookup_entry1 = CreateEntry("lookup-id", "url1", "", ""); | 262 const ArticleEntry lookup_entry1 = CreateEntry("lookup-id", "url1", "", ""); |
| 263 store_->LoadContent(lookup_entry1, | 263 store_->LoadContent(lookup_entry1, |
| 264 base::Bind(&InMemoryContentStoreTest::OnLoadCallback, | 264 base::Bind(&InMemoryContentStoreTest::OnLoadCallback, |
| 265 base::Unretained(this))); | 265 base::Unretained(this))); |
| 266 base::MessageLoop::current()->RunUntilIdle(); | 266 base::RunLoop().RunUntilIdle(); |
| 267 EXPECT_TRUE(load_success_); | 267 EXPECT_TRUE(load_success_); |
| 268 EXPECT_EQ(stored_proto.SerializeAsString(), | 268 EXPECT_EQ(stored_proto.SerializeAsString(), |
| 269 loaded_proto_->SerializeAsString()); | 269 loaded_proto_->SerializeAsString()); |
| 270 | 270 |
| 271 // Create an entry where the entry ID does not match, but the second URL does. | 271 // Create an entry where the entry ID does not match, but the second URL does. |
| 272 const ArticleEntry lookup_entry2 = | 272 const ArticleEntry lookup_entry2 = |
| 273 CreateEntry("lookup-id", "bogus", "url2", ""); | 273 CreateEntry("lookup-id", "bogus", "url2", ""); |
| 274 store_->LoadContent(lookup_entry2, | 274 store_->LoadContent(lookup_entry2, |
| 275 base::Bind(&InMemoryContentStoreTest::OnLoadCallback, | 275 base::Bind(&InMemoryContentStoreTest::OnLoadCallback, |
| 276 base::Unretained(this))); | 276 base::Unretained(this))); |
| 277 base::MessageLoop::current()->RunUntilIdle(); | 277 base::RunLoop().RunUntilIdle(); |
| 278 EXPECT_TRUE(load_success_); | 278 EXPECT_TRUE(load_success_); |
| 279 EXPECT_EQ(stored_proto.SerializeAsString(), | 279 EXPECT_EQ(stored_proto.SerializeAsString(), |
| 280 loaded_proto_->SerializeAsString()); | 280 loaded_proto_->SerializeAsString()); |
| 281 } | 281 } |
| 282 | 282 |
| 283 // Verifies that the content store does not store unlimited number of articles, | 283 // Verifies that the content store does not store unlimited number of articles, |
| 284 // but expires the oldest ones when the limit for number of articles is reached. | 284 // but expires the oldest ones when the limit for number of articles is reached. |
| 285 TEST_F(InMemoryContentStoreTest, LoadArticleByURLAfterExpungedFromCache) { | 285 TEST_F(InMemoryContentStoreTest, LoadArticleByURLAfterExpungedFromCache) { |
| 286 base::MessageLoop loop; | 286 base::MessageLoop loop; |
| 287 | 287 |
| 288 // Create a new store with only |kMaxNumArticles| articles as the limit. | 288 // Create a new store with only |kMaxNumArticles| articles as the limit. |
| 289 const int kMaxNumArticles = 1; | 289 const int kMaxNumArticles = 1; |
| 290 store_.reset(new InMemoryContentStore(kMaxNumArticles)); | 290 store_.reset(new InMemoryContentStore(kMaxNumArticles)); |
| 291 | 291 |
| 292 // Store an article. | 292 // Store an article. |
| 293 const ArticleEntry first_entry = CreateEntry("first", "url1", "url2", "url3"); | 293 const ArticleEntry first_entry = CreateEntry("first", "url1", "url2", "url3"); |
| 294 const DistilledArticleProto first_stored_proto = | 294 const DistilledArticleProto first_stored_proto = |
| 295 CreateDistilledArticleForEntry(first_entry); | 295 CreateDistilledArticleForEntry(first_entry); |
| 296 store_->SaveContent(first_entry, | 296 store_->SaveContent(first_entry, |
| 297 first_stored_proto, | 297 first_stored_proto, |
| 298 base::Bind(&InMemoryContentStoreTest::OnSaveCallback, | 298 base::Bind(&InMemoryContentStoreTest::OnSaveCallback, |
| 299 base::Unretained(this))); | 299 base::Unretained(this))); |
| 300 base::MessageLoop::current()->RunUntilIdle(); | 300 base::RunLoop().RunUntilIdle(); |
| 301 EXPECT_TRUE(save_success_); | 301 EXPECT_TRUE(save_success_); |
| 302 save_success_ = false; | 302 save_success_ = false; |
| 303 | 303 |
| 304 // Looking up the first entry by URL should succeed when it is still in the | 304 // Looking up the first entry by URL should succeed when it is still in the |
| 305 // cache. | 305 // cache. |
| 306 const ArticleEntry first_entry_lookup = | 306 const ArticleEntry first_entry_lookup = |
| 307 CreateEntry("lookup-id", "url1", "", ""); | 307 CreateEntry("lookup-id", "url1", "", ""); |
| 308 store_->LoadContent(first_entry_lookup, | 308 store_->LoadContent(first_entry_lookup, |
| 309 base::Bind(&InMemoryContentStoreTest::OnLoadCallback, | 309 base::Bind(&InMemoryContentStoreTest::OnLoadCallback, |
| 310 base::Unretained(this))); | 310 base::Unretained(this))); |
| 311 base::MessageLoop::current()->RunUntilIdle(); | 311 base::RunLoop().RunUntilIdle(); |
| 312 EXPECT_TRUE(load_success_); | 312 EXPECT_TRUE(load_success_); |
| 313 EXPECT_EQ(first_stored_proto.SerializeAsString(), | 313 EXPECT_EQ(first_stored_proto.SerializeAsString(), |
| 314 loaded_proto_->SerializeAsString()); | 314 loaded_proto_->SerializeAsString()); |
| 315 | 315 |
| 316 // Store second article. This will remove the first article from the cache. | 316 // Store second article. This will remove the first article from the cache. |
| 317 const ArticleEntry second_entry = | 317 const ArticleEntry second_entry = |
| 318 CreateEntry("second", "url4", "url5", "url6"); | 318 CreateEntry("second", "url4", "url5", "url6"); |
| 319 const DistilledArticleProto second_stored_proto = | 319 const DistilledArticleProto second_stored_proto = |
| 320 CreateDistilledArticleForEntry(second_entry); | 320 CreateDistilledArticleForEntry(second_entry); |
| 321 store_->SaveContent(second_entry, | 321 store_->SaveContent(second_entry, |
| 322 second_stored_proto, | 322 second_stored_proto, |
| 323 base::Bind(&InMemoryContentStoreTest::OnSaveCallback, | 323 base::Bind(&InMemoryContentStoreTest::OnSaveCallback, |
| 324 base::Unretained(this))); | 324 base::Unretained(this))); |
| 325 base::MessageLoop::current()->RunUntilIdle(); | 325 base::RunLoop().RunUntilIdle(); |
| 326 EXPECT_TRUE(save_success_); | 326 EXPECT_TRUE(save_success_); |
| 327 save_success_ = false; | 327 save_success_ = false; |
| 328 | 328 |
| 329 // 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. |
| 330 store_->LoadContent(first_entry_lookup, | 330 store_->LoadContent(first_entry_lookup, |
| 331 base::Bind(&InMemoryContentStoreTest::OnLoadCallback, | 331 base::Bind(&InMemoryContentStoreTest::OnLoadCallback, |
| 332 base::Unretained(this))); | 332 base::Unretained(this))); |
| 333 base::MessageLoop::current()->RunUntilIdle(); | 333 base::RunLoop().RunUntilIdle(); |
| 334 EXPECT_FALSE(load_success_); | 334 EXPECT_FALSE(load_success_); |
| 335 } | 335 } |
| 336 | 336 |
| 337 } // namespace dom_distiller | 337 } // namespace dom_distiller |
| OLD | NEW |