| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import <Foundation/Foundation.h> | |
| 6 | |
| 7 #include "base/mac/scoped_nsobject.h" | |
| 8 #include "ios/chrome/browser/reading_list/reading_list_model_storage_defaults.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 namespace { | |
| 12 NSUserDefaults* FakeNonPersistentUserDefaults() { | |
| 13 // Storage only uses two methods on NSUserDefaults: -setObject:forKey: and | |
| 14 // -objectForKey:, a dictionary is a perfect replacement for it. If it looks | |
| 15 // like a duck, swims like a duck and quacks as a duck, then it probably is a | |
| 16 // duck. | |
| 17 return (NSUserDefaults*)[[[NSMutableDictionary alloc] init] autorelease]; | |
| 18 } | |
| 19 } | |
| 20 | |
| 21 TEST(ReadingListStorage, CheckEmpties) { | |
| 22 ReadingListModelStorageDefaults storage(FakeNonPersistentUserDefaults()); | |
| 23 | |
| 24 std::vector<ReadingListEntry> entries; | |
| 25 | |
| 26 entries = storage.LoadPersistentReadList(); | |
| 27 EXPECT_EQ(0ul, entries.size()); | |
| 28 entries = storage.LoadPersistentUnreadList(); | |
| 29 EXPECT_EQ(0ul, entries.size()); | |
| 30 } | |
| 31 | |
| 32 TEST(ReadingListStorage, SaveOneRead) { | |
| 33 NSUserDefaults* defaults = FakeNonPersistentUserDefaults(); | |
| 34 std::vector<ReadingListEntry> entries; | |
| 35 entries.push_back( | |
| 36 ReadingListEntry(GURL("http://read.example.com"), "read title")); | |
| 37 | |
| 38 { | |
| 39 ReadingListModelStorageDefaults storage(defaults); | |
| 40 storage.SavePersistentReadList(entries); | |
| 41 } | |
| 42 | |
| 43 ReadingListModelStorageDefaults storage(defaults); | |
| 44 | |
| 45 const std::vector<ReadingListEntry> restored_entries( | |
| 46 storage.LoadPersistentReadList()); | |
| 47 EXPECT_EQ(1ul, restored_entries.size()); | |
| 48 EXPECT_EQ(GURL("http://read.example.com"), restored_entries[0].URL()); | |
| 49 EXPECT_EQ("read title", restored_entries[0].Title()); | |
| 50 EXPECT_EQ("read title", restored_entries[0].Title()); | |
| 51 } | |
| 52 | |
| 53 TEST(ReadingListStorage, SaveOneUnead) { | |
| 54 NSUserDefaults* defaults = FakeNonPersistentUserDefaults(); | |
| 55 std::vector<ReadingListEntry> entries; | |
| 56 entries.push_back( | |
| 57 ReadingListEntry(GURL("http://unread.example.com"), "unread title")); | |
| 58 | |
| 59 { | |
| 60 ReadingListModelStorageDefaults storage(defaults); | |
| 61 storage.SavePersistentUnreadList(entries); | |
| 62 } | |
| 63 | |
| 64 ReadingListModelStorageDefaults storage(defaults); | |
| 65 const std::vector<ReadingListEntry> restored_entries( | |
| 66 storage.LoadPersistentUnreadList()); | |
| 67 EXPECT_EQ(1ul, restored_entries.size()); | |
| 68 EXPECT_EQ(GURL("http://unread.example.com"), restored_entries[0].URL()); | |
| 69 EXPECT_EQ("unread title", restored_entries[0].Title()); | |
| 70 } | |
| 71 | |
| 72 TEST(ReadingListStorage, SaveOneModified) { | |
| 73 NSUserDefaults* defaults = FakeNonPersistentUserDefaults(); | |
| 74 std::vector<ReadingListEntry> entries; | |
| 75 entries.push_back( | |
| 76 ReadingListEntry(GURL("http://unread.example.com"), "unread title")); | |
| 77 { | |
| 78 ReadingListModelStorageDefaults storage(defaults); | |
| 79 entries[0].SetDistilledURL(GURL("http://distilled.example.com")); | |
| 80 storage.SavePersistentUnreadList(entries); | |
| 81 } | |
| 82 | |
| 83 ReadingListModelStorageDefaults storage(defaults); | |
| 84 const std::vector<ReadingListEntry> restored_entries( | |
| 85 storage.LoadPersistentUnreadList()); | |
| 86 EXPECT_EQ(1ul, restored_entries.size()); | |
| 87 EXPECT_EQ(GURL("http://unread.example.com"), restored_entries[0].URL()); | |
| 88 EXPECT_EQ(GURL("http://distilled.example.com"), | |
| 89 restored_entries[0].DistilledURL()); | |
| 90 EXPECT_EQ("unread title", restored_entries[0].Title()); | |
| 91 } | |
| OLD | NEW |