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

Side by Side Diff: content/renderer/pepper/plugin_power_saver_helper_browsertest.cc

Issue 1528653002: Revert of Plugin Power Saver: Improve Poster behavior for essential plugins. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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/run_loop.h" 5 #include "base/run_loop.h"
6 #include "content/common/frame_messages.h" 6 #include "content/common/frame_messages.h"
7 #include "content/common/view_message_enums.h" 7 #include "content/common/view_message_enums.h"
8 #include "content/public/common/content_constants.h" 8 #include "content/public/common/content_constants.h"
9 #include "content/public/test/frame_load_waiter.h" 9 #include "content/public/test/frame_load_waiter.h"
10 #include "content/public/test/render_view_test.h" 10 #include "content/public/test/render_view_test.h"
11 #include "content/renderer/pepper/plugin_power_saver_helper.h" 11 #include "content/renderer/pepper/plugin_power_saver_helper.h"
12 #include "content/renderer/render_frame_impl.h" 12 #include "content/renderer/render_frame_impl.h"
13 #include "content/renderer/render_view_impl.h" 13 #include "content/renderer/render_view_impl.h"
14 #include "content/test/test_render_frame.h" 14 #include "content/test/test_render_frame.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/WebKit/public/web/WebDocument.h" 16 #include "third_party/WebKit/public/web/WebDocument.h"
17 #include "third_party/WebKit/public/web/WebLocalFrame.h" 17 #include "third_party/WebKit/public/web/WebLocalFrame.h"
18 #include "third_party/WebKit/public/web/WebPluginParams.h" 18 #include "third_party/WebKit/public/web/WebPluginParams.h"
19 #include "ui/gfx/geometry/size.h"
20 #include "url/gurl.h" 19 #include "url/gurl.h"
21 20
22 namespace content { 21 namespace content {
23 22
24 class PluginPowerSaverHelperTest : public RenderViewTest { 23 class PluginPowerSaverHelperTest : public RenderViewTest {
25 public: 24 public:
26 PluginPowerSaverHelperTest() : sink_(NULL) {} 25 PluginPowerSaverHelperTest() : sink_(NULL) {}
27 26
28 void SetUp() override { 27 void SetUp() override {
29 RenderViewTest::SetUp(); 28 RenderViewTest::SetUp();
30 sink_ = &render_thread_->sink(); 29 sink_ = &render_thread_->sink();
31 } 30 }
32 31
33 RenderFrameImpl* frame() { 32 RenderFrameImpl* frame() {
34 return static_cast<RenderFrameImpl*>(view_->GetMainRenderFrame()); 33 return static_cast<RenderFrameImpl*>(view_->GetMainRenderFrame());
35 } 34 }
36 35
36 blink::WebPluginParams MakeParams(const std::string& url,
37 const std::string& poster,
38 const std::string& width,
39 const std::string& height) {
40 const size_t size = 3;
41 blink::WebVector<blink::WebString> names(size);
42 blink::WebVector<blink::WebString> values(size);
43
44 blink::WebPluginParams params;
45 params.url = GURL(url);
46
47 params.attributeNames.swap(names);
48 params.attributeValues.swap(values);
49
50 params.attributeNames[0] = "poster";
51 params.attributeNames[1] = "height";
52 params.attributeNames[2] = "width";
53 params.attributeValues[0] = blink::WebString::fromUTF8(poster);
54 params.attributeValues[1] = blink::WebString::fromUTF8(height);
55 params.attributeValues[2] = blink::WebString::fromUTF8(width);
56
57 return params;
58 }
59
37 protected: 60 protected:
38 IPC::TestSink* sink_; 61 IPC::TestSink* sink_;
39 62
40 DISALLOW_COPY_AND_ASSIGN(PluginPowerSaverHelperTest); 63 DISALLOW_COPY_AND_ASSIGN(PluginPowerSaverHelperTest);
41 }; 64 };
42 65
66 TEST_F(PluginPowerSaverHelperTest, AllowSameOrigin) {
67 EXPECT_FALSE(frame()->ShouldThrottleContent(
68 url::Origin(GURL("http://same.com")),
69 url::Origin(GURL("http://same.com")), 100, 100, nullptr));
70 EXPECT_FALSE(frame()->ShouldThrottleContent(
71 url::Origin(GURL("http://same.com")),
72 url::Origin(GURL("http://same.com")), 1000, 1000, nullptr));
73 }
74
75 TEST_F(PluginPowerSaverHelperTest, DisallowCrossOriginUnlessLarge) {
76 bool cross_origin_main_content = false;
77 EXPECT_TRUE(
78 frame()->ShouldThrottleContent(url::Origin(GURL("http://same.com")),
79 url::Origin(GURL("http://other.com")), 100,
80 100, &cross_origin_main_content));
81 EXPECT_FALSE(cross_origin_main_content);
82
83 EXPECT_FALSE(
84 frame()->ShouldThrottleContent(url::Origin(GURL("http://same.com")),
85 url::Origin(GURL("http://other.com")),
86 1000, 1000, &cross_origin_main_content));
87 EXPECT_TRUE(cross_origin_main_content);
88 }
89
90 TEST_F(PluginPowerSaverHelperTest, AlwaysAllowTinyContent) {
91 bool cross_origin_main_content = false;
92 EXPECT_FALSE(frame()->ShouldThrottleContent(
93 url::Origin(GURL("http://same.com")),
94 url::Origin(GURL("http://same.com")), 1, 1, nullptr));
95 EXPECT_FALSE(cross_origin_main_content);
96
97 EXPECT_FALSE(frame()->ShouldThrottleContent(
98 url::Origin(GURL("http://same.com")),
99 url::Origin(GURL("http://other.com")), 1, 1, &cross_origin_main_content));
100 EXPECT_FALSE(cross_origin_main_content);
101
102 EXPECT_FALSE(frame()->ShouldThrottleContent(
103 url::Origin(GURL("http://same.com")),
104 url::Origin(GURL("http://other.com")), 5, 5, &cross_origin_main_content));
105 EXPECT_FALSE(cross_origin_main_content);
106
107 EXPECT_TRUE(
108 frame()->ShouldThrottleContent(url::Origin(GURL("http://same.com")),
109 url::Origin(GURL("http://other.com")), 10,
110 10, &cross_origin_main_content));
111 EXPECT_FALSE(cross_origin_main_content);
112 }
113
43 TEST_F(PluginPowerSaverHelperTest, TemporaryOriginWhitelist) { 114 TEST_F(PluginPowerSaverHelperTest, TemporaryOriginWhitelist) {
44 EXPECT_EQ(RenderFrame::CONTENT_STATUS_PERIPHERAL, 115 bool cross_origin_main_content = false;
45 frame()->GetPeripheralContentStatus( 116 EXPECT_TRUE(
46 url::Origin(GURL("http://same.com")), 117 frame()->ShouldThrottleContent(url::Origin(GURL("http://same.com")),
47 url::Origin(GURL("http://other.com")), gfx::Size(100, 100))); 118 url::Origin(GURL("http://other.com")), 100,
119 100, &cross_origin_main_content));
120 EXPECT_FALSE(cross_origin_main_content);
48 121
49 // Clear out other messages so we find just the plugin power saver IPCs. 122 // Clear out other messages so we find just the plugin power saver IPCs.
50 sink_->ClearMessages(); 123 sink_->ClearMessages();
51 124
52 frame()->WhitelistContentOrigin(url::Origin(GURL("http://other.com"))); 125 frame()->WhitelistContentOrigin(url::Origin(GURL("http://other.com")));
53 126 EXPECT_FALSE(
54 EXPECT_EQ(RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_WHITELISTED, 127 frame()->ShouldThrottleContent(url::Origin(GURL("http://same.com")),
55 frame()->GetPeripheralContentStatus( 128 url::Origin(GURL("http://other.com")), 100,
56 url::Origin(GURL("http://same.com")), 129 100, &cross_origin_main_content));
57 url::Origin(GURL("http://other.com")), gfx::Size(100, 100))); 130 EXPECT_FALSE(cross_origin_main_content);
58 131
59 // Test that we've sent an IPC to the browser. 132 // Test that we've sent an IPC to the browser.
60 ASSERT_EQ(1u, sink_->message_count()); 133 ASSERT_EQ(1u, sink_->message_count());
61 const IPC::Message* msg = sink_->GetMessageAt(0); 134 const IPC::Message* msg = sink_->GetMessageAt(0);
62 EXPECT_EQ(FrameHostMsg_PluginContentOriginAllowed::ID, msg->type()); 135 EXPECT_EQ(FrameHostMsg_PluginContentOriginAllowed::ID, msg->type());
63 FrameHostMsg_PluginContentOriginAllowed::Param params; 136 FrameHostMsg_PluginContentOriginAllowed::Param params;
64 FrameHostMsg_PluginContentOriginAllowed::Read(msg, &params); 137 FrameHostMsg_PluginContentOriginAllowed::Read(msg, &params);
65 EXPECT_TRUE(url::Origin(GURL("http://other.com")) 138 EXPECT_TRUE(url::Origin(GURL("http://other.com"))
66 .IsSameOriginWith(base::get<0>(params))); 139 .IsSameOriginWith(base::get<0>(params)));
67 } 140 }
68 141
69 TEST_F(PluginPowerSaverHelperTest, UnthrottleOnExPostFactoWhitelist) { 142 TEST_F(PluginPowerSaverHelperTest, UnthrottleOnExPostFactoWhitelist) {
70 base::RunLoop loop; 143 base::RunLoop loop;
71 frame()->RegisterPeripheralPlugin(url::Origin(GURL("http://other.com")), 144 frame()->RegisterPeripheralPlugin(url::Origin(GURL("http://other.com")),
72 loop.QuitClosure()); 145 loop.QuitClosure());
73 146
74 std::set<url::Origin> origin_whitelist; 147 std::set<url::Origin> origin_whitelist;
75 origin_whitelist.insert(url::Origin(GURL("http://other.com"))); 148 origin_whitelist.insert(url::Origin(GURL("http://other.com")));
76 frame()->OnMessageReceived(FrameMsg_UpdatePluginContentOriginWhitelist( 149 frame()->OnMessageReceived(FrameMsg_UpdatePluginContentOriginWhitelist(
77 frame()->GetRoutingID(), origin_whitelist)); 150 frame()->GetRoutingID(), origin_whitelist));
78 151
79 // Runs until the unthrottle closure is run. 152 // Runs until the unthrottle closure is run.
80 loop.Run(); 153 loop.Run();
81 } 154 }
82 155
83 TEST_F(PluginPowerSaverHelperTest, ClearWhitelistOnNavigate) { 156 TEST_F(PluginPowerSaverHelperTest, ClearWhitelistOnNavigate) {
84 frame()->WhitelistContentOrigin(url::Origin(GURL("http://other.com"))); 157 frame()->WhitelistContentOrigin(url::Origin(GURL("http://other.com")));
85 158
86 EXPECT_EQ(RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_WHITELISTED, 159 EXPECT_FALSE(frame()->ShouldThrottleContent(
87 frame()->GetPeripheralContentStatus( 160 url::Origin(GURL("http://same.com")),
88 url::Origin(GURL("http://same.com")), 161 url::Origin(GURL("http://other.com")), 100, 100, nullptr));
89 url::Origin(GURL("http://other.com")), gfx::Size(100, 100)));
90 162
91 LoadHTML("<html></html>"); 163 LoadHTML("<html></html>");
92 164
93 EXPECT_EQ(RenderFrame::CONTENT_STATUS_PERIPHERAL, 165 EXPECT_TRUE(frame()->ShouldThrottleContent(
94 frame()->GetPeripheralContentStatus( 166 url::Origin(GURL("http://same.com")),
95 url::Origin(GURL("http://same.com")), 167 url::Origin(GURL("http://other.com")), 100, 100, nullptr));
96 url::Origin(GURL("http://other.com")), gfx::Size(100, 100)));
97 } 168 }
98 169
99 } // namespace content 170 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/plugin_power_saver_helper.cc ('k') | content/renderer/peripheral_content_heuristic.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698