OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/web_contents/web_contents_view_aura.h" | 5 #include "content/browser/web_contents/web_contents_view_aura.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #if defined(OS_WIN) | 12 #if defined(OS_WIN) |
13 #include "base/win/windows_version.h" | 13 #include "base/win/windows_version.h" |
14 #endif | 14 #endif |
15 #include "content/browser/frame_host/navigation_controller_impl.h" | 15 #include "content/browser/frame_host/navigation_controller_impl.h" |
16 #include "content/browser/frame_host/navigation_entry_impl.h" | 16 #include "content/browser/frame_host/navigation_entry_impl.h" |
17 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h" | 17 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h" |
18 #include "content/browser/renderer_host/render_widget_host_view_aura.h" | 18 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
19 #include "content/browser/web_contents/web_contents_impl.h" | 19 #include "content/browser/web_contents/web_contents_impl.h" |
20 #include "content/browser/web_contents/web_contents_view.h" | 20 #include "content/browser/web_contents/web_contents_view.h" |
21 #include "content/common/input/synthetic_web_input_event_builders.h" | 21 #include "content/common/input/synthetic_web_input_event_builders.h" |
22 #include "content/common/input_messages.h" | 22 #include "content/common/input_messages.h" |
23 #include "content/common/view_messages.h" | 23 #include "content/common/view_messages.h" |
24 #include "content/public/browser/browser_message_filter.h" | 24 #include "content/public/browser/browser_message_filter.h" |
25 #include "content/public/browser/render_frame_host.h" | 25 #include "content/public/browser/render_frame_host.h" |
| 26 #include "content/public/browser/web_contents_delegate.h" |
26 #include "content/public/browser/web_contents_observer.h" | 27 #include "content/public/browser/web_contents_observer.h" |
27 #include "content/public/common/content_switches.h" | 28 #include "content/public/common/content_switches.h" |
28 #include "content/public/test/browser_test_utils.h" | 29 #include "content/public/test/browser_test_utils.h" |
29 #include "content/public/test/content_browser_test.h" | 30 #include "content/public/test/content_browser_test.h" |
30 #include "content/public/test/content_browser_test_utils.h" | 31 #include "content/public/test/content_browser_test_utils.h" |
31 #include "content/public/test/test_renderer_host.h" | 32 #include "content/public/test/test_renderer_host.h" |
32 #include "content/public/test/test_utils.h" | 33 #include "content/public/test/test_utils.h" |
33 #include "content/shell/browser/shell.h" | 34 #include "content/shell/browser/shell.h" |
34 #include "ui/aura/window.h" | 35 #include "ui/aura/window.h" |
35 #include "ui/aura/window_tree_host.h" | 36 #include "ui/aura/window_tree_host.h" |
36 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 37 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
37 #include "ui/events/event_processor.h" | 38 #include "ui/events/event_processor.h" |
38 #include "ui/events/event_switches.h" | 39 #include "ui/events/event_switches.h" |
39 #include "ui/events/event_utils.h" | 40 #include "ui/events/event_utils.h" |
40 #include "ui/events/test/event_generator.h" | 41 #include "ui/events/test/event_generator.h" |
41 | 42 |
42 namespace { | 43 namespace { |
43 | 44 |
44 // TODO(tdresser): Find a way to avoid sleeping like this. See crbug.com/405282 | 45 // TODO(tdresser): Find a way to avoid sleeping like this. See crbug.com/405282 |
45 // for details. | 46 // for details. |
46 void GiveItSomeTime() { | 47 void GiveItSomeTime() { |
47 base::RunLoop run_loop; | 48 base::RunLoop run_loop; |
48 base::MessageLoop::current()->PostDelayedTask( | 49 base::MessageLoop::current()->PostDelayedTask( |
49 FROM_HERE, | 50 FROM_HERE, |
50 run_loop.QuitClosure(), | 51 run_loop.QuitClosure(), |
51 base::TimeDelta::FromMillisecondsD(10)); | 52 base::TimeDelta::FromMillisecondsD(10)); |
52 run_loop.Run(); | 53 run_loop.Run(); |
53 } | 54 } |
54 | 55 |
| 56 // WebContentsDelegate which tracks vertical overscroll updates. |
| 57 class VerticalOverscrollTracker : public content::WebContentsDelegate { |
| 58 public: |
| 59 VerticalOverscrollTracker() : count_(0), completed_(false) {} |
| 60 virtual ~VerticalOverscrollTracker() {} |
| 61 |
| 62 int num_overscroll_updates() const { |
| 63 return count_; |
| 64 } |
| 65 |
| 66 bool overscroll_completed() const { |
| 67 return completed_; |
| 68 } |
| 69 |
| 70 void Reset() { |
| 71 count_ = 0; |
| 72 completed_ = false; |
| 73 } |
| 74 |
| 75 private: |
| 76 virtual bool CanOverscrollContent() const OVERRIDE { |
| 77 return true; |
| 78 } |
| 79 |
| 80 virtual void OverscrollUpdate(int delta_y) OVERRIDE { |
| 81 ++count_; |
| 82 } |
| 83 |
| 84 virtual void OverscrollComplete() OVERRIDE { |
| 85 completed_ = true; |
| 86 } |
| 87 |
| 88 int count_; |
| 89 bool completed_; |
| 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(VerticalOverscrollTracker); |
| 92 }; |
| 93 |
55 } //namespace | 94 } //namespace |
56 | 95 |
57 | 96 |
58 namespace content { | 97 namespace content { |
59 | 98 |
60 // This class keeps track of the RenderViewHost whose screenshot was captured. | 99 // This class keeps track of the RenderViewHost whose screenshot was captured. |
61 class ScreenshotTracker : public NavigationEntryScreenshotManager { | 100 class ScreenshotTracker : public NavigationEntryScreenshotManager { |
62 public: | 101 public: |
63 explicit ScreenshotTracker(NavigationControllerImpl* controller) | 102 explicit ScreenshotTracker(NavigationControllerImpl* controller) |
64 : NavigationEntryScreenshotManager(controller), | 103 : NavigationEntryScreenshotManager(controller), |
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 scroll_end, ui::LatencyInfo()); | 1002 scroll_end, ui::LatencyInfo()); |
964 WaitAFrame(); | 1003 WaitAFrame(); |
965 | 1004 |
966 if (!navigated) | 1005 if (!navigated) |
967 EXPECT_EQ(10, ExecuteScriptAndExtractInt("touchmoveCount")); | 1006 EXPECT_EQ(10, ExecuteScriptAndExtractInt("touchmoveCount")); |
968 else | 1007 else |
969 EXPECT_GT(10, ExecuteScriptAndExtractInt("touchmoveCount")); | 1008 EXPECT_GT(10, ExecuteScriptAndExtractInt("touchmoveCount")); |
970 } | 1009 } |
971 } | 1010 } |
972 | 1011 |
| 1012 // Test that vertical overscroll updates are sent only when a user overscrolls |
| 1013 // vertically. |
| 1014 #if defined(OS_WIN) |
| 1015 #define MAYBE_VerticalOverscroll DISABLED_VerticalOverscroll |
| 1016 #else |
| 1017 #define MAYBE_VerticalOverscroll VerticalOverscroll |
| 1018 #endif |
| 1019 |
| 1020 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, MAYBE_VerticalOverscroll) { |
| 1021 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 1022 switches::kScrollEndEffect, "1"); |
| 1023 |
| 1024 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("about:blank")); |
| 1025 WebContentsImpl* web_contents = |
| 1026 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 1027 VerticalOverscrollTracker tracker; |
| 1028 web_contents->SetDelegate(&tracker); |
| 1029 |
| 1030 // This test triggers a large number of animations. Speed them up to ensure |
| 1031 // the test completes within its time limit. |
| 1032 ui::ScopedAnimationDurationScaleMode fast_duration_mode( |
| 1033 ui::ScopedAnimationDurationScaleMode::FAST_DURATION); |
| 1034 |
| 1035 aura::Window* content = web_contents->GetContentNativeView(); |
| 1036 ui::EventProcessor* dispatcher = content->GetHost()->event_processor(); |
| 1037 gfx::Rect bounds = content->GetBoundsInRootWindow(); |
| 1038 |
| 1039 // Overscroll horizontally. |
| 1040 { |
| 1041 int kXStep = bounds.width() / 10; |
| 1042 gfx::Point location(bounds.right() - kXStep, bounds.y() + 5); |
| 1043 base::TimeDelta timestamp = ui::EventTimeForNow(); |
| 1044 ui::TouchEvent press( |
| 1045 ui::ET_TOUCH_PRESSED, |
| 1046 location, |
| 1047 0, |
| 1048 timestamp); |
| 1049 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&press); |
| 1050 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1051 WaitAFrame(); |
| 1052 location -= gfx::Vector2d(kXStep, 0); |
| 1053 timestamp += base::TimeDelta::FromMilliseconds(10); |
| 1054 |
| 1055 while (location.x() > bounds.x() + kXStep) { |
| 1056 ui::TouchEvent inc(ui::ET_TOUCH_MOVED, location, 0, timestamp); |
| 1057 details = dispatcher->OnEventFromSource(&inc); |
| 1058 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1059 WaitAFrame(); |
| 1060 location -= gfx::Vector2d(10, 0); |
| 1061 timestamp += base::TimeDelta::FromMilliseconds(10); |
| 1062 } |
| 1063 |
| 1064 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, location, 0, timestamp); |
| 1065 details = dispatcher->OnEventFromSource(&press); |
| 1066 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1067 WaitAFrame(); |
| 1068 |
| 1069 EXPECT_EQ(0, tracker.num_overscroll_updates()); |
| 1070 EXPECT_FALSE(tracker.overscroll_completed()); |
| 1071 } |
| 1072 |
| 1073 // Overscroll vertically. |
| 1074 { |
| 1075 tracker.Reset(); |
| 1076 |
| 1077 int kYStep = bounds.height() / 10; |
| 1078 gfx::Point location(bounds.x() + 10, bounds.y() + kYStep); |
| 1079 base::TimeDelta timestamp = ui::EventTimeForNow(); |
| 1080 ui::TouchEvent press( |
| 1081 ui::ET_TOUCH_PRESSED, |
| 1082 location, |
| 1083 0, |
| 1084 timestamp); |
| 1085 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&press); |
| 1086 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1087 WaitAFrame(); |
| 1088 location += gfx::Vector2d(0, kYStep); |
| 1089 timestamp += base::TimeDelta::FromMilliseconds(10); |
| 1090 |
| 1091 while (location.y() < bounds.bottom() - kYStep) { |
| 1092 ui::TouchEvent inc(ui::ET_TOUCH_MOVED, location, 0, timestamp); |
| 1093 details = dispatcher->OnEventFromSource(&inc); |
| 1094 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1095 WaitAFrame(); |
| 1096 location += gfx::Vector2d(0, kYStep); |
| 1097 timestamp += base::TimeDelta::FromMilliseconds(10); |
| 1098 } |
| 1099 |
| 1100 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, location, 0, timestamp); |
| 1101 details = dispatcher->OnEventFromSource(&release); |
| 1102 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1103 WaitAFrame(); |
| 1104 |
| 1105 EXPECT_LT(0, tracker.num_overscroll_updates()); |
| 1106 EXPECT_TRUE(tracker.overscroll_completed()); |
| 1107 } |
| 1108 |
| 1109 // Start out overscrolling vertically, then switch directions and finish |
| 1110 // overscrolling horizontally. |
| 1111 { |
| 1112 tracker.Reset(); |
| 1113 |
| 1114 int kXStep = bounds.width() / 10; |
| 1115 int kYStep = bounds.height() / 10; |
| 1116 gfx::Point location = bounds.origin() + gfx::Vector2d(0, kYStep); |
| 1117 base::TimeDelta timestamp = ui::EventTimeForNow(); |
| 1118 ui::TouchEvent press( |
| 1119 ui::ET_TOUCH_PRESSED, |
| 1120 location, |
| 1121 0, |
| 1122 timestamp); |
| 1123 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&press); |
| 1124 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1125 WaitAFrame(); |
| 1126 location += gfx::Vector2d(0, kYStep); |
| 1127 timestamp += base::TimeDelta::FromMilliseconds(10); |
| 1128 |
| 1129 for (size_t i = 0; i < 3; ++i) { |
| 1130 ui::TouchEvent inc(ui::ET_TOUCH_MOVED, location, 0, timestamp); |
| 1131 details = dispatcher->OnEventFromSource(&inc); |
| 1132 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1133 WaitAFrame(); |
| 1134 location += gfx::Vector2d(0, kYStep); |
| 1135 timestamp += base::TimeDelta::FromMilliseconds(10); |
| 1136 } |
| 1137 |
| 1138 while (location.x() < bounds.right() - kXStep) { |
| 1139 ui::TouchEvent inc(ui::ET_TOUCH_MOVED, location, 0, timestamp); |
| 1140 details = dispatcher->OnEventFromSource(&inc); |
| 1141 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1142 WaitAFrame(); |
| 1143 location += gfx::Vector2d(kXStep, 0); |
| 1144 timestamp += base::TimeDelta::FromMilliseconds(10); |
| 1145 } |
| 1146 |
| 1147 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, location, 0, timestamp); |
| 1148 details = dispatcher->OnEventFromSource(&release); |
| 1149 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1150 WaitAFrame(); |
| 1151 |
| 1152 EXPECT_LT(0, tracker.num_overscroll_updates()); |
| 1153 EXPECT_FALSE(tracker.overscroll_completed()); |
| 1154 } |
| 1155 } |
| 1156 |
973 } // namespace content | 1157 } // namespace content |
OLD | NEW |