OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <blimp/engine/renderer/frame_scheduler.h> |
| 6 #include "base/run_loop.h" |
| 7 #include "base/threading/thread_task_runner_handle.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 namespace blimp { |
| 11 namespace engine { |
| 12 namespace { |
| 13 |
| 14 class FrameSchedulerForTesting : public FrameScheduler { |
| 15 public: |
| 16 explicit FrameSchedulerForTesting(FrameSchedulerClient* client) |
| 17 // Use a zero time delta to let tests run main frames back-to-back. |
| 18 : FrameScheduler(base::TimeDelta::FromSeconds(0), |
| 19 base::ThreadTaskRunnerHandle::Get(), |
| 20 client) {} |
| 21 ~FrameSchedulerForTesting() override = default; |
| 22 }; |
| 23 |
| 24 class FrameSchedulerTest : public testing::Test, public FrameSchedulerClient { |
| 25 public: |
| 26 FrameSchedulerTest() : scheduler_(this) {} |
| 27 ~FrameSchedulerTest() override {} |
| 28 |
| 29 // FrameSchedulerClient implementation. |
| 30 void StartFrameUpdate() override { |
| 31 num_frames_++; |
| 32 if (send_client_update_during_frame_) { |
| 33 scheduler_.DidSendFrameUpdateToClient(); |
| 34 send_client_update_during_frame_ = false; |
| 35 } |
| 36 } |
| 37 |
| 38 protected: |
| 39 base::MessageLoop loop_; |
| 40 FrameSchedulerForTesting scheduler_; |
| 41 int num_frames_ = 0; |
| 42 |
| 43 bool send_client_update_during_frame_ = false; |
| 44 }; |
| 45 |
| 46 TEST_F(FrameSchedulerTest, FirstMainFrameRequest) { |
| 47 // The request for the first main frame should be responded to right away. |
| 48 scheduler_.ScheduleFrameUpdate(); |
| 49 base::RunLoop().RunUntilIdle(); |
| 50 EXPECT_EQ(1, num_frames_); |
| 51 } |
| 52 |
| 53 TEST_F(FrameSchedulerTest, MultipleMainFrameRequestsResultInSingleFrame) { |
| 54 // Multiple main frame requests result in a single callback to the client. |
| 55 scheduler_.ScheduleFrameUpdate(); |
| 56 scheduler_.ScheduleFrameUpdate(); |
| 57 base::RunLoop().RunUntilIdle(); |
| 58 EXPECT_EQ(1, num_frames_); |
| 59 } |
| 60 |
| 61 TEST_F(FrameSchedulerTest, MainFrameBlockedOnAckFromClient) { |
| 62 // Request a main frame, start it and send an update to the client. The second |
| 63 // frame should remain blocked till an ack is received. |
| 64 scheduler_.ScheduleFrameUpdate(); |
| 65 send_client_update_during_frame_ = true; |
| 66 base::RunLoop().RunUntilIdle(); |
| 67 EXPECT_EQ(1, num_frames_); |
| 68 |
| 69 // Request a frame and ensure that the client is not asked to start it. |
| 70 scheduler_.ScheduleFrameUpdate(); |
| 71 base::RunLoop().RunUntilIdle(); |
| 72 EXPECT_EQ(1, num_frames_); |
| 73 |
| 74 // Now we have an ack from the client. This should start another frame. |
| 75 scheduler_.DidReceiveFrameUpdateAck(); |
| 76 base::RunLoop().RunUntilIdle(); |
| 77 EXPECT_EQ(2, num_frames_); |
| 78 } |
| 79 |
| 80 } // namespace |
| 81 } // namespace engine |
| 82 } // namespace blimp |
OLD | NEW |