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

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

Issue 1421693002: Plugin Power Saver: Do not always throttle plugins with posters. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@0025-pps-poster-pixel-tests
Patch Set: Created 5 years, 2 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 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"
(...skipping 15 matching lines...) Expand all
26 26
27 void SetUp() override { 27 void SetUp() override {
28 RenderViewTest::SetUp(); 28 RenderViewTest::SetUp();
29 sink_ = &render_thread_->sink(); 29 sink_ = &render_thread_->sink();
30 } 30 }
31 31
32 RenderFrameImpl* frame() { 32 RenderFrameImpl* frame() {
33 return static_cast<RenderFrameImpl*>(view_->GetMainRenderFrame()); 33 return static_cast<RenderFrameImpl*>(view_->GetMainRenderFrame());
34 } 34 }
35 35
36 PluginPowerSaverHelper* helper() {
37 return frame()->plugin_power_saver_helper();
38 }
39
40 blink::WebPluginParams MakeParams(const std::string& url, 36 blink::WebPluginParams MakeParams(const std::string& url,
41 const std::string& poster, 37 const std::string& poster,
42 const std::string& width, 38 const std::string& width,
43 const std::string& height) { 39 const std::string& height) {
44 const size_t size = 3; 40 const size_t size = 3;
45 blink::WebVector<blink::WebString> names(size); 41 blink::WebVector<blink::WebString> names(size);
46 blink::WebVector<blink::WebString> values(size); 42 blink::WebVector<blink::WebString> values(size);
47 43
48 blink::WebPluginParams params; 44 blink::WebPluginParams params;
49 params.url = GURL(url); 45 params.url = GURL(url);
(...skipping 12 matching lines...) Expand all
62 } 58 }
63 59
64 protected: 60 protected:
65 IPC::TestSink* sink_; 61 IPC::TestSink* sink_;
66 62
67 DISALLOW_COPY_AND_ASSIGN(PluginPowerSaverHelperTest); 63 DISALLOW_COPY_AND_ASSIGN(PluginPowerSaverHelperTest);
68 }; 64 };
69 65
70 TEST_F(PluginPowerSaverHelperTest, AllowSameOrigin) { 66 TEST_F(PluginPowerSaverHelperTest, AllowSameOrigin) {
71 EXPECT_FALSE( 67 EXPECT_FALSE(
72 helper()->ShouldThrottleContent(url::Origin(GURL("http://same.com")), 68 frame()->ShouldThrottleContent(url::Origin(GURL("http://same.com")),
73 url::Origin(GURL("http://same.com")), 69 url::Origin(GURL("http://same.com")),
74 kFlashPluginName, 100, 100, nullptr)); 70 kFlashPluginName, 100, 100, nullptr));
75 EXPECT_FALSE( 71 EXPECT_FALSE(
76 helper()->ShouldThrottleContent(url::Origin(GURL("http://same.com")), 72 frame()->ShouldThrottleContent(url::Origin(GURL("http://same.com")),
77 url::Origin(GURL("http://same.com")), 73 url::Origin(GURL("http://same.com")),
78 kFlashPluginName, 1000, 1000, nullptr)); 74 kFlashPluginName, 1000, 1000, nullptr));
79 } 75 }
80 76
81 TEST_F(PluginPowerSaverHelperTest, DisallowCrossOriginUnlessLarge) { 77 TEST_F(PluginPowerSaverHelperTest, DisallowCrossOriginUnlessLarge) {
82 bool cross_origin_main_content = false; 78 bool cross_origin_main_content = false;
83 EXPECT_TRUE(helper()->ShouldThrottleContent( 79 EXPECT_TRUE(frame()->ShouldThrottleContent(
84 url::Origin(GURL("http://same.com")), 80 url::Origin(GURL("http://same.com")),
85 url::Origin(GURL("http://other.com")), kFlashPluginName, 100, 100, 81 url::Origin(GURL("http://other.com")), kFlashPluginName, 100, 100,
86 &cross_origin_main_content)); 82 &cross_origin_main_content));
87 EXPECT_FALSE(cross_origin_main_content); 83 EXPECT_FALSE(cross_origin_main_content);
88 84
89 EXPECT_FALSE(helper()->ShouldThrottleContent( 85 EXPECT_FALSE(frame()->ShouldThrottleContent(
90 url::Origin(GURL("http://same.com")), 86 url::Origin(GURL("http://same.com")),
91 url::Origin(GURL("http://other.com")), kFlashPluginName, 1000, 1000, 87 url::Origin(GURL("http://other.com")), kFlashPluginName, 1000, 1000,
92 &cross_origin_main_content)); 88 &cross_origin_main_content));
93 EXPECT_TRUE(cross_origin_main_content); 89 EXPECT_TRUE(cross_origin_main_content);
94 } 90 }
95 91
96 TEST_F(PluginPowerSaverHelperTest, AlwaysAllowTinyContent) { 92 TEST_F(PluginPowerSaverHelperTest, AlwaysAllowTinyContent) {
97 bool cross_origin_main_content = false; 93 bool cross_origin_main_content = false;
98 EXPECT_FALSE(helper()->ShouldThrottleContent( 94 EXPECT_FALSE(frame()->ShouldThrottleContent(
99 url::Origin(GURL("http://same.com")), 95 url::Origin(GURL("http://same.com")),
100 url::Origin(GURL("http://same.com")), kFlashPluginName, 1, 1, nullptr)); 96 url::Origin(GURL("http://same.com")), kFlashPluginName, 1, 1, nullptr));
101 EXPECT_FALSE(cross_origin_main_content); 97 EXPECT_FALSE(cross_origin_main_content);
102 98
103 EXPECT_FALSE(helper()->ShouldThrottleContent( 99 EXPECT_FALSE(frame()->ShouldThrottleContent(
104 url::Origin(GURL("http://same.com")), 100 url::Origin(GURL("http://same.com")),
105 url::Origin(GURL("http://other.com")), kFlashPluginName, 1, 1, 101 url::Origin(GURL("http://other.com")), kFlashPluginName, 1, 1,
106 &cross_origin_main_content)); 102 &cross_origin_main_content));
107 EXPECT_FALSE(cross_origin_main_content); 103 EXPECT_FALSE(cross_origin_main_content);
108 104
109 EXPECT_FALSE(helper()->ShouldThrottleContent( 105 EXPECT_FALSE(frame()->ShouldThrottleContent(
110 url::Origin(GURL("http://same.com")), 106 url::Origin(GURL("http://same.com")),
111 url::Origin(GURL("http://other.com")), kFlashPluginName, 5, 5, 107 url::Origin(GURL("http://other.com")), kFlashPluginName, 5, 5,
112 &cross_origin_main_content)); 108 &cross_origin_main_content));
113 EXPECT_FALSE(cross_origin_main_content); 109 EXPECT_FALSE(cross_origin_main_content);
114 110
115 EXPECT_TRUE(helper()->ShouldThrottleContent( 111 EXPECT_TRUE(frame()->ShouldThrottleContent(
116 url::Origin(GURL("http://same.com")), 112 url::Origin(GURL("http://same.com")),
117 url::Origin(GURL("http://other.com")), kFlashPluginName, 10, 10, 113 url::Origin(GURL("http://other.com")), kFlashPluginName, 10, 10,
118 &cross_origin_main_content)); 114 &cross_origin_main_content));
119 EXPECT_FALSE(cross_origin_main_content); 115 EXPECT_FALSE(cross_origin_main_content);
120 } 116 }
121 117
122 TEST_F(PluginPowerSaverHelperTest, TemporaryOriginWhitelist) { 118 TEST_F(PluginPowerSaverHelperTest, TemporaryOriginWhitelist) {
123 bool cross_origin_main_content = false; 119 bool cross_origin_main_content = false;
124 EXPECT_TRUE(helper()->ShouldThrottleContent( 120 EXPECT_TRUE(frame()->ShouldThrottleContent(
125 url::Origin(GURL("http://same.com")), 121 url::Origin(GURL("http://same.com")),
126 url::Origin(GURL("http://other.com")), kFlashPluginName, 100, 100, 122 url::Origin(GURL("http://other.com")), kFlashPluginName, 100, 100,
127 &cross_origin_main_content)); 123 &cross_origin_main_content));
128 EXPECT_FALSE(cross_origin_main_content); 124 EXPECT_FALSE(cross_origin_main_content);
129 125
130 // Clear out other messages so we find just the plugin power saver IPCs. 126 // Clear out other messages so we find just the plugin power saver IPCs.
131 sink_->ClearMessages(); 127 sink_->ClearMessages();
132 128
133 helper()->WhitelistContentOrigin(url::Origin(GURL("http://other.com"))); 129 frame()->WhitelistContentOrigin(url::Origin(GURL("http://other.com")));
134 EXPECT_FALSE(helper()->ShouldThrottleContent( 130 EXPECT_FALSE(frame()->ShouldThrottleContent(
135 url::Origin(GURL("http://same.com")), 131 url::Origin(GURL("http://same.com")),
136 url::Origin(GURL("http://other.com")), kFlashPluginName, 100, 100, 132 url::Origin(GURL("http://other.com")), kFlashPluginName, 100, 100,
137 &cross_origin_main_content)); 133 &cross_origin_main_content));
138 EXPECT_FALSE(cross_origin_main_content); 134 EXPECT_FALSE(cross_origin_main_content);
139 135
140 // Test that we've sent an IPC to the browser. 136 // Test that we've sent an IPC to the browser.
141 ASSERT_EQ(1u, sink_->message_count()); 137 ASSERT_EQ(1u, sink_->message_count());
142 const IPC::Message* msg = sink_->GetMessageAt(0); 138 const IPC::Message* msg = sink_->GetMessageAt(0);
143 EXPECT_EQ(FrameHostMsg_PluginContentOriginAllowed::ID, msg->type()); 139 EXPECT_EQ(FrameHostMsg_PluginContentOriginAllowed::ID, msg->type());
144 FrameHostMsg_PluginContentOriginAllowed::Param params; 140 FrameHostMsg_PluginContentOriginAllowed::Param params;
(...skipping 10 matching lines...) Expand all
155 std::set<url::Origin> origin_whitelist; 151 std::set<url::Origin> origin_whitelist;
156 origin_whitelist.insert(url::Origin(GURL("http://other.com"))); 152 origin_whitelist.insert(url::Origin(GURL("http://other.com")));
157 frame()->OnMessageReceived(FrameMsg_UpdatePluginContentOriginWhitelist( 153 frame()->OnMessageReceived(FrameMsg_UpdatePluginContentOriginWhitelist(
158 frame()->GetRoutingID(), origin_whitelist)); 154 frame()->GetRoutingID(), origin_whitelist));
159 155
160 // Runs until the unthrottle closure is run. 156 // Runs until the unthrottle closure is run.
161 loop.Run(); 157 loop.Run();
162 } 158 }
163 159
164 TEST_F(PluginPowerSaverHelperTest, ClearWhitelistOnNavigate) { 160 TEST_F(PluginPowerSaverHelperTest, ClearWhitelistOnNavigate) {
165 helper()->WhitelistContentOrigin(url::Origin(GURL("http://other.com"))); 161 frame()->WhitelistContentOrigin(url::Origin(GURL("http://other.com")));
166 162
167 EXPECT_FALSE( 163 EXPECT_FALSE(
168 helper()->ShouldThrottleContent(url::Origin(GURL("http://same.com")), 164 frame()->ShouldThrottleContent(url::Origin(GURL("http://same.com")),
169 url::Origin(GURL("http://other.com")), 165 url::Origin(GURL("http://other.com")),
170 kFlashPluginName, 100, 100, nullptr)); 166 kFlashPluginName, 100, 100, nullptr));
171 167
172 LoadHTML("<html></html>"); 168 LoadHTML("<html></html>");
173 169
174 EXPECT_TRUE( 170 EXPECT_TRUE(
175 helper()->ShouldThrottleContent(url::Origin(GURL("http://same.com")), 171 frame()->ShouldThrottleContent(url::Origin(GURL("http://same.com")),
176 url::Origin(GURL("http://other.com")), 172 url::Origin(GURL("http://other.com")),
177 kFlashPluginName, 100, 100, nullptr)); 173 kFlashPluginName, 100, 100, nullptr));
178 } 174 }
179 175
180 } // namespace content 176 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/plugin_power_saver_helper.h ('k') | content/renderer/render_frame_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698