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

Unified Diff: content/renderer/pepper/plugin_power_saver_helper_browsertest.cc

Issue 1341563002: Plugin Power Saver: Improve origin handling esp. with OOPIF. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/pepper/plugin_power_saver_helper.cc ('k') | content/renderer/render_frame_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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, &params);
- 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
« no previous file with comments | « content/renderer/pepper/plugin_power_saver_helper.cc ('k') | content/renderer/render_frame_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698