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

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: Merge with trunk (no changes) 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 2194 matching lines...) Expand 10 before | Expand all | Expand 10 after
2225 2227
2226 // Reset the last active time to a known-bad value. 2228 // Reset the last active time to a known-bad value.
2227 contents()->last_active_time_ = base::TimeTicks(); 2229 contents()->last_active_time_ = base::TimeTicks();
2228 ASSERT_TRUE(contents()->GetLastActiveTime().is_null()); 2230 ASSERT_TRUE(contents()->GetLastActiveTime().is_null());
2229 2231
2230 // Simulate activating the WebContents. The active time should update. 2232 // Simulate activating the WebContents. The active time should update.
2231 contents()->WasShown(); 2233 contents()->WasShown();
2232 EXPECT_FALSE(contents()->GetLastActiveTime().is_null()); 2234 EXPECT_FALSE(contents()->GetLastActiveTime().is_null());
2233 } 2235 }
2234 2236
2237 class ContentsZoomChangedDelegate : public WebContentsDelegate {
2238 public:
2239 ContentsZoomChangedDelegate() :
2240 contents_zoom_changed_call_count_(0),
2241 last_zoom_in_(false) {
2242 }
2243
2244 int GetAndResetContentsZoomChangedCallCount() {
2245 int count = contents_zoom_changed_call_count_;
2246 contents_zoom_changed_call_count_ = 0;
2247 return count;
2248 }
2249
2250 bool last_zoom_in() const {
2251 return last_zoom_in_;
2252 }
2253
2254 // WebContentsDelegate:
2255 virtual void ContentsZoomChange(bool zoom_in) OVERRIDE {
2256 contents_zoom_changed_call_count_++;
2257 last_zoom_in_ = zoom_in;
2258 }
2259
2260 private:
2261 int contents_zoom_changed_call_count_;
2262 bool last_zoom_in_;
2263
2264 DISALLOW_COPY_AND_ASSIGN(ContentsZoomChangedDelegate);
2265 };
2266
2267 // Tests that some mouseehweel events get turned into browser zoom requests.
2268 TEST_F(WebContentsImplTest, HandleWheelEvent) {
2269 using blink::WebInputEvent;
2270
2271 scoped_ptr<ContentsZoomChangedDelegate> delegate(
2272 new ContentsZoomChangedDelegate());
2273 contents()->SetDelegate(delegate.get());
2274
2275 int modifiers = 0;
2276 float dy = 1;
2277 // Verify that normal mouse wheel events do nothing to change the zoom level.
2278 blink::WebMouseWheelEvent event =
2279 SyntheticWebMouseWheelEventBuilder::Build(0, dy, modifiers, false);
2280 EXPECT_FALSE(contents()->HandleWheelEvent(event));
2281 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount());
2282
2283 modifiers = WebInputEvent::ShiftKey | WebInputEvent::AltKey;
2284 event = SyntheticWebMouseWheelEventBuilder::Build(0, dy, modifiers, false);
2285 EXPECT_FALSE(contents()->HandleWheelEvent(event));
2286 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount());
2287
2288 // But whenever the ctrl modifier is applied, they can increase/decrease zoom.
2289 // Except on MacOS where we never want to adjust zoom with mousewheel.
2290 modifiers = WebInputEvent::ControlKey;
2291 event = SyntheticWebMouseWheelEventBuilder::Build(0, dy, modifiers, false);
2292 bool handled = contents()->HandleWheelEvent(event);
2293 #if defined(OS_MACOSX)
2294 EXPECT_FALSE(handled);
2295 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount());
2296 #else
2297 EXPECT_TRUE(handled);
2298 EXPECT_EQ(1, delegate->GetAndResetContentsZoomChangedCallCount());
2299 EXPECT_TRUE(delegate->last_zoom_in());
2300 #endif
2301
2302 modifiers = WebInputEvent::ControlKey | WebInputEvent::ShiftKey |
2303 WebInputEvent::AltKey;
2304 dy = -5;
2305 event = SyntheticWebMouseWheelEventBuilder::Build(2, dy, modifiers, false);
2306 handled = contents()->HandleWheelEvent(event);
2307 #if defined(OS_MACOSX)
2308 EXPECT_FALSE(handled);
2309 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount());
2310 #else
2311 EXPECT_TRUE(handled);
2312 EXPECT_EQ(1, delegate->GetAndResetContentsZoomChangedCallCount());
2313 EXPECT_FALSE(delegate->last_zoom_in());
2314 #endif
2315
2316 // Unless there is no vertical movement.
2317 dy = 0;
2318 event = SyntheticWebMouseWheelEventBuilder::Build(2, dy, modifiers, false);
2319 EXPECT_FALSE(contents()->HandleWheelEvent(event));
2320 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount());
2321
2322 // Ensure pointers to the delegate aren't kept beyond it's lifetime.
2323 contents()->SetDelegate(NULL);
2324 }
2325
2235 } // namespace content 2326 } // 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