| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/dom_distiller_service.h" | 5 #include "components/dom_distiller/core/dom_distiller_service.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 MOCK_METHOD1(DistillationCompleted, void(bool)); | 53 MOCK_METHOD1(DistillationCompleted, void(bool)); |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 DomDistillerService::ArticleAvailableCallback ArticleCallback( | 56 DomDistillerService::ArticleAvailableCallback ArticleCallback( |
| 57 MockArticleAvailableCallback* callback) { | 57 MockArticleAvailableCallback* callback) { |
| 58 return base::Bind(&MockArticleAvailableCallback::DistillationCompleted, | 58 return base::Bind(&MockArticleAvailableCallback::DistillationCompleted, |
| 59 base::Unretained(callback)); | 59 base::Unretained(callback)); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void RunDistillerCallback(FakeDistiller* distiller, | 62 void RunDistillerCallback(FakeDistiller* distiller, |
| 63 scoped_ptr<DistilledArticleProto> proto) { | 63 std::unique_ptr<DistilledArticleProto> proto) { |
| 64 distiller->RunDistillerCallback(std::move(proto)); | 64 distiller->RunDistillerCallback(std::move(proto)); |
| 65 base::RunLoop().RunUntilIdle(); | 65 base::RunLoop().RunUntilIdle(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 scoped_ptr<DistilledArticleProto> CreateArticleWithURL(const std::string& url) { | 68 std::unique_ptr<DistilledArticleProto> CreateArticleWithURL( |
| 69 scoped_ptr<DistilledArticleProto> proto(new DistilledArticleProto); | 69 const std::string& url) { |
| 70 std::unique_ptr<DistilledArticleProto> proto(new DistilledArticleProto); |
| 70 DistilledPageProto* page = proto->add_pages(); | 71 DistilledPageProto* page = proto->add_pages(); |
| 71 page->set_url(url); | 72 page->set_url(url); |
| 72 return proto; | 73 return proto; |
| 73 } | 74 } |
| 74 | 75 |
| 75 scoped_ptr<DistilledArticleProto> CreateDefaultArticle() { | 76 std::unique_ptr<DistilledArticleProto> CreateDefaultArticle() { |
| 76 return CreateArticleWithURL("http://www.example.com/default_article_page1"); | 77 return CreateArticleWithURL("http://www.example.com/default_article_page1"); |
| 77 } | 78 } |
| 78 | 79 |
| 79 } // namespace | 80 } // namespace |
| 80 | 81 |
| 81 class DomDistillerServiceTest : public testing::Test { | 82 class DomDistillerServiceTest : public testing::Test { |
| 82 public: | 83 public: |
| 83 void SetUp() override { | 84 void SetUp() override { |
| 84 main_loop_.reset(new base::MessageLoop()); | 85 main_loop_.reset(new base::MessageLoop()); |
| 85 FakeDB<ArticleEntry>* fake_db = new FakeDB<ArticleEntry>(&db_model_); | 86 FakeDB<ArticleEntry>* fake_db = new FakeDB<ArticleEntry>(&db_model_); |
| 86 FakeDB<ArticleEntry>::EntryMap store_model; | 87 FakeDB<ArticleEntry>::EntryMap store_model; |
| 87 store_ = | 88 store_ = |
| 88 test::util::CreateStoreWithFakeDB(fake_db, store_model); | 89 test::util::CreateStoreWithFakeDB(fake_db, store_model); |
| 89 distiller_factory_ = new MockDistillerFactory(); | 90 distiller_factory_ = new MockDistillerFactory(); |
| 90 distiller_page_factory_ = new MockDistillerPageFactory(); | 91 distiller_page_factory_ = new MockDistillerPageFactory(); |
| 91 service_.reset(new DomDistillerService( | 92 service_.reset(new DomDistillerService( |
| 92 scoped_ptr<DomDistillerStoreInterface>(store_), | 93 std::unique_ptr<DomDistillerStoreInterface>(store_), |
| 93 scoped_ptr<DistillerFactory>(distiller_factory_), | 94 std::unique_ptr<DistillerFactory>(distiller_factory_), |
| 94 scoped_ptr<DistillerPageFactory>(distiller_page_factory_), | 95 std::unique_ptr<DistillerPageFactory>(distiller_page_factory_), |
| 95 scoped_ptr<DistilledPagePrefs>())); | 96 std::unique_ptr<DistilledPagePrefs>())); |
| 96 fake_db->InitCallback(true); | 97 fake_db->InitCallback(true); |
| 97 fake_db->LoadCallback(true); | 98 fake_db->LoadCallback(true); |
| 98 } | 99 } |
| 99 | 100 |
| 100 void TearDown() override { | 101 void TearDown() override { |
| 101 base::RunLoop().RunUntilIdle(); | 102 base::RunLoop().RunUntilIdle(); |
| 102 store_ = NULL; | 103 store_ = NULL; |
| 103 distiller_factory_ = NULL; | 104 distiller_factory_ = NULL; |
| 104 service_.reset(); | 105 service_.reset(); |
| 105 } | 106 } |
| 106 | 107 |
| 107 protected: | 108 protected: |
| 108 // store is owned by service_. | 109 // store is owned by service_. |
| 109 DomDistillerStoreInterface* store_; | 110 DomDistillerStoreInterface* store_; |
| 110 MockDistillerFactory* distiller_factory_; | 111 MockDistillerFactory* distiller_factory_; |
| 111 MockDistillerPageFactory* distiller_page_factory_; | 112 MockDistillerPageFactory* distiller_page_factory_; |
| 112 scoped_ptr<DomDistillerService> service_; | 113 std::unique_ptr<DomDistillerService> service_; |
| 113 scoped_ptr<base::MessageLoop> main_loop_; | 114 std::unique_ptr<base::MessageLoop> main_loop_; |
| 114 FakeDB<ArticleEntry>::EntryMap db_model_; | 115 FakeDB<ArticleEntry>::EntryMap db_model_; |
| 115 }; | 116 }; |
| 116 | 117 |
| 117 TEST_F(DomDistillerServiceTest, TestViewEntry) { | 118 TEST_F(DomDistillerServiceTest, TestViewEntry) { |
| 118 FakeDistiller* distiller = new FakeDistiller(false); | 119 FakeDistiller* distiller = new FakeDistiller(false); |
| 119 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) | 120 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) |
| 120 .WillOnce(Return(distiller)); | 121 .WillOnce(Return(distiller)); |
| 121 | 122 |
| 122 GURL url("http://www.example.com/p1"); | 123 GURL url("http://www.example.com/p1"); |
| 123 std::string entry_id("id0"); | 124 std::string entry_id("id0"); |
| 124 ArticleEntry entry; | 125 ArticleEntry entry; |
| 125 entry.set_entry_id(entry_id); | 126 entry.set_entry_id(entry_id); |
| 126 entry.add_pages()->set_url(url.spec()); | 127 entry.add_pages()->set_url(url.spec()); |
| 127 | 128 |
| 128 store_->AddEntry(entry); | 129 store_->AddEntry(entry); |
| 129 | 130 |
| 130 FakeViewRequestDelegate viewer_delegate; | 131 FakeViewRequestDelegate viewer_delegate; |
| 131 scoped_ptr<ViewerHandle> handle = service_->ViewEntry( | 132 std::unique_ptr<ViewerHandle> handle = service_->ViewEntry( |
| 132 &viewer_delegate, service_->CreateDefaultDistillerPage(gfx::Size()), | 133 &viewer_delegate, service_->CreateDefaultDistillerPage(gfx::Size()), |
| 133 entry_id); | 134 entry_id); |
| 134 | 135 |
| 135 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); | 136 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); |
| 136 | 137 |
| 137 scoped_ptr<DistilledArticleProto> proto = CreateDefaultArticle(); | 138 std::unique_ptr<DistilledArticleProto> proto = CreateDefaultArticle(); |
| 138 EXPECT_CALL(viewer_delegate, OnArticleReady(proto.get())); | 139 EXPECT_CALL(viewer_delegate, OnArticleReady(proto.get())); |
| 139 | 140 |
| 140 RunDistillerCallback(distiller, std::move(proto)); | 141 RunDistillerCallback(distiller, std::move(proto)); |
| 141 } | 142 } |
| 142 | 143 |
| 143 TEST_F(DomDistillerServiceTest, TestViewUrl) { | 144 TEST_F(DomDistillerServiceTest, TestViewUrl) { |
| 144 FakeDistiller* distiller = new FakeDistiller(false); | 145 FakeDistiller* distiller = new FakeDistiller(false); |
| 145 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) | 146 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) |
| 146 .WillOnce(Return(distiller)); | 147 .WillOnce(Return(distiller)); |
| 147 | 148 |
| 148 FakeViewRequestDelegate viewer_delegate; | 149 FakeViewRequestDelegate viewer_delegate; |
| 149 GURL url("http://www.example.com/p1"); | 150 GURL url("http://www.example.com/p1"); |
| 150 scoped_ptr<ViewerHandle> handle = service_->ViewUrl( | 151 std::unique_ptr<ViewerHandle> handle = service_->ViewUrl( |
| 151 &viewer_delegate, service_->CreateDefaultDistillerPage(gfx::Size()), url); | 152 &viewer_delegate, service_->CreateDefaultDistillerPage(gfx::Size()), url); |
| 152 | 153 |
| 153 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); | 154 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); |
| 154 EXPECT_EQ(url, distiller->GetUrl()); | 155 EXPECT_EQ(url, distiller->GetUrl()); |
| 155 | 156 |
| 156 scoped_ptr<DistilledArticleProto> proto = CreateDefaultArticle(); | 157 std::unique_ptr<DistilledArticleProto> proto = CreateDefaultArticle(); |
| 157 EXPECT_CALL(viewer_delegate, OnArticleReady(proto.get())); | 158 EXPECT_CALL(viewer_delegate, OnArticleReady(proto.get())); |
| 158 | 159 |
| 159 RunDistillerCallback(distiller, std::move(proto)); | 160 RunDistillerCallback(distiller, std::move(proto)); |
| 160 } | 161 } |
| 161 | 162 |
| 162 TEST_F(DomDistillerServiceTest, TestMultipleViewUrl) { | 163 TEST_F(DomDistillerServiceTest, TestMultipleViewUrl) { |
| 163 FakeDistiller* distiller = new FakeDistiller(false); | 164 FakeDistiller* distiller = new FakeDistiller(false); |
| 164 FakeDistiller* distiller2 = new FakeDistiller(false); | 165 FakeDistiller* distiller2 = new FakeDistiller(false); |
| 165 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) | 166 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) |
| 166 .WillOnce(Return(distiller)) | 167 .WillOnce(Return(distiller)) |
| 167 .WillOnce(Return(distiller2)); | 168 .WillOnce(Return(distiller2)); |
| 168 | 169 |
| 169 FakeViewRequestDelegate viewer_delegate; | 170 FakeViewRequestDelegate viewer_delegate; |
| 170 FakeViewRequestDelegate viewer_delegate2; | 171 FakeViewRequestDelegate viewer_delegate2; |
| 171 | 172 |
| 172 GURL url("http://www.example.com/p1"); | 173 GURL url("http://www.example.com/p1"); |
| 173 GURL url2("http://www.example.com/a/p1"); | 174 GURL url2("http://www.example.com/a/p1"); |
| 174 | 175 |
| 175 scoped_ptr<ViewerHandle> handle = service_->ViewUrl( | 176 std::unique_ptr<ViewerHandle> handle = service_->ViewUrl( |
| 176 &viewer_delegate, service_->CreateDefaultDistillerPage(gfx::Size()), url); | 177 &viewer_delegate, service_->CreateDefaultDistillerPage(gfx::Size()), url); |
| 177 scoped_ptr<ViewerHandle> handle2 = service_->ViewUrl( | 178 std::unique_ptr<ViewerHandle> handle2 = service_->ViewUrl( |
| 178 &viewer_delegate2, service_->CreateDefaultDistillerPage(gfx::Size()), | 179 &viewer_delegate2, service_->CreateDefaultDistillerPage(gfx::Size()), |
| 179 url2); | 180 url2); |
| 180 | 181 |
| 181 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); | 182 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); |
| 182 EXPECT_EQ(url, distiller->GetUrl()); | 183 EXPECT_EQ(url, distiller->GetUrl()); |
| 183 | 184 |
| 184 scoped_ptr<DistilledArticleProto> proto = CreateDefaultArticle(); | 185 std::unique_ptr<DistilledArticleProto> proto = CreateDefaultArticle(); |
| 185 EXPECT_CALL(viewer_delegate, OnArticleReady(proto.get())); | 186 EXPECT_CALL(viewer_delegate, OnArticleReady(proto.get())); |
| 186 | 187 |
| 187 RunDistillerCallback(distiller, std::move(proto)); | 188 RunDistillerCallback(distiller, std::move(proto)); |
| 188 | 189 |
| 189 ASSERT_FALSE(distiller2->GetArticleCallback().is_null()); | 190 ASSERT_FALSE(distiller2->GetArticleCallback().is_null()); |
| 190 EXPECT_EQ(url2, distiller2->GetUrl()); | 191 EXPECT_EQ(url2, distiller2->GetUrl()); |
| 191 | 192 |
| 192 scoped_ptr<DistilledArticleProto> proto2 = CreateDefaultArticle(); | 193 std::unique_ptr<DistilledArticleProto> proto2 = CreateDefaultArticle(); |
| 193 EXPECT_CALL(viewer_delegate2, OnArticleReady(proto2.get())); | 194 EXPECT_CALL(viewer_delegate2, OnArticleReady(proto2.get())); |
| 194 | 195 |
| 195 RunDistillerCallback(distiller2, std::move(proto2)); | 196 RunDistillerCallback(distiller2, std::move(proto2)); |
| 196 } | 197 } |
| 197 | 198 |
| 198 TEST_F(DomDistillerServiceTest, TestViewUrlCancelled) { | 199 TEST_F(DomDistillerServiceTest, TestViewUrlCancelled) { |
| 199 FakeDistiller* distiller = new FakeDistiller(false); | 200 FakeDistiller* distiller = new FakeDistiller(false); |
| 200 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) | 201 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) |
| 201 .WillOnce(Return(distiller)); | 202 .WillOnce(Return(distiller)); |
| 202 | 203 |
| 203 bool distiller_destroyed = false; | 204 bool distiller_destroyed = false; |
| 204 EXPECT_CALL(*distiller, Die()) | 205 EXPECT_CALL(*distiller, Die()) |
| 205 .WillOnce(testing::Assign(&distiller_destroyed, true)); | 206 .WillOnce(testing::Assign(&distiller_destroyed, true)); |
| 206 | 207 |
| 207 FakeViewRequestDelegate viewer_delegate; | 208 FakeViewRequestDelegate viewer_delegate; |
| 208 GURL url("http://www.example.com/p1"); | 209 GURL url("http://www.example.com/p1"); |
| 209 scoped_ptr<ViewerHandle> handle = service_->ViewUrl( | 210 std::unique_ptr<ViewerHandle> handle = service_->ViewUrl( |
| 210 &viewer_delegate, service_->CreateDefaultDistillerPage(gfx::Size()), url); | 211 &viewer_delegate, service_->CreateDefaultDistillerPage(gfx::Size()), url); |
| 211 | 212 |
| 212 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); | 213 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); |
| 213 EXPECT_EQ(url, distiller->GetUrl()); | 214 EXPECT_EQ(url, distiller->GetUrl()); |
| 214 | 215 |
| 215 EXPECT_CALL(viewer_delegate, OnArticleReady(_)).Times(0); | 216 EXPECT_CALL(viewer_delegate, OnArticleReady(_)).Times(0); |
| 216 | 217 |
| 217 EXPECT_FALSE(distiller_destroyed); | 218 EXPECT_FALSE(distiller_destroyed); |
| 218 | 219 |
| 219 handle.reset(); | 220 handle.reset(); |
| 220 base::RunLoop().RunUntilIdle(); | 221 base::RunLoop().RunUntilIdle(); |
| 221 EXPECT_TRUE(distiller_destroyed); | 222 EXPECT_TRUE(distiller_destroyed); |
| 222 } | 223 } |
| 223 | 224 |
| 224 TEST_F(DomDistillerServiceTest, TestViewUrlDoesNotAddEntry) { | 225 TEST_F(DomDistillerServiceTest, TestViewUrlDoesNotAddEntry) { |
| 225 FakeDistiller* distiller = new FakeDistiller(false); | 226 FakeDistiller* distiller = new FakeDistiller(false); |
| 226 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) | 227 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) |
| 227 .WillOnce(Return(distiller)); | 228 .WillOnce(Return(distiller)); |
| 228 | 229 |
| 229 FakeViewRequestDelegate viewer_delegate; | 230 FakeViewRequestDelegate viewer_delegate; |
| 230 GURL url("http://www.example.com/p1"); | 231 GURL url("http://www.example.com/p1"); |
| 231 scoped_ptr<ViewerHandle> handle = service_->ViewUrl( | 232 std::unique_ptr<ViewerHandle> handle = service_->ViewUrl( |
| 232 &viewer_delegate, service_->CreateDefaultDistillerPage(gfx::Size()), url); | 233 &viewer_delegate, service_->CreateDefaultDistillerPage(gfx::Size()), url); |
| 233 | 234 |
| 234 scoped_ptr<DistilledArticleProto> proto = CreateArticleWithURL(url.spec()); | 235 std::unique_ptr<DistilledArticleProto> proto = |
| 236 CreateArticleWithURL(url.spec()); |
| 235 EXPECT_CALL(viewer_delegate, OnArticleReady(proto.get())); | 237 EXPECT_CALL(viewer_delegate, OnArticleReady(proto.get())); |
| 236 | 238 |
| 237 RunDistillerCallback(distiller, std::move(proto)); | 239 RunDistillerCallback(distiller, std::move(proto)); |
| 238 base::RunLoop().RunUntilIdle(); | 240 base::RunLoop().RunUntilIdle(); |
| 239 // The entry should not be added to the store. | 241 // The entry should not be added to the store. |
| 240 EXPECT_EQ(0u, store_->GetEntries().size()); | 242 EXPECT_EQ(0u, store_->GetEntries().size()); |
| 241 } | 243 } |
| 242 | 244 |
| 243 TEST_F(DomDistillerServiceTest, TestAddAndRemoveEntry) { | 245 TEST_F(DomDistillerServiceTest, TestAddAndRemoveEntry) { |
| 244 FakeDistiller* distiller = new FakeDistiller(false); | 246 FakeDistiller* distiller = new FakeDistiller(false); |
| 245 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) | 247 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) |
| 246 .WillOnce(Return(distiller)); | 248 .WillOnce(Return(distiller)); |
| 247 | 249 |
| 248 GURL url("http://www.example.com/p1"); | 250 GURL url("http://www.example.com/p1"); |
| 249 | 251 |
| 250 MockArticleAvailableCallback article_cb; | 252 MockArticleAvailableCallback article_cb; |
| 251 EXPECT_CALL(article_cb, DistillationCompleted(true)); | 253 EXPECT_CALL(article_cb, DistillationCompleted(true)); |
| 252 | 254 |
| 253 std::string entry_id = service_->AddToList( | 255 std::string entry_id = service_->AddToList( |
| 254 url, service_->CreateDefaultDistillerPage(gfx::Size()), | 256 url, service_->CreateDefaultDistillerPage(gfx::Size()), |
| 255 ArticleCallback(&article_cb)); | 257 ArticleCallback(&article_cb)); |
| 256 | 258 |
| 257 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); | 259 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); |
| 258 EXPECT_EQ(url, distiller->GetUrl()); | 260 EXPECT_EQ(url, distiller->GetUrl()); |
| 259 | 261 |
| 260 scoped_ptr<DistilledArticleProto> proto = CreateArticleWithURL(url.spec()); | 262 std::unique_ptr<DistilledArticleProto> proto = |
| 263 CreateArticleWithURL(url.spec()); |
| 261 RunDistillerCallback(distiller, std::move(proto)); | 264 RunDistillerCallback(distiller, std::move(proto)); |
| 262 | 265 |
| 263 ArticleEntry entry; | 266 ArticleEntry entry; |
| 264 EXPECT_TRUE(store_->GetEntryByUrl(url, &entry)); | 267 EXPECT_TRUE(store_->GetEntryByUrl(url, &entry)); |
| 265 EXPECT_EQ(entry.entry_id(), entry_id); | 268 EXPECT_EQ(entry.entry_id(), entry_id); |
| 266 EXPECT_EQ(1u, store_->GetEntries().size()); | 269 EXPECT_EQ(1u, store_->GetEntries().size()); |
| 267 service_->RemoveEntry(entry_id); | 270 service_->RemoveEntry(entry_id); |
| 268 base::RunLoop().RunUntilIdle(); | 271 base::RunLoop().RunUntilIdle(); |
| 269 EXPECT_EQ(0u, store_->GetEntries().size()); | 272 EXPECT_EQ(0u, store_->GetEntries().size()); |
| 270 } | 273 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 DomDistillerObserver::ArticleUpdate update; | 314 DomDistillerObserver::ArticleUpdate update; |
| 312 update.entry_id = entry_id; | 315 update.entry_id = entry_id; |
| 313 update.update_type = DomDistillerObserver::ArticleUpdate::ADD; | 316 update.update_type = DomDistillerObserver::ArticleUpdate::ADD; |
| 314 expected_updates.push_back(update); | 317 expected_updates.push_back(update); |
| 315 | 318 |
| 316 for (int i = 0; i < kObserverCount; ++i) { | 319 for (int i = 0; i < kObserverCount; ++i) { |
| 317 EXPECT_CALL(observers[i], ArticleEntriesUpdated( | 320 EXPECT_CALL(observers[i], ArticleEntriesUpdated( |
| 318 util::HasExpectedUpdates(expected_updates))); | 321 util::HasExpectedUpdates(expected_updates))); |
| 319 } | 322 } |
| 320 | 323 |
| 321 scoped_ptr<DistilledArticleProto> proto = CreateDefaultArticle(); | 324 std::unique_ptr<DistilledArticleProto> proto = CreateDefaultArticle(); |
| 322 RunDistillerCallback(distiller, std::move(proto)); | 325 RunDistillerCallback(distiller, std::move(proto)); |
| 323 | 326 |
| 324 // Remove should notify all observers that article is removed. | 327 // Remove should notify all observers that article is removed. |
| 325 update.update_type = DomDistillerObserver::ArticleUpdate::REMOVE; | 328 update.update_type = DomDistillerObserver::ArticleUpdate::REMOVE; |
| 326 expected_updates.clear(); | 329 expected_updates.clear(); |
| 327 expected_updates.push_back(update); | 330 expected_updates.push_back(update); |
| 328 for (int i = 0; i < kObserverCount; ++i) { | 331 for (int i = 0; i < kObserverCount; ++i) { |
| 329 EXPECT_CALL(observers[i], ArticleEntriesUpdated( | 332 EXPECT_CALL(observers[i], ArticleEntriesUpdated( |
| 330 util::HasExpectedUpdates(expected_updates))); | 333 util::HasExpectedUpdates(expected_updates))); |
| 331 } | 334 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 349 EXPECT_CALL(article_cb[0], DistillationCompleted(true)); | 352 EXPECT_CALL(article_cb[0], DistillationCompleted(true)); |
| 350 | 353 |
| 351 for (int i = 1; i < kClientsCount; ++i) { | 354 for (int i = 1; i < kClientsCount; ++i) { |
| 352 EXPECT_EQ(entry_id, | 355 EXPECT_EQ(entry_id, |
| 353 service_->AddToList( | 356 service_->AddToList( |
| 354 url, service_->CreateDefaultDistillerPage(gfx::Size()), | 357 url, service_->CreateDefaultDistillerPage(gfx::Size()), |
| 355 ArticleCallback(&article_cb[i]))); | 358 ArticleCallback(&article_cb[i]))); |
| 356 EXPECT_CALL(article_cb[i], DistillationCompleted(true)); | 359 EXPECT_CALL(article_cb[i], DistillationCompleted(true)); |
| 357 } | 360 } |
| 358 | 361 |
| 359 scoped_ptr<DistilledArticleProto> proto = CreateArticleWithURL(url.spec()); | 362 std::unique_ptr<DistilledArticleProto> proto = |
| 363 CreateArticleWithURL(url.spec()); |
| 360 RunDistillerCallback(distiller, std::move(proto)); | 364 RunDistillerCallback(distiller, std::move(proto)); |
| 361 | 365 |
| 362 // Add the same url again, all callbacks should be called with true. | 366 // Add the same url again, all callbacks should be called with true. |
| 363 for (int i = 0; i < kClientsCount; ++i) { | 367 for (int i = 0; i < kClientsCount; ++i) { |
| 364 EXPECT_CALL(article_cb[i], DistillationCompleted(true)); | 368 EXPECT_CALL(article_cb[i], DistillationCompleted(true)); |
| 365 EXPECT_EQ(entry_id, | 369 EXPECT_EQ(entry_id, |
| 366 service_->AddToList( | 370 service_->AddToList( |
| 367 url, service_->CreateDefaultDistillerPage(gfx::Size()), | 371 url, service_->CreateDefaultDistillerPage(gfx::Size()), |
| 368 ArticleCallback(&article_cb[i]))); | 372 ArticleCallback(&article_cb[i]))); |
| 369 } | 373 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 | 420 |
| 417 std::string entry_id = service_->AddToList( | 421 std::string entry_id = service_->AddToList( |
| 418 pages_url[0], service_->CreateDefaultDistillerPage(gfx::Size()), | 422 pages_url[0], service_->CreateDefaultDistillerPage(gfx::Size()), |
| 419 ArticleCallback(&article_cb)); | 423 ArticleCallback(&article_cb)); |
| 420 | 424 |
| 421 ArticleEntry entry; | 425 ArticleEntry entry; |
| 422 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); | 426 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); |
| 423 EXPECT_EQ(pages_url[0], distiller->GetUrl()); | 427 EXPECT_EQ(pages_url[0], distiller->GetUrl()); |
| 424 | 428 |
| 425 // Create the article with pages to pass to the distiller. | 429 // Create the article with pages to pass to the distiller. |
| 426 scoped_ptr<DistilledArticleProto> proto = | 430 std::unique_ptr<DistilledArticleProto> proto = |
| 427 CreateArticleWithURL(pages_url[0].spec()); | 431 CreateArticleWithURL(pages_url[0].spec()); |
| 428 for (int page_num = 1; page_num < kPageCount; ++page_num) { | 432 for (int page_num = 1; page_num < kPageCount; ++page_num) { |
| 429 DistilledPageProto* distilled_page = proto->add_pages(); | 433 DistilledPageProto* distilled_page = proto->add_pages(); |
| 430 distilled_page->set_url(pages_url[page_num].spec()); | 434 distilled_page->set_url(pages_url[page_num].spec()); |
| 431 } | 435 } |
| 432 | 436 |
| 433 RunDistillerCallback(distiller, std::move(proto)); | 437 RunDistillerCallback(distiller, std::move(proto)); |
| 434 EXPECT_TRUE(store_->GetEntryByUrl(pages_url[0], &entry)); | 438 EXPECT_TRUE(store_->GetEntryByUrl(pages_url[0], &entry)); |
| 435 | 439 |
| 436 EXPECT_EQ(kPageCount, entry.pages_size()); | 440 EXPECT_EQ(kPageCount, entry.pages_size()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 462 MockArticleAvailableCallback article_cb; | 466 MockArticleAvailableCallback article_cb; |
| 463 EXPECT_CALL(article_cb, DistillationCompleted(true)); | 467 EXPECT_CALL(article_cb, DistillationCompleted(true)); |
| 464 | 468 |
| 465 std::string entry_id = service_->AddToList( | 469 std::string entry_id = service_->AddToList( |
| 466 url, service_->CreateDefaultDistillerPage(gfx::Size()), | 470 url, service_->CreateDefaultDistillerPage(gfx::Size()), |
| 467 ArticleCallback(&article_cb)); | 471 ArticleCallback(&article_cb)); |
| 468 | 472 |
| 469 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); | 473 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); |
| 470 EXPECT_EQ(url, distiller->GetUrl()); | 474 EXPECT_EQ(url, distiller->GetUrl()); |
| 471 | 475 |
| 472 scoped_ptr<DistilledArticleProto> proto = CreateArticleWithURL(url.spec()); | 476 std::unique_ptr<DistilledArticleProto> proto = |
| 477 CreateArticleWithURL(url.spec()); |
| 473 RunDistillerCallback(distiller, std::move(proto)); | 478 RunDistillerCallback(distiller, std::move(proto)); |
| 474 | 479 |
| 475 // Check that HasEntry returns true for the article just added. | 480 // Check that HasEntry returns true for the article just added. |
| 476 EXPECT_TRUE(service_->HasEntry(entry_id)); | 481 EXPECT_TRUE(service_->HasEntry(entry_id)); |
| 477 | 482 |
| 478 // Remove article and check that there is no longer an entry for the given | 483 // Remove article and check that there is no longer an entry for the given |
| 479 // entry id. | 484 // entry id. |
| 480 service_->RemoveEntry(entry_id); | 485 service_->RemoveEntry(entry_id); |
| 481 base::RunLoop().RunUntilIdle(); | 486 base::RunLoop().RunUntilIdle(); |
| 482 EXPECT_EQ(0u, store_->GetEntries().size()); | 487 EXPECT_EQ(0u, store_->GetEntries().size()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 493 MockArticleAvailableCallback article_cb; | 498 MockArticleAvailableCallback article_cb; |
| 494 EXPECT_CALL(article_cb, DistillationCompleted(true)); | 499 EXPECT_CALL(article_cb, DistillationCompleted(true)); |
| 495 | 500 |
| 496 std::string entry_id = service_->AddToList( | 501 std::string entry_id = service_->AddToList( |
| 497 url, service_->CreateDefaultDistillerPage(gfx::Size()), | 502 url, service_->CreateDefaultDistillerPage(gfx::Size()), |
| 498 ArticleCallback(&article_cb)); | 503 ArticleCallback(&article_cb)); |
| 499 | 504 |
| 500 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); | 505 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); |
| 501 EXPECT_EQ(url, distiller->GetUrl()); | 506 EXPECT_EQ(url, distiller->GetUrl()); |
| 502 | 507 |
| 503 scoped_ptr<DistilledArticleProto> proto = CreateArticleWithURL(url.spec()); | 508 std::unique_ptr<DistilledArticleProto> proto = |
| 509 CreateArticleWithURL(url.spec()); |
| 504 RunDistillerCallback(distiller, std::move(proto)); | 510 RunDistillerCallback(distiller, std::move(proto)); |
| 505 | 511 |
| 506 // Check if retrieved URL is same as given URL. | 512 // Check if retrieved URL is same as given URL. |
| 507 GURL retrieved_url(service_->GetUrlForEntry(entry_id)); | 513 GURL retrieved_url(service_->GetUrlForEntry(entry_id)); |
| 508 EXPECT_EQ(url, retrieved_url); | 514 EXPECT_EQ(url, retrieved_url); |
| 509 | 515 |
| 510 // Remove article and check that there is no longer an entry for the given | 516 // Remove article and check that there is no longer an entry for the given |
| 511 // entry id. | 517 // entry id. |
| 512 service_->RemoveEntry(entry_id); | 518 service_->RemoveEntry(entry_id); |
| 513 base::RunLoop().RunUntilIdle(); | 519 base::RunLoop().RunUntilIdle(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 533 | 539 |
| 534 std::string entry_id = service_->AddToList( | 540 std::string entry_id = service_->AddToList( |
| 535 pages_url[0], service_->CreateDefaultDistillerPage(gfx::Size()), | 541 pages_url[0], service_->CreateDefaultDistillerPage(gfx::Size()), |
| 536 ArticleCallback(&article_cb)); | 542 ArticleCallback(&article_cb)); |
| 537 | 543 |
| 538 ArticleEntry entry; | 544 ArticleEntry entry; |
| 539 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); | 545 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); |
| 540 EXPECT_EQ(pages_url[0], distiller->GetUrl()); | 546 EXPECT_EQ(pages_url[0], distiller->GetUrl()); |
| 541 | 547 |
| 542 // Create the article with pages to pass to the distiller. | 548 // Create the article with pages to pass to the distiller. |
| 543 scoped_ptr<DistilledArticleProto> proto = | 549 std::unique_ptr<DistilledArticleProto> proto = |
| 544 CreateArticleWithURL(pages_url[0].spec()); | 550 CreateArticleWithURL(pages_url[0].spec()); |
| 545 for (int page_num = 1; page_num < kPageCount; ++page_num) { | 551 for (int page_num = 1; page_num < kPageCount; ++page_num) { |
| 546 DistilledPageProto* distilled_page = proto->add_pages(); | 552 DistilledPageProto* distilled_page = proto->add_pages(); |
| 547 distilled_page->set_url(pages_url[page_num].spec()); | 553 distilled_page->set_url(pages_url[page_num].spec()); |
| 548 } | 554 } |
| 549 | 555 |
| 550 RunDistillerCallback(distiller, std::move(proto)); | 556 RunDistillerCallback(distiller, std::move(proto)); |
| 551 EXPECT_TRUE(store_->GetEntryByUrl(pages_url[0], &entry)); | 557 EXPECT_TRUE(store_->GetEntryByUrl(pages_url[0], &entry)); |
| 552 | 558 |
| 553 // Check if retrieved URL is same as given URL for the first page. | 559 // Check if retrieved URL is same as given URL for the first page. |
| 554 GURL retrieved_url(service_->GetUrlForEntry(entry_id)); | 560 GURL retrieved_url(service_->GetUrlForEntry(entry_id)); |
| 555 EXPECT_EQ(pages_url[0], retrieved_url); | 561 EXPECT_EQ(pages_url[0], retrieved_url); |
| 556 | 562 |
| 557 // Remove the article and check that no URL can be retrieved for the entry. | 563 // Remove the article and check that no URL can be retrieved for the entry. |
| 558 service_->RemoveEntry(entry_id); | 564 service_->RemoveEntry(entry_id); |
| 559 base::RunLoop().RunUntilIdle(); | 565 base::RunLoop().RunUntilIdle(); |
| 560 EXPECT_EQ(0u, store_->GetEntries().size()); | 566 EXPECT_EQ(0u, store_->GetEntries().size()); |
| 561 EXPECT_EQ("", service_->GetUrlForEntry(entry_id)); | 567 EXPECT_EQ("", service_->GetUrlForEntry(entry_id)); |
| 562 } | 568 } |
| 563 | 569 |
| 564 } // namespace test | 570 } // namespace test |
| 565 } // namespace dom_distiller | 571 } // namespace dom_distiller |
| OLD | NEW |