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

Unified Diff: components/offline_pages/snapshot_controller_unittest.cc

Issue 2380093002: [Offline Pages] SnapshotController support for delay after onLoadCompleted and also parameterized c… (Closed)
Patch Set: Fixed a comment Created 4 years, 2 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
« no previous file with comments | « components/offline_pages/snapshot_controller.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/offline_pages/snapshot_controller_unittest.cc
diff --git a/components/offline_pages/snapshot_controller_unittest.cc b/components/offline_pages/snapshot_controller_unittest.cc
index 08ddbdd87d801632a24eb1d70a1479ca043ea776..df561bc3f6b74bbbc12d379752eb9d03b2b9a3a9 100644
--- a/components/offline_pages/snapshot_controller_unittest.cc
+++ b/components/offline_pages/snapshot_controller_unittest.cc
@@ -77,10 +77,12 @@ void SnapshotControllerTest::FastForwardBy(base::TimeDelta delta) {
}
TEST_F(SnapshotControllerTest, OnLoad) {
- // Onload should make snapshot right away.
- EXPECT_EQ(0, snapshot_count());
+ // Onload should make snapshot after its delay.
controller()->DocumentOnLoadCompletedInMainFrame();
PumpLoop();
+ EXPECT_EQ(0, snapshot_count());
+ FastForwardBy(base::TimeDelta::FromMilliseconds(
+ controller()->GetDelayAfterDocumentOnLoadCompletedForTest()));
EXPECT_EQ(1, snapshot_count());
}
@@ -96,17 +98,22 @@ TEST_F(SnapshotControllerTest, OnDocumentAvailable) {
}
TEST_F(SnapshotControllerTest, OnLoadSnapshotIsTheLastOne) {
+ // This test assumes DocumentAvailable delay is longer than OnLoadCompleted.
+ EXPECT_GT(controller()->GetDelayAfterDocumentAvailableForTest(),
+ controller()->GetDelayAfterDocumentOnLoadCompletedForTest());
// OnDOM should make snapshot after a delay.
controller()->DocumentAvailableInMainFrame();
PumpLoop();
EXPECT_EQ(0, snapshot_count());
- // This should start snapshot immediately.
controller()->DocumentOnLoadCompletedInMainFrame();
+ // Advance time to OnLoadCompleted delay to trigger snapshot.
+ FastForwardBy(base::TimeDelta::FromMilliseconds(
+ controller()->GetDelayAfterDocumentOnLoadCompletedForTest()));
EXPECT_EQ(1, snapshot_count());
// Report that snapshot is completed.
controller()->PendingSnapshotCompleted();
// Even though previous snapshot is completed, new one should not start
- // when this delay expires.
+ // when this DocumentAvailable delay expires.
FastForwardBy(base::TimeDelta::FromMilliseconds(
controller()->GetDelayAfterDocumentAvailableForTest()));
EXPECT_EQ(1, snapshot_count());
@@ -122,8 +129,10 @@ TEST_F(SnapshotControllerTest, OnLoadSnapshotAfterLongDelay) {
EXPECT_EQ(1, snapshot_count());
// Report that snapshot is completed.
controller()->PendingSnapshotCompleted();
- // This should start snapshot immediately.
+ // OnLoad should make 2nd snapshot after its delay.
controller()->DocumentOnLoadCompletedInMainFrame();
+ FastForwardBy(base::TimeDelta::FromMilliseconds(
+ controller()->GetDelayAfterDocumentOnLoadCompletedForTest()));
EXPECT_EQ(2, snapshot_count());
}
@@ -151,6 +160,8 @@ TEST_F(SnapshotControllerTest, ClientReset) {
// No snapshot since session was reset.
EXPECT_EQ(0, snapshot_count());
controller()->DocumentOnLoadCompletedInMainFrame();
+ FastForwardBy(base::TimeDelta::FromMilliseconds(
+ controller()->GetDelayAfterDocumentOnLoadCompletedForTest()));
EXPECT_EQ(1, snapshot_count());
controller()->Reset();
@@ -165,6 +176,8 @@ TEST_F(SnapshotControllerTest, ClientReset) {
// as done later. That reporting should have no effect nor crash.
TEST_F(SnapshotControllerTest, ClientResetWhileSnapshotting) {
controller()->DocumentOnLoadCompletedInMainFrame();
+ FastForwardBy(base::TimeDelta::FromMilliseconds(
+ controller()->GetDelayAfterDocumentOnLoadCompletedForTest()));
EXPECT_EQ(1, snapshot_count());
// This normally happens when navigation starts.
controller()->Reset();
« no previous file with comments | « components/offline_pages/snapshot_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698