OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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 "base/bind.h" | |
6 #include "base/logging.h" | |
7 #include "content/renderer/pepper/pepper_plugin_instance_throttler.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 #include "third_party/WebKit/public/web/WebInputEvent.h" | |
10 | |
11 namespace content { | |
12 | |
13 namespace { | |
14 | |
15 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.
| |
16 public: | |
17 TestPepperPluginInstanceThrottler(bool power_saver_enabled, | |
18 bool is_peripheral_content) | |
19 : PepperPluginInstanceThrottler( | |
20 base::Bind(&TestPepperPluginInstanceThrottler::ChangeCallback, | |
21 base::Unretained(this)), | |
22 power_saver_enabled, | |
23 is_peripheral_content), | |
24 change_callback_calls_(0) {} | |
25 | |
26 int change_callback_calls() { return change_callback_calls_; } | |
27 | |
28 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
| |
29 SetPluginThrottled(throttled); | |
30 } | |
31 | |
32 void DisablePowerSaverByRetroactiveWhitelistForTest() { | |
33 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
| |
34 } | |
35 | |
36 private: | |
37 void ChangeCallback() { ++change_callback_calls_; } | |
38 | |
39 int change_callback_calls_; | |
40 }; | |
41 | |
42 } // namespace | |
43 | |
44 TEST(PepperPluginInstanceThrottlerTest, ThrottleAndUnthrottle) { | |
45 TestPepperPluginInstanceThrottler throttler(true /* power_saver_enabled */, | |
46 true /* is_perpheral_content */); | |
47 EXPECT_FALSE(throttler.is_throttled()); | |
48 EXPECT_EQ(0, throttler.change_callback_calls()); | |
49 | |
50 throttler.SetPluginThrottledForTest(true); | |
51 EXPECT_TRUE(throttler.is_throttled()); | |
52 EXPECT_EQ(1, throttler.change_callback_calls()); | |
53 | |
54 throttler.SetPluginThrottledForTest(false); | |
55 EXPECT_FALSE(throttler.is_throttled()); | |
56 EXPECT_EQ(2, throttler.change_callback_calls()); | |
57 } | |
58 | |
59 TEST(PepperPluginInstanceThrottlerTest, FastWhitelisting) { | |
60 TestPepperPluginInstanceThrottler throttler(true /* power_saver_enabled */, | |
61 true /* is_perpheral_content */); | |
62 EXPECT_FALSE(throttler.is_throttled()); | |
63 EXPECT_EQ(0, throttler.change_callback_calls()); | |
64 | |
65 throttler.DisablePowerSaverByRetroactiveWhitelistForTest(); | |
66 | |
67 throttler.SetPluginThrottledForTest(true); | |
68 EXPECT_FALSE(throttler.is_throttled()); | |
69 EXPECT_EQ(1, throttler.change_callback_calls()); | |
70 } | |
71 | |
72 TEST(PepperPluginInstanceThrottlerTest, SlowWhitelisting) { | |
73 TestPepperPluginInstanceThrottler throttler(true /* power_saver_enabled */, | |
74 true /* is_perpheral_content */); | |
75 EXPECT_FALSE(throttler.is_throttled()); | |
76 EXPECT_EQ(0, throttler.change_callback_calls()); | |
77 | |
78 throttler.SetPluginThrottledForTest(true); | |
79 EXPECT_TRUE(throttler.is_throttled()); | |
80 EXPECT_EQ(1, throttler.change_callback_calls()); | |
81 | |
82 throttler.DisablePowerSaverByRetroactiveWhitelistForTest(); | |
83 EXPECT_FALSE(throttler.is_throttled()); | |
84 EXPECT_EQ(2, throttler.change_callback_calls()); | |
85 } | |
86 | |
87 TEST(PepperPluginInstanceThrottlerTest, UnthrottleByClick) { | |
88 TestPepperPluginInstanceThrottler throttler(true /* power_saver_enabled */, | |
89 true /* is_perpheral_content */); | |
90 EXPECT_FALSE(throttler.is_throttled()); | |
91 EXPECT_EQ(0, throttler.change_callback_calls()); | |
92 | |
93 throttler.SetPluginThrottledForTest(true); | |
94 EXPECT_TRUE(throttler.is_throttled()); | |
95 EXPECT_EQ(1, throttler.change_callback_calls()); | |
96 | |
97 blink::WebMouseEvent event; | |
98 event.type = blink::WebInputEvent::Type::MouseUp; | |
99 EXPECT_TRUE(throttler.ConsumeInputEvent(event)); | |
100 | |
101 EXPECT_FALSE(throttler.is_throttled()); | |
102 EXPECT_EQ(2, throttler.change_callback_calls()); | |
103 } | |
104 | |
105 } // namespace content | |
OLD | NEW |