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

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: fix windows compile 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 20 matching lines...) Expand all
71 // PluginInstanceThrottlerImpl::Observer 73 // PluginInstanceThrottlerImpl::Observer
72 void OnThrottleStateChange() override { ++change_callback_calls_; } 74 void OnThrottleStateChange() override { ++change_callback_calls_; }
73 75
74 scoped_ptr<PluginInstanceThrottlerImpl> throttler_; 76 scoped_ptr<PluginInstanceThrottlerImpl> throttler_;
75 77
76 int change_callback_calls_; 78 int change_callback_calls_;
77 79
78 base::MessageLoop loop_; 80 base::MessageLoop loop_;
79 }; 81 };
80 82
83 TEST_F(PluginInstanceThrottlerImplTest, PosterImage) {
piman 2015/02/07 00:02:13 This could still go to chrome/renderer/chrome_cont
84 size_t size = 3;
85 blink::WebVector<blink::WebString> names(size);
86 blink::WebVector<blink::WebString> values(size);
87
88 blink::WebPluginParams params;
89 params.url = GURL("http://b.com/foo.swf");
90
91 params.attributeNames.swap(names);
92 params.attributeValues.swap(values);
93
94 params.attributeNames[0] = "poster";
95 params.attributeValues[0] = "poster.jpg";
96
97 EXPECT_EQ(GURL("http://a.com/poster.jpg"),
98 PluginInstanceThrottler::GetPluginInstancePosterImage(
99 params, GURL("http://a.com/page.html")));
100
101 params.attributeValues[0] = "http://b.com/poster.jpg";
102 EXPECT_EQ(GURL("http://b.com/poster.jpg"),
103 PluginInstanceThrottler::GetPluginInstancePosterImage(
104 params, GURL("http://a.com/page.html")));
105
106 // Ignore empty poster paramaters.
107 params.attributeValues[0] = "";
108 EXPECT_EQ(GURL(), PluginInstanceThrottler::GetPluginInstancePosterImage(
109 params, GURL("http://a.com/page.html")));
110 }
111
81 TEST_F(PluginInstanceThrottlerImplTest, ThrottleAndUnthrottleByClick) { 112 TEST_F(PluginInstanceThrottlerImplTest, ThrottleAndUnthrottleByClick) {
82 EXPECT_FALSE(throttler()->IsThrottled()); 113 EXPECT_FALSE(throttler()->IsThrottled());
83 EXPECT_EQ(0, change_callback_calls()); 114 EXPECT_EQ(0, change_callback_calls());
84 115
85 EngageThrottle(); 116 EngageThrottle();
86 EXPECT_TRUE(throttler()->IsThrottled()); 117 EXPECT_TRUE(throttler()->IsThrottled());
87 EXPECT_EQ(1, change_callback_calls()); 118 EXPECT_EQ(1, change_callback_calls());
88 119
89 // MouseUp while throttled should be consumed and disengage throttling. 120 // MouseUp while throttled should be consumed and disengage throttling.
90 SendEventAndTest(blink::WebInputEvent::Type::MouseUp, true, false, 2); 121 SendEventAndTest(blink::WebInputEvent::Type::MouseUp, true, false, 2);
(...skipping 27 matching lines...) Expand all
118 149
119 // Throttle after consecutive interesting frames. 150 // Throttle after consecutive interesting frames.
120 throttler()->OnImageFlush(&interesting_bitmap); 151 throttler()->OnImageFlush(&interesting_bitmap);
121 throttler()->OnImageFlush(&interesting_bitmap); 152 throttler()->OnImageFlush(&interesting_bitmap);
122 throttler()->OnImageFlush(&interesting_bitmap); 153 throttler()->OnImageFlush(&interesting_bitmap);
123 throttler()->OnImageFlush(&interesting_bitmap); 154 throttler()->OnImageFlush(&interesting_bitmap);
124 EXPECT_TRUE(throttler()->IsThrottled()); 155 EXPECT_TRUE(throttler()->IsThrottled());
125 EXPECT_EQ(1, change_callback_calls()); 156 EXPECT_EQ(1, change_callback_calls());
126 } 157 }
127 158
159 TEST_F(PluginInstanceThrottlerImplTest, MaximumKeyframesAnalyzed) {
160 EXPECT_FALSE(throttler()->IsThrottled());
161 EXPECT_EQ(0, change_callback_calls());
162
163 SkBitmap boring_bitmap;
164
165 // Throttle after tons of boring bitmaps.
166 for (int i = 0; i < PluginInstanceThrottlerImpl::kMaximumFramesToExamine;
167 ++i) {
168 throttler()->OnImageFlush(&boring_bitmap);
169 }
170 EXPECT_TRUE(throttler()->IsThrottled());
171 EXPECT_EQ(1, change_callback_calls());
172 }
128 TEST_F(PluginInstanceThrottlerImplTest, IgnoreThrottlingAfterMouseUp) { 173 TEST_F(PluginInstanceThrottlerImplTest, IgnoreThrottlingAfterMouseUp) {
129 EXPECT_FALSE(throttler()->IsThrottled()); 174 EXPECT_FALSE(throttler()->IsThrottled());
130 EXPECT_EQ(0, change_callback_calls()); 175 EXPECT_EQ(0, change_callback_calls());
131 176
132 // MouseUp before throttling engaged should not be consumed, but should 177 // MouseUp before throttling engaged should not be consumed, but should
133 // prevent subsequent throttling from engaging. 178 // prevent subsequent throttling from engaging.
134 SendEventAndTest(blink::WebInputEvent::Type::MouseUp, false, false, 0); 179 SendEventAndTest(blink::WebInputEvent::Type::MouseUp, false, false, 0);
135 180
136 EngageThrottle(); 181 EngageThrottle();
137 EXPECT_FALSE(throttler()->IsThrottled()); 182 EXPECT_FALSE(throttler()->IsThrottled());
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 event.modifiers = blink::WebInputEvent::Modifiers::MiddleButtonDown; 254 event.modifiers = blink::WebInputEvent::Modifiers::MiddleButtonDown;
210 EXPECT_TRUE(throttler()->ConsumeInputEvent(event)); 255 EXPECT_TRUE(throttler()->ConsumeInputEvent(event));
211 EXPECT_TRUE(throttler()->IsThrottled()); 256 EXPECT_TRUE(throttler()->IsThrottled());
212 257
213 event.modifiers = blink::WebInputEvent::Modifiers::LeftButtonDown; 258 event.modifiers = blink::WebInputEvent::Modifiers::LeftButtonDown;
214 EXPECT_TRUE(throttler()->ConsumeInputEvent(event)); 259 EXPECT_TRUE(throttler()->ConsumeInputEvent(event));
215 EXPECT_FALSE(throttler()->IsThrottled()); 260 EXPECT_FALSE(throttler()->IsThrottled());
216 } 261 }
217 262
218 } // namespace content 263 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698