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

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: Fix build error Created 3 years, 8 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_feature_list.h" 10 #include "base/test/scoped_feature_list.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 62 }
63 63
64 void CompleteSavingAsSuccess() { 64 void CompleteSavingAsSuccess() {
65 DCHECK(mock_saving_); 65 DCHECK(mock_saving_);
66 mock_saving_ = false; 66 mock_saving_ = false;
67 base::ThreadTaskRunnerHandle::Get()->PostTask( 67 base::ThreadTaskRunnerHandle::Get()->PostTask(
68 FROM_HERE, 68 FROM_HERE,
69 base::Bind(save_page_callback_, SavePageResult::SUCCESS, 123456)); 69 base::Bind(save_page_callback_, SavePageResult::SUCCESS, 123456));
70 } 70 }
71 71
72 void CompleteSavingAsAlreadyExists() {
73 DCHECK(mock_saving_);
74 mock_saving_ = false;
75 base::ThreadTaskRunnerHandle::Get()->PostTask(
76 FROM_HERE, base::Bind(save_page_callback_,
77 SavePageResult::ALREADY_EXISTS, 123456));
78 }
79
72 bool mock_saving() const { return mock_saving_; } 80 bool mock_saving() const { return mock_saving_; }
73 81
74 private: 82 private:
75 bool mock_saving_; 83 bool mock_saving_;
76 SavePageCallback save_page_callback_; 84 SavePageCallback save_page_callback_;
77 85
78 DISALLOW_COPY_AND_ASSIGN(MockOfflinePageModel); 86 DISALLOW_COPY_AND_ASSIGN(MockOfflinePageModel);
79 }; 87 };
80 88
81 } // namespace 89 } // namespace
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 PumpLoop(); 377 PumpLoop();
370 model()->CompleteSavingAsSuccess(); 378 model()->CompleteSavingAsSuccess();
371 PumpLoop(); 379 PumpLoop();
372 380
373 EXPECT_TRUE(completion_callback_called()); 381 EXPECT_TRUE(completion_callback_called());
374 EXPECT_EQ(Offliner::RequestStatus::SAVED, request_status()); 382 EXPECT_EQ(Offliner::RequestStatus::SAVED, request_status());
375 EXPECT_FALSE(offliner()->is_loading()); 383 EXPECT_FALSE(offliner()->is_loading());
376 EXPECT_FALSE(SaveInProgress()); 384 EXPECT_FALSE(SaveInProgress());
377 } 385 }
378 386
387 TEST_F(BackgroundLoaderOfflinerTest, LoadAndSaveAlreadyExists) {
388 base::Time creation_time = base::Time::Now();
389 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time,
390 kUserRequested);
391 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(),
392 progress_callback()));
393
394 CompleteLoading();
395 PumpLoop();
396 model()->CompleteSavingAsAlreadyExists();
397 PumpLoop();
398
399 EXPECT_TRUE(completion_callback_called());
400 EXPECT_EQ(Offliner::RequestStatus::SAVED, request_status());
401 EXPECT_FALSE(offliner()->is_loading());
402 EXPECT_FALSE(SaveInProgress());
403 }
404
379 TEST_F(BackgroundLoaderOfflinerTest, FailsOnInvalidURL) { 405 TEST_F(BackgroundLoaderOfflinerTest, FailsOnInvalidURL) {
380 base::Time creation_time = base::Time::Now(); 406 base::Time creation_time = base::Time::Now();
381 SavePageRequest request(kRequestId, kFileUrl, kClientId, creation_time, 407 SavePageRequest request(kRequestId, kFileUrl, kClientId, creation_time,
382 kUserRequested); 408 kUserRequested);
383 EXPECT_FALSE(offliner()->LoadAndSave(request, completion_callback(), 409 EXPECT_FALSE(offliner()->LoadAndSave(request, completion_callback(),
384 progress_callback())); 410 progress_callback()));
385 } 411 }
386 412
387 TEST_F(BackgroundLoaderOfflinerTest, ReturnsOnRenderCrash) { 413 TEST_F(BackgroundLoaderOfflinerTest, ReturnsOnRenderCrash) {
388 base::Time creation_time = base::Time::Now(); 414 base::Time creation_time = base::Time::Now();
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 CompleteLoading(); 624 CompleteLoading();
599 PumpLoop(); 625 PumpLoop();
600 626
601 // One extra part should be added if the flag is on. 627 // One extra part should be added if the flag is on.
602 content::MHTMLExtraParts* extra_parts = 628 content::MHTMLExtraParts* extra_parts =
603 content::MHTMLExtraParts::FromWebContents(offliner()->web_contents()); 629 content::MHTMLExtraParts::FromWebContents(offliner()->web_contents());
604 EXPECT_EQ(extra_parts->size(), 1); 630 EXPECT_EQ(extra_parts->size(), 1);
605 } 631 }
606 632
607 } // namespace offline_pages 633 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698