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

Unified Diff: content/renderer/pepper/plugin_instance_throttler_impl_unittest.cc

Issue 879403002: Plugin Power Saver: Mute throttled plugins. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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: content/renderer/pepper/plugin_instance_throttler_impl_unittest.cc
diff --git a/content/renderer/pepper/plugin_instance_throttler_impl_unittest.cc b/content/renderer/pepper/plugin_instance_throttler_impl_unittest.cc
index fc284b0ae74abf0292fc74decfecb04c24138fa4..9e3bce5ca1792507ffc717f242457f6f3e2aec0d 100644
--- a/content/renderer/pepper/plugin_instance_throttler_impl_unittest.cc
+++ b/content/renderer/pepper/plugin_instance_throttler_impl_unittest.cc
@@ -27,7 +27,7 @@ class PluginInstanceThrottlerImplTest
: public testing::Test,
public PluginInstanceThrottler::Observer {
protected:
- PluginInstanceThrottlerImplTest() : change_callback_calls_(0) {}
+ PluginInstanceThrottlerImplTest() : state_change_callback_calls_(0) {}
~PluginInstanceThrottlerImplTest() override {
throttler_->RemoveObserver(this);
}
@@ -51,40 +51,44 @@ class PluginInstanceThrottlerImplTest
PluginInstanceThrottlerImpl::UNTHROTTLE_METHOD_BY_WHITELIST);
}
- int change_callback_calls() { return change_callback_calls_; }
+ int state_change_callback_calls() { return state_change_callback_calls_; }
void EngageThrottle() { throttler_->EngageThrottle(); }
void SendEventAndTest(blink::WebInputEvent::Type event_type,
bool expect_consumed,
bool expect_throttled,
- int expect_change_callback_count) {
+ int expect_state_change_callback_count) {
blink::WebMouseEvent event;
event.type = event_type;
event.modifiers = blink::WebInputEvent::Modifiers::LeftButtonDown;
EXPECT_EQ(expect_consumed, throttler()->ConsumeInputEvent(event));
EXPECT_EQ(expect_throttled, throttler()->IsThrottled());
- EXPECT_EQ(expect_change_callback_count, change_callback_calls());
+ EXPECT_EQ(expect_state_change_callback_count,
+ state_change_callback_calls());
}
private:
// PluginInstanceThrottlerImpl::Observer
- void OnThrottleStateChange() override { ++change_callback_calls_; }
+ void OnPowerSaverStateChange(
+ PluginInstanceThrottler::PowerSaverState state) override {
+ ++state_change_callback_calls_;
+ }
scoped_ptr<PluginInstanceThrottlerImpl> throttler_;
- int change_callback_calls_;
+ int state_change_callback_calls_;
base::MessageLoop loop_;
};
TEST_F(PluginInstanceThrottlerImplTest, ThrottleAndUnthrottleByClick) {
EXPECT_FALSE(throttler()->IsThrottled());
- EXPECT_EQ(0, change_callback_calls());
+ EXPECT_EQ(0, state_change_callback_calls());
EngageThrottle();
EXPECT_TRUE(throttler()->IsThrottled());
- EXPECT_EQ(1, change_callback_calls());
+ EXPECT_EQ(1, state_change_callback_calls());
// MouseUp while throttled should be consumed and disengage throttling.
SendEventAndTest(blink::WebInputEvent::Type::MouseUp, true, false, 2);
@@ -92,7 +96,7 @@ TEST_F(PluginInstanceThrottlerImplTest, ThrottleAndUnthrottleByClick) {
TEST_F(PluginInstanceThrottlerImplTest, ThrottleByKeyframe) {
EXPECT_FALSE(throttler()->IsThrottled());
- EXPECT_EQ(0, change_callback_calls());
+ EXPECT_EQ(0, state_change_callback_calls());
SkBitmap boring_bitmap;
gfx::Canvas canvas(gfx::Size(20, 10), 1.0f, true);
@@ -104,7 +108,7 @@ TEST_F(PluginInstanceThrottlerImplTest, ThrottleByKeyframe) {
// Don't throttle for a boring frame.
throttler()->OnImageFlush(&boring_bitmap);
EXPECT_FALSE(throttler()->IsThrottled());
- EXPECT_EQ(0, change_callback_calls());
+ EXPECT_EQ(0, state_change_callback_calls());
// Don't throttle for non-consecutive interesting frames.
throttler()->OnImageFlush(&interesting_bitmap);
@@ -114,7 +118,7 @@ TEST_F(PluginInstanceThrottlerImplTest, ThrottleByKeyframe) {
throttler()->OnImageFlush(&interesting_bitmap);
throttler()->OnImageFlush(&boring_bitmap);
EXPECT_FALSE(throttler()->IsThrottled());
- EXPECT_EQ(0, change_callback_calls());
+ EXPECT_EQ(0, state_change_callback_calls());
// Throttle after consecutive interesting frames.
throttler()->OnImageFlush(&interesting_bitmap);
@@ -122,53 +126,53 @@ TEST_F(PluginInstanceThrottlerImplTest, ThrottleByKeyframe) {
throttler()->OnImageFlush(&interesting_bitmap);
throttler()->OnImageFlush(&interesting_bitmap);
EXPECT_TRUE(throttler()->IsThrottled());
- EXPECT_EQ(1, change_callback_calls());
+ EXPECT_EQ(1, state_change_callback_calls());
}
TEST_F(PluginInstanceThrottlerImplTest, IgnoreThrottlingAfterMouseUp) {
EXPECT_FALSE(throttler()->IsThrottled());
- EXPECT_EQ(0, change_callback_calls());
+ EXPECT_EQ(0, state_change_callback_calls());
// MouseUp before throttling engaged should not be consumed, but should
// prevent subsequent throttling from engaging.
- SendEventAndTest(blink::WebInputEvent::Type::MouseUp, false, false, 0);
+ SendEventAndTest(blink::WebInputEvent::Type::MouseUp, false, false, 1);
EngageThrottle();
EXPECT_FALSE(throttler()->IsThrottled());
- EXPECT_EQ(0, change_callback_calls());
+ EXPECT_EQ(1, state_change_callback_calls());
}
TEST_F(PluginInstanceThrottlerImplTest, FastWhitelisting) {
EXPECT_FALSE(throttler()->IsThrottled());
- EXPECT_EQ(0, change_callback_calls());
+ EXPECT_EQ(0, state_change_callback_calls());
DisablePowerSaverByRetroactiveWhitelist();
EngageThrottle();
EXPECT_FALSE(throttler()->IsThrottled());
- EXPECT_EQ(0, change_callback_calls());
+ EXPECT_EQ(1, state_change_callback_calls());
}
TEST_F(PluginInstanceThrottlerImplTest, SlowWhitelisting) {
EXPECT_FALSE(throttler()->IsThrottled());
- EXPECT_EQ(0, change_callback_calls());
+ EXPECT_EQ(0, state_change_callback_calls());
EngageThrottle();
EXPECT_TRUE(throttler()->IsThrottled());
- EXPECT_EQ(1, change_callback_calls());
+ EXPECT_EQ(1, state_change_callback_calls());
DisablePowerSaverByRetroactiveWhitelist();
EXPECT_FALSE(throttler()->IsThrottled());
- EXPECT_EQ(2, change_callback_calls());
+ EXPECT_EQ(2, state_change_callback_calls());
}
TEST_F(PluginInstanceThrottlerImplTest, EventConsumption) {
EXPECT_FALSE(throttler()->IsThrottled());
- EXPECT_EQ(0, change_callback_calls());
+ EXPECT_EQ(0, state_change_callback_calls());
EngageThrottle();
EXPECT_TRUE(throttler()->IsThrottled());
- EXPECT_EQ(1, change_callback_calls());
+ EXPECT_EQ(1, state_change_callback_calls());
// Consume but don't unthrottle on a variety of other events.
SendEventAndTest(blink::WebInputEvent::Type::MouseDown, true, true, 1);
@@ -193,11 +197,11 @@ TEST_F(PluginInstanceThrottlerImplTest, EventConsumption) {
TEST_F(PluginInstanceThrottlerImplTest, ThrottleOnLeftClickOnly) {
EXPECT_FALSE(throttler()->IsThrottled());
- EXPECT_EQ(0, change_callback_calls());
+ EXPECT_EQ(0, state_change_callback_calls());
EngageThrottle();
EXPECT_TRUE(throttler()->IsThrottled());
- EXPECT_EQ(1, change_callback_calls());
+ EXPECT_EQ(1, state_change_callback_calls());
blink::WebMouseEvent event;
event.type = blink::WebInputEvent::Type::MouseUp;

Powered by Google App Engine
This is Rietveld 408576698