Commit 8de4733a authored by Christopher Grant's avatar Christopher Grant Committed by Commit Bot

VR: Make unit tests fast again

Change RunFor() to execute a near-future frame, and a frame at the final time
if needed.  If we ever actually need all the intermedate frames, the tests that
need those frames should simulate them.  Our UI should generally never need
this.

BUG=
R=vollick

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_vr;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: Idf87a0fd524b6a6dcce06382cab96670a4f1e2dd
Reviewed-on: https://chromium-review.googlesource.com/986619Reviewed-by: default avatarIan Vollick <vollick@chromium.org>
Commit-Queue: Christopher Grant <cjgrant@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547713}
parent 51f305bf
...@@ -225,13 +225,17 @@ bool UiTest::RunFor(base::TimeDelta delta) { ...@@ -225,13 +225,17 @@ bool UiTest::RunFor(base::TimeDelta delta) {
base::TimeTicks target_time = current_time_ + delta; base::TimeTicks target_time = current_time_ + delta;
base::TimeDelta frame_time = base::TimeDelta::FromSecondsD(1.0 / 60.0); base::TimeDelta frame_time = base::TimeDelta::FromSecondsD(1.0 / 60.0);
bool changed = false; bool changed = false;
for (; current_time_ < target_time; current_time_ += frame_time) {
if (scene_->OnBeginFrame(current_time_, kStartHeadPose)) // Run a frame in the near future to trigger new state changes.
changed = true; current_time_ += frame_time;
changed |= scene_->OnBeginFrame(current_time_, kStartHeadPose);
// If needed, skip ahead and run another frame at the target time.
if (current_time_ < target_time) {
current_time_ = target_time;
changed |= scene_->OnBeginFrame(current_time_, kStartHeadPose);
} }
current_time_ = target_time;
if (scene_->OnBeginFrame(current_time_, kStartHeadPose))
changed = true;
return changed; return changed;
} }
...@@ -239,7 +243,7 @@ bool UiTest::OnBeginFrame() const { ...@@ -239,7 +243,7 @@ bool UiTest::OnBeginFrame() const {
return scene_->OnBeginFrame(current_time_, kStartHeadPose); return scene_->OnBeginFrame(current_time_, kStartHeadPose);
} }
bool UiTest::OnBeginFrame(base::TimeDelta delta) { bool UiTest::OnDelayedFrame(base::TimeDelta delta) {
current_time_ += delta; current_time_ += delta;
return OnBeginFrame(); return OnBeginFrame();
} }
......
...@@ -89,8 +89,10 @@ class UiTest : public testing::Test { ...@@ -89,8 +89,10 @@ class UiTest : public testing::Test {
// Check if element is using correct opacity in Render recursively. // Check if element is using correct opacity in Render recursively.
void CheckRendererOpacityRecursive(UiElement* element); void CheckRendererOpacityRecursive(UiElement* element);
// Advances current_time_ by delta. This is done in frame increments and // Advances current_time_ by delta. This is done by running the next frame,
// UiScene::OnBeginFrame is called at each increment. // then jumping time ahead to the final time. Generally, the UI should not
// require all intermediate frames to be called. Tests that require this
// should simulate the required intermediate frames.
bool RunFor(base::TimeDelta delta); bool RunFor(base::TimeDelta delta);
// A wrapper to call scene_->OnBeginFrame. // A wrapper to call scene_->OnBeginFrame.
...@@ -98,7 +100,8 @@ class UiTest : public testing::Test { ...@@ -98,7 +100,8 @@ class UiTest : public testing::Test {
// Also wraps scene_->OnBeginFrame, but advances the current time by the given // Also wraps scene_->OnBeginFrame, but advances the current time by the given
// delta before making the call. This is useful for simulating slow frames. // delta before making the call. This is useful for simulating slow frames.
bool OnBeginFrame(base::TimeDelta delta); // Generally, don't use this to simulate delay - use RunFor() instead.
bool OnDelayedFrame(base::TimeDelta delta);
void GetBackgroundColor(SkColor* background_color) const; void GetBackgroundColor(SkColor* background_color) const;
......
...@@ -1156,21 +1156,21 @@ TEST_F(UiTest, TransientToastsWithDelayedFirstFrame) { ...@@ -1156,21 +1156,21 @@ TEST_F(UiTest, TransientToastsWithDelayedFirstFrame) {
// Enter WebVR with autopresentation. // Enter WebVR with autopresentation.
ui_->SetWebVrMode(true); ui_->SetWebVrMode(true);
ui_->SetCapturingState(CapturingStateModel()); ui_->SetCapturingState(CapturingStateModel());
OnBeginFrame(MsToDelta(1000 * kSplashScreenMinDurationSeconds)); OnDelayedFrame(MsToDelta(1000 * kSplashScreenMinDurationSeconds));
EXPECT_TRUE(IsVisible(kSplashScreenText)); EXPECT_TRUE(IsVisible(kSplashScreenText));
EXPECT_TRUE(IsVisible(kWebVrBackground)); EXPECT_TRUE(IsVisible(kWebVrBackground));
EXPECT_FALSE(IsVisible(kWebVrUrlToast)); EXPECT_FALSE(IsVisible(kWebVrUrlToast));
OnBeginFrame(MsToDelta(2000)); OnDelayedFrame(MsToDelta(2000));
ui_->OnWebVrTimeoutImminent(); ui_->OnWebVrTimeoutImminent();
OnBeginFrame(MsToDelta(3000)); OnDelayedFrame(MsToDelta(3000));
ui_->OnWebVrTimedOut(); ui_->OnWebVrTimedOut();
// A while later, receive only one frame (possibly a splash screen). This will // A while later, receive only one frame (possibly a splash screen). This will
// trigger indicators to start fading in, but they won't actually be visible // trigger indicators to start fading in, but they won't actually be visible
// on the first frame. The transient element should know that it's not // on the first frame. The transient element should know that it's not
// visible, and not start its timeout. // visible, and not start its timeout.
OnBeginFrame(MsToDelta(5000)); OnDelayedFrame(MsToDelta(5000));
ui_->OnWebVrFrameAvailable(); ui_->OnWebVrFrameAvailable();
EXPECT_FALSE(IsVisible(kSplashScreenText)); EXPECT_FALSE(IsVisible(kSplashScreenText));
EXPECT_FALSE(IsVisible(kWebVrBackground)); EXPECT_FALSE(IsVisible(kWebVrBackground));
...@@ -1179,11 +1179,11 @@ TEST_F(UiTest, TransientToastsWithDelayedFirstFrame) { ...@@ -1179,11 +1179,11 @@ TEST_F(UiTest, TransientToastsWithDelayedFirstFrame) {
// If we advance far beyond the timeout for our first frame and our logic was // If we advance far beyond the timeout for our first frame and our logic was
// naive, we would start to hide the transient element. But, because the // naive, we would start to hide the transient element. But, because the
// transient element was never actually visible, it should still be showing. // transient element was never actually visible, it should still be showing.
OnBeginFrame(MsToDelta(40000)); OnDelayedFrame(MsToDelta(40000));
EXPECT_TRUE(IsVisible(kWebVrUrlToast)); EXPECT_TRUE(IsVisible(kWebVrUrlToast));
// Now that it's been seen, it should transiently fade. // Now that it's been seen, it should transiently fade.
OnBeginFrame(MsToDelta(10000)); OnDelayedFrame(MsToDelta(10000));
EXPECT_FALSE(IsVisible(kWebVrUrlToast)); EXPECT_FALSE(IsVisible(kWebVrUrlToast));
} }
......
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