Index: content/renderer/pepper/plugin_power_saver_helper_browsertest.cc |
diff --git a/content/renderer/pepper/plugin_power_saver_helper_browsertest.cc b/content/renderer/pepper/plugin_power_saver_helper_browsertest.cc |
index cb74cd1590e3286c90050d1cc02655b9681db8e7..9eb32bce2a70bc6671215484ca7367d5f35d66e3 100644 |
--- a/content/renderer/pepper/plugin_power_saver_helper_browsertest.cc |
+++ b/content/renderer/pepper/plugin_power_saver_helper_browsertest.cc |
@@ -6,10 +6,12 @@ |
#include "content/common/frame_messages.h" |
#include "content/common/view_message_enums.h" |
#include "content/public/common/content_constants.h" |
+#include "content/public/test/frame_load_waiter.h" |
#include "content/public/test/render_view_test.h" |
#include "content/renderer/pepper/plugin_power_saver_helper.h" |
#include "content/renderer/render_frame_impl.h" |
#include "content/renderer/render_view_impl.h" |
+#include "content/test/test_render_frame.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#include "third_party/WebKit/public/web/WebDocument.h" |
#include "third_party/WebKit/public/web/WebLocalFrame.h" |
@@ -22,6 +24,11 @@ class PluginPowerSaverHelperTest : public RenderViewTest { |
public: |
PluginPowerSaverHelperTest() : sink_(NULL) {} |
+ void SetUp() override { |
+ RenderViewTest::SetUp(); |
+ sink_ = &render_thread_->sink(); |
+ } |
+ |
RenderFrameImpl* frame() { |
return static_cast<RenderFrameImpl*>(view_->GetMainRenderFrame()); |
} |
@@ -30,11 +37,6 @@ class PluginPowerSaverHelperTest : public RenderViewTest { |
return frame()->plugin_power_saver_helper(); |
} |
- void SetUp() override { |
- RenderViewTest::SetUp(); |
- sink_ = &render_thread_->sink(); |
- } |
- |
blink::WebPluginParams MakeParams(const std::string& url, |
const std::string& poster, |
const std::string& width, |
@@ -66,61 +68,73 @@ class PluginPowerSaverHelperTest : public RenderViewTest { |
}; |
TEST_F(PluginPowerSaverHelperTest, AllowSameOrigin) { |
- EXPECT_FALSE(helper()->ShouldThrottleContent(GURL(), kFlashPluginName, 100, |
- 100, nullptr)); |
- EXPECT_FALSE(helper()->ShouldThrottleContent(GURL(), kFlashPluginName, 1000, |
- 1000, nullptr)); |
+ EXPECT_FALSE( |
+ helper()->ShouldThrottleContent(url::Origin(GURL("http://same.com")), |
+ url::Origin(GURL("http://same.com")), |
+ kFlashPluginName, 100, 100, nullptr)); |
+ EXPECT_FALSE( |
+ helper()->ShouldThrottleContent(url::Origin(GURL("http://same.com")), |
+ url::Origin(GURL("http://same.com")), |
+ kFlashPluginName, 1000, 1000, nullptr)); |
} |
TEST_F(PluginPowerSaverHelperTest, DisallowCrossOriginUnlessLarge) { |
bool cross_origin_main_content = false; |
- EXPECT_TRUE(helper()->ShouldThrottleContent(GURL("http://b.com"), |
- kFlashPluginName, 100, 100, |
- &cross_origin_main_content)); |
+ EXPECT_TRUE(helper()->ShouldThrottleContent( |
+ url::Origin(GURL("http://same.com")), |
+ url::Origin(GURL("http://other.com")), kFlashPluginName, 100, 100, |
+ &cross_origin_main_content)); |
EXPECT_FALSE(cross_origin_main_content); |
- EXPECT_FALSE(helper()->ShouldThrottleContent(GURL("http://b.com"), |
- kFlashPluginName, 1000, 1000, |
- &cross_origin_main_content)); |
+ EXPECT_FALSE(helper()->ShouldThrottleContent( |
+ url::Origin(GURL("http://same.com")), |
+ url::Origin(GURL("http://other.com")), kFlashPluginName, 1000, 1000, |
+ &cross_origin_main_content)); |
EXPECT_TRUE(cross_origin_main_content); |
} |
TEST_F(PluginPowerSaverHelperTest, AlwaysAllowTinyContent) { |
bool cross_origin_main_content = false; |
- EXPECT_FALSE( |
- helper()->ShouldThrottleContent(GURL(), kFlashPluginName, 1, 1, nullptr)); |
+ EXPECT_FALSE(helper()->ShouldThrottleContent( |
+ url::Origin(GURL("http://same.com")), |
+ url::Origin(GURL("http://same.com")), kFlashPluginName, 1, 1, nullptr)); |
EXPECT_FALSE(cross_origin_main_content); |
- EXPECT_FALSE(helper()->ShouldThrottleContent(GURL("http://b.com"), |
- kFlashPluginName, 1, 1, |
- &cross_origin_main_content)); |
+ EXPECT_FALSE(helper()->ShouldThrottleContent( |
+ url::Origin(GURL("http://same.com")), |
+ url::Origin(GURL("http://other.com")), kFlashPluginName, 1, 1, |
+ &cross_origin_main_content)); |
EXPECT_FALSE(cross_origin_main_content); |
- EXPECT_FALSE(helper()->ShouldThrottleContent(GURL("http://b.com"), |
- kFlashPluginName, 5, 5, |
- &cross_origin_main_content)); |
+ EXPECT_FALSE(helper()->ShouldThrottleContent( |
+ url::Origin(GURL("http://same.com")), |
+ url::Origin(GURL("http://other.com")), kFlashPluginName, 5, 5, |
+ &cross_origin_main_content)); |
EXPECT_FALSE(cross_origin_main_content); |
- EXPECT_TRUE(helper()->ShouldThrottleContent(GURL("http://b.com"), |
- kFlashPluginName, 10, 10, |
- &cross_origin_main_content)); |
+ EXPECT_TRUE(helper()->ShouldThrottleContent( |
+ url::Origin(GURL("http://same.com")), |
+ url::Origin(GURL("http://other.com")), kFlashPluginName, 10, 10, |
+ &cross_origin_main_content)); |
EXPECT_FALSE(cross_origin_main_content); |
} |
TEST_F(PluginPowerSaverHelperTest, TemporaryOriginWhitelist) { |
bool cross_origin_main_content = false; |
- EXPECT_TRUE(helper()->ShouldThrottleContent(GURL("http://b.com"), |
- kFlashPluginName, 100, 100, |
- &cross_origin_main_content)); |
+ EXPECT_TRUE(helper()->ShouldThrottleContent( |
+ url::Origin(GURL("http://same.com")), |
+ url::Origin(GURL("http://other.com")), kFlashPluginName, 100, 100, |
+ &cross_origin_main_content)); |
EXPECT_FALSE(cross_origin_main_content); |
// Clear out other messages so we find just the plugin power saver IPCs. |
sink_->ClearMessages(); |
- helper()->WhitelistContentOrigin(GURL("http://b.com")); |
- EXPECT_FALSE(helper()->ShouldThrottleContent(GURL("http://b.com"), |
- kFlashPluginName, 100, 100, |
- &cross_origin_main_content)); |
+ helper()->WhitelistContentOrigin(url::Origin(GURL("http://other.com"))); |
+ EXPECT_FALSE(helper()->ShouldThrottleContent( |
+ url::Origin(GURL("http://same.com")), |
+ url::Origin(GURL("http://other.com")), kFlashPluginName, 100, 100, |
+ &cross_origin_main_content)); |
EXPECT_FALSE(cross_origin_main_content); |
// Test that we've sent an IPC to the browser. |
@@ -129,16 +143,17 @@ TEST_F(PluginPowerSaverHelperTest, TemporaryOriginWhitelist) { |
EXPECT_EQ(FrameHostMsg_PluginContentOriginAllowed::ID, msg->type()); |
FrameHostMsg_PluginContentOriginAllowed::Param params; |
FrameHostMsg_PluginContentOriginAllowed::Read(msg, ¶ms); |
- EXPECT_EQ(GURL("http://b.com"), base::get<0>(params)); |
+ EXPECT_TRUE(url::Origin(GURL("http://other.com")) |
+ .IsSameOriginWith(base::get<0>(params))); |
} |
TEST_F(PluginPowerSaverHelperTest, UnthrottleOnExPostFactoWhitelist) { |
base::RunLoop loop; |
- frame()->RegisterPeripheralPlugin(GURL("http://other.com"), |
+ frame()->RegisterPeripheralPlugin(url::Origin(GURL("http://other.com")), |
loop.QuitClosure()); |
- std::set<GURL> origin_whitelist; |
- origin_whitelist.insert(GURL("http://other.com")); |
+ std::set<url::Origin> origin_whitelist; |
+ origin_whitelist.insert(url::Origin(GURL("http://other.com"))); |
frame()->OnMessageReceived(FrameMsg_UpdatePluginContentOriginWhitelist( |
frame()->GetRoutingID(), origin_whitelist)); |
@@ -147,15 +162,19 @@ TEST_F(PluginPowerSaverHelperTest, UnthrottleOnExPostFactoWhitelist) { |
} |
TEST_F(PluginPowerSaverHelperTest, ClearWhitelistOnNavigate) { |
- helper()->WhitelistContentOrigin(GURL("http://b.com")); |
+ helper()->WhitelistContentOrigin(url::Origin(GURL("http://other.com"))); |
- EXPECT_FALSE(helper()->ShouldThrottleContent( |
- GURL("http://b.com"), kFlashPluginName, 100, 100, nullptr)); |
+ EXPECT_FALSE( |
+ helper()->ShouldThrottleContent(url::Origin(GURL("http://same.com")), |
+ url::Origin(GURL("http://other.com")), |
+ kFlashPluginName, 100, 100, nullptr)); |
LoadHTML("<html></html>"); |
- EXPECT_TRUE(helper()->ShouldThrottleContent( |
- GURL("http://b.com"), kFlashPluginName, 100, 100, nullptr)); |
+ EXPECT_TRUE( |
+ helper()->ShouldThrottleContent(url::Origin(GURL("http://same.com")), |
+ url::Origin(GURL("http://other.com")), |
+ kFlashPluginName, 100, 100, nullptr)); |
} |
} // namespace content |