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

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

Issue 2569273002: Add constructors to WebInputEvents and setters so we can work at cleaning up these public structs. (Closed)
Patch Set: Rebase Created 3 years, 11 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 "content/renderer/pepper/plugin_instance_throttler_impl.h" 5 #include "content/renderer/pepper/plugin_instance_throttler_impl.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "content/public/common/content_switches.h" 13 #include "content/public/common/content_switches.h"
14 #include "content/public/renderer/render_frame.h" 14 #include "content/public/renderer/render_frame.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "third_party/WebKit/public/platform/WebInputEvent.h" 17 #include "third_party/WebKit/public/platform/WebInputEvent.h"
18 #include "third_party/WebKit/public/web/WebPluginParams.h" 18 #include "third_party/WebKit/public/web/WebPluginParams.h"
19 #include "ui/events/base_event_utils.h"
19 #include "ui/gfx/canvas.h" 20 #include "ui/gfx/canvas.h"
20 #include "url/gurl.h" 21 #include "url/gurl.h"
21 #include "url/origin.h" 22 #include "url/origin.h"
22 23
23 using testing::_; 24 using testing::_;
24 using testing::Return; 25 using testing::Return;
25 26
26 namespace content { 27 namespace content {
27 28
28 class PluginInstanceThrottlerImplTest 29 class PluginInstanceThrottlerImplTest
(...skipping 27 matching lines...) Expand all
56 } 57 }
57 58
58 int change_callback_calls() { return change_callback_calls_; } 59 int change_callback_calls() { return change_callback_calls_; }
59 60
60 void EngageThrottle() { throttler_->EngageThrottle(); } 61 void EngageThrottle() { throttler_->EngageThrottle(); }
61 62
62 void SendEventAndTest(blink::WebInputEvent::Type event_type, 63 void SendEventAndTest(blink::WebInputEvent::Type event_type,
63 bool expect_consumed, 64 bool expect_consumed,
64 bool expect_throttled, 65 bool expect_throttled,
65 int expect_change_callback_count) { 66 int expect_change_callback_count) {
66 blink::WebMouseEvent event; 67 blink::WebMouseEvent event(
67 event.type = event_type; 68 event_type, blink::WebInputEvent::Modifiers::LeftButtonDown,
68 event.modifiers = blink::WebInputEvent::Modifiers::LeftButtonDown; 69 ui::EventTimeStampToSeconds(ui::EventTimeForNow()));
69 EXPECT_EQ(expect_consumed, throttler()->ConsumeInputEvent(event)); 70 EXPECT_EQ(expect_consumed, throttler()->ConsumeInputEvent(event));
70 EXPECT_EQ(expect_throttled, throttler()->IsThrottled()); 71 EXPECT_EQ(expect_throttled, throttler()->IsThrottled());
71 EXPECT_EQ(expect_change_callback_count, change_callback_calls()); 72 EXPECT_EQ(expect_change_callback_count, change_callback_calls());
72 } 73 }
73 74
74 private: 75 private:
75 // PluginInstanceThrottlerImpl::Observer 76 // PluginInstanceThrottlerImpl::Observer
76 void OnThrottleStateChange() override { ++change_callback_calls_; } 77 void OnThrottleStateChange() override { ++change_callback_calls_; }
77 78
78 std::unique_ptr<PluginInstanceThrottlerImpl> throttler_; 79 std::unique_ptr<PluginInstanceThrottlerImpl> throttler_;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 } 196 }
196 197
197 TEST_F(PluginInstanceThrottlerImplTest, ThrottleOnLeftClickOnly) { 198 TEST_F(PluginInstanceThrottlerImplTest, ThrottleOnLeftClickOnly) {
198 EXPECT_FALSE(throttler()->IsThrottled()); 199 EXPECT_FALSE(throttler()->IsThrottled());
199 EXPECT_EQ(0, change_callback_calls()); 200 EXPECT_EQ(0, change_callback_calls());
200 201
201 EngageThrottle(); 202 EngageThrottle();
202 EXPECT_TRUE(throttler()->IsThrottled()); 203 EXPECT_TRUE(throttler()->IsThrottled());
203 EXPECT_EQ(1, change_callback_calls()); 204 EXPECT_EQ(1, change_callback_calls());
204 205
205 blink::WebMouseEvent event; 206 blink::WebMouseEvent event(
206 event.type = blink::WebInputEvent::Type::MouseUp; 207 blink::WebInputEvent::Type::MouseUp,
207 208 blink::WebInputEvent::Modifiers::RightButtonDown,
208 event.modifiers = blink::WebInputEvent::Modifiers::RightButtonDown; 209 ui::EventTimeStampToSeconds(ui::EventTimeForNow()));
209 EXPECT_FALSE(throttler()->ConsumeInputEvent(event)); 210 EXPECT_FALSE(throttler()->ConsumeInputEvent(event));
210 EXPECT_TRUE(throttler()->IsThrottled()); 211 EXPECT_TRUE(throttler()->IsThrottled());
211 212
212 event.modifiers = blink::WebInputEvent::Modifiers::MiddleButtonDown; 213 event.setModifiers(blink::WebInputEvent::Modifiers::MiddleButtonDown);
213 EXPECT_TRUE(throttler()->ConsumeInputEvent(event)); 214 EXPECT_TRUE(throttler()->ConsumeInputEvent(event));
214 EXPECT_TRUE(throttler()->IsThrottled()); 215 EXPECT_TRUE(throttler()->IsThrottled());
215 216
216 event.modifiers = blink::WebInputEvent::Modifiers::LeftButtonDown; 217 event.setModifiers(blink::WebInputEvent::Modifiers::LeftButtonDown);
217 EXPECT_TRUE(throttler()->ConsumeInputEvent(event)); 218 EXPECT_TRUE(throttler()->ConsumeInputEvent(event));
218 EXPECT_FALSE(throttler()->IsThrottled()); 219 EXPECT_FALSE(throttler()->IsThrottled());
219 } 220 }
220 221
221 } // namespace content 222 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698