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 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 scroll_end, ui::LatencyInfo()); | 1001 scroll_end, ui::LatencyInfo()); |
963 WaitAFrame(); | 1002 WaitAFrame(); |
964 | 1003 |
965 if (!navigated) | 1004 if (!navigated) |
966 EXPECT_EQ(10, ExecuteScriptAndExtractInt("touchmoveCount")); | 1005 EXPECT_EQ(10, ExecuteScriptAndExtractInt("touchmoveCount")); |
967 else | 1006 else |
968 EXPECT_GT(10, ExecuteScriptAndExtractInt("touchmoveCount")); | 1007 EXPECT_GT(10, ExecuteScriptAndExtractInt("touchmoveCount")); |
969 } | 1008 } |
970 } | 1009 } |
971 | 1010 |
| 1011 // Test that vertical overscroll updates are sent only when a user overscrolls |
| 1012 // vertically. |
| 1013 #if defined(OS_WIN) |
| 1014 #define MAYBE_VerticalOverscroll DISABLED_VerticalOverscroll |
| 1015 #else |
| 1016 #define MAYBE_VerticalOverscroll VerticalOverscroll |
| 1017 #endif |
| 1018 |
| 1019 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, MAYBE_VerticalOverscroll) { |
| 1020 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 1021 switches::kScrollEndEffect, "1"); |
| 1022 |
| 1023 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("about:blank")); |
| 1024 WebContentsImpl* web_contents = |
| 1025 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 1026 VerticalOverscrollTracker tracker; |
| 1027 web_contents->SetDelegate(&tracker); |
| 1028 |
| 1029 // This test triggers a large number of animations. Speed them up to ensure |
| 1030 // the test completes within its time limit. |
| 1031 ui::ScopedAnimationDurationScaleMode fast_duration_mode( |
| 1032 ui::ScopedAnimationDurationScaleMode::FAST_DURATION); |
| 1033 |
| 1034 aura::Window* content = web_contents->GetContentNativeView(); |
| 1035 ui::EventProcessor* dispatcher = content->GetHost()->event_processor(); |
| 1036 gfx::Rect bounds = content->GetBoundsInRootWindow(); |
| 1037 |
| 1038 // Overscroll horizontally. |
| 1039 { |
| 1040 int kXStep = bounds.width() / 10; |
| 1041 gfx::Point location(bounds.right() - kXStep, bounds.y() + 5); |
| 1042 base::TimeDelta timestamp = ui::EventTimeForNow(); |
| 1043 ui::TouchEvent press( |
| 1044 ui::ET_TOUCH_PRESSED, |
| 1045 location, |
| 1046 0, |
| 1047 timestamp); |
| 1048 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&press); |
| 1049 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1050 WaitAFrame(); |
| 1051 location -= gfx::Vector2d(kXStep, 0); |
| 1052 timestamp += base::TimeDelta::FromMilliseconds(10); |
| 1053 |
| 1054 while (location.x() > bounds.x() + kXStep) { |
| 1055 ui::TouchEvent inc(ui::ET_TOUCH_MOVED, location, 0, timestamp); |
| 1056 details = dispatcher->OnEventFromSource(&inc); |
| 1057 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1058 WaitAFrame(); |
| 1059 location -= gfx::Vector2d(10, 0); |
| 1060 timestamp += base::TimeDelta::FromMilliseconds(10); |
| 1061 } |
| 1062 |
| 1063 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, location, 0, timestamp); |
| 1064 details = dispatcher->OnEventFromSource(&press); |
| 1065 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1066 WaitAFrame(); |
| 1067 |
| 1068 EXPECT_EQ(0, tracker.num_overscroll_updates()); |
| 1069 EXPECT_FALSE(tracker.overscroll_completed()); |
| 1070 } |
| 1071 |
| 1072 // Overscroll vertically. |
| 1073 { |
| 1074 tracker.Reset(); |
| 1075 |
| 1076 int kYStep = bounds.height() / 10; |
| 1077 gfx::Point location(bounds.x() + 10, bounds.y() + kYStep); |
| 1078 base::TimeDelta timestamp = ui::EventTimeForNow(); |
| 1079 ui::TouchEvent press( |
| 1080 ui::ET_TOUCH_PRESSED, |
| 1081 location, |
| 1082 0, |
| 1083 timestamp); |
| 1084 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&press); |
| 1085 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1086 WaitAFrame(); |
| 1087 location += gfx::Vector2d(0, kYStep); |
| 1088 timestamp += base::TimeDelta::FromMilliseconds(10); |
| 1089 |
| 1090 while (location.y() < bounds.bottom() - kYStep) { |
| 1091 ui::TouchEvent inc(ui::ET_TOUCH_MOVED, location, 0, timestamp); |
| 1092 details = dispatcher->OnEventFromSource(&inc); |
| 1093 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1094 WaitAFrame(); |
| 1095 location += gfx::Vector2d(0, kYStep); |
| 1096 timestamp += base::TimeDelta::FromMilliseconds(10); |
| 1097 } |
| 1098 |
| 1099 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, location, 0, timestamp); |
| 1100 details = dispatcher->OnEventFromSource(&release); |
| 1101 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1102 WaitAFrame(); |
| 1103 |
| 1104 EXPECT_LT(0, tracker.num_overscroll_updates()); |
| 1105 EXPECT_TRUE(tracker.overscroll_completed()); |
| 1106 } |
| 1107 |
| 1108 // Start out overscrolling vertically, then switch directions and finish |
| 1109 // overscrolling horizontally. |
| 1110 { |
| 1111 tracker.Reset(); |
| 1112 |
| 1113 int kXStep = bounds.width() / 10; |
| 1114 int kYStep = bounds.height() / 10; |
| 1115 gfx::Point location = bounds.origin() + gfx::Vector2d(0, kYStep); |
| 1116 base::TimeDelta timestamp = ui::EventTimeForNow(); |
| 1117 ui::TouchEvent press( |
| 1118 ui::ET_TOUCH_PRESSED, |
| 1119 location, |
| 1120 0, |
| 1121 timestamp); |
| 1122 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&press); |
| 1123 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1124 WaitAFrame(); |
| 1125 location += gfx::Vector2d(0, kYStep); |
| 1126 timestamp += base::TimeDelta::FromMilliseconds(10); |
| 1127 |
| 1128 for (size_t i = 0; i < 3; ++i) { |
| 1129 ui::TouchEvent inc(ui::ET_TOUCH_MOVED, location, 0, timestamp); |
| 1130 details = dispatcher->OnEventFromSource(&inc); |
| 1131 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1132 WaitAFrame(); |
| 1133 location += gfx::Vector2d(0, kYStep); |
| 1134 timestamp += base::TimeDelta::FromMilliseconds(10); |
| 1135 } |
| 1136 |
| 1137 while (location.x() < bounds.right() - kXStep) { |
| 1138 ui::TouchEvent inc(ui::ET_TOUCH_MOVED, location, 0, timestamp); |
| 1139 details = dispatcher->OnEventFromSource(&inc); |
| 1140 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1141 WaitAFrame(); |
| 1142 location += gfx::Vector2d(kXStep, 0); |
| 1143 timestamp += base::TimeDelta::FromMilliseconds(10); |
| 1144 } |
| 1145 |
| 1146 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, location, 0, timestamp); |
| 1147 details = dispatcher->OnEventFromSource(&release); |
| 1148 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1149 WaitAFrame(); |
| 1150 |
| 1151 EXPECT_LT(0, tracker.num_overscroll_updates()); |
| 1152 EXPECT_FALSE(tracker.overscroll_completed()); |
| 1153 } |
| 1154 } |
| 1155 |
972 } // namespace content | 1156 } // namespace content |
OLD | NEW |