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

Side by Side Diff: ios/chrome/browser/reading_list/reading_list_model_unittest.cc

Issue 2352973002: Method to call a method with an entry based on its url (Closed)
Patch Set: Add tests Created 4 years, 3 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
« no previous file with comments | « ios/chrome/browser/reading_list/reading_list_model_impl.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 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 "base/bind.h"
5 #include "ios/chrome/browser/reading_list/reading_list_model_impl.h" 6 #include "ios/chrome/browser/reading_list/reading_list_model_impl.h"
6 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
7 8
8 namespace { 9 namespace {
9 10
11 const GURL callback_url("http://example.com");
12 const std::string callback_title("test title");
13
10 class ReadingListModelTest : public ReadingListModelObserver, 14 class ReadingListModelTest : public ReadingListModelObserver,
11 public testing::Test { 15 public testing::Test {
12 public: 16 public:
13 ReadingListModelTest() : model_(new ReadingListModelImpl()) { 17 ReadingListModelTest()
18 : callback_called_(false), model_(new ReadingListModelImpl()) {
14 ClearCounts(); 19 ClearCounts();
15 model_->AddObserver(this); 20 model_->AddObserver(this);
16 } 21 }
17 ~ReadingListModelTest() override {} 22 ~ReadingListModelTest() override {}
18 23
19 void ClearCounts() { 24 void ClearCounts() {
20 observer_loaded_ = observer_started_batch_update_ = 25 observer_loaded_ = observer_started_batch_update_ =
21 observer_completed_batch_update_ = observer_deleted_ = 26 observer_completed_batch_update_ = observer_deleted_ =
22 observer_remove_unread_ = observer_remove_read_ = observer_move_ = 27 observer_remove_unread_ = observer_remove_read_ = observer_move_ =
23 observer_add_unread_ = observer_add_read_ = 28 observer_add_unread_ = observer_add_read_ =
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 size_t index) override { 96 size_t index) override {
92 observer_update_unread_ += 1; 97 observer_update_unread_ += 1;
93 } 98 }
94 void ReadingListWillUpdateReadEntry(const ReadingListModel* model, 99 void ReadingListWillUpdateReadEntry(const ReadingListModel* model,
95 size_t index) override { 100 size_t index) override {
96 observer_update_read_ += 1; 101 observer_update_read_ += 1;
97 } 102 }
98 void ReadingListDidApplyChanges(ReadingListModel* model) override { 103 void ReadingListDidApplyChanges(ReadingListModel* model) override {
99 observer_did_apply_ += 1; 104 observer_did_apply_ += 1;
100 } 105 }
106 void Callback(const ReadingListEntry& entry) {
107 EXPECT_EQ(callback_url, entry.URL());
108 EXPECT_EQ(callback_title, entry.Title());
109 callback_called_ = true;
110 }
111
112 bool CallbackCalled() { return callback_called_; }
101 113
102 protected: 114 protected:
103 int observer_loaded_; 115 int observer_loaded_;
104 int observer_started_batch_update_; 116 int observer_started_batch_update_;
105 int observer_completed_batch_update_; 117 int observer_completed_batch_update_;
106 int observer_deleted_; 118 int observer_deleted_;
107 int observer_remove_unread_; 119 int observer_remove_unread_;
108 int observer_remove_read_; 120 int observer_remove_read_;
109 int observer_move_; 121 int observer_move_;
110 int observer_add_unread_; 122 int observer_add_unread_;
111 int observer_add_read_; 123 int observer_add_read_;
112 int observer_update_unread_; 124 int observer_update_unread_;
113 int observer_update_read_; 125 int observer_update_read_;
114 int observer_did_apply_; 126 int observer_did_apply_;
127 bool callback_called_;
115 128
116 std::unique_ptr<ReadingListModelImpl> model_; 129 std::unique_ptr<ReadingListModelImpl> model_;
117 }; 130 };
118 131
119 TEST_F(ReadingListModelTest, EmptyLoaded) { 132 TEST_F(ReadingListModelTest, EmptyLoaded) {
120 EXPECT_TRUE(model_->loaded()); 133 EXPECT_TRUE(model_->loaded());
121 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); 134 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
122 EXPECT_EQ(0ul, model_->unread_size()); 135 EXPECT_EQ(0ul, model_->unread_size());
123 EXPECT_EQ(0ul, model_->read_size()); 136 EXPECT_EQ(0ul, model_->read_size());
124 model_->Shutdown(); 137 model_->Shutdown();
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 model_->MarkReadByURL(gurl); 273 model_->MarkReadByURL(gurl);
261 const ReadingListEntry& entry = model_->GetReadEntryAtIndex(0); 274 const ReadingListEntry& entry = model_->GetReadEntryAtIndex(0);
262 ClearCounts(); 275 ClearCounts();
263 276
264 model_->SetEntryDistilledURL(gurl, gurl); 277 model_->SetEntryDistilledURL(gurl, gurl);
265 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1); 278 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1);
266 EXPECT_EQ(ReadingListEntry::PROCESSED, entry.DistilledState()); 279 EXPECT_EQ(ReadingListEntry::PROCESSED, entry.DistilledState());
267 EXPECT_EQ(gurl, entry.DistilledURL()); 280 EXPECT_EQ(gurl, entry.DistilledURL());
268 } 281 }
269 282
283 // Tests that the callback is called when the entry is unread.
284 TEST_F(ReadingListModelTest, CallbackEntryURLUnread) {
285 // Setup.
286 model_->AddEntry(callback_url, callback_title);
287
288 ASSERT_EQ(0UL, model_->read_size());
289 ASSERT_EQ(1UL, model_->unread_size());
290
291 // Action.
292 bool result = model_->CallbackEntryURL(
293 callback_url,
294 base::Bind(&ReadingListModelTest::Callback, base::Unretained(this)));
295
296 // Test.
297 EXPECT_TRUE(result);
298 EXPECT_TRUE(CallbackCalled());
299 }
300
301 // Tests that the callback is called when the entry is read.
302 TEST_F(ReadingListModelTest, CallbackEntryURLRead) {
303 // Setup.
304 model_->AddEntry(callback_url, callback_title);
305 model_->MarkReadByURL(callback_url);
306
307 ASSERT_EQ(1UL, model_->read_size());
308 ASSERT_EQ(0UL, model_->unread_size());
309
310 // Action.
311 bool result = model_->CallbackEntryURL(
312 callback_url,
313 base::Bind(&ReadingListModelTest::Callback, base::Unretained(this)));
314
315 // Test.
316 EXPECT_TRUE(result);
317 EXPECT_TRUE(CallbackCalled());
318 }
319
320 // Tests that the callback is not called when the entry is not present.
321 TEST_F(ReadingListModelTest, CallbackEntryURLNotPresent) {
322 // Setup.
323 const GURL gurl("http://foo.bar");
324 ASSERT_NE(gurl, callback_url);
325 model_->AddEntry(gurl, callback_title);
326
327 // Action.
328 bool result = model_->CallbackEntryURL(
329 callback_url,
330 base::Bind(&ReadingListModelTest::Callback, base::Unretained(this)));
331
332 // Test.
333 EXPECT_FALSE(result);
334 EXPECT_FALSE(CallbackCalled());
335 }
336
270 } // namespace 337 } // namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/reading_list/reading_list_model_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698