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

Unified Diff: blimp/engine/renderer/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/scheduler_unittest.cc
diff --git a/blimp/engine/renderer/scheduler_unittest.cc b/blimp/engine/renderer/scheduler_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..30ecb0e6696966fcbaac0d721e1745bded52bc58
--- /dev/null
+++ b/blimp/engine/renderer/scheduler_unittest.cc
@@ -0,0 +1,83 @@
+// 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/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 SchedulerForTesting : public Scheduler {
+ public:
+ explicit SchedulerForTesting(SchedulerClient* client)
+ // Use a zero time delta to let tests run main frames back-to-back.
+ : Scheduler(base::TimeDelta::FromSeconds(0),
+ base::ThreadTaskRunnerHandle::Get(),
+ client) {}
+ ~SchedulerForTesting() override = default;
+};
+
+class SchedulerTest : public testing::Test, public SchedulerClient {
+ public:
+ SchedulerTest() : scheduler_(this) {}
+ ~SchedulerTest() override {}
+
+ // SchedulerClient implementation.
+ void StartFrameUpdate() override {
+ num_main_frames_++;
+ if (send_client_update_during_main_frame_) {
+ scheduler_.DidSendFrameUpdateToClient();
+ send_client_update_during_main_frame_ = false;
+ }
+ }
+
+ protected:
+ base::MessageLoop loop_;
+ SchedulerForTesting scheduler_;
+ int num_main_frames_ = 0;
+
+ bool send_client_update_during_main_frame_ = false;
+};
+
+TEST_F(SchedulerTest, FirstMainFrameRequest) {
+ // The request for the first main frame should be responded to right away.
+ scheduler_.SetNeedsFrameUpdate();
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(1, num_main_frames_);
+}
+
+TEST_F(SchedulerTest, MultipleMainFrameRequestsResultInSingleFrame) {
+ // Multiple main frame requests result in a single callback to the client.
+ scheduler_.SetNeedsFrameUpdate();
+ scheduler_.SetNeedsFrameUpdate();
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(1, num_main_frames_);
+}
+
+TEST_F(SchedulerTest, 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_.SetNeedsFrameUpdate();
+ send_client_update_during_main_frame_ = true;
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(1, num_main_frames_);
+
+ // Request a frame and ensure that the client is not asked to start it.
+ scheduler_.SetNeedsFrameUpdate();
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(1, num_main_frames_);
+
+ // Now we have an ack from the client. This should start another frame.
+ scheduler_.DidReceiveFrameUpdateAck();
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(2, num_main_frames_);
+}
+
+} // namespace
+} // namespace engine
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698