Chromium Code Reviews| Index: content/renderer/pepper/pepper_plugin_instance_throttler_unittest.cc |
| diff --git a/content/renderer/pepper/pepper_plugin_instance_throttler_unittest.cc b/content/renderer/pepper/pepper_plugin_instance_throttler_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..91b65b33e312b777a2e55aa386b341e8478f4307 |
| --- /dev/null |
| +++ b/content/renderer/pepper/pepper_plugin_instance_throttler_unittest.cc |
| @@ -0,0 +1,105 @@ |
| +// Copyright 2014 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 "base/bind.h" |
| +#include "base/logging.h" |
| +#include "content/renderer/pepper/pepper_plugin_instance_throttler.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "third_party/WebKit/public/web/WebInputEvent.h" |
| + |
| +namespace content { |
| + |
| +namespace { |
| + |
| +class TestPepperPluginInstanceThrottler : public PepperPluginInstanceThrottler { |
|
raymes
2014/11/12 06:38:20
I think we can avoid inheriting from the throttler
tommycli
2014/11/12 21:18:14
Done.
|
| + public: |
| + TestPepperPluginInstanceThrottler(bool power_saver_enabled, |
| + bool is_peripheral_content) |
| + : PepperPluginInstanceThrottler( |
| + base::Bind(&TestPepperPluginInstanceThrottler::ChangeCallback, |
| + base::Unretained(this)), |
| + power_saver_enabled, |
| + is_peripheral_content), |
| + change_callback_calls_(0) {} |
| + |
| + int change_callback_calls() { return change_callback_calls_; } |
| + |
| + void SetPluginThrottledForTest(bool throttled) { |
|
tommycli
2014/11/11 19:54:30
This seems a bit janky. Let me know if you have a
raymes
2014/11/12 06:38:20
Rather than calling SetPluginThrottled directly, c
tommycli
2014/11/12 21:18:14
ConsumeInputEvent can only unthrottle, not throttl
|
| + SetPluginThrottled(throttled); |
| + } |
| + |
| + void DisablePowerSaverByRetroactiveWhitelistForTest() { |
| + DisablePowerSaverByRetroactiveWhitelist(); |
|
raymes
2014/11/12 06:38:20
Similarly here, you could instead pass in a mocked
tommycli
2014/11/12 21:18:14
The 'real' PluginPowerSaverHelper underlying the m
|
| + } |
| + |
| + private: |
| + void ChangeCallback() { ++change_callback_calls_; } |
| + |
| + int change_callback_calls_; |
| +}; |
| + |
| +} // namespace |
| + |
| +TEST(PepperPluginInstanceThrottlerTest, ThrottleAndUnthrottle) { |
| + TestPepperPluginInstanceThrottler throttler(true /* power_saver_enabled */, |
| + true /* is_perpheral_content */); |
| + EXPECT_FALSE(throttler.is_throttled()); |
| + EXPECT_EQ(0, throttler.change_callback_calls()); |
| + |
| + throttler.SetPluginThrottledForTest(true); |
| + EXPECT_TRUE(throttler.is_throttled()); |
| + EXPECT_EQ(1, throttler.change_callback_calls()); |
| + |
| + throttler.SetPluginThrottledForTest(false); |
| + EXPECT_FALSE(throttler.is_throttled()); |
| + EXPECT_EQ(2, throttler.change_callback_calls()); |
| +} |
| + |
| +TEST(PepperPluginInstanceThrottlerTest, FastWhitelisting) { |
| + TestPepperPluginInstanceThrottler throttler(true /* power_saver_enabled */, |
| + true /* is_perpheral_content */); |
| + EXPECT_FALSE(throttler.is_throttled()); |
| + EXPECT_EQ(0, throttler.change_callback_calls()); |
| + |
| + throttler.DisablePowerSaverByRetroactiveWhitelistForTest(); |
| + |
| + throttler.SetPluginThrottledForTest(true); |
| + EXPECT_FALSE(throttler.is_throttled()); |
| + EXPECT_EQ(1, throttler.change_callback_calls()); |
| +} |
| + |
| +TEST(PepperPluginInstanceThrottlerTest, SlowWhitelisting) { |
| + TestPepperPluginInstanceThrottler throttler(true /* power_saver_enabled */, |
| + true /* is_perpheral_content */); |
| + EXPECT_FALSE(throttler.is_throttled()); |
| + EXPECT_EQ(0, throttler.change_callback_calls()); |
| + |
| + throttler.SetPluginThrottledForTest(true); |
| + EXPECT_TRUE(throttler.is_throttled()); |
| + EXPECT_EQ(1, throttler.change_callback_calls()); |
| + |
| + throttler.DisablePowerSaverByRetroactiveWhitelistForTest(); |
| + EXPECT_FALSE(throttler.is_throttled()); |
| + EXPECT_EQ(2, throttler.change_callback_calls()); |
| +} |
| + |
| +TEST(PepperPluginInstanceThrottlerTest, UnthrottleByClick) { |
| + TestPepperPluginInstanceThrottler throttler(true /* power_saver_enabled */, |
| + true /* is_perpheral_content */); |
| + EXPECT_FALSE(throttler.is_throttled()); |
| + EXPECT_EQ(0, throttler.change_callback_calls()); |
| + |
| + throttler.SetPluginThrottledForTest(true); |
| + EXPECT_TRUE(throttler.is_throttled()); |
| + EXPECT_EQ(1, throttler.change_callback_calls()); |
| + |
| + blink::WebMouseEvent event; |
| + event.type = blink::WebInputEvent::Type::MouseUp; |
| + EXPECT_TRUE(throttler.ConsumeInputEvent(event)); |
| + |
| + EXPECT_FALSE(throttler.is_throttled()); |
| + EXPECT_EQ(2, throttler.change_callback_calls()); |
| +} |
| + |
| +} // namespace content |