| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 GURL url("http://www.example.com/p1"); | 121 GURL url("http://www.example.com/p1"); |
| 122 std::string entry_id("id0"); | 122 std::string entry_id("id0"); |
| 123 ArticleEntry entry; | 123 ArticleEntry entry; |
| 124 entry.set_entry_id(entry_id); | 124 entry.set_entry_id(entry_id); |
| 125 entry.add_pages()->set_url(url.spec()); | 125 entry.add_pages()->set_url(url.spec()); |
| 126 | 126 |
| 127 store_->AddEntry(entry); | 127 store_->AddEntry(entry); |
| 128 | 128 |
| 129 FakeViewRequestDelegate viewer_delegate; | 129 FakeViewRequestDelegate viewer_delegate; |
| 130 scoped_ptr<ViewerHandle> handle = service_->ViewEntry( | 130 scoped_ptr<ViewerHandle> handle = service_->ViewEntry( |
| 131 &viewer_delegate, service_->CreateDefaultDistillerPage(), entry_id); | 131 &viewer_delegate, service_->CreateDefaultDistillerPage(gfx::Size()), |
| 132 entry_id); |
| 132 | 133 |
| 133 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); | 134 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); |
| 134 | 135 |
| 135 scoped_ptr<DistilledArticleProto> proto = CreateDefaultArticle(); | 136 scoped_ptr<DistilledArticleProto> proto = CreateDefaultArticle(); |
| 136 EXPECT_CALL(viewer_delegate, OnArticleReady(proto.get())); | 137 EXPECT_CALL(viewer_delegate, OnArticleReady(proto.get())); |
| 137 | 138 |
| 138 RunDistillerCallback(distiller, proto.Pass()); | 139 RunDistillerCallback(distiller, proto.Pass()); |
| 139 } | 140 } |
| 140 | 141 |
| 141 TEST_F(DomDistillerServiceTest, TestViewUrl) { | 142 TEST_F(DomDistillerServiceTest, TestViewUrl) { |
| 142 FakeDistiller* distiller = new FakeDistiller(false); | 143 FakeDistiller* distiller = new FakeDistiller(false); |
| 143 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) | 144 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) |
| 144 .WillOnce(Return(distiller)); | 145 .WillOnce(Return(distiller)); |
| 145 | 146 |
| 146 FakeViewRequestDelegate viewer_delegate; | 147 FakeViewRequestDelegate viewer_delegate; |
| 147 GURL url("http://www.example.com/p1"); | 148 GURL url("http://www.example.com/p1"); |
| 148 scoped_ptr<ViewerHandle> handle = service_->ViewUrl( | 149 scoped_ptr<ViewerHandle> handle = service_->ViewUrl( |
| 149 &viewer_delegate, service_->CreateDefaultDistillerPage(), url); | 150 &viewer_delegate, service_->CreateDefaultDistillerPage(gfx::Size()), url); |
| 150 | 151 |
| 151 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); | 152 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); |
| 152 EXPECT_EQ(url, distiller->GetUrl()); | 153 EXPECT_EQ(url, distiller->GetUrl()); |
| 153 | 154 |
| 154 scoped_ptr<DistilledArticleProto> proto = CreateDefaultArticle(); | 155 scoped_ptr<DistilledArticleProto> proto = CreateDefaultArticle(); |
| 155 EXPECT_CALL(viewer_delegate, OnArticleReady(proto.get())); | 156 EXPECT_CALL(viewer_delegate, OnArticleReady(proto.get())); |
| 156 | 157 |
| 157 RunDistillerCallback(distiller, proto.Pass()); | 158 RunDistillerCallback(distiller, proto.Pass()); |
| 158 } | 159 } |
| 159 | 160 |
| 160 TEST_F(DomDistillerServiceTest, TestMultipleViewUrl) { | 161 TEST_F(DomDistillerServiceTest, TestMultipleViewUrl) { |
| 161 FakeDistiller* distiller = new FakeDistiller(false); | 162 FakeDistiller* distiller = new FakeDistiller(false); |
| 162 FakeDistiller* distiller2 = new FakeDistiller(false); | 163 FakeDistiller* distiller2 = new FakeDistiller(false); |
| 163 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) | 164 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) |
| 164 .WillOnce(Return(distiller)) | 165 .WillOnce(Return(distiller)) |
| 165 .WillOnce(Return(distiller2)); | 166 .WillOnce(Return(distiller2)); |
| 166 | 167 |
| 167 FakeViewRequestDelegate viewer_delegate; | 168 FakeViewRequestDelegate viewer_delegate; |
| 168 FakeViewRequestDelegate viewer_delegate2; | 169 FakeViewRequestDelegate viewer_delegate2; |
| 169 | 170 |
| 170 GURL url("http://www.example.com/p1"); | 171 GURL url("http://www.example.com/p1"); |
| 171 GURL url2("http://www.example.com/a/p1"); | 172 GURL url2("http://www.example.com/a/p1"); |
| 172 | 173 |
| 173 scoped_ptr<ViewerHandle> handle = service_->ViewUrl( | 174 scoped_ptr<ViewerHandle> handle = service_->ViewUrl( |
| 174 &viewer_delegate, service_->CreateDefaultDistillerPage(), url); | 175 &viewer_delegate, service_->CreateDefaultDistillerPage(gfx::Size()), url); |
| 175 scoped_ptr<ViewerHandle> handle2 = service_->ViewUrl( | 176 scoped_ptr<ViewerHandle> handle2 = service_->ViewUrl( |
| 176 &viewer_delegate2, service_->CreateDefaultDistillerPage(), url2); | 177 &viewer_delegate2, service_->CreateDefaultDistillerPage(gfx::Size()), |
| 178 url2); |
| 177 | 179 |
| 178 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); | 180 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); |
| 179 EXPECT_EQ(url, distiller->GetUrl()); | 181 EXPECT_EQ(url, distiller->GetUrl()); |
| 180 | 182 |
| 181 scoped_ptr<DistilledArticleProto> proto = CreateDefaultArticle(); | 183 scoped_ptr<DistilledArticleProto> proto = CreateDefaultArticle(); |
| 182 EXPECT_CALL(viewer_delegate, OnArticleReady(proto.get())); | 184 EXPECT_CALL(viewer_delegate, OnArticleReady(proto.get())); |
| 183 | 185 |
| 184 RunDistillerCallback(distiller, proto.Pass()); | 186 RunDistillerCallback(distiller, proto.Pass()); |
| 185 | 187 |
| 186 ASSERT_FALSE(distiller2->GetArticleCallback().is_null()); | 188 ASSERT_FALSE(distiller2->GetArticleCallback().is_null()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 197 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) | 199 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) |
| 198 .WillOnce(Return(distiller)); | 200 .WillOnce(Return(distiller)); |
| 199 | 201 |
| 200 bool distiller_destroyed = false; | 202 bool distiller_destroyed = false; |
| 201 EXPECT_CALL(*distiller, Die()) | 203 EXPECT_CALL(*distiller, Die()) |
| 202 .WillOnce(testing::Assign(&distiller_destroyed, true)); | 204 .WillOnce(testing::Assign(&distiller_destroyed, true)); |
| 203 | 205 |
| 204 FakeViewRequestDelegate viewer_delegate; | 206 FakeViewRequestDelegate viewer_delegate; |
| 205 GURL url("http://www.example.com/p1"); | 207 GURL url("http://www.example.com/p1"); |
| 206 scoped_ptr<ViewerHandle> handle = service_->ViewUrl( | 208 scoped_ptr<ViewerHandle> handle = service_->ViewUrl( |
| 207 &viewer_delegate, service_->CreateDefaultDistillerPage(), url); | 209 &viewer_delegate, service_->CreateDefaultDistillerPage(gfx::Size()), url); |
| 208 | 210 |
| 209 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); | 211 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); |
| 210 EXPECT_EQ(url, distiller->GetUrl()); | 212 EXPECT_EQ(url, distiller->GetUrl()); |
| 211 | 213 |
| 212 EXPECT_CALL(viewer_delegate, OnArticleReady(_)).Times(0); | 214 EXPECT_CALL(viewer_delegate, OnArticleReady(_)).Times(0); |
| 213 | 215 |
| 214 EXPECT_FALSE(distiller_destroyed); | 216 EXPECT_FALSE(distiller_destroyed); |
| 215 | 217 |
| 216 handle.reset(); | 218 handle.reset(); |
| 217 base::RunLoop().RunUntilIdle(); | 219 base::RunLoop().RunUntilIdle(); |
| 218 EXPECT_TRUE(distiller_destroyed); | 220 EXPECT_TRUE(distiller_destroyed); |
| 219 } | 221 } |
| 220 | 222 |
| 221 TEST_F(DomDistillerServiceTest, TestViewUrlDoesNotAddEntry) { | 223 TEST_F(DomDistillerServiceTest, TestViewUrlDoesNotAddEntry) { |
| 222 FakeDistiller* distiller = new FakeDistiller(false); | 224 FakeDistiller* distiller = new FakeDistiller(false); |
| 223 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) | 225 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) |
| 224 .WillOnce(Return(distiller)); | 226 .WillOnce(Return(distiller)); |
| 225 | 227 |
| 226 FakeViewRequestDelegate viewer_delegate; | 228 FakeViewRequestDelegate viewer_delegate; |
| 227 GURL url("http://www.example.com/p1"); | 229 GURL url("http://www.example.com/p1"); |
| 228 scoped_ptr<ViewerHandle> handle = service_->ViewUrl( | 230 scoped_ptr<ViewerHandle> handle = service_->ViewUrl( |
| 229 &viewer_delegate, service_->CreateDefaultDistillerPage(), url); | 231 &viewer_delegate, service_->CreateDefaultDistillerPage(gfx::Size()), url); |
| 230 | 232 |
| 231 scoped_ptr<DistilledArticleProto> proto = CreateArticleWithURL(url.spec()); | 233 scoped_ptr<DistilledArticleProto> proto = CreateArticleWithURL(url.spec()); |
| 232 EXPECT_CALL(viewer_delegate, OnArticleReady(proto.get())); | 234 EXPECT_CALL(viewer_delegate, OnArticleReady(proto.get())); |
| 233 | 235 |
| 234 RunDistillerCallback(distiller, proto.Pass()); | 236 RunDistillerCallback(distiller, proto.Pass()); |
| 235 base::RunLoop().RunUntilIdle(); | 237 base::RunLoop().RunUntilIdle(); |
| 236 // The entry should not be added to the store. | 238 // The entry should not be added to the store. |
| 237 EXPECT_EQ(0u, store_->GetEntries().size()); | 239 EXPECT_EQ(0u, store_->GetEntries().size()); |
| 238 } | 240 } |
| 239 | 241 |
| 240 TEST_F(DomDistillerServiceTest, TestAddAndRemoveEntry) { | 242 TEST_F(DomDistillerServiceTest, TestAddAndRemoveEntry) { |
| 241 FakeDistiller* distiller = new FakeDistiller(false); | 243 FakeDistiller* distiller = new FakeDistiller(false); |
| 242 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) | 244 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) |
| 243 .WillOnce(Return(distiller)); | 245 .WillOnce(Return(distiller)); |
| 244 | 246 |
| 245 GURL url("http://www.example.com/p1"); | 247 GURL url("http://www.example.com/p1"); |
| 246 | 248 |
| 247 MockArticleAvailableCallback article_cb; | 249 MockArticleAvailableCallback article_cb; |
| 248 EXPECT_CALL(article_cb, DistillationCompleted(true)); | 250 EXPECT_CALL(article_cb, DistillationCompleted(true)); |
| 249 | 251 |
| 250 std::string entry_id = | 252 std::string entry_id = |
| 251 service_->AddToList(url, service_->CreateDefaultDistillerPage().Pass(), | 253 service_->AddToList(url, |
| 252 ArticleCallback(&article_cb)); | 254 service_->CreateDefaultDistillerPage(gfx::Size()).Pass(), |
| 255 ArticleCallback(&article_cb)); |
| 253 | 256 |
| 254 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); | 257 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); |
| 255 EXPECT_EQ(url, distiller->GetUrl()); | 258 EXPECT_EQ(url, distiller->GetUrl()); |
| 256 | 259 |
| 257 scoped_ptr<DistilledArticleProto> proto = CreateArticleWithURL(url.spec()); | 260 scoped_ptr<DistilledArticleProto> proto = CreateArticleWithURL(url.spec()); |
| 258 RunDistillerCallback(distiller, proto.Pass()); | 261 RunDistillerCallback(distiller, proto.Pass()); |
| 259 | 262 |
| 260 ArticleEntry entry; | 263 ArticleEntry entry; |
| 261 EXPECT_TRUE(store_->GetEntryByUrl(url, &entry)); | 264 EXPECT_TRUE(store_->GetEntryByUrl(url, &entry)); |
| 262 EXPECT_EQ(entry.entry_id(), entry_id); | 265 EXPECT_EQ(entry.entry_id(), entry_id); |
| 263 EXPECT_EQ(1u, store_->GetEntries().size()); | 266 EXPECT_EQ(1u, store_->GetEntries().size()); |
| 264 service_->RemoveEntry(entry_id); | 267 service_->RemoveEntry(entry_id); |
| 265 base::RunLoop().RunUntilIdle(); | 268 base::RunLoop().RunUntilIdle(); |
| 266 EXPECT_EQ(0u, store_->GetEntries().size()); | 269 EXPECT_EQ(0u, store_->GetEntries().size()); |
| 267 } | 270 } |
| 268 | 271 |
| 269 TEST_F(DomDistillerServiceTest, TestCancellation) { | 272 TEST_F(DomDistillerServiceTest, TestCancellation) { |
| 270 FakeDistiller* distiller = new FakeDistiller(false); | 273 FakeDistiller* distiller = new FakeDistiller(false); |
| 271 MockDistillerObserver observer; | 274 MockDistillerObserver observer; |
| 272 service_->AddObserver(&observer); | 275 service_->AddObserver(&observer); |
| 273 | 276 |
| 274 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) | 277 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) |
| 275 .WillOnce(Return(distiller)); | 278 .WillOnce(Return(distiller)); |
| 276 | 279 |
| 277 MockArticleAvailableCallback article_cb; | 280 MockArticleAvailableCallback article_cb; |
| 278 EXPECT_CALL(article_cb, DistillationCompleted(false)); | 281 EXPECT_CALL(article_cb, DistillationCompleted(false)); |
| 279 | 282 |
| 280 GURL url("http://www.example.com/p1"); | 283 GURL url("http://www.example.com/p1"); |
| 281 std::string entry_id = | 284 std::string entry_id = |
| 282 service_->AddToList(url, service_->CreateDefaultDistillerPage().Pass(), | 285 service_->AddToList(url, |
| 283 ArticleCallback(&article_cb)); | 286 service_->CreateDefaultDistillerPage(gfx::Size()).Pass(), |
| 287 ArticleCallback(&article_cb)); |
| 284 | 288 |
| 285 // Remove entry will cause the |article_cb| to be called with false value. | 289 // Remove entry will cause the |article_cb| to be called with false value. |
| 286 service_->RemoveEntry(entry_id); | 290 service_->RemoveEntry(entry_id); |
| 287 base::RunLoop().RunUntilIdle(); | 291 base::RunLoop().RunUntilIdle(); |
| 288 } | 292 } |
| 289 | 293 |
| 290 TEST_F(DomDistillerServiceTest, TestMultipleObservers) { | 294 TEST_F(DomDistillerServiceTest, TestMultipleObservers) { |
| 291 FakeDistiller* distiller = new FakeDistiller(false); | 295 FakeDistiller* distiller = new FakeDistiller(false); |
| 292 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) | 296 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) |
| 293 .WillOnce(Return(distiller)); | 297 .WillOnce(Return(distiller)); |
| 294 | 298 |
| 295 const int kObserverCount = 5; | 299 const int kObserverCount = 5; |
| 296 MockDistillerObserver observers[kObserverCount]; | 300 MockDistillerObserver observers[kObserverCount]; |
| 297 for (int i = 0; i < kObserverCount; ++i) { | 301 for (int i = 0; i < kObserverCount; ++i) { |
| 298 service_->AddObserver(&observers[i]); | 302 service_->AddObserver(&observers[i]); |
| 299 } | 303 } |
| 300 | 304 |
| 301 DomDistillerService::ArticleAvailableCallback article_cb; | 305 DomDistillerService::ArticleAvailableCallback article_cb; |
| 302 GURL url("http://www.example.com/p1"); | 306 GURL url("http://www.example.com/p1"); |
| 303 std::string entry_id = service_->AddToList( | 307 std::string entry_id = service_->AddToList( |
| 304 url, service_->CreateDefaultDistillerPage().Pass(), article_cb); | 308 url, service_->CreateDefaultDistillerPage(gfx::Size()).Pass(), |
| 309 article_cb); |
| 305 | 310 |
| 306 // Distillation should notify all observers that article is added. | 311 // Distillation should notify all observers that article is added. |
| 307 std::vector<DomDistillerObserver::ArticleUpdate> expected_updates; | 312 std::vector<DomDistillerObserver::ArticleUpdate> expected_updates; |
| 308 DomDistillerObserver::ArticleUpdate update; | 313 DomDistillerObserver::ArticleUpdate update; |
| 309 update.entry_id = entry_id; | 314 update.entry_id = entry_id; |
| 310 update.update_type = DomDistillerObserver::ArticleUpdate::ADD; | 315 update.update_type = DomDistillerObserver::ArticleUpdate::ADD; |
| 311 expected_updates.push_back(update); | 316 expected_updates.push_back(update); |
| 312 | 317 |
| 313 for (int i = 0; i < kObserverCount; ++i) { | 318 for (int i = 0; i < kObserverCount; ++i) { |
| 314 EXPECT_CALL(observers[i], ArticleEntriesUpdated( | 319 EXPECT_CALL(observers[i], ArticleEntriesUpdated( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 334 TEST_F(DomDistillerServiceTest, TestMultipleCallbacks) { | 339 TEST_F(DomDistillerServiceTest, TestMultipleCallbacks) { |
| 335 FakeDistiller* distiller = new FakeDistiller(false); | 340 FakeDistiller* distiller = new FakeDistiller(false); |
| 336 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) | 341 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) |
| 337 .WillOnce(Return(distiller)); | 342 .WillOnce(Return(distiller)); |
| 338 | 343 |
| 339 const int kClientsCount = 5; | 344 const int kClientsCount = 5; |
| 340 MockArticleAvailableCallback article_cb[kClientsCount]; | 345 MockArticleAvailableCallback article_cb[kClientsCount]; |
| 341 // Adding a URL and then distilling calls all clients. | 346 // Adding a URL and then distilling calls all clients. |
| 342 GURL url("http://www.example.com/p1"); | 347 GURL url("http://www.example.com/p1"); |
| 343 const std::string entry_id = | 348 const std::string entry_id = |
| 344 service_->AddToList(url, service_->CreateDefaultDistillerPage().Pass(), | 349 service_->AddToList(url, |
| 345 ArticleCallback(&article_cb[0])); | 350 service_->CreateDefaultDistillerPage(gfx::Size()).Pass(), |
| 351 ArticleCallback(&article_cb[0])); |
| 346 EXPECT_CALL(article_cb[0], DistillationCompleted(true)); | 352 EXPECT_CALL(article_cb[0], DistillationCompleted(true)); |
| 347 | 353 |
| 348 for (int i = 1; i < kClientsCount; ++i) { | 354 for (int i = 1; i < kClientsCount; ++i) { |
| 349 EXPECT_EQ(entry_id, service_->AddToList( | 355 EXPECT_EQ(entry_id, |
| 350 url, service_->CreateDefaultDistillerPage().Pass(), | 356 service_->AddToList( |
| 351 ArticleCallback(&article_cb[i]))); | 357 url, |
| 358 service_->CreateDefaultDistillerPage(gfx::Size()).Pass(), |
| 359 ArticleCallback(&article_cb[i]))); |
| 352 EXPECT_CALL(article_cb[i], DistillationCompleted(true)); | 360 EXPECT_CALL(article_cb[i], DistillationCompleted(true)); |
| 353 } | 361 } |
| 354 | 362 |
| 355 scoped_ptr<DistilledArticleProto> proto = CreateArticleWithURL(url.spec()); | 363 scoped_ptr<DistilledArticleProto> proto = CreateArticleWithURL(url.spec()); |
| 356 RunDistillerCallback(distiller, proto.Pass()); | 364 RunDistillerCallback(distiller, proto.Pass()); |
| 357 | 365 |
| 358 // 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. |
| 359 for (int i = 0; i < kClientsCount; ++i) { | 367 for (int i = 0; i < kClientsCount; ++i) { |
| 360 EXPECT_CALL(article_cb[i], DistillationCompleted(true)); | 368 EXPECT_CALL(article_cb[i], DistillationCompleted(true)); |
| 361 EXPECT_EQ(entry_id, service_->AddToList( | 369 EXPECT_EQ(entry_id, |
| 362 url, service_->CreateDefaultDistillerPage().Pass(), | 370 service_->AddToList( |
| 363 ArticleCallback(&article_cb[i]))); | 371 url, |
| 372 service_->CreateDefaultDistillerPage(gfx::Size()).Pass(), |
| 373 ArticleCallback(&article_cb[i]))); |
| 364 } | 374 } |
| 365 | 375 |
| 366 base::RunLoop().RunUntilIdle(); | 376 base::RunLoop().RunUntilIdle(); |
| 367 } | 377 } |
| 368 | 378 |
| 369 TEST_F(DomDistillerServiceTest, TestMultipleCallbacksOnRemove) { | 379 TEST_F(DomDistillerServiceTest, TestMultipleCallbacksOnRemove) { |
| 370 FakeDistiller* distiller = new FakeDistiller(false); | 380 FakeDistiller* distiller = new FakeDistiller(false); |
| 371 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) | 381 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) |
| 372 .WillOnce(Return(distiller)); | 382 .WillOnce(Return(distiller)); |
| 373 | 383 |
| 374 const int kClientsCount = 5; | 384 const int kClientsCount = 5; |
| 375 MockArticleAvailableCallback article_cb[kClientsCount]; | 385 MockArticleAvailableCallback article_cb[kClientsCount]; |
| 376 // Adding a URL and remove the entry before distillation. Callback should be | 386 // Adding a URL and remove the entry before distillation. Callback should be |
| 377 // called with false. | 387 // called with false. |
| 378 GURL url("http://www.example.com/p1"); | 388 GURL url("http://www.example.com/p1"); |
| 379 const std::string entry_id = | 389 const std::string entry_id = |
| 380 service_->AddToList(url, service_->CreateDefaultDistillerPage().Pass(), | 390 service_->AddToList(url, |
| 381 ArticleCallback(&article_cb[0])); | 391 service_->CreateDefaultDistillerPage(gfx::Size()).Pass(), |
| 392 ArticleCallback(&article_cb[0])); |
| 382 | 393 |
| 383 EXPECT_CALL(article_cb[0], DistillationCompleted(false)); | 394 EXPECT_CALL(article_cb[0], DistillationCompleted(false)); |
| 384 for (int i = 1; i < kClientsCount; ++i) { | 395 for (int i = 1; i < kClientsCount; ++i) { |
| 385 EXPECT_EQ(entry_id, service_->AddToList( | 396 EXPECT_EQ(entry_id, |
| 386 url, service_->CreateDefaultDistillerPage().Pass(), | 397 service_->AddToList( |
| 387 ArticleCallback(&article_cb[i]))); | 398 url, service_->CreateDefaultDistillerPage(gfx::Size()).Pass(), |
| 399 ArticleCallback(&article_cb[i]))); |
| 388 EXPECT_CALL(article_cb[i], DistillationCompleted(false)); | 400 EXPECT_CALL(article_cb[i], DistillationCompleted(false)); |
| 389 } | 401 } |
| 390 | 402 |
| 391 service_->RemoveEntry(entry_id); | 403 service_->RemoveEntry(entry_id); |
| 392 base::RunLoop().RunUntilIdle(); | 404 base::RunLoop().RunUntilIdle(); |
| 393 } | 405 } |
| 394 | 406 |
| 395 TEST_F(DomDistillerServiceTest, TestMultiplePageArticle) { | 407 TEST_F(DomDistillerServiceTest, TestMultiplePageArticle) { |
| 396 FakeDistiller* distiller = new FakeDistiller(false); | 408 FakeDistiller* distiller = new FakeDistiller(false); |
| 397 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) | 409 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) |
| 398 .WillOnce(Return(distiller)); | 410 .WillOnce(Return(distiller)); |
| 399 | 411 |
| 400 const int kPageCount = 8; | 412 const int kPageCount = 8; |
| 401 | 413 |
| 402 std::string base_url("http://www.example.com/p"); | 414 std::string base_url("http://www.example.com/p"); |
| 403 GURL pages_url[kPageCount]; | 415 GURL pages_url[kPageCount]; |
| 404 for (int page_num = 0; page_num < kPageCount; ++page_num) { | 416 for (int page_num = 0; page_num < kPageCount; ++page_num) { |
| 405 pages_url[page_num] = GURL(base_url + base::IntToString(page_num)); | 417 pages_url[page_num] = GURL(base_url + base::IntToString(page_num)); |
| 406 } | 418 } |
| 407 | 419 |
| 408 MockArticleAvailableCallback article_cb; | 420 MockArticleAvailableCallback article_cb; |
| 409 EXPECT_CALL(article_cb, DistillationCompleted(true)); | 421 EXPECT_CALL(article_cb, DistillationCompleted(true)); |
| 410 | 422 |
| 411 std::string entry_id = service_->AddToList( | 423 std::string entry_id = service_->AddToList( |
| 412 pages_url[0], service_->CreateDefaultDistillerPage().Pass(), | 424 pages_url[0], service_->CreateDefaultDistillerPage(gfx::Size()).Pass(), |
| 413 ArticleCallback(&article_cb)); | 425 ArticleCallback(&article_cb)); |
| 414 | 426 |
| 415 ArticleEntry entry; | 427 ArticleEntry entry; |
| 416 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); | 428 ASSERT_FALSE(distiller->GetArticleCallback().is_null()); |
| 417 EXPECT_EQ(pages_url[0], distiller->GetUrl()); | 429 EXPECT_EQ(pages_url[0], distiller->GetUrl()); |
| 418 | 430 |
| 419 // Create the article with pages to pass to the distiller. | 431 // Create the article with pages to pass to the distiller. |
| 420 scoped_ptr<DistilledArticleProto> proto = | 432 scoped_ptr<DistilledArticleProto> proto = |
| 421 CreateArticleWithURL(pages_url[0].spec()); | 433 CreateArticleWithURL(pages_url[0].spec()); |
| 422 for (int page_num = 1; page_num < kPageCount; ++page_num) { | 434 for (int page_num = 1; page_num < kPageCount; ++page_num) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 441 EXPECT_TRUE(store_->GetEntryByUrl(pages_url[page_num], &entry)); | 453 EXPECT_TRUE(store_->GetEntryByUrl(pages_url[page_num], &entry)); |
| 442 } | 454 } |
| 443 | 455 |
| 444 service_->RemoveEntry(entry_id); | 456 service_->RemoveEntry(entry_id); |
| 445 base::RunLoop().RunUntilIdle(); | 457 base::RunLoop().RunUntilIdle(); |
| 446 EXPECT_EQ(0u, store_->GetEntries().size()); | 458 EXPECT_EQ(0u, store_->GetEntries().size()); |
| 447 } | 459 } |
| 448 | 460 |
| 449 } // namespace test | 461 } // namespace test |
| 450 } // namespace dom_distiller | 462 } // namespace dom_distiller |
| OLD | NEW |