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

Side by Side Diff: content/browser/web_contents/web_contents_impl_unittest.cc

Issue 177213016: Give blink a chance to consume ctrl+wheel events before zooming (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add tests Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
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 "base/logging.h" 5 #include "base/logging.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "content/browser/frame_host/interstitial_page_impl.h" 7 #include "content/browser/frame_host/interstitial_page_impl.h"
8 #include "content/browser/frame_host/navigation_entry_impl.h" 8 #include "content/browser/frame_host/navigation_entry_impl.h"
9 #include "content/browser/renderer_host/cross_site_transferring_request.h" 9 #include "content/browser/renderer_host/cross_site_transferring_request.h"
10 #include "content/browser/renderer_host/render_view_host_impl.h" 10 #include "content/browser/renderer_host/render_view_host_impl.h"
11 #include "content/browser/site_instance_impl.h" 11 #include "content/browser/site_instance_impl.h"
12 #include "content/browser/webui/web_ui_controller_factory_registry.h" 12 #include "content/browser/webui/web_ui_controller_factory_registry.h"
13 #include "content/common/frame_messages.h" 13 #include "content/common/frame_messages.h"
14 #include "content/common/input/synthetic_web_input_event_builders.h"
14 #include "content/common/view_messages.h" 15 #include "content/common/view_messages.h"
15 #include "content/public/browser/global_request_id.h" 16 #include "content/public/browser/global_request_id.h"
16 #include "content/public/browser/interstitial_page_delegate.h" 17 #include "content/public/browser/interstitial_page_delegate.h"
17 #include "content/public/browser/navigation_details.h" 18 #include "content/public/browser/navigation_details.h"
18 #include "content/public/browser/notification_details.h" 19 #include "content/public/browser/notification_details.h"
19 #include "content/public/browser/notification_source.h" 20 #include "content/public/browser/notification_source.h"
20 #include "content/public/browser/render_widget_host_view.h" 21 #include "content/public/browser/render_widget_host_view.h"
22 #include "content/public/browser/web_contents_delegate.h"
21 #include "content/public/browser/web_contents_observer.h" 23 #include "content/public/browser/web_contents_observer.h"
22 #include "content/public/browser/web_ui_controller.h" 24 #include "content/public/browser/web_ui_controller.h"
23 #include "content/public/common/bindings_policy.h" 25 #include "content/public/common/bindings_policy.h"
24 #include "content/public/common/content_constants.h" 26 #include "content/public/common/content_constants.h"
25 #include "content/public/common/url_constants.h" 27 #include "content/public/common/url_constants.h"
26 #include "content/public/common/url_utils.h" 28 #include "content/public/common/url_utils.h"
27 #include "content/public/test/mock_render_process_host.h" 29 #include "content/public/test/mock_render_process_host.h"
28 #include "content/public/test/test_utils.h" 30 #include "content/public/test/test_utils.h"
29 #include "content/test/test_content_browser_client.h" 31 #include "content/test/test_content_browser_client.h"
30 #include "content/test/test_content_client.h" 32 #include "content/test/test_content_client.h"
(...skipping 2192 matching lines...) Expand 10 before | Expand all | Expand 10 after
2223 2225
2224 // Reset the last active time to a known-bad value. 2226 // Reset the last active time to a known-bad value.
2225 contents()->last_active_time_ = base::TimeTicks(); 2227 contents()->last_active_time_ = base::TimeTicks();
2226 ASSERT_TRUE(contents()->GetLastActiveTime().is_null()); 2228 ASSERT_TRUE(contents()->GetLastActiveTime().is_null());
2227 2229
2228 // Simulate activating the WebContents. The active time should update. 2230 // Simulate activating the WebContents. The active time should update.
2229 contents()->WasShown(); 2231 contents()->WasShown();
2230 EXPECT_FALSE(contents()->GetLastActiveTime().is_null()); 2232 EXPECT_FALSE(contents()->GetLastActiveTime().is_null());
2231 } 2233 }
2232 2234
2235 class ContentsZoomChangedDelegate : public WebContentsDelegate {
2236 public:
2237 ContentsZoomChangedDelegate() :
2238 contents_zoom_changed_call_count_(0),
2239 last_zoom_in_(false)
sadrul 2014/03/03 12:37:56 brace here
Rick Byers 2014/03/03 14:52:53 Done.
2240 {
2241 }
2242
2243 int GetAndResetContentsZoomChangedCallCount() {
2244 int count = contents_zoom_changed_call_count_;
2245 contents_zoom_changed_call_count_ = 0;
2246 return count;
2247 }
2248
2249 bool last_zoom_in() const {
2250 return last_zoom_in_;
2251 }
2252
2253 // WebContentsDelegate:
2254 virtual void ContentsZoomChange(bool zoom_in) OVERRIDE {
2255 contents_zoom_changed_call_count_++;
2256 last_zoom_in_ = zoom_in;
2257 }
2258
2259 private:
2260 int contents_zoom_changed_call_count_;
2261 bool last_zoom_in_;
sadrul 2014/03/03 12:37:56 DISALLOW_COPY_..
Rick Byers 2014/03/03 14:52:53 Done.
2262 };
2263
2264 // Tests that some mouseehweel events get turned into browser zoom requests.
2265 TEST_F(WebContentsImplTest, HandleWheelEvent) {
2266 using blink::WebInputEvent;
2267
2268 scoped_ptr<ContentsZoomChangedDelegate> delegate(
2269 new ContentsZoomChangedDelegate());
2270 contents()->SetDelegate(delegate.get());
2271
2272 int modifiers = 0;
2273 float dy = 1;
2274 // Verify that normal mouse wheel events do nothing to change the zoom level.
2275 blink::WebMouseWheelEvent event =
2276 SyntheticWebMouseWheelEventBuilder::Build(0, dy, modifiers, false);
2277 EXPECT_FALSE(contents()->HandleWheelEvent(event));
2278 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount());
2279
2280 modifiers = WebInputEvent::ShiftKey | WebInputEvent::AltKey;
2281 event = SyntheticWebMouseWheelEventBuilder::Build(0, dy, modifiers, false);
2282 EXPECT_FALSE(contents()->HandleWheelEvent(event));
2283 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount());
2284
2285 // But whenever the ctrl modifier is applied, they can increase/decrease zoom.
2286 // Except on MacOS where we never want to adjust zoom with mousewheel.
2287 modifiers = WebInputEvent::ControlKey;
2288 event = SyntheticWebMouseWheelEventBuilder::Build(0, dy, modifiers, false);
2289 bool handled = contents()->HandleWheelEvent(event);
2290 #if defined(OS_MACOSX)
2291 EXPECT_FALSE(handled);
2292 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount());
2293 #else
2294 EXPECT_TRUE(handled);
2295 EXPECT_EQ(1, delegate->GetAndResetContentsZoomChangedCallCount());
2296 EXPECT_TRUE(delegate->last_zoom_in());
2297 #endif
2298
2299 modifiers = WebInputEvent::ControlKey | WebInputEvent::ShiftKey |
2300 WebInputEvent::AltKey;
2301 dy = -5;
2302 event = SyntheticWebMouseWheelEventBuilder::Build(2, dy, modifiers, false);
2303 handled = contents()->HandleWheelEvent(event);
2304 #if defined(OS_MACOSX)
2305 EXPECT_FALSE(handled);
2306 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount());
2307 #else
2308 EXPECT_TRUE(handled);
2309 EXPECT_EQ(1, delegate->GetAndResetContentsZoomChangedCallCount());
2310 EXPECT_FALSE(delegate->last_zoom_in());
2311 #endif
2312
2313 // Unless there is no vertical movement.
2314 dy = 0;
2315 event = SyntheticWebMouseWheelEventBuilder::Build(2, dy, modifiers, false);
2316 EXPECT_FALSE(contents()->HandleWheelEvent(event));
2317 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount());
2318
2319 // Ensure pointers to the delegate aren't kept beyond it's lifetime.
2320 contents()->SetDelegate(NULL);
2321 }
2322
2233 } // namespace content 2323 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl.cc ('k') | content/renderer/input/input_handler_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698