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