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

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

Issue 2715433006: [Offline Pages] Turn Offliner::Cancel into an async operation to resolve conflicting assumptions (Closed)
Patch Set: Created 3 years, 10 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/prerendering_offliner_unittest.cc
diff --git a/chrome/browser/android/offline_pages/prerendering_offliner_unittest.cc b/chrome/browser/android/offline_pages/prerendering_offliner_unittest.cc
index b9a3f70ce48c1cfcdd025149306d2d4bb4e012d2..188a88a9a9c7907cdbc23e7d3458268b65a2c5d9 100644
--- a/chrome/browser/android/offline_pages/prerendering_offliner_unittest.cc
+++ b/chrome/browser/android/offline_pages/prerendering_offliner_unittest.cc
@@ -156,16 +156,22 @@ class PrerenderingOfflinerTest : public testing::Test {
return base::Bind(&PrerenderingOfflinerTest::OnCompletion,
base::Unretained(this));
}
+ Offliner::CancelCallback const cancel_callback() {
+ return base::Bind(&PrerenderingOfflinerTest::OnCancel,
+ base::Unretained(this));
+ }
bool SaveInProgress() const { return model_->mock_saving(); }
MockPrerenderingLoader* loader() { return loader_; }
MockOfflinePageModel* model() { return model_; }
bool completion_callback_called() { return completion_callback_called_; }
Offliner::RequestStatus request_status() { return request_status_; }
+ bool cancel_callback_called() { return cancel_callback_called_; }
private:
void OnCompletion(const SavePageRequest& request,
Offliner::RequestStatus status);
+ void OnCancel(int64_t offline_id);
content::TestBrowserThreadBundle thread_bundle_;
TestingProfile profile_;
@@ -174,6 +180,7 @@ class PrerenderingOfflinerTest : public testing::Test {
MockPrerenderingLoader* loader_;
MockOfflinePageModel* model_;
bool completion_callback_called_;
+ bool cancel_callback_called_;
Offliner::RequestStatus request_status_;
DISALLOW_COPY_AND_ASSIGN(PrerenderingOfflinerTest);
@@ -202,6 +209,11 @@ void PrerenderingOfflinerTest::OnCompletion(const SavePageRequest& request,
request_status_ = status;
}
+void PrerenderingOfflinerTest::OnCancel(int64_t offline_id) {
+ DCHECK(!cancel_callback_called_);
+ cancel_callback_called_ = true;
+}
+
TEST_F(PrerenderingOfflinerTest, LoadAndSaveBadUrl) {
base::Time creation_time = base::Time::Now();
SavePageRequest request(
@@ -266,7 +278,9 @@ TEST_F(PrerenderingOfflinerTest, CancelWhenLoading) {
EXPECT_TRUE(offliner()->LoadAndSave(request, callback()));
EXPECT_FALSE(loader()->IsIdle());
- offliner()->Cancel();
+ offliner()->Cancel(cancel_callback());
+ PumpLoop();
+ EXPECT_TRUE(cancel_callback_called());
EXPECT_TRUE(loader()->IsIdle());
}
@@ -284,9 +298,10 @@ TEST_F(PrerenderingOfflinerTest, CancelWhenLoaded) {
EXPECT_TRUE(loader()->IsLoaded());
EXPECT_TRUE(SaveInProgress());
- offliner()->Cancel();
+ offliner()->Cancel(cancel_callback());
PumpLoop();
EXPECT_FALSE(completion_callback_called());
+ EXPECT_TRUE(cancel_callback_called());
EXPECT_FALSE(loader()->IsLoaded());
// Note: save still in progress since it does not support canceling.
EXPECT_TRUE(SaveInProgress());

Powered by Google App Engine
This is Rietveld 408576698