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

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

Issue 2211753002: Plugin Power Saver Tiny: Fix Plugin.PowerSaver.PeripheralHeuristic UMA (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 <tuple> 5 #include <tuple>
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "content/common/frame_messages.h" 9 #include "content/common/frame_messages.h"
10 #include "content/common/view_message_enums.h" 10 #include "content/common/view_message_enums.h"
(...skipping 26 matching lines...) Expand all
37 return static_cast<RenderFrameImpl*>(view_->GetMainRenderFrame()); 37 return static_cast<RenderFrameImpl*>(view_->GetMainRenderFrame());
38 } 38 }
39 39
40 protected: 40 protected:
41 IPC::TestSink* sink_; 41 IPC::TestSink* sink_;
42 42
43 DISALLOW_COPY_AND_ASSIGN(PluginPowerSaverHelperTest); 43 DISALLOW_COPY_AND_ASSIGN(PluginPowerSaverHelperTest);
44 }; 44 };
45 45
46 TEST_F(PluginPowerSaverHelperTest, TemporaryOriginWhitelist) { 46 TEST_F(PluginPowerSaverHelperTest, TemporaryOriginWhitelist) {
47 EXPECT_EQ(RenderFrame::CONTENT_STATUS_PERIPHERAL, 47 EXPECT_EQ(
48 frame()->GetPeripheralContentStatus( 48 RenderFrame::CONTENT_STATUS_PERIPHERAL,
49 url::Origin(GURL("http://same.com")), 49 frame()->GetPeripheralContentStatus(url::Origin(GURL("http://same.com")),
50 url::Origin(GURL("http://other.com")), gfx::Size(100, 100))); 50 url::Origin(GURL("http://other.com")),
51 gfx::Size(100, 100), false));
51 52
52 // Clear out other messages so we find just the plugin power saver IPCs. 53 // Clear out other messages so we find just the plugin power saver IPCs.
53 sink_->ClearMessages(); 54 sink_->ClearMessages();
54 55
55 frame()->WhitelistContentOrigin(url::Origin(GURL("http://other.com"))); 56 frame()->WhitelistContentOrigin(url::Origin(GURL("http://other.com")));
56 57
57 EXPECT_EQ(RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_WHITELISTED, 58 EXPECT_EQ(
58 frame()->GetPeripheralContentStatus( 59 RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_WHITELISTED,
59 url::Origin(GURL("http://same.com")), 60 frame()->GetPeripheralContentStatus(url::Origin(GURL("http://same.com")),
60 url::Origin(GURL("http://other.com")), gfx::Size(100, 100))); 61 url::Origin(GURL("http://other.com")),
62 gfx::Size(100, 100), false));
61 63
62 // Test that we've sent an IPC to the browser. 64 // Test that we've sent an IPC to the browser.
63 ASSERT_EQ(1u, sink_->message_count()); 65 ASSERT_EQ(1u, sink_->message_count());
64 const IPC::Message* msg = sink_->GetMessageAt(0); 66 const IPC::Message* msg = sink_->GetMessageAt(0);
65 EXPECT_EQ(FrameHostMsg_PluginContentOriginAllowed::ID, msg->type()); 67 EXPECT_EQ(FrameHostMsg_PluginContentOriginAllowed::ID, msg->type());
66 FrameHostMsg_PluginContentOriginAllowed::Param params; 68 FrameHostMsg_PluginContentOriginAllowed::Param params;
67 FrameHostMsg_PluginContentOriginAllowed::Read(msg, &params); 69 FrameHostMsg_PluginContentOriginAllowed::Read(msg, &params);
68 EXPECT_TRUE(url::Origin(GURL("http://other.com")) 70 EXPECT_TRUE(url::Origin(GURL("http://other.com"))
69 .IsSameOriginWith(std::get<0>(params))); 71 .IsSameOriginWith(std::get<0>(params)));
70 } 72 }
71 73
72 TEST_F(PluginPowerSaverHelperTest, UnthrottleOnExPostFactoWhitelist) { 74 TEST_F(PluginPowerSaverHelperTest, UnthrottleOnExPostFactoWhitelist) {
73 base::RunLoop loop; 75 base::RunLoop loop;
74 frame()->RegisterPeripheralPlugin(url::Origin(GURL("http://other.com")), 76 frame()->RegisterPeripheralPlugin(url::Origin(GURL("http://other.com")),
75 loop.QuitClosure()); 77 loop.QuitClosure());
76 78
77 std::set<url::Origin> origin_whitelist; 79 std::set<url::Origin> origin_whitelist;
78 origin_whitelist.insert(url::Origin(GURL("http://other.com"))); 80 origin_whitelist.insert(url::Origin(GURL("http://other.com")));
79 frame()->OnMessageReceived(FrameMsg_UpdatePluginContentOriginWhitelist( 81 frame()->OnMessageReceived(FrameMsg_UpdatePluginContentOriginWhitelist(
80 frame()->GetRoutingID(), origin_whitelist)); 82 frame()->GetRoutingID(), origin_whitelist));
81 83
82 // Runs until the unthrottle closure is run. 84 // Runs until the unthrottle closure is run.
83 loop.Run(); 85 loop.Run();
84 } 86 }
85 87
86 TEST_F(PluginPowerSaverHelperTest, ClearWhitelistOnNavigate) { 88 TEST_F(PluginPowerSaverHelperTest, ClearWhitelistOnNavigate) {
87 frame()->WhitelistContentOrigin(url::Origin(GURL("http://other.com"))); 89 frame()->WhitelistContentOrigin(url::Origin(GURL("http://other.com")));
88 90
89 EXPECT_EQ(RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_WHITELISTED, 91 EXPECT_EQ(
90 frame()->GetPeripheralContentStatus( 92 RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_WHITELISTED,
91 url::Origin(GURL("http://same.com")), 93 frame()->GetPeripheralContentStatus(url::Origin(GURL("http://same.com")),
92 url::Origin(GURL("http://other.com")), gfx::Size(100, 100))); 94 url::Origin(GURL("http://other.com")),
95 gfx::Size(100, 100), false));
93 96
94 LoadHTML("<html></html>"); 97 LoadHTML("<html></html>");
95 98
96 EXPECT_EQ(RenderFrame::CONTENT_STATUS_PERIPHERAL, 99 EXPECT_EQ(
97 frame()->GetPeripheralContentStatus( 100 RenderFrame::CONTENT_STATUS_PERIPHERAL,
98 url::Origin(GURL("http://same.com")), 101 frame()->GetPeripheralContentStatus(url::Origin(GURL("http://same.com")),
99 url::Origin(GURL("http://other.com")), gfx::Size(100, 100))); 102 url::Origin(GURL("http://other.com")),
103 gfx::Size(100, 100), false));
100 } 104 }
101 105
102 } // namespace content 106 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698