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

Side by Side Diff: chrome/browser/android/offline_pages/background_loader_offliner_unittest.cc

Issue 2835253002: Treat already existing saved pages as success. (Closed)
Patch Set: Created 3 years, 7 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
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 "chrome/browser/android/offline_pages/background_loader_offliner.h" 5 #include "chrome/browser/android/offline_pages/background_loader_offliner.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/test/histogram_tester.h" 9 #include "base/test/histogram_tester.h"
10 #include "base/test/scoped_mock_time_message_loop_task_runner.h" 10 #include "base/test/scoped_mock_time_message_loop_task_runner.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 } 59 }
60 60
61 void CompleteSavingAsSuccess() { 61 void CompleteSavingAsSuccess() {
62 DCHECK(mock_saving_); 62 DCHECK(mock_saving_);
63 mock_saving_ = false; 63 mock_saving_ = false;
64 base::ThreadTaskRunnerHandle::Get()->PostTask( 64 base::ThreadTaskRunnerHandle::Get()->PostTask(
65 FROM_HERE, 65 FROM_HERE,
66 base::Bind(save_page_callback_, SavePageResult::SUCCESS, 123456)); 66 base::Bind(save_page_callback_, SavePageResult::SUCCESS, 123456));
67 } 67 }
68 68
69 void CompleteSavingAsAlreadyExists() {
70 DCHECK(mock_saving_);
71 mock_saving_ = false;
72 base::ThreadTaskRunnerHandle::Get()->PostTask(
73 FROM_HERE, base::Bind(save_page_callback_,
74 SavePageResult::ALREADY_EXISTS, 123456));
75 }
76
69 bool mock_saving() const { return mock_saving_; } 77 bool mock_saving() const { return mock_saving_; }
70 78
71 private: 79 private:
72 bool mock_saving_; 80 bool mock_saving_;
73 SavePageCallback save_page_callback_; 81 SavePageCallback save_page_callback_;
74 82
75 DISALLOW_COPY_AND_ASSIGN(MockOfflinePageModel); 83 DISALLOW_COPY_AND_ASSIGN(MockOfflinePageModel);
76 }; 84 };
77 85
78 } // namespace 86 } // namespace
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 PumpLoop(); 374 PumpLoop();
367 model()->CompleteSavingAsSuccess(); 375 model()->CompleteSavingAsSuccess();
368 PumpLoop(); 376 PumpLoop();
369 377
370 EXPECT_TRUE(completion_callback_called()); 378 EXPECT_TRUE(completion_callback_called());
371 EXPECT_EQ(Offliner::RequestStatus::SAVED, request_status()); 379 EXPECT_EQ(Offliner::RequestStatus::SAVED, request_status());
372 EXPECT_FALSE(offliner()->is_loading()); 380 EXPECT_FALSE(offliner()->is_loading());
373 EXPECT_FALSE(SaveInProgress()); 381 EXPECT_FALSE(SaveInProgress());
374 } 382 }
375 383
384 TEST_F(BackgroundLoaderOfflinerTest, LoadAndSaveAlreadyExists) {
385 base::Time creation_time = base::Time::Now();
386 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time,
387 kUserRequested);
388 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(),
389 progress_callback()));
390
391 CompleteLoading();
392 PumpLoop();
393 model()->CompleteSavingAsAlreadyExists();
394 PumpLoop();
395
396 EXPECT_TRUE(completion_callback_called());
397 EXPECT_EQ(Offliner::RequestStatus::SAVED, request_status());
398 EXPECT_FALSE(offliner()->is_loading());
399 EXPECT_FALSE(SaveInProgress());
400 }
401
376 TEST_F(BackgroundLoaderOfflinerTest, FailsOnInvalidURL) { 402 TEST_F(BackgroundLoaderOfflinerTest, FailsOnInvalidURL) {
377 base::Time creation_time = base::Time::Now(); 403 base::Time creation_time = base::Time::Now();
378 SavePageRequest request(kRequestId, kFileUrl, kClientId, creation_time, 404 SavePageRequest request(kRequestId, kFileUrl, kClientId, creation_time,
379 kUserRequested); 405 kUserRequested);
380 EXPECT_FALSE(offliner()->LoadAndSave(request, completion_callback(), 406 EXPECT_FALSE(offliner()->LoadAndSave(request, completion_callback(),
381 progress_callback())); 407 progress_callback()));
382 } 408 }
383 409
384 TEST_F(BackgroundLoaderOfflinerTest, ReturnsOnRenderCrash) { 410 TEST_F(BackgroundLoaderOfflinerTest, ReturnsOnRenderCrash) {
385 base::Time creation_time = base::Time::Now(); 411 base::Time creation_time = base::Time::Now();
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(), 580 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(),
555 progress_callback())); 581 progress_callback()));
556 // Sets lowbar. 582 // Sets lowbar.
557 offliner()->DocumentAvailableInMainFrame(); 583 offliner()->DocumentAvailableInMainFrame();
558 // Timeout 584 // Timeout
559 EXPECT_FALSE(offliner()->HandleTimeout(request)); 585 EXPECT_FALSE(offliner()->HandleTimeout(request));
560 EXPECT_FALSE(SaveInProgress()); 586 EXPECT_FALSE(SaveInProgress());
561 } 587 }
562 588
563 } // namespace offline_pages 589 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698