Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <utility> | |
| 6 | |
| 7 #include "base/auto_reset.h" | |
| 8 #include "base/bind.h" | |
| 9 #include "base/command_line.h" | |
| 10 #include "base/macros.h" | |
| 11 #include "base/run_loop.h" | |
| 12 #include "base/strings/utf_string_conversions.h" | |
| 13 #include "build/build_config.h" | |
| 14 #include "content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.h" | |
| 15 #include "content/browser/renderer_host/render_widget_host_impl.h" | |
| 16 #include "content/browser/renderer_host/render_widget_host_view_base.h" | |
| 17 #include "content/browser/web_contents/web_contents_impl.h" | |
| 18 #include "content/common/input/synthetic_web_input_event_builders.h" | |
| 19 #include "content/common/input_messages.h" | |
| 20 #include "content/public/browser/render_view_host.h" | |
| 21 #include "content/public/browser/render_widget_host_view.h" | |
| 22 #include "content/public/common/content_switches.h" | |
| 23 #include "content/public/test/browser_test_utils.h" | |
| 24 #include "content/public/test/content_browser_test.h" | |
| 25 #include "content/public/test/content_browser_test_utils.h" | |
| 26 #include "content/public/test/test_utils.h" | |
| 27 #include "content/shell/browser/shell.h" | |
| 28 #include "third_party/WebKit/public/web/WebInputEvent.h" | |
| 29 #include "ui/events/event_switches.h" | |
| 30 #include "ui/events/latency_info.h" | |
| 31 | |
| 32 using blink::WebInputEvent; | |
| 33 | |
| 34 namespace { | |
| 35 | |
| 36 const char kNonBlockingEventDataURL[] = | |
| 37 "data:text/html;charset=utf-8," | |
| 38 "<!DOCTYPE html>" | |
| 39 "<style>" | |
| 40 "html, body {" | |
| 41 " margin: 0;" | |
| 42 "}" | |
| 43 ".spacer { height: 1000px; }" | |
| 44 "</style>" | |
| 45 "<div class=spacer></div>" | |
| 46 "<script>" | |
| 47 " document.addEventListener('wheel', function(e) { while(true) {} }, " | |
| 48 "{'passive': true});" | |
| 49 " document.addEventListener('touchstart', function(e) { while(true) {} }, " | |
| 50 "{'passive': true});" | |
| 51 " document.title='ready';" | |
| 52 "</script>"; | |
| 53 | |
| 54 } // namespace | |
| 55 | |
| 56 namespace content { | |
| 57 | |
| 58 class NonBlockingEventBrowserTest : public ContentBrowserTest { | |
| 59 public: | |
| 60 NonBlockingEventBrowserTest() {} | |
| 61 ~NonBlockingEventBrowserTest() override {} | |
| 62 | |
| 63 RenderWidgetHostImpl* GetWidgetHost() { | |
| 64 return RenderWidgetHostImpl::From( | |
| 65 shell()->web_contents()->GetRenderViewHost()->GetWidget()); | |
| 66 } | |
| 67 | |
| 68 void OnSyntheticGestureCompleted(SyntheticGesture::Result result) { | |
| 69 EXPECT_EQ(SyntheticGesture::GESTURE_FINISHED, result); | |
| 70 } | |
| 71 | |
| 72 protected: | |
| 73 void LoadURL() { | |
| 74 const GURL data_url(kNonBlockingEventDataURL); | |
| 75 NavigateToURL(shell(), data_url); | |
| 76 | |
| 77 RenderWidgetHostImpl* host = GetWidgetHost(); | |
| 78 host->GetView()->SetSize(gfx::Size(400, 400)); | |
| 79 | |
| 80 base::string16 ready_title(base::ASCIIToUTF16("ready")); | |
| 81 TitleWatcher watcher(shell()->web_contents(), ready_title); | |
| 82 ignore_result(watcher.WaitAndGetTitle()); | |
| 83 | |
| 84 MainThreadFrameObserver main_thread_sync(host); | |
| 85 main_thread_sync.Wait(); | |
| 86 } | |
| 87 | |
| 88 // ContentBrowserTest: | |
| 89 void SetUpCommandLine(base::CommandLine* cmd) override { | |
| 90 // TODO(dtapuska): Remove this switch once wheel-gestures ships. | |
| 91 cmd->AppendSwitch(switches::kEnableExperimentalWebPlatformFeatures); | |
| 92 cmd->AppendSwitch(switches::kEnableWheelGestures); | |
| 93 } | |
| 94 | |
| 95 int ExecuteScriptAndExtractInt(const std::string& script) { | |
| 96 int value = 0; | |
| 97 EXPECT_TRUE(content::ExecuteScriptAndExtractInt( | |
| 98 shell()->web_contents(), "domAutomationController.send(" + script + ")", | |
| 99 &value)); | |
| 100 return value; | |
| 101 } | |
| 102 | |
| 103 int GetScrollTop() { | |
| 104 return ExecuteScriptAndExtractInt("document.scrollingElement.scrollTop"); | |
| 105 } | |
| 106 | |
| 107 void DoWheelScroll() { | |
| 108 EXPECT_EQ(0, GetScrollTop()); | |
| 109 | |
| 110 int scrollHeight = | |
| 111 ExecuteScriptAndExtractInt("document.documentElement.scrollHeight"); | |
| 112 EXPECT_EQ(1000, scrollHeight); | |
| 113 | |
| 114 scoped_refptr<FrameWatcher> frame_watcher(new FrameWatcher()); | |
| 115 GetWidgetHost()->GetProcess()->AddFilter(frame_watcher.get()); | |
| 116 scoped_refptr<InputMsgWatcher> input_msg_watcher( | |
| 117 new InputMsgWatcher(GetWidgetHost(), blink::WebInputEvent::MouseWheel)); | |
| 118 | |
| 119 GetWidgetHost()->ForwardWheelEvent( | |
| 120 SyntheticWebMouseWheelEventBuilder::Build(10, 10, 0, -53, 0, true)); | |
| 121 | |
| 122 // Runs until we get the InputMsgAck callback | |
| 123 EXPECT_EQ(INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING, | |
| 124 input_msg_watcher->Wait()); | |
| 125 frame_watcher->WaitFrames(1); | |
| 126 EXPECT_LT(0, frame_watcher->LastMetaData().root_scroll_offset.y()); | |
|
aelias_OOO_until_Jul13
2016/02/10 03:30:23
Why _LT, don't you expect exactly zero? If so it
tdresser
2016/02/10 14:09:41
This is EXPECT'ing that we've scrolled, which is c
dtapuska
2016/02/10 16:46:26
There is a check at the top to assert the scrollto
| |
| 127 } | |
| 128 | |
| 129 void DoTouchScroll() { | |
| 130 EXPECT_EQ(0, GetScrollTop()); | |
| 131 | |
| 132 int scrollHeight = | |
| 133 ExecuteScriptAndExtractInt("document.documentElement.scrollHeight"); | |
| 134 EXPECT_EQ(1000, scrollHeight); | |
| 135 | |
| 136 scoped_refptr<FrameWatcher> frame_watcher(new FrameWatcher()); | |
| 137 GetWidgetHost()->GetProcess()->AddFilter(frame_watcher.get()); | |
| 138 | |
| 139 SyntheticSmoothScrollGestureParams params; | |
| 140 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | |
| 141 params.anchor = gfx::PointF(50, 50); | |
| 142 params.distances.push_back(gfx::Vector2d(0, -45)); | |
| 143 | |
| 144 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | |
| 145 new SyntheticSmoothScrollGesture(params)); | |
| 146 GetWidgetHost()->QueueSyntheticGesture( | |
| 147 std::move(gesture), | |
| 148 base::Bind(&NonBlockingEventBrowserTest::OnSyntheticGestureCompleted, | |
| 149 base::Unretained(this))); | |
| 150 | |
| 151 while (frame_watcher->LastMetaData().root_scroll_offset.y() <= 0) | |
|
aelias_OOO_until_Jul13
2016/02/10 03:30:23
Likewise here, could it be == 0?
dtapuska
2016/02/10 16:46:26
We want to scroll at least one pixel as above.
| |
| 152 frame_watcher->WaitFrames(1); | |
| 153 } | |
| 154 | |
| 155 private: | |
| 156 DISALLOW_COPY_AND_ASSIGN(NonBlockingEventBrowserTest); | |
| 157 }; | |
| 158 | |
| 159 IN_PROC_BROWSER_TEST_F(NonBlockingEventBrowserTest, MouseWheel) { | |
| 160 LoadURL(); | |
| 161 DoWheelScroll(); | |
| 162 } | |
| 163 | |
| 164 IN_PROC_BROWSER_TEST_F(NonBlockingEventBrowserTest, TouchStart) { | |
| 165 LoadURL(); | |
| 166 DoTouchScroll(); | |
| 167 } | |
| 168 | |
| 169 } // namespace content | |
| OLD | NEW |