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

Unified Diff: chrome/browser/android/offline_pages/background_loader_offliner_unittest.cc

Issue 2744553005: [Offline Pages] Turn Offliner::Cancel into an async operation to resolve conflicting assumptions be… (Closed)
Patch Set: Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/offline_pages/background_loader_offliner_unittest.cc
diff --git a/chrome/browser/android/offline_pages/background_loader_offliner_unittest.cc b/chrome/browser/android/offline_pages/background_loader_offliner_unittest.cc
index 2efe125e4fbd5718abd4a73f062e6bf39f763906..47f6b4011a825c0ed68231edfcbdeb3f27df88ac 100644
--- a/chrome/browser/android/offline_pages/background_loader_offliner_unittest.cc
+++ b/chrome/browser/android/offline_pages/background_loader_offliner_unittest.cc
@@ -134,9 +134,14 @@ class BackgroundLoaderOfflinerTest : public testing::Test {
return base::Bind(&BackgroundLoaderOfflinerTest::OnProgress,
base::Unretained(this));
}
+ Offliner::CancelCallback const cancel_callback() {
+ return base::Bind(&BackgroundLoaderOfflinerTest::OnCancel,
+ base::Unretained(this));
+ }
Profile* profile() { return &profile_; }
bool completion_callback_called() { return completion_callback_called_; }
Offliner::RequestStatus request_status() { return request_status_; }
+ bool cancel_callback_called() { return cancel_callback_called_; }
bool SaveInProgress() const { return model_->mock_saving(); }
MockOfflinePageModel* model() const { return model_; }
const base::HistogramTester& histograms() const { return histogram_tester_; }
@@ -153,11 +158,13 @@ class BackgroundLoaderOfflinerTest : public testing::Test {
void OnCompletion(const SavePageRequest& request,
Offliner::RequestStatus status);
void OnProgress(const SavePageRequest& request, int64_t bytes);
+ void OnCancel(int64_t offline_id);
content::TestBrowserThreadBundle thread_bundle_;
TestingProfile profile_;
std::unique_ptr<TestBackgroundLoaderOffliner> offliner_;
MockOfflinePageModel* model_;
bool completion_callback_called_;
+ bool cancel_callback_called_;
Offliner::RequestStatus request_status_;
base::HistogramTester histogram_tester_;
@@ -167,6 +174,7 @@ class BackgroundLoaderOfflinerTest : public testing::Test {
BackgroundLoaderOfflinerTest::BackgroundLoaderOfflinerTest()
: thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
completion_callback_called_(false),
+ cancel_callback_called_(false),
request_status_(Offliner::RequestStatus::UNKNOWN) {}
BackgroundLoaderOfflinerTest::~BackgroundLoaderOfflinerTest() {}
@@ -187,6 +195,10 @@ void BackgroundLoaderOfflinerTest::OnCompletion(
void BackgroundLoaderOfflinerTest::OnProgress(const SavePageRequest& request,
int64_t bytes) {}
+void BackgroundLoaderOfflinerTest::OnCancel(int64_t offline_id) {
+ DCHECK(!cancel_callback_called_);
+ cancel_callback_called_ = true;
+}
TEST_F(BackgroundLoaderOfflinerTest,
LoadAndSaveBlockThirdPartyCookiesForCustomTabs) {
@@ -262,7 +274,9 @@ TEST_F(BackgroundLoaderOfflinerTest, CancelWhenLoading) {
kUserRequested);
EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(),
progress_callback()));
- offliner()->Cancel();
+ offliner()->Cancel(cancel_callback());
+ PumpLoop();
+ EXPECT_TRUE(cancel_callback_called());
EXPECT_FALSE(offliner()->is_loading()); // Offliner reset.
}
@@ -274,11 +288,13 @@ TEST_F(BackgroundLoaderOfflinerTest, CancelWhenLoaded) {
progress_callback()));
CompleteLoading();
PumpLoop();
- offliner()->Cancel();
+ offliner()->Cancel(cancel_callback());
+ PumpLoop();
// Subsequent save callback cause no crash.
model()->CompleteSavingAsArchiveCreationFailed();
PumpLoop();
+ EXPECT_TRUE(cancel_callback_called());
EXPECT_FALSE(completion_callback_called());
EXPECT_FALSE(SaveInProgress());
EXPECT_FALSE(offliner()->is_loading()); // Offliner reset.

Powered by Google App Engine
This is Rietveld 408576698