| 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 "chrome/browser/android/offline_pages/recent_tab_helper.h" | 5 #include "chrome/browser/android/offline_pages/recent_tab_helper.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 10 #include "base/test/scoped_feature_list.h" | 10 #include "base/test/scoped_feature_list.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 RecentTabHelper* recent_tab_helper() const { return recent_tab_helper_; } | 88 RecentTabHelper* recent_tab_helper() const { return recent_tab_helper_; } |
| 89 | 89 |
| 90 OfflinePageModel* model() const { return model_; } | 90 OfflinePageModel* model() const { return model_; } |
| 91 | 91 |
| 92 const std::vector<OfflinePageItem>& all_pages() { return all_pages_; } | 92 const std::vector<OfflinePageItem>& all_pages() { return all_pages_; } |
| 93 | 93 |
| 94 scoped_refptr<base::TestMockTimeTaskRunner>& task_runner() { | 94 scoped_refptr<base::TestMockTimeTaskRunner>& task_runner() { |
| 95 return task_runner_; | 95 return task_runner_; |
| 96 } | 96 } |
| 97 | 97 |
| 98 size_t model_changed_count() { return model_changed_count_; } | 98 size_t page_added_count() { return page_added_count_; } |
| 99 size_t model_removed_count() { return model_removed_count_; } | 99 size_t model_removed_count() { return model_removed_count_; } |
| 100 | 100 |
| 101 // OfflinePageModel::Observer | 101 // OfflinePageModel::Observer |
| 102 void OfflinePageModelLoaded(OfflinePageModel* model) override { } | 102 void OfflinePageModelLoaded(OfflinePageModel* model) override { } |
| 103 void OfflinePageModelChanged(OfflinePageModel* model) override { | 103 void OfflinePageAdded(OfflinePageModel* model, |
| 104 model_changed_count_++; | 104 const OfflinePageItem& added_page) override { |
| 105 page_added_count_++; |
| 105 } | 106 } |
| 106 void OfflinePageDeleted(int64_t, const offline_pages::ClientId&) override { | 107 void OfflinePageDeleted(int64_t, const offline_pages::ClientId&) override { |
| 107 model_removed_count_++; | 108 model_removed_count_++; |
| 108 } | 109 } |
| 109 | 110 |
| 110 // OfflinePageTestArchiver::Observer | 111 // OfflinePageTestArchiver::Observer |
| 111 void SetLastPathCreatedByArchiver(const base::FilePath& file_path) override {} | 112 void SetLastPathCreatedByArchiver(const base::FilePath& file_path) override {} |
| 112 | 113 |
| 113 private: | 114 private: |
| 114 void OnGetAllPagesDone(const std::vector<OfflinePageItem>& result); | 115 void OnGetAllPagesDone(const std::vector<OfflinePageItem>& result); |
| 115 | 116 |
| 116 RecentTabHelper* recent_tab_helper_; // Owned by WebContents. | 117 RecentTabHelper* recent_tab_helper_; // Owned by WebContents. |
| 117 OfflinePageModel* model_; // Keyed service | 118 OfflinePageModel* model_; // Keyed service |
| 118 size_t model_changed_count_; | 119 size_t page_added_count_; |
| 119 size_t model_removed_count_; | 120 size_t model_removed_count_; |
| 120 std::vector<OfflinePageItem> all_pages_; | 121 std::vector<OfflinePageItem> all_pages_; |
| 121 scoped_refptr<base::TestMockTimeTaskRunner> task_runner_; | 122 scoped_refptr<base::TestMockTimeTaskRunner> task_runner_; |
| 122 base::test::ScopedFeatureList scoped_feature_list_; | 123 base::test::ScopedFeatureList scoped_feature_list_; |
| 123 | 124 |
| 124 base::WeakPtrFactory<RecentTabHelperTest> weak_ptr_factory_; | 125 base::WeakPtrFactory<RecentTabHelperTest> weak_ptr_factory_; |
| 125 | 126 |
| 126 DISALLOW_COPY_AND_ASSIGN(RecentTabHelperTest); | 127 DISALLOW_COPY_AND_ASSIGN(RecentTabHelperTest); |
| 127 }; | 128 }; |
| 128 | 129 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 151 } | 152 } |
| 152 // There is no expectations that tab_id is always present. | 153 // There is no expectations that tab_id is always present. |
| 153 bool TestDelegate::GetTabId(content::WebContents* web_contents, int* tab_id) { | 154 bool TestDelegate::GetTabId(content::WebContents* web_contents, int* tab_id) { |
| 154 *tab_id = tab_id_; | 155 *tab_id = tab_id_; |
| 155 return tab_id_result_; | 156 return tab_id_result_; |
| 156 } | 157 } |
| 157 | 158 |
| 158 RecentTabHelperTest::RecentTabHelperTest() | 159 RecentTabHelperTest::RecentTabHelperTest() |
| 159 : recent_tab_helper_(nullptr), | 160 : recent_tab_helper_(nullptr), |
| 160 model_(nullptr), | 161 model_(nullptr), |
| 161 model_changed_count_(0), | 162 page_added_count_(0), |
| 162 model_removed_count_(0), | 163 model_removed_count_(0), |
| 163 task_runner_(new base::TestMockTimeTaskRunner), | 164 task_runner_(new base::TestMockTimeTaskRunner), |
| 164 weak_ptr_factory_(this) { | 165 weak_ptr_factory_(this) {} |
| 165 } | |
| 166 | 166 |
| 167 void RecentTabHelperTest::SetUp() { | 167 void RecentTabHelperTest::SetUp() { |
| 168 content::RenderViewHostTestHarness::SetUp(); | 168 content::RenderViewHostTestHarness::SetUp(); |
| 169 | 169 |
| 170 scoped_feature_list_.InitAndEnableFeature(kOffliningRecentPagesFeature); | 170 scoped_feature_list_.InitAndEnableFeature(kOffliningRecentPagesFeature); |
| 171 // Sets up the factory for testing. | 171 // Sets up the factory for testing. |
| 172 OfflinePageModelFactory::GetInstance()->SetTestingFactoryAndUse( | 172 OfflinePageModelFactory::GetInstance()->SetTestingFactoryAndUse( |
| 173 browser_context(), BuildTestOfflinePageModel); | 173 browser_context(), BuildTestOfflinePageModel); |
| 174 RunUntilIdle(); | 174 RunUntilIdle(); |
| 175 | 175 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 } | 252 } |
| 253 | 253 |
| 254 // Triggers two snapshot captures during a single page load. Should end up with | 254 // Triggers two snapshot captures during a single page load. Should end up with |
| 255 // one offline page (the 2nd snapshot should be kept). | 255 // one offline page (the 2nd snapshot should be kept). |
| 256 TEST_F(RecentTabHelperTest, TwoCapturesSamePageLoad) { | 256 TEST_F(RecentTabHelperTest, TwoCapturesSamePageLoad) { |
| 257 NavigateAndCommit(kTestPageUrl); | 257 NavigateAndCommit(kTestPageUrl); |
| 258 // Triggers snapshot after a time delay. | 258 // Triggers snapshot after a time delay. |
| 259 recent_tab_helper()->DocumentAvailableInMainFrame(); | 259 recent_tab_helper()->DocumentAvailableInMainFrame(); |
| 260 RunUntilIdle(); | 260 RunUntilIdle(); |
| 261 EXPECT_TRUE(model()->is_loaded()); | 261 EXPECT_TRUE(model()->is_loaded()); |
| 262 EXPECT_EQ(0U, model_changed_count()); | 262 EXPECT_EQ(0U, page_added_count()); |
| 263 // Move the snapshot controller's time forward so it gets past timeouts. | 263 // Move the snapshot controller's time forward so it gets past timeouts. |
| 264 FastForwardSnapshotController(); | 264 FastForwardSnapshotController(); |
| 265 RunUntilIdle(); | 265 RunUntilIdle(); |
| 266 EXPECT_EQ(1U, model_changed_count()); | 266 EXPECT_EQ(1U, page_added_count()); |
| 267 EXPECT_EQ(0U, model_removed_count()); | 267 EXPECT_EQ(0U, model_removed_count()); |
| 268 GetAllPages(); | 268 GetAllPages(); |
| 269 EXPECT_EQ(1U, all_pages().size()); | 269 EXPECT_EQ(1U, all_pages().size()); |
| 270 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); | 270 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); |
| 271 int64_t first_offline_id = all_pages()[0].offline_id; | 271 int64_t first_offline_id = all_pages()[0].offline_id; |
| 272 | 272 |
| 273 // Triggers snapshot after a time delay. | 273 // Triggers snapshot after a time delay. |
| 274 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); | 274 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); |
| 275 // Move the snapshot controller's time forward so it gets past timeouts. | 275 // Move the snapshot controller's time forward so it gets past timeouts. |
| 276 FastForwardSnapshotController(); | 276 FastForwardSnapshotController(); |
| 277 RunUntilIdle(); | 277 RunUntilIdle(); |
| 278 EXPECT_EQ(2U, model_changed_count()); | 278 EXPECT_EQ(2U, page_added_count()); |
| 279 EXPECT_EQ(1U, model_removed_count()); | 279 EXPECT_EQ(1U, model_removed_count()); |
| 280 // the same page should be simply overridden. | 280 // the same page should be simply overridden. |
| 281 GetAllPages(); | 281 GetAllPages(); |
| 282 EXPECT_EQ(1U, all_pages().size()); | 282 EXPECT_EQ(1U, all_pages().size()); |
| 283 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); | 283 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); |
| 284 EXPECT_NE(first_offline_id, all_pages()[0].offline_id); | 284 EXPECT_NE(first_offline_id, all_pages()[0].offline_id); |
| 285 } | 285 } |
| 286 | 286 |
| 287 // Triggers two snapshot captures during a single page load, where the 2nd one | 287 // Triggers two snapshot captures during a single page load, where the 2nd one |
| 288 // fails. Should end up with one offline page (the 1st, successful snapshot | 288 // fails. Should end up with one offline page (the 1st, successful snapshot |
| 289 // should be kept). | 289 // should be kept). |
| 290 TEST_F(RecentTabHelperTest, TwoCapturesSamePageLoadSecondFails) { | 290 TEST_F(RecentTabHelperTest, TwoCapturesSamePageLoadSecondFails) { |
| 291 NavigateAndCommit(kTestPageUrl); | 291 NavigateAndCommit(kTestPageUrl); |
| 292 // Triggers snapshot after a time delay. | 292 // Triggers snapshot after a time delay. |
| 293 recent_tab_helper()->DocumentAvailableInMainFrame(); | 293 recent_tab_helper()->DocumentAvailableInMainFrame(); |
| 294 RunUntilIdle(); | 294 RunUntilIdle(); |
| 295 EXPECT_TRUE(model()->is_loaded()); | 295 EXPECT_TRUE(model()->is_loaded()); |
| 296 EXPECT_EQ(0U, model_changed_count()); | 296 EXPECT_EQ(0U, page_added_count()); |
| 297 // Move the snapshot controller's time forward so it gets past timeouts. | 297 // Move the snapshot controller's time forward so it gets past timeouts. |
| 298 FastForwardSnapshotController(); | 298 FastForwardSnapshotController(); |
| 299 RunUntilIdle(); | 299 RunUntilIdle(); |
| 300 EXPECT_EQ(1U, model_changed_count()); | 300 EXPECT_EQ(1U, page_added_count()); |
| 301 EXPECT_EQ(0U, model_removed_count()); | 301 EXPECT_EQ(0U, model_removed_count()); |
| 302 GetAllPages(); | 302 GetAllPages(); |
| 303 EXPECT_EQ(1U, all_pages().size()); | 303 EXPECT_EQ(1U, all_pages().size()); |
| 304 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); | 304 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); |
| 305 int64_t first_offline_id = all_pages()[0].offline_id; | 305 int64_t first_offline_id = all_pages()[0].offline_id; |
| 306 | 306 |
| 307 // Sets a new delegate that will make the second snapshot fail. | 307 // Sets a new delegate that will make the second snapshot fail. |
| 308 TestDelegate* failing_delegate = | 308 TestDelegate* failing_delegate = |
| 309 new TestDelegate(this, task_runner(), kTabId, true); | 309 new TestDelegate(this, task_runner(), kTabId, true); |
| 310 failing_delegate->set_archive_size(-1); | 310 failing_delegate->set_archive_size(-1); |
| 311 failing_delegate->set_archive_result( | 311 failing_delegate->set_archive_result( |
| 312 offline_pages::OfflinePageArchiver::ArchiverResult:: | 312 offline_pages::OfflinePageArchiver::ArchiverResult:: |
| 313 ERROR_ARCHIVE_CREATION_FAILED); | 313 ERROR_ARCHIVE_CREATION_FAILED); |
| 314 recent_tab_helper()->SetDelegate( | 314 recent_tab_helper()->SetDelegate( |
| 315 std::unique_ptr<TestDelegate>(failing_delegate)); | 315 std::unique_ptr<TestDelegate>(failing_delegate)); |
| 316 | 316 |
| 317 // Triggers snapshot after a time delay. | 317 // Triggers snapshot after a time delay. |
| 318 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); | 318 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); |
| 319 // Move the snapshot controller's time forward so it gets past timeouts. | 319 // Move the snapshot controller's time forward so it gets past timeouts. |
| 320 FastForwardSnapshotController(); | 320 FastForwardSnapshotController(); |
| 321 RunUntilIdle(); | 321 RunUntilIdle(); |
| 322 EXPECT_EQ(1U, model_changed_count()); | 322 EXPECT_EQ(1U, page_added_count()); |
| 323 EXPECT_EQ(0U, model_removed_count()); | 323 EXPECT_EQ(0U, model_removed_count()); |
| 324 // The exact same page should still be available. | 324 // The exact same page should still be available. |
| 325 GetAllPages(); | 325 GetAllPages(); |
| 326 EXPECT_EQ(1U, all_pages().size()); | 326 EXPECT_EQ(1U, all_pages().size()); |
| 327 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); | 327 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); |
| 328 EXPECT_EQ(first_offline_id, all_pages()[0].offline_id); | 328 EXPECT_EQ(first_offline_id, all_pages()[0].offline_id); |
| 329 } | 329 } |
| 330 | 330 |
| 331 // Triggers two snapshot captures for two different page loads for the same URL. | 331 // Triggers two snapshot captures for two different page loads for the same URL. |
| 332 // Should end up with one offline page (snapshot from the 2nd load). | 332 // Should end up with one offline page (snapshot from the 2nd load). |
| 333 TEST_F(RecentTabHelperTest, TwoCapturesDifferentPageLoadsSameUrl) { | 333 TEST_F(RecentTabHelperTest, TwoCapturesDifferentPageLoadsSameUrl) { |
| 334 NavigateAndCommit(kTestPageUrl); | 334 NavigateAndCommit(kTestPageUrl); |
| 335 // Triggers snapshot after a time delay. | 335 // Triggers snapshot after a time delay. |
| 336 recent_tab_helper()->DocumentAvailableInMainFrame(); | 336 recent_tab_helper()->DocumentAvailableInMainFrame(); |
| 337 RunUntilIdle(); | 337 RunUntilIdle(); |
| 338 EXPECT_TRUE(model()->is_loaded()); | 338 EXPECT_TRUE(model()->is_loaded()); |
| 339 EXPECT_EQ(0U, model_changed_count()); | 339 EXPECT_EQ(0U, page_added_count()); |
| 340 // Move the snapshot controller's time forward so it gets past timeouts. | 340 // Move the snapshot controller's time forward so it gets past timeouts. |
| 341 FastForwardSnapshotController(); | 341 FastForwardSnapshotController(); |
| 342 RunUntilIdle(); | 342 RunUntilIdle(); |
| 343 EXPECT_EQ(1U, model_changed_count()); | 343 EXPECT_EQ(1U, page_added_count()); |
| 344 EXPECT_EQ(0U, model_removed_count()); | 344 EXPECT_EQ(0U, model_removed_count()); |
| 345 GetAllPages(); | 345 GetAllPages(); |
| 346 EXPECT_EQ(1U, all_pages().size()); | 346 EXPECT_EQ(1U, all_pages().size()); |
| 347 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); | 347 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); |
| 348 int64_t first_offline_id = all_pages()[0].offline_id; | 348 int64_t first_offline_id = all_pages()[0].offline_id; |
| 349 | 349 |
| 350 NavigateAndCommit(kTestPageUrl); | 350 NavigateAndCommit(kTestPageUrl); |
| 351 // Triggers snapshot after a time delay. | 351 // Triggers snapshot after a time delay. |
| 352 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); | 352 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); |
| 353 // Move the snapshot controller's time forward so it gets past timeouts. | 353 // Move the snapshot controller's time forward so it gets past timeouts. |
| 354 FastForwardSnapshotController(); | 354 FastForwardSnapshotController(); |
| 355 RunUntilIdle(); | 355 RunUntilIdle(); |
| 356 EXPECT_EQ(2U, model_changed_count()); | 356 EXPECT_EQ(2U, page_added_count()); |
| 357 EXPECT_EQ(1U, model_removed_count()); | 357 EXPECT_EQ(1U, model_removed_count()); |
| 358 // the same page should be simply overridden. | 358 // the same page should be simply overridden. |
| 359 GetAllPages(); | 359 GetAllPages(); |
| 360 EXPECT_EQ(1U, all_pages().size()); | 360 EXPECT_EQ(1U, all_pages().size()); |
| 361 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); | 361 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); |
| 362 EXPECT_NE(first_offline_id, all_pages()[0].offline_id); | 362 EXPECT_NE(first_offline_id, all_pages()[0].offline_id); |
| 363 } | 363 } |
| 364 | 364 |
| 365 // Triggers two snapshot captures for two different page loads for the same URL, | 365 // Triggers two snapshot captures for two different page loads for the same URL, |
| 366 // where the 2nd one fails. Should end up with no offline pages (privacy driven | 366 // where the 2nd one fails. Should end up with no offline pages (privacy driven |
| 367 // decision). | 367 // decision). |
| 368 TEST_F(RecentTabHelperTest, TwoCapturesDifferentPageLoadsSameUrlSecondFails) { | 368 TEST_F(RecentTabHelperTest, TwoCapturesDifferentPageLoadsSameUrlSecondFails) { |
| 369 NavigateAndCommit(kTestPageUrl); | 369 NavigateAndCommit(kTestPageUrl); |
| 370 // Triggers snapshot after a time delay. | 370 // Triggers snapshot after a time delay. |
| 371 recent_tab_helper()->DocumentAvailableInMainFrame(); | 371 recent_tab_helper()->DocumentAvailableInMainFrame(); |
| 372 RunUntilIdle(); | 372 RunUntilIdle(); |
| 373 EXPECT_TRUE(model()->is_loaded()); | 373 EXPECT_TRUE(model()->is_loaded()); |
| 374 EXPECT_EQ(0U, model_changed_count()); | 374 EXPECT_EQ(0U, page_added_count()); |
| 375 // Move the snapshot controller's time forward so it gets past timeouts. | 375 // Move the snapshot controller's time forward so it gets past timeouts. |
| 376 FastForwardSnapshotController(); | 376 FastForwardSnapshotController(); |
| 377 RunUntilIdle(); | 377 RunUntilIdle(); |
| 378 EXPECT_EQ(1U, model_changed_count()); | 378 EXPECT_EQ(1U, page_added_count()); |
| 379 EXPECT_EQ(0U, model_removed_count()); | 379 EXPECT_EQ(0U, model_removed_count()); |
| 380 GetAllPages(); | 380 GetAllPages(); |
| 381 EXPECT_EQ(1U, all_pages().size()); | 381 EXPECT_EQ(1U, all_pages().size()); |
| 382 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); | 382 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); |
| 383 | 383 |
| 384 // Sets a new delegate that will make the second snapshot fail. | 384 // Sets a new delegate that will make the second snapshot fail. |
| 385 TestDelegate* failing_delegate = | 385 TestDelegate* failing_delegate = |
| 386 new TestDelegate(this, task_runner(), kTabId, true); | 386 new TestDelegate(this, task_runner(), kTabId, true); |
| 387 failing_delegate->set_archive_size(-1); | 387 failing_delegate->set_archive_size(-1); |
| 388 failing_delegate->set_archive_result( | 388 failing_delegate->set_archive_result( |
| 389 offline_pages::OfflinePageArchiver::ArchiverResult:: | 389 offline_pages::OfflinePageArchiver::ArchiverResult:: |
| 390 ERROR_ARCHIVE_CREATION_FAILED); | 390 ERROR_ARCHIVE_CREATION_FAILED); |
| 391 recent_tab_helper()->SetDelegate( | 391 recent_tab_helper()->SetDelegate( |
| 392 std::unique_ptr<TestDelegate>(failing_delegate)); | 392 std::unique_ptr<TestDelegate>(failing_delegate)); |
| 393 | 393 |
| 394 NavigateAndCommit(kTestPageUrl); | 394 NavigateAndCommit(kTestPageUrl); |
| 395 // Triggers snapshot after a time delay. | 395 // Triggers snapshot after a time delay. |
| 396 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); | 396 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); |
| 397 // Move the snapshot controller's time forward so it gets past timeouts. | 397 // Move the snapshot controller's time forward so it gets past timeouts. |
| 398 FastForwardSnapshotController(); | 398 FastForwardSnapshotController(); |
| 399 RunUntilIdle(); | 399 RunUntilIdle(); |
| 400 EXPECT_EQ(1U, model_changed_count()); | 400 EXPECT_EQ(1U, page_added_count()); |
| 401 EXPECT_EQ(1U, model_removed_count()); | 401 EXPECT_EQ(1U, model_removed_count()); |
| 402 // the same page should be simply overridden. | 402 // the same page should be simply overridden. |
| 403 GetAllPages(); | 403 GetAllPages(); |
| 404 EXPECT_EQ(0U, all_pages().size()); | 404 EXPECT_EQ(0U, all_pages().size()); |
| 405 } | 405 } |
| 406 | 406 |
| 407 // Triggers two snapshot captures for two different page loads and URLs. Should | 407 // Triggers two snapshot captures for two different page loads and URLs. Should |
| 408 // end up with one offline page. | 408 // end up with one offline page. |
| 409 TEST_F(RecentTabHelperTest, TwoCapturesDifferentPageLoadsAndUrls) { | 409 TEST_F(RecentTabHelperTest, TwoCapturesDifferentPageLoadsAndUrls) { |
| 410 NavigateAndCommit(kTestPageUrl); | 410 NavigateAndCommit(kTestPageUrl); |
| 411 // Triggers snapshot after a time delay. | 411 // Triggers snapshot after a time delay. |
| 412 recent_tab_helper()->DocumentAvailableInMainFrame(); | 412 recent_tab_helper()->DocumentAvailableInMainFrame(); |
| 413 RunUntilIdle(); | 413 RunUntilIdle(); |
| 414 EXPECT_TRUE(model()->is_loaded()); | 414 EXPECT_TRUE(model()->is_loaded()); |
| 415 EXPECT_EQ(0U, model_changed_count()); | 415 EXPECT_EQ(0U, page_added_count()); |
| 416 // Move the snapshot controller's time forward so it gets past timeouts. | 416 // Move the snapshot controller's time forward so it gets past timeouts. |
| 417 FastForwardSnapshotController(); | 417 FastForwardSnapshotController(); |
| 418 RunUntilIdle(); | 418 RunUntilIdle(); |
| 419 EXPECT_EQ(1U, model_changed_count()); | 419 EXPECT_EQ(1U, page_added_count()); |
| 420 EXPECT_EQ(0U, model_removed_count()); | 420 EXPECT_EQ(0U, model_removed_count()); |
| 421 GetAllPages(); | 421 GetAllPages(); |
| 422 EXPECT_EQ(1U, all_pages().size()); | 422 EXPECT_EQ(1U, all_pages().size()); |
| 423 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); | 423 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); |
| 424 | 424 |
| 425 NavigateAndCommit(kTestPageUrlOther); | 425 NavigateAndCommit(kTestPageUrlOther); |
| 426 // Triggers snapshot after a time delay. | 426 // Triggers snapshot after a time delay. |
| 427 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); | 427 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); |
| 428 // Move the snapshot controller's time forward so it gets past timeouts. | 428 // Move the snapshot controller's time forward so it gets past timeouts. |
| 429 FastForwardSnapshotController(); | 429 FastForwardSnapshotController(); |
| 430 RunUntilIdle(); | 430 RunUntilIdle(); |
| 431 EXPECT_EQ(2U, model_changed_count()); | 431 EXPECT_EQ(2U, page_added_count()); |
| 432 EXPECT_EQ(1U, model_removed_count()); | 432 EXPECT_EQ(1U, model_removed_count()); |
| 433 // the same page should be simply overridden. | 433 // the same page should be simply overridden. |
| 434 GetAllPages(); | 434 GetAllPages(); |
| 435 EXPECT_EQ(1U, all_pages().size()); | 435 EXPECT_EQ(1U, all_pages().size()); |
| 436 EXPECT_EQ(kTestPageUrlOther, all_pages()[0].url); | 436 EXPECT_EQ(kTestPageUrlOther, all_pages()[0].url); |
| 437 } | 437 } |
| 438 | 438 |
| 439 // Simulates an error (disconnection) during the load of a page. Should end up | 439 // Simulates an error (disconnection) during the load of a page. Should end up |
| 440 // with no offline pages. | 440 // with no offline pages. |
| 441 TEST_F(RecentTabHelperTest, NoCaptureOnErrorPage) { | 441 TEST_F(RecentTabHelperTest, NoCaptureOnErrorPage) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 GetAllPages(); | 475 GetAllPages(); |
| 476 EXPECT_EQ(1U, all_pages().size()); | 476 EXPECT_EQ(1U, all_pages().size()); |
| 477 const OfflinePageItem& page = all_pages()[0]; | 477 const OfflinePageItem& page = all_pages()[0]; |
| 478 EXPECT_EQ(kTestPageUrl, page.url); | 478 EXPECT_EQ(kTestPageUrl, page.url); |
| 479 EXPECT_EQ("download", page.client_id.name_space); | 479 EXPECT_EQ("download", page.client_id.name_space); |
| 480 EXPECT_EQ("id1", page.client_id.id); | 480 EXPECT_EQ("id1", page.client_id.id); |
| 481 EXPECT_EQ(153l, page.offline_id); | 481 EXPECT_EQ(153l, page.offline_id); |
| 482 } | 482 } |
| 483 | 483 |
| 484 } // namespace offline_pages | 484 } // namespace offline_pages |
| OLD | NEW |