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

Unified Diff: third_party/WebKit/Source/platform/scheduler/base/delayed_switch_unittest.cc

Issue 2383473002: [scheduler] Teach scheduler about audio state (Closed)
Patch Set: Created 4 years, 3 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: third_party/WebKit/Source/platform/scheduler/base/delayed_switch_unittest.cc
diff --git a/third_party/WebKit/Source/platform/scheduler/base/delayed_switch_unittest.cc b/third_party/WebKit/Source/platform/scheduler/base/delayed_switch_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f40f72429f09993412b83b39a1dd58e56ad6f6a5
--- /dev/null
+++ b/third_party/WebKit/Source/platform/scheduler/base/delayed_switch_unittest.cc
@@ -0,0 +1,106 @@
+// 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 "platform/scheduler/base/delayed_switch.h"
+
+#include "base/test/simple_test_tick_clock.h"
+#include "cc/test/ordered_simple_task_runner.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using testing::ElementsAre;
+
+namespace blink {
+namespace scheduler {
+
+class DelayedSwitchTest : public testing::Test {
+ public:
+ DelayedSwitchTest() {}
+ ~DelayedSwitchTest() override {}
+
+ void SetUp() override {
+ clock_.reset(new base::SimpleTestTickClock());
+ mock_task_runner_ = make_scoped_refptr(
+ new cc::OrderedSimpleTaskRunner(clock_.get(), true));
+ }
+
+ protected:
+ std::unique_ptr<base::SimpleTestTickClock> clock_;
+ scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_;
+
+ DISALLOW_COPY_AND_ASSIGN(DelayedSwitchTest);
+};
+
+namespace {
+
+void TestTask(std::vector<base::TimeTicks>* run_times,
+ base::SimpleTestTickClock* clock) {
+ run_times->push_back(clock->NowTicks());
+}
+
+};
+
+TEST_F(DelayedSwitchTest, TestDelayedSwitch) {
+ std::vector<base::TimeTicks> enable_run_times;
+ std::vector<base::TimeTicks> disable_run_times;
+
+ DelayedSwitch delayed_switch(
+ mock_task_runner_.get(),
+ base::TimeDelta::FromSeconds(1),
+ base::Bind(&TestTask, &enable_run_times, clock_.get()),
+ base::Bind(&TestTask, &disable_run_times, clock_.get()));
+
+ base::TimeTicks time_zero = clock_->NowTicks();
+
+ EXPECT_FALSE(delayed_switch.IsEnabled());
+
+ delayed_switch.Enable();
+
+ EXPECT_TRUE(delayed_switch.IsEnabled());
+
+ mock_task_runner_->RunUntilTime(time_zero + base::TimeDelta::FromMilliseconds(250));
+
+ EXPECT_TRUE(delayed_switch.IsEnabled());
+ // Subsequent calls to |Enable| should not produce additional calls
+ // to |enable_callback|.
+ delayed_switch.Enable();
+
+ mock_task_runner_->RunUntilTime(time_zero + base::TimeDelta::FromMilliseconds(500));
+
+ EXPECT_TRUE(delayed_switch.IsEnabled());
+ delayed_switch.Disable();
+ // |Disable| is scheduled, but not active yet.
+ EXPECT_TRUE(delayed_switch.IsEnabled());
+
+ mock_task_runner_->RunUntilTime(time_zero + base::TimeDelta::FromMilliseconds(1000));
+
+ EXPECT_TRUE(delayed_switch.IsEnabled());
+ // A call to |Disable| while one is scheduled should not do anything.
+ delayed_switch.Disable();
+ EXPECT_TRUE(delayed_switch.IsEnabled());
+
+ mock_task_runner_->RunUntilTime(time_zero + base::TimeDelta::FromMilliseconds(1600));
+
+ // At 1500 ms disable was activated after a call to |Disable| at 500 ms with
+ // 1 s delay.
+ EXPECT_FALSE(delayed_switch.IsEnabled());
+ delayed_switch.Enable();
+ EXPECT_TRUE(delayed_switch.IsEnabled());
+
+ mock_task_runner_->RunUntilTime(time_zero + base::TimeDelta::FromMilliseconds(2100));
+
+ // We scheduled a call to |Disable| at 1000 ms with 1 s delay.
+ // Make sure it has done nothing.
+ EXPECT_TRUE(delayed_switch.IsEnabled());
+
+ EXPECT_THAT(enable_run_times, ElementsAre(
+ time_zero,
+ time_zero + base::TimeDelta::FromMilliseconds(1600)));
+
+ EXPECT_THAT(disable_run_times, ElementsAre(
+ time_zero + base::TimeDelta::FromMilliseconds(1500)));
+}
+
+} // namespace scheduler
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698