Index: content/public/renderer/plugin_instance_throttler_unittest.cc |
diff --git a/content/renderer/pepper/pepper_plugin_instance_throttler_unittest.cc b/content/public/renderer/plugin_instance_throttler_unittest.cc |
similarity index 83% |
rename from content/renderer/pepper/pepper_plugin_instance_throttler_unittest.cc |
rename to content/public/renderer/plugin_instance_throttler_unittest.cc |
index 1ada9add6985b6dd3426f201a064ccf6154cef73..f2d2da4e41ee235cb37fb7e2eae24703dd91b81a 100644 |
--- a/content/renderer/pepper/pepper_plugin_instance_throttler_unittest.cc |
+++ b/content/public/renderer/plugin_instance_throttler_unittest.cc |
@@ -8,8 +8,8 @@ |
#include "base/memory/scoped_ptr.h" |
#include "base/message_loop/message_loop.h" |
#include "content/public/common/content_switches.h" |
+#include "content/public/renderer/plugin_instance_throttler.h" |
#include "content/public/renderer/render_frame.h" |
-#include "content/renderer/pepper/pepper_plugin_instance_throttler.h" |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#include "third_party/WebKit/public/web/WebInputEvent.h" |
@@ -23,36 +23,35 @@ class GURL; |
namespace content { |
-class PepperPluginInstanceThrottlerTest : public testing::Test { |
+class PluginInstanceThrottlerTest : public testing::Test, |
+ public PluginInstanceThrottler::Observer { |
protected: |
- PepperPluginInstanceThrottlerTest() : change_callback_calls_(0) {} |
+ PluginInstanceThrottlerTest() : change_callback_calls_(0) {} |
+ ~PluginInstanceThrottlerTest() override { throttler_->RemoveObserver(this); } |
void SetUp() override { |
blink::WebRect rect; |
rect.width = 100; |
rect.height = 100; |
- throttler_.reset(new PepperPluginInstanceThrottler( |
- nullptr, rect, true /* is_flash_plugin */, GURL("http://example.com"), |
- content::RenderFrame::POWER_SAVER_MODE_PERIPHERAL_THROTTLED, |
- base::Bind(&PepperPluginInstanceThrottlerTest::ChangeCallback, |
- base::Unretained(this)))); |
+ throttler_.reset(new PluginInstanceThrottler( |
+ nullptr, GURL("http://example.com"), |
+ PluginInstanceThrottler::POWER_SAVER_MODE_PERIPHERAL_THROTTLED)); |
+ throttler_->AddObserver(this); |
} |
- PepperPluginInstanceThrottler* throttler() { |
+ PluginInstanceThrottler* throttler() { |
DCHECK(throttler_.get()); |
return throttler_.get(); |
} |
void DisablePowerSaverByRetroactiveWhitelist() { |
throttler()->DisablePowerSaver( |
- PepperPluginInstanceThrottler::UNTHROTTLE_METHOD_BY_WHITELIST); |
+ PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_WHITELIST); |
} |
int change_callback_calls() { return change_callback_calls_; } |
- void EngageThrottle() { |
- throttler_->SetPluginThrottled(true); |
- } |
+ void EngageThrottle() { throttler_->SetPluginThrottled(true); } |
void SendEventAndTest(blink::WebInputEvent::Type event_type, |
bool expect_consumed, |
@@ -67,16 +66,17 @@ class PepperPluginInstanceThrottlerTest : public testing::Test { |
} |
private: |
- void ChangeCallback() { ++change_callback_calls_; } |
+ // PluginInstanceThrottler::Observer |
+ void OnThrottleStateChange() override { ++change_callback_calls_; } |
- scoped_ptr<PepperPluginInstanceThrottler> throttler_; |
+ scoped_ptr<PluginInstanceThrottler> throttler_; |
int change_callback_calls_; |
base::MessageLoop loop_; |
}; |
-TEST_F(PepperPluginInstanceThrottlerTest, ThrottleAndUnthrottleByClick) { |
+TEST_F(PluginInstanceThrottlerTest, ThrottleAndUnthrottleByClick) { |
EXPECT_FALSE(throttler()->is_throttled()); |
EXPECT_EQ(0, change_callback_calls()); |
@@ -88,7 +88,7 @@ TEST_F(PepperPluginInstanceThrottlerTest, ThrottleAndUnthrottleByClick) { |
SendEventAndTest(blink::WebInputEvent::Type::MouseUp, true, false, 2); |
} |
-TEST_F(PepperPluginInstanceThrottlerTest, ThrottleByKeyframe) { |
+TEST_F(PluginInstanceThrottlerTest, ThrottleByKeyframe) { |
EXPECT_FALSE(throttler()->is_throttled()); |
EXPECT_EQ(0, change_callback_calls()); |
@@ -123,7 +123,7 @@ TEST_F(PepperPluginInstanceThrottlerTest, ThrottleByKeyframe) { |
EXPECT_EQ(1, change_callback_calls()); |
} |
-TEST_F(PepperPluginInstanceThrottlerTest, IgnoreThrottlingAfterMouseUp) { |
+TEST_F(PluginInstanceThrottlerTest, IgnoreThrottlingAfterMouseUp) { |
EXPECT_FALSE(throttler()->is_throttled()); |
EXPECT_EQ(0, change_callback_calls()); |
@@ -136,7 +136,7 @@ TEST_F(PepperPluginInstanceThrottlerTest, IgnoreThrottlingAfterMouseUp) { |
EXPECT_EQ(0, change_callback_calls()); |
} |
-TEST_F(PepperPluginInstanceThrottlerTest, FastWhitelisting) { |
+TEST_F(PluginInstanceThrottlerTest, FastWhitelisting) { |
EXPECT_FALSE(throttler()->is_throttled()); |
EXPECT_EQ(0, change_callback_calls()); |
@@ -147,7 +147,7 @@ TEST_F(PepperPluginInstanceThrottlerTest, FastWhitelisting) { |
EXPECT_EQ(1, change_callback_calls()); |
} |
-TEST_F(PepperPluginInstanceThrottlerTest, SlowWhitelisting) { |
+TEST_F(PluginInstanceThrottlerTest, SlowWhitelisting) { |
EXPECT_FALSE(throttler()->is_throttled()); |
EXPECT_EQ(0, change_callback_calls()); |
@@ -160,7 +160,7 @@ TEST_F(PepperPluginInstanceThrottlerTest, SlowWhitelisting) { |
EXPECT_EQ(2, change_callback_calls()); |
} |
-TEST_F(PepperPluginInstanceThrottlerTest, EventConsumption) { |
+TEST_F(PluginInstanceThrottlerTest, EventConsumption) { |
EXPECT_FALSE(throttler()->is_throttled()); |
EXPECT_EQ(0, change_callback_calls()); |
@@ -189,7 +189,7 @@ TEST_F(PepperPluginInstanceThrottlerTest, EventConsumption) { |
SendEventAndTest(blink::WebInputEvent::Type::MouseUp, false, false, 2); |
} |
-TEST_F(PepperPluginInstanceThrottlerTest, ThrottleOnLeftClickOnly) { |
+TEST_F(PluginInstanceThrottlerTest, ThrottleOnLeftClickOnly) { |
EXPECT_FALSE(throttler()->is_throttled()); |
EXPECT_EQ(0, change_callback_calls()); |