| OLD | NEW |
| 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" |
| 11 #include "content/public/renderer/render_frame.h" | 11 #include "content/public/renderer/render_frame.h" |
| 12 #include "content/renderer/pepper/plugin_instance_throttler_impl.h" | 12 #include "content/renderer/pepper/plugin_instance_throttler_impl.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "third_party/WebKit/public/web/WebInputEvent.h" | 15 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 16 #include "third_party/WebKit/public/web/WebPluginParams.h" | 16 #include "third_party/WebKit/public/web/WebPluginParams.h" |
| 17 #include "ui/gfx/canvas.h" | 17 #include "ui/gfx/canvas.h" |
| 18 | 18 |
| 19 using testing::_; | 19 using testing::_; |
| 20 using testing::Return; | 20 using testing::Return; |
| 21 | 21 |
| 22 class GURL; | 22 class GURL; |
| 23 | 23 |
| 24 namespace content { | 24 namespace content { |
| 25 | 25 |
| 26 class PluginInstanceThrottlerImplTest | 26 class PluginInstanceThrottlerImplTest |
| 27 : public testing::Test, | 27 : public testing::Test, |
| 28 public PluginInstanceThrottler::Observer { | 28 public PluginInstanceThrottler::Observer { |
| 29 protected: | 29 protected: |
| 30 const int kMaximumFramesToExamine = |
| 31 PluginInstanceThrottlerImpl::kMaximumFramesToExamine; |
| 32 |
| 30 PluginInstanceThrottlerImplTest() : change_callback_calls_(0) {} | 33 PluginInstanceThrottlerImplTest() : change_callback_calls_(0) {} |
| 31 ~PluginInstanceThrottlerImplTest() override { | 34 ~PluginInstanceThrottlerImplTest() override { |
| 32 throttler_->RemoveObserver(this); | 35 throttler_->RemoveObserver(this); |
| 33 } | 36 } |
| 34 | 37 |
| 35 void SetUp() override { | 38 void SetUp() override { |
| 36 blink::WebRect rect; | 39 blink::WebRect rect; |
| 37 rect.width = 100; | 40 rect.width = 100; |
| 38 rect.height = 100; | 41 rect.height = 100; |
| 39 throttler_.reset(new PluginInstanceThrottlerImpl( | 42 throttler_.reset( |
| 40 nullptr, GURL("http://example.com"), true /* power_saver_enabled */)); | 43 new PluginInstanceThrottlerImpl(true /* power_saver_enabled */)); |
| 44 throttler_->Initialize(nullptr, GURL("http://example.com"), |
| 45 "Shockwave Flash", rect); |
| 41 throttler_->AddObserver(this); | 46 throttler_->AddObserver(this); |
| 42 } | 47 } |
| 43 | 48 |
| 44 PluginInstanceThrottlerImpl* throttler() { | 49 PluginInstanceThrottlerImpl* throttler() { |
| 45 DCHECK(throttler_.get()); | 50 DCHECK(throttler_.get()); |
| 46 return throttler_.get(); | 51 return throttler_.get(); |
| 47 } | 52 } |
| 48 | 53 |
| 49 void DisablePowerSaverByRetroactiveWhitelist() { | 54 void DisablePowerSaverByRetroactiveWhitelist() { |
| 50 throttler()->MarkPluginEssential( | 55 throttler()->MarkPluginEssential( |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 123 |
| 119 // Throttle after consecutive interesting frames. | 124 // Throttle after consecutive interesting frames. |
| 120 throttler()->OnImageFlush(&interesting_bitmap); | 125 throttler()->OnImageFlush(&interesting_bitmap); |
| 121 throttler()->OnImageFlush(&interesting_bitmap); | 126 throttler()->OnImageFlush(&interesting_bitmap); |
| 122 throttler()->OnImageFlush(&interesting_bitmap); | 127 throttler()->OnImageFlush(&interesting_bitmap); |
| 123 throttler()->OnImageFlush(&interesting_bitmap); | 128 throttler()->OnImageFlush(&interesting_bitmap); |
| 124 EXPECT_TRUE(throttler()->IsThrottled()); | 129 EXPECT_TRUE(throttler()->IsThrottled()); |
| 125 EXPECT_EQ(1, change_callback_calls()); | 130 EXPECT_EQ(1, change_callback_calls()); |
| 126 } | 131 } |
| 127 | 132 |
| 133 TEST_F(PluginInstanceThrottlerImplTest, MaximumKeyframesAnalyzed) { |
| 134 EXPECT_FALSE(throttler()->IsThrottled()); |
| 135 EXPECT_EQ(0, change_callback_calls()); |
| 136 |
| 137 SkBitmap boring_bitmap; |
| 138 |
| 139 // Throttle after tons of boring bitmaps. |
| 140 for (int i = 0; i < kMaximumFramesToExamine; ++i) { |
| 141 throttler()->OnImageFlush(&boring_bitmap); |
| 142 } |
| 143 EXPECT_TRUE(throttler()->IsThrottled()); |
| 144 EXPECT_EQ(1, change_callback_calls()); |
| 145 } |
| 128 TEST_F(PluginInstanceThrottlerImplTest, IgnoreThrottlingAfterMouseUp) { | 146 TEST_F(PluginInstanceThrottlerImplTest, IgnoreThrottlingAfterMouseUp) { |
| 129 EXPECT_FALSE(throttler()->IsThrottled()); | 147 EXPECT_FALSE(throttler()->IsThrottled()); |
| 130 EXPECT_EQ(0, change_callback_calls()); | 148 EXPECT_EQ(0, change_callback_calls()); |
| 131 | 149 |
| 132 // MouseUp before throttling engaged should not be consumed, but should | 150 // MouseUp before throttling engaged should not be consumed, but should |
| 133 // prevent subsequent throttling from engaging. | 151 // prevent subsequent throttling from engaging. |
| 134 SendEventAndTest(blink::WebInputEvent::Type::MouseUp, false, false, 0); | 152 SendEventAndTest(blink::WebInputEvent::Type::MouseUp, false, false, 0); |
| 135 | 153 |
| 136 EngageThrottle(); | 154 EngageThrottle(); |
| 137 EXPECT_FALSE(throttler()->IsThrottled()); | 155 EXPECT_FALSE(throttler()->IsThrottled()); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 event.modifiers = blink::WebInputEvent::Modifiers::MiddleButtonDown; | 227 event.modifiers = blink::WebInputEvent::Modifiers::MiddleButtonDown; |
| 210 EXPECT_TRUE(throttler()->ConsumeInputEvent(event)); | 228 EXPECT_TRUE(throttler()->ConsumeInputEvent(event)); |
| 211 EXPECT_TRUE(throttler()->IsThrottled()); | 229 EXPECT_TRUE(throttler()->IsThrottled()); |
| 212 | 230 |
| 213 event.modifiers = blink::WebInputEvent::Modifiers::LeftButtonDown; | 231 event.modifiers = blink::WebInputEvent::Modifiers::LeftButtonDown; |
| 214 EXPECT_TRUE(throttler()->ConsumeInputEvent(event)); | 232 EXPECT_TRUE(throttler()->ConsumeInputEvent(event)); |
| 215 EXPECT_FALSE(throttler()->IsThrottled()); | 233 EXPECT_FALSE(throttler()->IsThrottled()); |
| 216 } | 234 } |
| 217 | 235 |
| 218 } // namespace content | 236 } // namespace content |
| OLD | NEW |