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

Side by Side Diff: content/renderer/pepper/plugin_instance_throttler_impl_unittest.cc

Issue 904913003: Plugin Power Saver: Fix implicitly sized and below the fold plugins. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move Get Poster call to anon namespace Created 5 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "content/public/common/content_switches.h" 10 #include "content/public/common/content_switches.h"
(...skipping 18 matching lines...) Expand all
29 protected: 29 protected:
30 PluginInstanceThrottlerImplTest() : change_callback_calls_(0) {} 30 PluginInstanceThrottlerImplTest() : change_callback_calls_(0) {}
31 ~PluginInstanceThrottlerImplTest() override { 31 ~PluginInstanceThrottlerImplTest() override {
32 throttler_->RemoveObserver(this); 32 throttler_->RemoveObserver(this);
33 } 33 }
34 34
35 void SetUp() override { 35 void SetUp() override {
36 blink::WebRect rect; 36 blink::WebRect rect;
37 rect.width = 100; 37 rect.width = 100;
38 rect.height = 100; 38 rect.height = 100;
39 throttler_.reset(new PluginInstanceThrottlerImpl( 39 throttler_.reset(
40 nullptr, GURL("http://example.com"), true /* power_saver_enabled */)); 40 new PluginInstanceThrottlerImpl(true /* power_saver_enabled */));
41 throttler_->Initialize(nullptr, GURL("http://example.com"),
42 "Shockwave Flash", rect);
41 throttler_->AddObserver(this); 43 throttler_->AddObserver(this);
42 } 44 }
43 45
44 PluginInstanceThrottlerImpl* throttler() { 46 PluginInstanceThrottlerImpl* throttler() {
45 DCHECK(throttler_.get()); 47 DCHECK(throttler_.get());
46 return throttler_.get(); 48 return throttler_.get();
47 } 49 }
48 50
49 void DisablePowerSaverByRetroactiveWhitelist() { 51 void DisablePowerSaverByRetroactiveWhitelist() {
50 throttler()->MarkPluginEssential( 52 throttler()->MarkPluginEssential(
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 120
119 // Throttle after consecutive interesting frames. 121 // Throttle after consecutive interesting frames.
120 throttler()->OnImageFlush(&interesting_bitmap); 122 throttler()->OnImageFlush(&interesting_bitmap);
121 throttler()->OnImageFlush(&interesting_bitmap); 123 throttler()->OnImageFlush(&interesting_bitmap);
122 throttler()->OnImageFlush(&interesting_bitmap); 124 throttler()->OnImageFlush(&interesting_bitmap);
123 throttler()->OnImageFlush(&interesting_bitmap); 125 throttler()->OnImageFlush(&interesting_bitmap);
124 EXPECT_TRUE(throttler()->IsThrottled()); 126 EXPECT_TRUE(throttler()->IsThrottled());
125 EXPECT_EQ(1, change_callback_calls()); 127 EXPECT_EQ(1, change_callback_calls());
126 } 128 }
127 129
130 TEST_F(PluginInstanceThrottlerImplTest, MaximumKeyframesAnalyzed) {
131 EXPECT_FALSE(throttler()->IsThrottled());
132 EXPECT_EQ(0, change_callback_calls());
133
134 SkBitmap boring_bitmap;
135
136 // Throttle after tons of boring bitmaps.
137 for (int i = 0; i < PluginInstanceThrottlerImpl::kMaximumFramesToExamine;
138 ++i) {
139 throttler()->OnImageFlush(&boring_bitmap);
140 }
141 EXPECT_TRUE(throttler()->IsThrottled());
142 EXPECT_EQ(1, change_callback_calls());
143 }
128 TEST_F(PluginInstanceThrottlerImplTest, IgnoreThrottlingAfterMouseUp) { 144 TEST_F(PluginInstanceThrottlerImplTest, IgnoreThrottlingAfterMouseUp) {
129 EXPECT_FALSE(throttler()->IsThrottled()); 145 EXPECT_FALSE(throttler()->IsThrottled());
130 EXPECT_EQ(0, change_callback_calls()); 146 EXPECT_EQ(0, change_callback_calls());
131 147
132 // MouseUp before throttling engaged should not be consumed, but should 148 // MouseUp before throttling engaged should not be consumed, but should
133 // prevent subsequent throttling from engaging. 149 // prevent subsequent throttling from engaging.
134 SendEventAndTest(blink::WebInputEvent::Type::MouseUp, false, false, 0); 150 SendEventAndTest(blink::WebInputEvent::Type::MouseUp, false, false, 0);
135 151
136 EngageThrottle(); 152 EngageThrottle();
137 EXPECT_FALSE(throttler()->IsThrottled()); 153 EXPECT_FALSE(throttler()->IsThrottled());
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 event.modifiers = blink::WebInputEvent::Modifiers::MiddleButtonDown; 225 event.modifiers = blink::WebInputEvent::Modifiers::MiddleButtonDown;
210 EXPECT_TRUE(throttler()->ConsumeInputEvent(event)); 226 EXPECT_TRUE(throttler()->ConsumeInputEvent(event));
211 EXPECT_TRUE(throttler()->IsThrottled()); 227 EXPECT_TRUE(throttler()->IsThrottled());
212 228
213 event.modifiers = blink::WebInputEvent::Modifiers::LeftButtonDown; 229 event.modifiers = blink::WebInputEvent::Modifiers::LeftButtonDown;
214 EXPECT_TRUE(throttler()->ConsumeInputEvent(event)); 230 EXPECT_TRUE(throttler()->ConsumeInputEvent(event));
215 EXPECT_FALSE(throttler()->IsThrottled()); 231 EXPECT_FALSE(throttler()->IsThrottled());
216 } 232 }
217 233
218 } // namespace content 234 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698