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

Side by Side Diff: components/reading_list/ios/reading_list_model_unittest.mm

Issue 2647763005: Store the distilled_url in Reading List entry in Reading List on iOS. (Closed)
Patch Set: feedback Created 3 years, 11 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/reading_list/ios/reading_list_model.h" 5 #include "components/reading_list/ios/reading_list_model.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #import "base/test/ios/wait_util.h" 9 #import "base/test/ios/wait_util.h"
10 #include "components/reading_list/ios/reading_list_model_impl.h" 10 #include "components/reading_list/ios/reading_list_model_impl.h"
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 int observer_did_add_; 288 int observer_did_add_;
289 int observer_update_; 289 int observer_update_;
290 int observer_did_apply_; 290 int observer_did_apply_;
291 int storage_saved_; 291 int storage_saved_;
292 int storage_removed_; 292 int storage_removed_;
293 bool callback_called_; 293 bool callback_called_;
294 294
295 std::unique_ptr<ReadingListModelImpl> model_; 295 std::unique_ptr<ReadingListModelImpl> model_;
296 }; 296 };
297 297
298 // Tests creating an empty model.
298 TEST_F(ReadingListModelTest, EmptyLoaded) { 299 TEST_F(ReadingListModelTest, EmptyLoaded) {
299 EXPECT_TRUE(model_->loaded()); 300 EXPECT_TRUE(model_->loaded());
300 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); 301 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0);
301 EXPECT_EQ(0ul, UnreadSize()); 302 EXPECT_EQ(0ul, UnreadSize());
302 EXPECT_EQ(0ul, ReadSize()); 303 EXPECT_EQ(0ul, ReadSize());
303 model_->Shutdown(); 304 model_->Shutdown();
304 EXPECT_FALSE(model_->loaded()); 305 EXPECT_FALSE(model_->loaded());
305 AssertObserverCount(1, 0, 0, 1, 0, 0, 0, 0, 0); 306 AssertObserverCount(1, 0, 0, 1, 0, 0, 0, 0, 0);
306 } 307 }
307 308
309 // Tests load model.
308 TEST_F(ReadingListModelTest, ModelLoaded) { 310 TEST_F(ReadingListModelTest, ModelLoaded) {
309 ClearCounts(); 311 ClearCounts();
310 auto storage = base::MakeUnique<TestReadingListStorage>(this); 312 auto storage = base::MakeUnique<TestReadingListStorage>(this);
311 storage->AddSampleEntries(); 313 storage->AddSampleEntries();
312 SetStorage(std::move(storage)); 314 SetStorage(std::move(storage));
313 315
314 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); 316 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0);
315 std::map<GURL, std::string> loaded_entries; 317 std::map<GURL, std::string> loaded_entries;
316 int size = 0; 318 int size = 0;
317 for (const auto& url : model_->Keys()) { 319 for (const auto& url : model_->Keys()) {
318 size++; 320 size++;
319 const ReadingListEntry* entry = model_->GetEntryByURL(url); 321 const ReadingListEntry* entry = model_->GetEntryByURL(url);
320 loaded_entries[url] = entry->Title(); 322 loaded_entries[url] = entry->Title();
321 } 323 }
322 EXPECT_EQ(size, 7); 324 EXPECT_EQ(size, 7);
323 EXPECT_EQ(loaded_entries[GURL("http://unread_a.com")], "unread_a"); 325 EXPECT_EQ(loaded_entries[GURL("http://unread_a.com")], "unread_a");
324 EXPECT_EQ(loaded_entries[GURL("http://unread_b.com")], "unread_b"); 326 EXPECT_EQ(loaded_entries[GURL("http://unread_b.com")], "unread_b");
325 EXPECT_EQ(loaded_entries[GURL("http://unread_c.com")], "unread_c"); 327 EXPECT_EQ(loaded_entries[GURL("http://unread_c.com")], "unread_c");
326 EXPECT_EQ(loaded_entries[GURL("http://unread_d.com")], "unread_d"); 328 EXPECT_EQ(loaded_entries[GURL("http://unread_d.com")], "unread_d");
327 EXPECT_EQ(loaded_entries[GURL("http://read_a.com")], "read_a"); 329 EXPECT_EQ(loaded_entries[GURL("http://read_a.com")], "read_a");
328 EXPECT_EQ(loaded_entries[GURL("http://read_b.com")], "read_b"); 330 EXPECT_EQ(loaded_entries[GURL("http://read_b.com")], "read_b");
329 EXPECT_EQ(loaded_entries[GURL("http://read_c.com")], "read_c"); 331 EXPECT_EQ(loaded_entries[GURL("http://read_c.com")], "read_c");
330 } 332 }
331 333
334 // Tests adding entry.
332 TEST_F(ReadingListModelTest, AddEntry) { 335 TEST_F(ReadingListModelTest, AddEntry) {
333 auto storage = base::MakeUnique<TestReadingListStorage>(this); 336 auto storage = base::MakeUnique<TestReadingListStorage>(this);
334 SetStorage(std::move(storage)); 337 SetStorage(std::move(storage));
335 ClearCounts(); 338 ClearCounts();
336 339
337 const ReadingListEntry& entry = 340 const ReadingListEntry& entry =
338 model_->AddEntry(GURL("http://example.com"), "\n \tsample Test ", 341 model_->AddEntry(GURL("http://example.com"), "\n \tsample Test ",
339 reading_list::ADDED_VIA_CURRENT_APP); 342 reading_list::ADDED_VIA_CURRENT_APP);
340 EXPECT_EQ(GURL("http://example.com"), entry.URL()); 343 EXPECT_EQ(GURL("http://example.com"), entry.URL());
341 EXPECT_EQ("sample Test", entry.Title()); 344 EXPECT_EQ("sample Test", entry.Title());
342 345
343 AssertObserverCount(0, 0, 0, 0, 0, 0, 1, 0, 1); 346 AssertObserverCount(0, 0, 0, 0, 0, 0, 1, 0, 1);
344 AssertStorageCount(1, 0); 347 AssertStorageCount(1, 0);
345 EXPECT_EQ(1ul, UnreadSize()); 348 EXPECT_EQ(1ul, UnreadSize());
346 EXPECT_EQ(0ul, ReadSize()); 349 EXPECT_EQ(0ul, ReadSize());
347 EXPECT_TRUE(model_->GetLocalUnseenFlag()); 350 EXPECT_TRUE(model_->GetLocalUnseenFlag());
348 351
349 const ReadingListEntry* other_entry = 352 const ReadingListEntry* other_entry =
350 model_->GetEntryByURL(GURL("http://example.com")); 353 model_->GetEntryByURL(GURL("http://example.com"));
351 EXPECT_NE(other_entry, nullptr); 354 EXPECT_NE(other_entry, nullptr);
352 EXPECT_FALSE(other_entry->IsRead()); 355 EXPECT_FALSE(other_entry->IsRead());
353 EXPECT_EQ(GURL("http://example.com"), other_entry->URL()); 356 EXPECT_EQ(GURL("http://example.com"), other_entry->URL());
354 EXPECT_EQ("sample Test", other_entry->Title()); 357 EXPECT_EQ("sample Test", other_entry->Title());
355 } 358 }
356 359
360 // Tests addin entry from sync.
357 TEST_F(ReadingListModelTest, SyncAddEntry) { 361 TEST_F(ReadingListModelTest, SyncAddEntry) {
358 auto storage = base::MakeUnique<TestReadingListStorage>(this); 362 auto storage = base::MakeUnique<TestReadingListStorage>(this);
359 SetStorage(std::move(storage)); 363 SetStorage(std::move(storage));
360 auto entry = 364 auto entry =
361 base::MakeUnique<ReadingListEntry>(GURL("http://example.com"), "sample"); 365 base::MakeUnique<ReadingListEntry>(GURL("http://example.com"), "sample");
362 entry->SetRead(true); 366 entry->SetRead(true);
363 ClearCounts(); 367 ClearCounts();
364 368
365 model_->SyncAddEntry(std::move(entry)); 369 model_->SyncAddEntry(std::move(entry));
366 AssertObserverCount(0, 0, 0, 0, 0, 0, 1, 0, 1); 370 AssertObserverCount(0, 0, 0, 0, 0, 0, 1, 0, 1);
367 AssertStorageCount(0, 0); 371 AssertStorageCount(0, 0);
368 EXPECT_EQ(0ul, UnreadSize()); 372 EXPECT_EQ(0ul, UnreadSize());
369 EXPECT_EQ(1ul, ReadSize()); 373 EXPECT_EQ(1ul, ReadSize());
370 ClearCounts(); 374 ClearCounts();
371 } 375 }
372 376
377 // Tests updating entry from sync.
373 TEST_F(ReadingListModelTest, SyncMergeEntry) { 378 TEST_F(ReadingListModelTest, SyncMergeEntry) {
374 auto storage = base::MakeUnique<TestReadingListStorage>(this); 379 auto storage = base::MakeUnique<TestReadingListStorage>(this);
375 SetStorage(std::move(storage)); 380 SetStorage(std::move(storage));
376 model_->AddEntry(GURL("http://example.com"), "sample", 381 model_->AddEntry(GURL("http://example.com"), "sample",
377 reading_list::ADDED_VIA_CURRENT_APP); 382 reading_list::ADDED_VIA_CURRENT_APP);
378 model_->SetEntryDistilledPath(GURL("http://example.com"), 383 const base::FilePath distilled_path("distilled/page.html");
379 base::FilePath("distilled/page.html")); 384 const GURL distilled_url("http://example.com/distilled");
385 model_->SetEntryDistilledInfo(GURL("http://example.com"), distilled_path,
386 distilled_url);
380 const ReadingListEntry* local_entry = 387 const ReadingListEntry* local_entry =
381 model_->GetEntryByURL(GURL("http://example.com")); 388 model_->GetEntryByURL(GURL("http://example.com"));
382 int64_t local_update_time = local_entry->UpdateTime(); 389 int64_t local_update_time = local_entry->UpdateTime();
383 390
384 base::test::ios::SpinRunLoopWithMinDelay( 391 base::test::ios::SpinRunLoopWithMinDelay(
385 base::TimeDelta::FromMilliseconds(10)); 392 base::TimeDelta::FromMilliseconds(10));
386 auto sync_entry = 393 auto sync_entry =
387 base::MakeUnique<ReadingListEntry>(GURL("http://example.com"), "sample"); 394 base::MakeUnique<ReadingListEntry>(GURL("http://example.com"), "sample");
388 sync_entry->SetRead(true); 395 sync_entry->SetRead(true);
389 ASSERT_GT(sync_entry->UpdateTime(), local_update_time); 396 ASSERT_GT(sync_entry->UpdateTime(), local_update_time);
390 int64_t sync_update_time = sync_entry->UpdateTime(); 397 int64_t sync_update_time = sync_entry->UpdateTime();
391 EXPECT_TRUE(sync_entry->DistilledPath().empty()); 398 EXPECT_TRUE(sync_entry->DistilledPath().empty());
392 399
393 EXPECT_EQ(1ul, UnreadSize()); 400 EXPECT_EQ(1ul, UnreadSize());
394 EXPECT_EQ(0ul, ReadSize()); 401 EXPECT_EQ(0ul, ReadSize());
395 402
396 ReadingListEntry* merged_entry = 403 ReadingListEntry* merged_entry =
397 model_->SyncMergeEntry(std::move(sync_entry)); 404 model_->SyncMergeEntry(std::move(sync_entry));
398 EXPECT_EQ(0ul, UnreadSize()); 405 EXPECT_EQ(0ul, UnreadSize());
399 EXPECT_EQ(1ul, ReadSize()); 406 EXPECT_EQ(1ul, ReadSize());
400 EXPECT_EQ(merged_entry->DistilledPath(), 407 EXPECT_EQ(merged_entry->DistilledPath(),
401 base::FilePath("distilled/page.html")); 408 base::FilePath("distilled/page.html"));
402 EXPECT_EQ(merged_entry->UpdateTime(), sync_update_time); 409 EXPECT_EQ(merged_entry->UpdateTime(), sync_update_time);
403 } 410 }
404 411
412 // Tests deleting entry.
405 TEST_F(ReadingListModelTest, RemoveEntryByUrl) { 413 TEST_F(ReadingListModelTest, RemoveEntryByUrl) {
406 auto storage = base::MakeUnique<TestReadingListStorage>(this); 414 auto storage = base::MakeUnique<TestReadingListStorage>(this);
407 SetStorage(std::move(storage)); 415 SetStorage(std::move(storage));
408 model_->AddEntry(GURL("http://example.com"), "sample", 416 model_->AddEntry(GURL("http://example.com"), "sample",
409 reading_list::ADDED_VIA_CURRENT_APP); 417 reading_list::ADDED_VIA_CURRENT_APP);
410 ClearCounts(); 418 ClearCounts();
411 EXPECT_NE(model_->GetEntryByURL(GURL("http://example.com")), nullptr); 419 EXPECT_NE(model_->GetEntryByURL(GURL("http://example.com")), nullptr);
412 EXPECT_EQ(1ul, UnreadSize()); 420 EXPECT_EQ(1ul, UnreadSize());
413 EXPECT_EQ(0ul, ReadSize()); 421 EXPECT_EQ(0ul, ReadSize());
414 model_->RemoveEntryByURL(GURL("http://example.com")); 422 model_->RemoveEntryByURL(GURL("http://example.com"));
(...skipping 11 matching lines...) Expand all
426 EXPECT_EQ(0ul, UnreadSize()); 434 EXPECT_EQ(0ul, UnreadSize());
427 EXPECT_EQ(1ul, ReadSize()); 435 EXPECT_EQ(1ul, ReadSize());
428 model_->RemoveEntryByURL(GURL("http://example.com")); 436 model_->RemoveEntryByURL(GURL("http://example.com"));
429 AssertObserverCount(0, 0, 0, 0, 1, 0, 0, 0, 1); 437 AssertObserverCount(0, 0, 0, 0, 1, 0, 0, 0, 1);
430 AssertStorageCount(0, 1); 438 AssertStorageCount(0, 1);
431 EXPECT_EQ(0ul, UnreadSize()); 439 EXPECT_EQ(0ul, UnreadSize());
432 EXPECT_EQ(0ul, ReadSize()); 440 EXPECT_EQ(0ul, ReadSize());
433 EXPECT_EQ(model_->GetEntryByURL(GURL("http://example.com")), nullptr); 441 EXPECT_EQ(model_->GetEntryByURL(GURL("http://example.com")), nullptr);
434 } 442 }
435 443
444 // Tests deleting entry from sync.
436 TEST_F(ReadingListModelTest, RemoveSyncEntryByUrl) { 445 TEST_F(ReadingListModelTest, RemoveSyncEntryByUrl) {
437 auto storage = base::MakeUnique<TestReadingListStorage>(this); 446 auto storage = base::MakeUnique<TestReadingListStorage>(this);
438 SetStorage(std::move(storage)); 447 SetStorage(std::move(storage));
439 model_->AddEntry(GURL("http://example.com"), "sample", 448 model_->AddEntry(GURL("http://example.com"), "sample",
440 reading_list::ADDED_VIA_CURRENT_APP); 449 reading_list::ADDED_VIA_CURRENT_APP);
441 ClearCounts(); 450 ClearCounts();
442 EXPECT_NE(model_->GetEntryByURL(GURL("http://example.com")), nullptr); 451 EXPECT_NE(model_->GetEntryByURL(GURL("http://example.com")), nullptr);
443 EXPECT_EQ(1ul, UnreadSize()); 452 EXPECT_EQ(1ul, UnreadSize());
444 EXPECT_EQ(0ul, ReadSize()); 453 EXPECT_EQ(0ul, ReadSize());
445 model_->SyncRemoveEntry(GURL("http://example.com")); 454 model_->SyncRemoveEntry(GURL("http://example.com"));
(...skipping 11 matching lines...) Expand all
457 EXPECT_EQ(0ul, UnreadSize()); 466 EXPECT_EQ(0ul, UnreadSize());
458 EXPECT_EQ(1ul, ReadSize()); 467 EXPECT_EQ(1ul, ReadSize());
459 model_->SyncRemoveEntry(GURL("http://example.com")); 468 model_->SyncRemoveEntry(GURL("http://example.com"));
460 AssertObserverCount(0, 0, 0, 0, 1, 0, 0, 0, 1); 469 AssertObserverCount(0, 0, 0, 0, 1, 0, 0, 0, 1);
461 AssertStorageCount(0, 0); 470 AssertStorageCount(0, 0);
462 EXPECT_EQ(0ul, UnreadSize()); 471 EXPECT_EQ(0ul, UnreadSize());
463 EXPECT_EQ(0ul, ReadSize()); 472 EXPECT_EQ(0ul, ReadSize());
464 EXPECT_EQ(model_->GetEntryByURL(GURL("http://example.com")), nullptr); 473 EXPECT_EQ(model_->GetEntryByURL(GURL("http://example.com")), nullptr);
465 } 474 }
466 475
476 // Tests marking entry read.
467 TEST_F(ReadingListModelTest, ReadEntry) { 477 TEST_F(ReadingListModelTest, ReadEntry) {
468 model_->AddEntry(GURL("http://example.com"), "sample", 478 model_->AddEntry(GURL("http://example.com"), "sample",
469 reading_list::ADDED_VIA_CURRENT_APP); 479 reading_list::ADDED_VIA_CURRENT_APP);
470 480
471 ClearCounts(); 481 ClearCounts();
472 model_->SetReadStatus(GURL("http://example.com"), true); 482 model_->SetReadStatus(GURL("http://example.com"), true);
473 AssertObserverCount(0, 0, 0, 0, 0, 1, 0, 0, 1); 483 AssertObserverCount(0, 0, 0, 0, 0, 1, 0, 0, 1);
474 EXPECT_EQ(0ul, UnreadSize()); 484 EXPECT_EQ(0ul, UnreadSize());
475 EXPECT_EQ(1ul, ReadSize()); 485 EXPECT_EQ(1ul, ReadSize());
476 EXPECT_EQ(0ul, model_->unseen_size()); 486 EXPECT_EQ(0ul, model_->unseen_size());
477 487
478 const ReadingListEntry* other_entry = 488 const ReadingListEntry* other_entry =
479 model_->GetEntryByURL(GURL("http://example.com")); 489 model_->GetEntryByURL(GURL("http://example.com"));
480 EXPECT_NE(other_entry, nullptr); 490 EXPECT_NE(other_entry, nullptr);
481 EXPECT_TRUE(other_entry->IsRead()); 491 EXPECT_TRUE(other_entry->IsRead());
482 EXPECT_EQ(GURL("http://example.com"), other_entry->URL()); 492 EXPECT_EQ(GURL("http://example.com"), other_entry->URL());
483 EXPECT_EQ("sample", other_entry->Title()); 493 EXPECT_EQ("sample", other_entry->Title());
484 } 494 }
485 495
496 // Tests accessing existing entry.
486 TEST_F(ReadingListModelTest, EntryFromURL) { 497 TEST_F(ReadingListModelTest, EntryFromURL) {
487 GURL url1("http://example.com"); 498 GURL url1("http://example.com");
488 GURL url2("http://example2.com"); 499 GURL url2("http://example2.com");
489 std::string entry1_title = "foo bar qux"; 500 std::string entry1_title = "foo bar qux";
490 model_->AddEntry(url1, entry1_title, reading_list::ADDED_VIA_CURRENT_APP); 501 model_->AddEntry(url1, entry1_title, reading_list::ADDED_VIA_CURRENT_APP);
491 502
492 // Check call with nullptr |read| parameter. 503 // Check call with nullptr |read| parameter.
493 const ReadingListEntry* entry1 = model_->GetEntryByURL(url1); 504 const ReadingListEntry* entry1 = model_->GetEntryByURL(url1);
494 EXPECT_NE(nullptr, entry1); 505 EXPECT_NE(nullptr, entry1);
495 EXPECT_EQ(entry1_title, entry1->Title()); 506 EXPECT_EQ(entry1_title, entry1->Title());
496 507
497 entry1 = model_->GetEntryByURL(url1); 508 entry1 = model_->GetEntryByURL(url1);
498 EXPECT_NE(nullptr, entry1); 509 EXPECT_NE(nullptr, entry1);
499 EXPECT_EQ(entry1_title, entry1->Title()); 510 EXPECT_EQ(entry1_title, entry1->Title());
500 EXPECT_EQ(entry1->IsRead(), false); 511 EXPECT_EQ(entry1->IsRead(), false);
501 model_->SetReadStatus(url1, true); 512 model_->SetReadStatus(url1, true);
502 entry1 = model_->GetEntryByURL(url1); 513 entry1 = model_->GetEntryByURL(url1);
503 EXPECT_NE(nullptr, entry1); 514 EXPECT_NE(nullptr, entry1);
504 EXPECT_EQ(entry1_title, entry1->Title()); 515 EXPECT_EQ(entry1_title, entry1->Title());
505 EXPECT_EQ(entry1->IsRead(), true); 516 EXPECT_EQ(entry1->IsRead(), true);
506 517
507 const ReadingListEntry* entry2 = model_->GetEntryByURL(url2); 518 const ReadingListEntry* entry2 = model_->GetEntryByURL(url2);
508 EXPECT_EQ(nullptr, entry2); 519 EXPECT_EQ(nullptr, entry2);
509 } 520 }
510 521
522 // Tests mark entry unread.
511 TEST_F(ReadingListModelTest, UnreadEntry) { 523 TEST_F(ReadingListModelTest, UnreadEntry) {
512 // Setup. 524 // Setup.
513 model_->AddEntry(GURL("http://example.com"), "sample", 525 model_->AddEntry(GURL("http://example.com"), "sample",
514 reading_list::ADDED_VIA_CURRENT_APP); 526 reading_list::ADDED_VIA_CURRENT_APP);
515 EXPECT_TRUE(model_->GetLocalUnseenFlag()); 527 EXPECT_TRUE(model_->GetLocalUnseenFlag());
516 model_->SetReadStatus(GURL("http://example.com"), true); 528 model_->SetReadStatus(GURL("http://example.com"), true);
517 ClearCounts(); 529 ClearCounts();
518 EXPECT_EQ(0ul, UnreadSize()); 530 EXPECT_EQ(0ul, UnreadSize());
519 EXPECT_EQ(1ul, ReadSize()); 531 EXPECT_EQ(1ul, ReadSize());
520 EXPECT_FALSE(model_->GetLocalUnseenFlag()); 532 EXPECT_FALSE(model_->GetLocalUnseenFlag());
521 533
522 // Action. 534 // Action.
523 model_->SetReadStatus(GURL("http://example.com"), false); 535 model_->SetReadStatus(GURL("http://example.com"), false);
524 536
525 // Tests. 537 // Tests.
526 AssertObserverCount(0, 0, 0, 0, 0, 1, 0, 0, 1); 538 AssertObserverCount(0, 0, 0, 0, 0, 1, 0, 0, 1);
527 EXPECT_EQ(1ul, UnreadSize()); 539 EXPECT_EQ(1ul, UnreadSize());
528 EXPECT_EQ(0ul, ReadSize()); 540 EXPECT_EQ(0ul, ReadSize());
529 EXPECT_FALSE(model_->GetLocalUnseenFlag()); 541 EXPECT_FALSE(model_->GetLocalUnseenFlag());
530 542
531 const ReadingListEntry* other_entry = 543 const ReadingListEntry* other_entry =
532 model_->GetEntryByURL(GURL("http://example.com")); 544 model_->GetEntryByURL(GURL("http://example.com"));
533 EXPECT_NE(other_entry, nullptr); 545 EXPECT_NE(other_entry, nullptr);
534 EXPECT_FALSE(other_entry->IsRead()); 546 EXPECT_FALSE(other_entry->IsRead());
535 EXPECT_EQ(GURL("http://example.com"), other_entry->URL()); 547 EXPECT_EQ(GURL("http://example.com"), other_entry->URL());
536 EXPECT_EQ("sample", other_entry->Title()); 548 EXPECT_EQ("sample", other_entry->Title());
537 } 549 }
538 550
551 // Tests batch updates observers are called.
539 TEST_F(ReadingListModelTest, BatchUpdates) { 552 TEST_F(ReadingListModelTest, BatchUpdates) {
540 auto token = model_->BeginBatchUpdates(); 553 auto token = model_->BeginBatchUpdates();
541 AssertObserverCount(1, 1, 0, 0, 0, 0, 0, 0, 0); 554 AssertObserverCount(1, 1, 0, 0, 0, 0, 0, 0, 0);
542 EXPECT_TRUE(model_->IsPerformingBatchUpdates()); 555 EXPECT_TRUE(model_->IsPerformingBatchUpdates());
543 556
544 delete token.release(); 557 delete token.release();
545 AssertObserverCount(1, 1, 1, 0, 0, 0, 0, 0, 0); 558 AssertObserverCount(1, 1, 1, 0, 0, 0, 0, 0, 0);
546 EXPECT_FALSE(model_->IsPerformingBatchUpdates()); 559 EXPECT_FALSE(model_->IsPerformingBatchUpdates());
547 } 560 }
548 561
562 // Tests batch updates are reentrant.
549 TEST_F(ReadingListModelTest, BatchUpdatesReentrant) { 563 TEST_F(ReadingListModelTest, BatchUpdatesReentrant) {
550 // When two updates happen at the same time, the notification is only sent 564 // When two updates happen at the same time, the notification is only sent
551 // for beginning of first update and completion of last update. 565 // for beginning of first update and completion of last update.
552 EXPECT_FALSE(model_->IsPerformingBatchUpdates()); 566 EXPECT_FALSE(model_->IsPerformingBatchUpdates());
553 567
554 auto token = model_->BeginBatchUpdates(); 568 auto token = model_->BeginBatchUpdates();
555 AssertObserverCount(1, 1, 0, 0, 0, 0, 0, 0, 0); 569 AssertObserverCount(1, 1, 0, 0, 0, 0, 0, 0, 0);
556 EXPECT_TRUE(model_->IsPerformingBatchUpdates()); 570 EXPECT_TRUE(model_->IsPerformingBatchUpdates());
557 571
558 auto second_token = model_->BeginBatchUpdates(); 572 auto second_token = model_->BeginBatchUpdates();
(...skipping 11 matching lines...) Expand all
570 // Consequent updates send notifications. 584 // Consequent updates send notifications.
571 auto third_token = model_->BeginBatchUpdates(); 585 auto third_token = model_->BeginBatchUpdates();
572 AssertObserverCount(1, 2, 1, 0, 0, 0, 0, 0, 0); 586 AssertObserverCount(1, 2, 1, 0, 0, 0, 0, 0, 0);
573 EXPECT_TRUE(model_->IsPerformingBatchUpdates()); 587 EXPECT_TRUE(model_->IsPerformingBatchUpdates());
574 588
575 delete third_token.release(); 589 delete third_token.release();
576 AssertObserverCount(1, 2, 2, 0, 0, 0, 0, 0, 0); 590 AssertObserverCount(1, 2, 2, 0, 0, 0, 0, 0, 0);
577 EXPECT_FALSE(model_->IsPerformingBatchUpdates()); 591 EXPECT_FALSE(model_->IsPerformingBatchUpdates());
578 } 592 }
579 593
594 // Tests setting title on unread entry.
580 TEST_F(ReadingListModelTest, UpdateEntryTitle) { 595 TEST_F(ReadingListModelTest, UpdateEntryTitle) {
581 const GURL gurl("http://example.com"); 596 const GURL gurl("http://example.com");
582 const ReadingListEntry& entry = 597 const ReadingListEntry& entry =
583 model_->AddEntry(gurl, "sample", reading_list::ADDED_VIA_CURRENT_APP); 598 model_->AddEntry(gurl, "sample", reading_list::ADDED_VIA_CURRENT_APP);
584 ClearCounts(); 599 ClearCounts();
585 600
586 model_->SetEntryTitle(gurl, "ping"); 601 model_->SetEntryTitle(gurl, "ping");
587 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1); 602 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1);
588 EXPECT_EQ("ping", entry.Title()); 603 EXPECT_EQ("ping", entry.Title());
589 } 604 }
590 605 // Tests setting distillation state on unread entry.
591 TEST_F(ReadingListModelTest, UpdateEntryDistilledState) { 606 TEST_F(ReadingListModelTest, UpdateEntryDistilledState) {
592 const GURL gurl("http://example.com"); 607 const GURL gurl("http://example.com");
593 const ReadingListEntry& entry = 608 const ReadingListEntry& entry =
594 model_->AddEntry(gurl, "sample", reading_list::ADDED_VIA_CURRENT_APP); 609 model_->AddEntry(gurl, "sample", reading_list::ADDED_VIA_CURRENT_APP);
595 ClearCounts(); 610 ClearCounts();
596 611
597 model_->SetEntryDistilledState(gurl, ReadingListEntry::PROCESSING); 612 model_->SetEntryDistilledState(gurl, ReadingListEntry::PROCESSING);
598 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1); 613 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1);
599 EXPECT_EQ(ReadingListEntry::PROCESSING, entry.DistilledState()); 614 EXPECT_EQ(ReadingListEntry::PROCESSING, entry.DistilledState());
600 } 615 }
601 616
602 TEST_F(ReadingListModelTest, UpdateDistilledPath) { 617 // Tests setting distillation info on unread entry.
618 TEST_F(ReadingListModelTest, UpdateDistilledInfo) {
603 const GURL gurl("http://example.com"); 619 const GURL gurl("http://example.com");
604 const ReadingListEntry& entry = 620 const ReadingListEntry& entry =
605 model_->AddEntry(gurl, "sample", reading_list::ADDED_VIA_CURRENT_APP); 621 model_->AddEntry(gurl, "sample", reading_list::ADDED_VIA_CURRENT_APP);
606 ClearCounts(); 622 ClearCounts();
607 623
608 model_->SetEntryDistilledPath(gurl, base::FilePath("distilled/page.html")); 624 const base::FilePath distilled_path("distilled/page.html");
625 const GURL distilled_url("http://example.com/distilled");
626 model_->SetEntryDistilledInfo(GURL("http://example.com"), distilled_path,
627 distilled_url);
609 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1); 628 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1);
610 EXPECT_EQ(ReadingListEntry::PROCESSED, entry.DistilledState()); 629 EXPECT_EQ(ReadingListEntry::PROCESSED, entry.DistilledState());
611 EXPECT_EQ(base::FilePath("distilled/page.html"), entry.DistilledPath()); 630 EXPECT_EQ(distilled_path, entry.DistilledPath());
631 EXPECT_EQ(distilled_url, entry.DistilledURL());
612 } 632 }
613 633
634 // Tests setting title on read entry.
614 TEST_F(ReadingListModelTest, UpdateReadEntryTitle) { 635 TEST_F(ReadingListModelTest, UpdateReadEntryTitle) {
615 const GURL gurl("http://example.com"); 636 const GURL gurl("http://example.com");
616 model_->AddEntry(gurl, "sample", reading_list::ADDED_VIA_CURRENT_APP); 637 model_->AddEntry(gurl, "sample", reading_list::ADDED_VIA_CURRENT_APP);
617 model_->SetReadStatus(gurl, true); 638 model_->SetReadStatus(gurl, true);
618 const ReadingListEntry* entry = model_->GetEntryByURL(gurl); 639 const ReadingListEntry* entry = model_->GetEntryByURL(gurl);
619 ClearCounts(); 640 ClearCounts();
620 641
621 model_->SetEntryTitle(gurl, "ping"); 642 model_->SetEntryTitle(gurl, "ping");
622 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1); 643 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1);
623 EXPECT_EQ("ping", entry->Title()); 644 EXPECT_EQ("ping", entry->Title());
624 } 645 }
625 646
647 // Tests setting distillation state on read entry.
626 TEST_F(ReadingListModelTest, UpdateReadEntryState) { 648 TEST_F(ReadingListModelTest, UpdateReadEntryState) {
627 const GURL gurl("http://example.com"); 649 const GURL gurl("http://example.com");
628 model_->AddEntry(gurl, "sample", reading_list::ADDED_VIA_CURRENT_APP); 650 model_->AddEntry(gurl, "sample", reading_list::ADDED_VIA_CURRENT_APP);
629 model_->SetReadStatus(gurl, true); 651 model_->SetReadStatus(gurl, true);
630 const ReadingListEntry* entry = model_->GetEntryByURL(gurl); 652 const ReadingListEntry* entry = model_->GetEntryByURL(gurl);
631 ClearCounts(); 653 ClearCounts();
632 654
633 model_->SetEntryDistilledState(gurl, ReadingListEntry::PROCESSING); 655 model_->SetEntryDistilledState(gurl, ReadingListEntry::PROCESSING);
634 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1); 656 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1);
635 EXPECT_EQ(ReadingListEntry::PROCESSING, entry->DistilledState()); 657 EXPECT_EQ(ReadingListEntry::PROCESSING, entry->DistilledState());
636 } 658 }
637 659
638 TEST_F(ReadingListModelTest, UpdateReadDistilledPath) { 660 // Tests setting distillation info on read entry.
661 TEST_F(ReadingListModelTest, UpdateReadDistilledInfo) {
639 const GURL gurl("http://example.com"); 662 const GURL gurl("http://example.com");
640 model_->AddEntry(gurl, "sample", reading_list::ADDED_VIA_CURRENT_APP); 663 model_->AddEntry(gurl, "sample", reading_list::ADDED_VIA_CURRENT_APP);
641 model_->SetReadStatus(gurl, true); 664 model_->SetReadStatus(gurl, true);
642 const ReadingListEntry* entry = model_->GetEntryByURL(gurl); 665 const ReadingListEntry* entry = model_->GetEntryByURL(gurl);
643 ClearCounts(); 666 ClearCounts();
644 667
645 model_->SetEntryDistilledPath(gurl, base::FilePath("distilled/page.html")); 668 const base::FilePath distilled_path("distilled/page.html");
669 const GURL distilled_url("http://example.com/distilled");
670 model_->SetEntryDistilledInfo(GURL("http://example.com"), distilled_path,
671 distilled_url);
646 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1); 672 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1);
647 EXPECT_EQ(ReadingListEntry::PROCESSED, entry->DistilledState()); 673 EXPECT_EQ(ReadingListEntry::PROCESSED, entry->DistilledState());
648 EXPECT_EQ(base::FilePath("distilled/page.html"), entry->DistilledPath()); 674 EXPECT_EQ(distilled_path, entry->DistilledPath());
675 EXPECT_EQ(distilled_url, entry->DistilledURL());
649 } 676 }
650 677
651 // Tests that ReadingListModel calls CallbackModelBeingDeleted when destroyed. 678 // Tests that ReadingListModel calls CallbackModelBeingDeleted when destroyed.
652 TEST_F(ReadingListModelTest, CallbackModelBeingDeleted) { 679 TEST_F(ReadingListModelTest, CallbackModelBeingDeleted) {
653 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); 680 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0);
654 model_.reset(); 681 model_.reset();
655 AssertObserverCount(1, 0, 0, 1, 0, 0, 0, 0, 0); 682 AssertObserverCount(1, 0, 0, 1, 0, 0, 0, 0, 0);
656 } 683 }
657 684
658 } // namespace 685 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698