Commit ae0d959a authored by Collin Baker's avatar Collin Baker Committed by Commit Bot

Invalidate thumbnail when a tab navigates to a new page

This behavior broke in a recent change, causing stale thumbnails and a
DCHECK in enabled builds.

Fixed: 1137330
Bug: 1136247
Change-Id: I70bee4d25e2c0693bcf55fe95dc2744dfb354456
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2464785Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Commit-Queue: Collin Baker <collinbaker@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816305}
parent fd81834d
...@@ -54,6 +54,15 @@ void ThumbnailCaptureDriver::SetCapturePermittedByScheduler(bool scheduled) { ...@@ -54,6 +54,15 @@ void ThumbnailCaptureDriver::SetCapturePermittedByScheduler(bool scheduled) {
} }
void ThumbnailCaptureDriver::UpdateCaptureState() { void ThumbnailCaptureDriver::UpdateCaptureState() {
// If there was a final thumbnail but the page has changed, get set up
// for a new capture.
if (page_readiness_ < PageReadiness::kReadyForFinalCapture &&
capture_state_ == CaptureState::kHaveFinalCapture) {
client_->StopCapture();
capture_state_ = CaptureState::kNoCapture;
}
// If de-scheduled, stop any ongoing capture.
if (!scheduled_) { if (!scheduled_) {
client_->StopCapture(); client_->StopCapture();
......
...@@ -526,3 +526,58 @@ TEST_F(ThumbnailCaptureDriverTest, DoesNotReCaptureAfterFinalThumbnail) { ...@@ -526,3 +526,58 @@ TEST_F(ThumbnailCaptureDriverTest, DoesNotReCaptureAfterFinalThumbnail) {
EXPECT_EQ(scheduler_.priority(), EXPECT_EQ(scheduler_.priority(),
ThumbnailScheduler::TabCapturePriority::kNone); ThumbnailScheduler::TabCapturePriority::kNone);
} }
// Going from kReadyForFinalCapture to a lower readiness should always
// invalidate the current thumbnail. Capture should restart from
// scratch. Regression test for https://crbug.com/1137330
TEST_F(ThumbnailCaptureDriverTest, InvalidatesThumbnailOnReadinessDecrease) {
{
InSequence s;
EXPECT_CALL(mock_client_, StopCapture()).Times(AnyNumber());
EXPECT_CALL(mock_client_, RequestCapture());
EXPECT_CALL(mock_client_, StartCapture());
EXPECT_CALL(mock_client_, StopCapture()).Times(AnyNumber());
EXPECT_CALL(mock_client_, RequestCapture());
EXPECT_CALL(mock_client_, StartCapture());
}
capture_driver_.UpdateThumbnailVisibility(true);
capture_driver_.UpdatePageVisibility(false);
capture_driver_.UpdatePageReadiness(
ThumbnailReadinessTracker::Readiness::kNotReady);
capture_driver_.UpdatePageReadiness(
ThumbnailReadinessTracker::Readiness::kReadyForInitialCapture);
capture_driver_.SetCapturePermittedByScheduler(true);
capture_driver_.SetCanCapture(true);
capture_driver_.UpdatePageReadiness(
ThumbnailReadinessTracker::Readiness::kReadyForFinalCapture);
EXPECT_EQ(scheduler_.priority(),
ThumbnailScheduler::TabCapturePriority::kHigh);
capture_driver_.SetCapturePermittedByScheduler(true);
capture_driver_.GotFrame();
task_environment_.FastForwardBy(ThumbnailCaptureDriver::kCooldownDelay);
EXPECT_EQ(scheduler_.priority(),
ThumbnailScheduler::TabCapturePriority::kNone);
// This should result in the thumbnail being invalidated. Subsequent
// loading should trigger capture again.
capture_driver_.UpdatePageReadiness(
ThumbnailReadinessTracker::Readiness::kNotReady);
EXPECT_EQ(scheduler_.priority(),
ThumbnailScheduler::TabCapturePriority::kNone);
capture_driver_.UpdatePageReadiness(
ThumbnailReadinessTracker::Readiness::kReadyForInitialCapture);
EXPECT_EQ(scheduler_.priority(),
ThumbnailScheduler::TabCapturePriority::kLow);
capture_driver_.SetCapturePermittedByScheduler(true);
capture_driver_.SetCanCapture(true);
capture_driver_.UpdatePageReadiness(
ThumbnailReadinessTracker::Readiness::kReadyForFinalCapture);
EXPECT_EQ(scheduler_.priority(),
ThumbnailScheduler::TabCapturePriority::kHigh);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment