Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 <utility> | 5 #include <utility> |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 #include "content/public/test/test_utils.h" | 26 #include "content/public/test/test_utils.h" |
| 27 #include "content/shell/browser/shell.h" | 27 #include "content/shell/browser/shell.h" |
| 28 #include "third_party/WebKit/public/web/WebInputEvent.h" | 28 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 29 #include "ui/events/event_switches.h" | 29 #include "ui/events/event_switches.h" |
| 30 #include "ui/events/latency_info.h" | 30 #include "ui/events/latency_info.h" |
| 31 | 31 |
| 32 using blink::WebInputEvent; | 32 using blink::WebInputEvent; |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 const char kNonBlockingEventDataURL[] = | 36 // This value has to be larger than the height of the device this test is |
| 37 "data:text/html;charset=utf-8," | 37 // executed on, otherwise the device will be unable to scroll thus failing |
| 38 "<!DOCTYPE html>" | 38 // tests. |
| 39 "<meta name='viewport' content='width=device-width'/>" | 39 const int kWebsiteHeight = 10000; |
| 40 "<style>" | 40 |
| 41 "html, body {" | 41 const std::string kNonBlockingEventDataURL = |
| 42 " margin: 0;" | 42 R"(data:text/html;charset=utf-8, |
|
tdresser
2016/03/11 17:01:24
Sadly C++11 raw string literals aren't allowed in
| |
| 43 "}" | 43 <!DOCTYPE html> |
| 44 ".spacer { height: 1000px; }" | 44 <meta name='viewport' content='width=device-width'/> |
| 45 "</style>" | 45 <style> |
| 46 "<div class=spacer></div>" | 46 html, body { |
| 47 "<script>" | 47 margin: 0; |
| 48 " document.addEventListener('wheel', function(e) { while(true) {} }, " | 48 } |
| 49 "{'passive': true});" | 49 .spacer { height: )" + std::to_string(kWebsiteHeight) + R"(px; } |
| 50 " document.addEventListener('touchstart', function(e) { while(true) {} }, " | 50 </style> |
| 51 "{'passive': true});" | 51 <div class=spacer></div> |
| 52 " document.title='ready';" | 52 <script> |
| 53 "</script>"; | 53 document.addEventListener('wheel', function(e) { while(true) {} }, |
| 54 {'passive': true}); | |
| 55 document.addEventListener('touchstart', function(e) { while(true) {} }, | |
| 56 {'passive': true}); | |
| 57 document.title='ready'; | |
| 58 </script>)"; | |
| 54 | 59 |
| 55 } // namespace | 60 } // namespace |
| 56 | 61 |
| 57 namespace content { | 62 namespace content { |
| 58 | 63 |
| 59 class NonBlockingEventBrowserTest : public ContentBrowserTest { | 64 class NonBlockingEventBrowserTest : public ContentBrowserTest { |
| 60 public: | 65 public: |
| 61 NonBlockingEventBrowserTest() {} | 66 NonBlockingEventBrowserTest() {} |
| 62 ~NonBlockingEventBrowserTest() override {} | 67 ~NonBlockingEventBrowserTest() override {} |
| 63 | 68 |
| 64 RenderWidgetHostImpl* GetWidgetHost() { | 69 RenderWidgetHostImpl* GetWidgetHost() { |
| 65 return RenderWidgetHostImpl::From( | 70 return RenderWidgetHostImpl::From( |
| 66 shell()->web_contents()->GetRenderViewHost()->GetWidget()); | 71 shell()->web_contents()->GetRenderViewHost()->GetWidget()); |
| 67 } | 72 } |
| 68 | 73 |
| 69 void OnSyntheticGestureCompleted(SyntheticGesture::Result result) { | 74 void OnSyntheticGestureCompleted(SyntheticGesture::Result result) { |
| 70 EXPECT_EQ(SyntheticGesture::GESTURE_FINISHED, result); | 75 EXPECT_EQ(SyntheticGesture::GESTURE_FINISHED, result); |
| 71 } | 76 } |
| 72 | 77 |
| 73 protected: | 78 protected: |
| 74 void LoadURL() { | 79 void LoadURL() { |
| 75 const GURL data_url(kNonBlockingEventDataURL); | 80 const GURL data_url(kNonBlockingEventDataURL.c_str()); |
| 76 NavigateToURL(shell(), data_url); | 81 NavigateToURL(shell(), data_url); |
| 77 | 82 |
| 78 RenderWidgetHostImpl* host = GetWidgetHost(); | 83 RenderWidgetHostImpl* host = GetWidgetHost(); |
| 79 host->GetView()->SetSize(gfx::Size(400, 400)); | 84 host->GetView()->SetSize(gfx::Size(400, 400)); |
| 80 | 85 |
| 81 base::string16 ready_title(base::ASCIIToUTF16("ready")); | 86 base::string16 ready_title(base::ASCIIToUTF16("ready")); |
| 82 TitleWatcher watcher(shell()->web_contents(), ready_title); | 87 TitleWatcher watcher(shell()->web_contents(), ready_title); |
| 83 ignore_result(watcher.WaitAndGetTitle()); | 88 ignore_result(watcher.WaitAndGetTitle()); |
| 84 | 89 |
| 85 MainThreadFrameObserver main_thread_sync(host); | 90 MainThreadFrameObserver main_thread_sync(host); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 103 | 108 |
| 104 int GetScrollTop() { | 109 int GetScrollTop() { |
| 105 return ExecuteScriptAndExtractInt("document.scrollingElement.scrollTop"); | 110 return ExecuteScriptAndExtractInt("document.scrollingElement.scrollTop"); |
| 106 } | 111 } |
| 107 | 112 |
| 108 void DoWheelScroll() { | 113 void DoWheelScroll() { |
| 109 EXPECT_EQ(0, GetScrollTop()); | 114 EXPECT_EQ(0, GetScrollTop()); |
| 110 | 115 |
| 111 int scrollHeight = | 116 int scrollHeight = |
| 112 ExecuteScriptAndExtractInt("document.documentElement.scrollHeight"); | 117 ExecuteScriptAndExtractInt("document.documentElement.scrollHeight"); |
| 113 EXPECT_EQ(1000, scrollHeight); | 118 EXPECT_EQ(kWebsiteHeight, scrollHeight); |
| 114 | 119 |
| 115 scoped_refptr<FrameWatcher> frame_watcher(new FrameWatcher()); | 120 scoped_refptr<FrameWatcher> frame_watcher(new FrameWatcher()); |
| 116 GetWidgetHost()->GetProcess()->AddFilter(frame_watcher.get()); | 121 GetWidgetHost()->GetProcess()->AddFilter(frame_watcher.get()); |
| 117 scoped_refptr<InputMsgWatcher> input_msg_watcher( | 122 scoped_refptr<InputMsgWatcher> input_msg_watcher( |
| 118 new InputMsgWatcher(GetWidgetHost(), blink::WebInputEvent::MouseWheel)); | 123 new InputMsgWatcher(GetWidgetHost(), blink::WebInputEvent::MouseWheel)); |
| 119 | 124 |
| 120 GetWidgetHost()->ForwardWheelEvent( | 125 GetWidgetHost()->ForwardWheelEvent( |
| 121 SyntheticWebMouseWheelEventBuilder::Build(10, 10, 0, -53, 0, true)); | 126 SyntheticWebMouseWheelEventBuilder::Build(10, 10, 0, -53, 0, true)); |
| 122 | 127 |
| 123 // Runs until we get the InputMsgAck callback | 128 // Runs until we get the InputMsgAck callback |
| 124 EXPECT_EQ(INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING, | 129 EXPECT_EQ(INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING, |
| 125 input_msg_watcher->WaitForAck()); | 130 input_msg_watcher->WaitForAck()); |
| 126 frame_watcher->WaitFrames(1); | 131 frame_watcher->WaitFrames(1); |
| 127 | 132 |
| 128 // Expect that the compositor scrolled at least one pixel while the | 133 // Expect that the compositor scrolled at least one pixel while the |
| 129 // main thread was in a busy loop. | 134 // main thread was in a busy loop. |
| 130 EXPECT_LT(0, frame_watcher->LastMetadata().root_scroll_offset.y()); | 135 EXPECT_LT(0, frame_watcher->LastMetadata().root_scroll_offset.y()); |
| 131 } | 136 } |
| 132 | 137 |
| 133 void DoTouchScroll() { | 138 void DoTouchScroll() { |
| 134 EXPECT_EQ(0, GetScrollTop()); | 139 EXPECT_EQ(0, GetScrollTop()); |
| 135 | 140 |
| 136 int scrollHeight = | 141 int scrollHeight = |
| 137 ExecuteScriptAndExtractInt("document.documentElement.scrollHeight"); | 142 ExecuteScriptAndExtractInt("document.documentElement.scrollHeight"); |
| 138 EXPECT_EQ(1000, scrollHeight); | 143 EXPECT_EQ(kWebsiteHeight, scrollHeight); |
| 139 | 144 |
| 140 scoped_refptr<FrameWatcher> frame_watcher(new FrameWatcher()); | 145 scoped_refptr<FrameWatcher> frame_watcher(new FrameWatcher()); |
| 141 GetWidgetHost()->GetProcess()->AddFilter(frame_watcher.get()); | 146 GetWidgetHost()->GetProcess()->AddFilter(frame_watcher.get()); |
| 142 | 147 |
| 143 SyntheticSmoothScrollGestureParams params; | 148 SyntheticSmoothScrollGestureParams params; |
| 144 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 149 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
| 145 params.anchor = gfx::PointF(50, 50); | 150 params.anchor = gfx::PointF(50, 50); |
| 146 params.distances.push_back(gfx::Vector2d(0, -45)); | 151 params.distances.push_back(gfx::Vector2d(0, -45)); |
| 147 | 152 |
| 148 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 153 scoped_ptr<SyntheticSmoothScrollGesture> gesture( |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 #define MAYBE_TouchStart DISABLED_TouchStart | 189 #define MAYBE_TouchStart DISABLED_TouchStart |
| 185 #else | 190 #else |
| 186 #define MAYBE_TouchStart TouchStart | 191 #define MAYBE_TouchStart TouchStart |
| 187 #endif | 192 #endif |
| 188 IN_PROC_BROWSER_TEST_F(NonBlockingEventBrowserTest, MAYBE_TouchStart) { | 193 IN_PROC_BROWSER_TEST_F(NonBlockingEventBrowserTest, MAYBE_TouchStart) { |
| 189 LoadURL(); | 194 LoadURL(); |
| 190 DoTouchScroll(); | 195 DoTouchScroll(); |
| 191 } | 196 } |
| 192 | 197 |
| 193 } // namespace content | 198 } // namespace content |
| OLD | NEW |