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

Unified Diff: blimp/engine/renderer/frame_scheduler_unittest.cc

Issue 2413063002: content/blimp: Set up hooks for enabling LTHRemote in the renderer. (Closed)
Patch Set: Rebase 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
Index: blimp/engine/renderer/frame_scheduler_unittest.cc
diff --git a/blimp/engine/renderer/frame_scheduler_unittest.cc b/blimp/engine/renderer/frame_scheduler_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b2d2dc8d3f30d9362befd28ecc03c1d18da5498b
--- /dev/null
+++ b/blimp/engine/renderer/frame_scheduler_unittest.cc
@@ -0,0 +1,82 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <blimp/engine/renderer/frame_scheduler.h>
+#include "base/run_loop.h"
+#include "base/threading/thread_task_runner_handle.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blimp {
+namespace engine {
+namespace {
+
+class FrameSchedulerForTesting : public FrameScheduler {
+ public:
+ explicit FrameSchedulerForTesting(FrameSchedulerClient* client)
+ // Use a zero time delta to let tests run main frames back-to-back.
+ : FrameScheduler(base::TimeDelta::FromSeconds(0),
+ base::ThreadTaskRunnerHandle::Get(),
+ client) {}
+ ~FrameSchedulerForTesting() override = default;
+};
+
+class FrameSchedulerTest : public testing::Test, public FrameSchedulerClient {
+ public:
+ FrameSchedulerTest() : scheduler_(this) {}
+ ~FrameSchedulerTest() override {}
+
+ // SchedulerClient implementation.
+ void StartFrameUpdate() override {
+ num_frames_++;
+ if (send_client_update_during_frame_) {
+ scheduler_.DidSendFrameUpdateToClient();
+ send_client_update_during_frame_ = false;
+ }
+ }
+
+ protected:
+ base::MessageLoop loop_;
+ FrameSchedulerForTesting scheduler_;
+ int num_frames_ = 0;
+
+ bool send_client_update_during_frame_ = false;
+};
+
+TEST_F(FrameSchedulerTest, FirstMainFrameRequest) {
+ // The request for the first main frame should be responded to right away.
+ scheduler_.ScheduleFrameUpdate();
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(1, num_frames_);
+}
+
+TEST_F(FrameSchedulerTest, MultipleMainFrameRequestsResultInSingleFrame) {
+ // Multiple main frame requests result in a single callback to the client.
+ scheduler_.ScheduleFrameUpdate();
+ scheduler_.ScheduleFrameUpdate();
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(1, num_frames_);
+}
+
+TEST_F(FrameSchedulerTest, MainFrameBlockedOnAckFromClient) {
+ // Request a main frame, start it and send an update to the client. The second
+ // frame should remain blocked till an ack is received.
+ scheduler_.ScheduleFrameUpdate();
+ send_client_update_during_frame_ = true;
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(1, num_frames_);
+
+ // Request a frame and ensure that the client is not asked to start it.
+ scheduler_.ScheduleFrameUpdate();
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(1, num_frames_);
+
+ // Now we have an ack from the client. This should start another frame.
+ scheduler_.DidReceiveFrameUpdateAck();
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(2, num_frames_);
+}
+
+} // namespace
+} // namespace engine
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698