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

Unified 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, 10 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/web_contents/web_contents_impl_unittest.cc
diff --git a/content/browser/web_contents/web_contents_impl_unittest.cc b/content/browser/web_contents/web_contents_impl_unittest.cc
index 635543d9d0fad61c1e845d752e9fee62c01e56fb..a11682067211757fb11e7c62011d961771a982c4 100644
--- a/content/browser/web_contents/web_contents_impl_unittest.cc
+++ b/content/browser/web_contents/web_contents_impl_unittest.cc
@@ -11,6 +11,7 @@
#include "content/browser/site_instance_impl.h"
#include "content/browser/webui/web_ui_controller_factory_registry.h"
#include "content/common/frame_messages.h"
+#include "content/common/input/synthetic_web_input_event_builders.h"
#include "content/common/view_messages.h"
#include "content/public/browser/global_request_id.h"
#include "content/public/browser/interstitial_page_delegate.h"
@@ -18,6 +19,7 @@
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/render_widget_host_view.h"
+#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_ui_controller.h"
#include "content/public/common/bindings_policy.h"
@@ -2232,4 +2234,93 @@ TEST_F(WebContentsImplTest, GetLastActiveTime) {
EXPECT_FALSE(contents()->GetLastActiveTime().is_null());
}
+class ContentsZoomChangedDelegate : public WebContentsDelegate {
+ public:
+ ContentsZoomChangedDelegate() :
+ contents_zoom_changed_call_count_(0),
+ last_zoom_in_(false) {
+ }
+
+ int GetAndResetContentsZoomChangedCallCount() {
+ int count = contents_zoom_changed_call_count_;
+ contents_zoom_changed_call_count_ = 0;
+ return count;
+ }
+
+ bool last_zoom_in() const {
+ return last_zoom_in_;
+ }
+
+ // WebContentsDelegate:
+ virtual void ContentsZoomChange(bool zoom_in) OVERRIDE {
+ contents_zoom_changed_call_count_++;
+ last_zoom_in_ = zoom_in;
+ }
+
+ private:
+ int contents_zoom_changed_call_count_;
+ bool last_zoom_in_;
+
+ DISALLOW_COPY_AND_ASSIGN(ContentsZoomChangedDelegate);
+};
+
+// Tests that some mouseehweel events get turned into browser zoom requests.
+TEST_F(WebContentsImplTest, HandleWheelEvent) {
+ using blink::WebInputEvent;
+
+ scoped_ptr<ContentsZoomChangedDelegate> delegate(
+ new ContentsZoomChangedDelegate());
+ contents()->SetDelegate(delegate.get());
+
+ int modifiers = 0;
+ float dy = 1;
+ // Verify that normal mouse wheel events do nothing to change the zoom level.
+ blink::WebMouseWheelEvent event =
+ SyntheticWebMouseWheelEventBuilder::Build(0, dy, modifiers, false);
+ EXPECT_FALSE(contents()->HandleWheelEvent(event));
+ EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount());
+
+ modifiers = WebInputEvent::ShiftKey | WebInputEvent::AltKey;
+ event = SyntheticWebMouseWheelEventBuilder::Build(0, dy, modifiers, false);
+ EXPECT_FALSE(contents()->HandleWheelEvent(event));
+ EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount());
+
+ // But whenever the ctrl modifier is applied, they can increase/decrease zoom.
+ // Except on MacOS where we never want to adjust zoom with mousewheel.
+ modifiers = WebInputEvent::ControlKey;
+ event = SyntheticWebMouseWheelEventBuilder::Build(0, dy, modifiers, false);
+ bool handled = contents()->HandleWheelEvent(event);
+#if defined(OS_MACOSX)
+ EXPECT_FALSE(handled);
+ EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount());
+#else
+ EXPECT_TRUE(handled);
+ EXPECT_EQ(1, delegate->GetAndResetContentsZoomChangedCallCount());
+ EXPECT_TRUE(delegate->last_zoom_in());
+#endif
+
+ modifiers = WebInputEvent::ControlKey | WebInputEvent::ShiftKey |
+ WebInputEvent::AltKey;
+ dy = -5;
+ event = SyntheticWebMouseWheelEventBuilder::Build(2, dy, modifiers, false);
+ handled = contents()->HandleWheelEvent(event);
+#if defined(OS_MACOSX)
+ EXPECT_FALSE(handled);
+ EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount());
+#else
+ EXPECT_TRUE(handled);
+ EXPECT_EQ(1, delegate->GetAndResetContentsZoomChangedCallCount());
+ EXPECT_FALSE(delegate->last_zoom_in());
+#endif
+
+ // Unless there is no vertical movement.
+ dy = 0;
+ event = SyntheticWebMouseWheelEventBuilder::Build(2, dy, modifiers, false);
+ EXPECT_FALSE(contents()->HandleWheelEvent(event));
+ EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount());
+
+ // Ensure pointers to the delegate aren't kept beyond it's lifetime.
+ contents()->SetDelegate(NULL);
+}
+
} // namespace content
« 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