| OLD | NEW |
| 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 "ios/chrome/browser/reading_list/reading_list_web_state_observer.h" | 5 #include "ios/chrome/browser/reading_list/reading_list_web_state_observer.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "components/reading_list/ios/reading_list_model_impl.h" | 8 #include "components/reading_list/ios/reading_list_model_impl.h" |
| 9 #include "ios/chrome/browser/reading_list/offline_url_utils.h" | 9 #include "ios/chrome/browser/reading_list/offline_url_utils.h" |
| 10 #import "ios/web/public/navigation_item.h" | 10 #import "ios/web/public/navigation_item.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 EXPECT_EQ(test_navigation_manager_->GetLastCommittedItem()->GetURL(), GURL()); | 87 EXPECT_EQ(test_navigation_manager_->GetLastCommittedItem()->GetURL(), GURL()); |
| 88 EXPECT_FALSE(entry->IsRead()); | 88 EXPECT_FALSE(entry->IsRead()); |
| 89 } | 89 } |
| 90 | 90 |
| 91 // Tests that loading an online version of an entry does not alter navigation | 91 // Tests that loading an online version of an entry does not alter navigation |
| 92 // stack and mark entry read. | 92 // stack and mark entry read. |
| 93 TEST_F(ReadingListWebStateObserverTest, TestLoadReadingListOnline) { | 93 TEST_F(ReadingListWebStateObserverTest, TestLoadReadingListOnline) { |
| 94 GURL url(kTestURL); | 94 GURL url(kTestURL); |
| 95 std::string distilled_path = kTestDistilledPath; | 95 std::string distilled_path = kTestDistilledPath; |
| 96 reading_list_model_->SetEntryDistilledInfo( | 96 reading_list_model_->SetEntryDistilledInfo( |
| 97 url, base::FilePath(distilled_path), GURL(kTestDistilledURL)); | 97 url, base::FilePath(distilled_path), GURL(kTestDistilledURL), 50, 100); |
| 98 const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url); | 98 const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url); |
| 99 | 99 |
| 100 test_navigation_manager_->GetPendingItem()->SetURL(url); | 100 test_navigation_manager_->GetPendingItem()->SetURL(url); |
| 101 test_web_state_.SetLoading(true); | 101 test_web_state_.SetLoading(true); |
| 102 test_web_state_.OnPageLoaded(web::PageLoadCompletionStatus::SUCCESS); | 102 test_web_state_.OnPageLoaded(web::PageLoadCompletionStatus::SUCCESS); |
| 103 test_web_state_.SetLoading(false); | 103 test_web_state_.SetLoading(false); |
| 104 | 104 |
| 105 EXPECT_FALSE(test_navigation_manager_->ReloadCalled()); | 105 EXPECT_FALSE(test_navigation_manager_->ReloadCalled()); |
| 106 // Check that |GetLastCommittedItem()| has not been altered. | 106 // Check that |GetLastCommittedItem()| has not been altered. |
| 107 EXPECT_EQ(test_navigation_manager_->GetLastCommittedItem()->GetVirtualURL(), | 107 EXPECT_EQ(test_navigation_manager_->GetLastCommittedItem()->GetVirtualURL(), |
| 108 GURL()); | 108 GURL()); |
| 109 EXPECT_EQ(test_navigation_manager_->GetLastCommittedItem()->GetURL(), GURL()); | 109 EXPECT_EQ(test_navigation_manager_->GetLastCommittedItem()->GetURL(), GURL()); |
| 110 EXPECT_TRUE(entry->IsRead()); | 110 EXPECT_TRUE(entry->IsRead()); |
| 111 } | 111 } |
| 112 | 112 |
| 113 // Tests that loading an online version of an entry does update navigation | 113 // Tests that loading an online version of an entry does update navigation |
| 114 // stack and mark entry read. | 114 // stack and mark entry read. |
| 115 TEST_F(ReadingListWebStateObserverTest, TestLoadReadingListDistilledCommitted) { | 115 TEST_F(ReadingListWebStateObserverTest, TestLoadReadingListDistilledCommitted) { |
| 116 GURL url(kTestURL); | 116 GURL url(kTestURL); |
| 117 std::string distilled_path = kTestDistilledPath; | 117 std::string distilled_path = kTestDistilledPath; |
| 118 reading_list_model_->SetEntryDistilledInfo( | 118 reading_list_model_->SetEntryDistilledInfo( |
| 119 url, base::FilePath(distilled_path), GURL(kTestDistilledURL)); | 119 url, base::FilePath(distilled_path), GURL(kTestDistilledURL), 50, 100); |
| 120 const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url); | 120 const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url); |
| 121 GURL distilled_url = reading_list::OfflineURLForPath( | 121 GURL distilled_url = reading_list::OfflineURLForPath( |
| 122 entry->DistilledPath(), entry->URL(), entry->DistilledURL()); | 122 entry->DistilledPath(), entry->URL(), entry->DistilledURL()); |
| 123 | 123 |
| 124 // Test on commited entry, there must be no pending item. | 124 // Test on commited entry, there must be no pending item. |
| 125 test_navigation_manager_->SetPendingItem(nullptr); | 125 test_navigation_manager_->SetPendingItem(nullptr); |
| 126 test_navigation_manager_->GetLastCommittedItem()->SetURL(url); | 126 test_navigation_manager_->GetLastCommittedItem()->SetURL(url); |
| 127 test_web_state_.SetLoading(true); | 127 test_web_state_.SetLoading(true); |
| 128 test_web_state_.OnPageLoaded(web::PageLoadCompletionStatus::FAILURE); | 128 test_web_state_.OnPageLoaded(web::PageLoadCompletionStatus::FAILURE); |
| 129 test_web_state_.SetLoading(false); | 129 test_web_state_.SetLoading(false); |
| 130 | 130 |
| 131 EXPECT_TRUE(test_navigation_manager_->ReloadCalled()); | 131 EXPECT_TRUE(test_navigation_manager_->ReloadCalled()); |
| 132 EXPECT_EQ(test_navigation_manager_->GetLastCommittedItem()->GetVirtualURL(), | 132 EXPECT_EQ(test_navigation_manager_->GetLastCommittedItem()->GetVirtualURL(), |
| 133 url); | 133 url); |
| 134 EXPECT_EQ(test_navigation_manager_->GetLastCommittedItem()->GetURL(), | 134 EXPECT_EQ(test_navigation_manager_->GetLastCommittedItem()->GetURL(), |
| 135 distilled_url); | 135 distilled_url); |
| 136 EXPECT_TRUE(entry->IsRead()); | 136 EXPECT_TRUE(entry->IsRead()); |
| 137 } | 137 } |
| 138 | 138 |
| 139 // Tests that loading an online version of a pending entry on reload does update | 139 // Tests that loading an online version of a pending entry on reload does update |
| 140 // committed entry, reload, and mark entry read. | 140 // committed entry, reload, and mark entry read. |
| 141 TEST_F(ReadingListWebStateObserverTest, TestLoadReadingListDistilledPending) { | 141 TEST_F(ReadingListWebStateObserverTest, TestLoadReadingListDistilledPending) { |
| 142 GURL url(kTestURL); | 142 GURL url(kTestURL); |
| 143 std::string distilled_path = kTestDistilledPath; | 143 std::string distilled_path = kTestDistilledPath; |
| 144 reading_list_model_->SetEntryDistilledInfo( | 144 reading_list_model_->SetEntryDistilledInfo( |
| 145 url, base::FilePath(distilled_path), GURL(kTestDistilledURL)); | 145 url, base::FilePath(distilled_path), GURL(kTestDistilledURL), 50, 100); |
| 146 const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url); | 146 const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url); |
| 147 GURL distilled_url = reading_list::OfflineURLForPath( | 147 GURL distilled_url = reading_list::OfflineURLForPath( |
| 148 entry->DistilledPath(), entry->URL(), entry->DistilledURL()); | 148 entry->DistilledPath(), entry->URL(), entry->DistilledURL()); |
| 149 | 149 |
| 150 test_navigation_manager_->SetPendingItem(nil); | 150 test_navigation_manager_->SetPendingItem(nil); |
| 151 test_navigation_manager_->GetLastCommittedItem()->SetURL(url); | 151 test_navigation_manager_->GetLastCommittedItem()->SetURL(url); |
| 152 test_web_state_.SetLoading(true); | 152 test_web_state_.SetLoading(true); |
| 153 test_web_state_.OnPageLoaded(web::PageLoadCompletionStatus::FAILURE); | 153 test_web_state_.OnPageLoaded(web::PageLoadCompletionStatus::FAILURE); |
| 154 test_web_state_.SetLoading(false); | 154 test_web_state_.SetLoading(false); |
| 155 | 155 |
| 156 EXPECT_TRUE(test_navigation_manager_->ReloadCalled()); | 156 EXPECT_TRUE(test_navigation_manager_->ReloadCalled()); |
| 157 EXPECT_EQ(test_navigation_manager_->GetLastCommittedItem()->GetVirtualURL(), | 157 EXPECT_EQ(test_navigation_manager_->GetLastCommittedItem()->GetVirtualURL(), |
| 158 url); | 158 url); |
| 159 EXPECT_EQ(test_navigation_manager_->GetLastCommittedItem()->GetURL(), | 159 EXPECT_EQ(test_navigation_manager_->GetLastCommittedItem()->GetURL(), |
| 160 distilled_url); | 160 distilled_url); |
| 161 | 161 |
| 162 EXPECT_TRUE(entry->IsRead()); | 162 EXPECT_TRUE(entry->IsRead()); |
| 163 } | 163 } |
| OLD | NEW |