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

Side by Side Diff: Source/web/tests/WebInputEventConversionTest.cpp

Issue 225303014: [Pinch-to-zoom] Moved scale factor into PinchViewport (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed layout test breakage Created 6 years, 8 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
« no previous file with comments | « Source/web/tests/WebFrameTest.cpp ('k') | Source/web/tests/WebViewTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 26 matching lines...) Expand all
37 #include "URLTestHelpers.h" 37 #include "URLTestHelpers.h"
38 #include "WebFrame.h" 38 #include "WebFrame.h"
39 #include "WebSettings.h" 39 #include "WebSettings.h"
40 #include "WebViewImpl.h" 40 #include "WebViewImpl.h"
41 #include "core/events/GestureEvent.h" 41 #include "core/events/GestureEvent.h"
42 #include "core/events/KeyboardEvent.h" 42 #include "core/events/KeyboardEvent.h"
43 #include "core/events/MouseEvent.h" 43 #include "core/events/MouseEvent.h"
44 #include "core/dom/Touch.h" 44 #include "core/dom/Touch.h"
45 #include "core/events/TouchEvent.h" 45 #include "core/events/TouchEvent.h"
46 #include "core/dom/TouchList.h" 46 #include "core/dom/TouchList.h"
47 #include "core/frame/FrameHost.h"
47 #include "core/frame/FrameView.h" 48 #include "core/frame/FrameView.h"
48 #include "core/frame/LocalFrame.h" 49 #include "core/frame/LocalFrame.h"
49 50
50 using namespace blink; 51 using namespace blink;
51 using namespace WebCore; 52 using namespace WebCore;
52 53
53 namespace { 54 namespace {
54 55
55 PassRefPtrWillBeRawPtr<WebCore::KeyboardEvent> createKeyboardEventWithLocation(W ebCore::KeyboardEvent::KeyLocationCode location) 56 PassRefPtrWillBeRawPtr<WebCore::KeyboardEvent> createKeyboardEventWithLocation(W ebCore::KeyboardEvent::KeyLocationCode location)
56 { 57 {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 98
98 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL.c_s tr()), WebString::fromUTF8("fixed_layout.html")); 99 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL.c_s tr()), WebString::fromUTF8("fixed_layout.html"));
99 FrameTestHelpers::WebViewHelper webViewHelper; 100 FrameTestHelpers::WebViewHelper webViewHelper;
100 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(baseURL + fileNam e, true); 101 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(baseURL + fileNam e, true);
101 webViewImpl->settings()->setViewportEnabled(true); 102 webViewImpl->settings()->setViewportEnabled(true);
102 int pageWidth = 640; 103 int pageWidth = 640;
103 int pageHeight = 480; 104 int pageHeight = 480;
104 webViewImpl->resize(WebSize(pageWidth, pageHeight)); 105 webViewImpl->resize(WebSize(pageWidth, pageHeight));
105 webViewImpl->layout(); 106 webViewImpl->layout();
106 107
107 webViewImpl->setPageScaleFactor(2, WebPoint()); 108 webViewImpl->setPageScaleFactor(2);
108 109
109 FrameView* view = webViewImpl->page()->mainFrame()->view(); 110 FrameView* view = webViewImpl->page()->mainFrame()->view();
110 RefPtr<Document> document = webViewImpl->page()->mainFrame()->document(); 111 RefPtr<Document> document = webViewImpl->page()->mainFrame()->document();
111 DOMWindow* domWindow = webViewImpl->page()->mainFrame()->document()->domWind ow(); 112 DOMWindow* domWindow = webViewImpl->page()->mainFrame()->document()->domWind ow();
112 RenderObject* docRenderer = webViewImpl->page()->mainFrame()->document()->re nderer(); 113 RenderObject* docRenderer = webViewImpl->page()->mainFrame()->document()->re nderer();
113 114
114 { 115 {
115 WebMouseEvent webMouseEvent; 116 WebMouseEvent webMouseEvent;
116 webMouseEvent.type = WebInputEvent::MouseMove; 117 webMouseEvent.type = WebInputEvent::MouseMove;
117 webMouseEvent.x = 10; 118 webMouseEvent.x = 10;
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 305
305 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL.c_s tr()), WebString::fromUTF8("fixed_layout.html")); 306 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL.c_s tr()), WebString::fromUTF8("fixed_layout.html"));
306 FrameTestHelpers::WebViewHelper webViewHelper; 307 FrameTestHelpers::WebViewHelper webViewHelper;
307 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(baseURL + fileNam e, true); 308 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(baseURL + fileNam e, true);
308 webViewImpl->settings()->setViewportEnabled(true); 309 webViewImpl->settings()->setViewportEnabled(true);
309 int pageWidth = 640; 310 int pageWidth = 640;
310 int pageHeight = 480; 311 int pageHeight = 480;
311 webViewImpl->resize(WebSize(pageWidth, pageHeight)); 312 webViewImpl->resize(WebSize(pageWidth, pageHeight));
312 webViewImpl->layout(); 313 webViewImpl->layout();
313 314
314 webViewImpl->setPageScaleFactor(2, WebPoint()); 315 webViewImpl->setPageScaleFactor(2);
315 webViewImpl->setRootLayerTransform(WebSize(10, 20), 1.5); 316 webViewImpl->setRootLayerTransform(WebSize(10, 20), 1.5);
316 317
317 FrameView* view = webViewImpl->page()->mainFrame()->view(); 318 FrameView* view = webViewImpl->page()->mainFrame()->view();
318 RefPtr<Document> document = webViewImpl->page()->mainFrame()->document(); 319 RefPtr<Document> document = webViewImpl->page()->mainFrame()->document();
319 320
320 { 321 {
321 WebMouseEvent webMouseEvent; 322 WebMouseEvent webMouseEvent;
322 webMouseEvent.type = WebInputEvent::MouseMove; 323 webMouseEvent.type = WebInputEvent::MouseMove;
323 webMouseEvent.x = 100; 324 webMouseEvent.x = 100;
324 webMouseEvent.y = 110; 325 webMouseEvent.y = 110;
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 WebGestureEventBuilder recreatedWebGestureEvent(view, docRenderer, *core GestureEvent); 486 WebGestureEventBuilder recreatedWebGestureEvent(view, docRenderer, *core GestureEvent);
486 EXPECT_EQ(webGestureEvent.type, recreatedWebGestureEvent.type); 487 EXPECT_EQ(webGestureEvent.type, recreatedWebGestureEvent.type);
487 EXPECT_EQ(webGestureEvent.x, recreatedWebGestureEvent.x); 488 EXPECT_EQ(webGestureEvent.x, recreatedWebGestureEvent.x);
488 EXPECT_EQ(webGestureEvent.y, recreatedWebGestureEvent.y); 489 EXPECT_EQ(webGestureEvent.y, recreatedWebGestureEvent.y);
489 EXPECT_EQ(webGestureEvent.globalX, recreatedWebGestureEvent.globalX); 490 EXPECT_EQ(webGestureEvent.globalX, recreatedWebGestureEvent.globalX);
490 EXPECT_EQ(webGestureEvent.globalY, recreatedWebGestureEvent.globalY); 491 EXPECT_EQ(webGestureEvent.globalY, recreatedWebGestureEvent.globalY);
491 EXPECT_EQ(webGestureEvent.data.tap.tapCount, recreatedWebGestureEvent.da ta.tap.tapCount); 492 EXPECT_EQ(webGestureEvent.data.tap.tapCount, recreatedWebGestureEvent.da ta.tap.tapCount);
492 } 493 }
493 } 494 }
494 495
496 static void setupVirtualViewportPinch(WebSettings* settings)
497 {
498 settings->setPinchVirtualViewportEnabled(true);
499 settings->setAcceleratedCompositingEnabled(true);
500 }
501
502 TEST(WebInputEventConversionTest, PinchViewportOffset)
503 {
504 const std::string baseURL("http://www.test4.com/");
505 const std::string fileName("fixed_layout.html");
506
507 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL.c_s tr()), WebString::fromUTF8("fixed_layout.html"));
508 FrameTestHelpers::WebViewHelper webViewHelper;
509 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(baseURL + fileNam e, true, 0, 0, setupVirtualViewportPinch);
510 int pageWidth = 640;
511 int pageHeight = 480;
512 webViewImpl->resize(WebSize(pageWidth, pageHeight));
513 webViewImpl->layout();
514
515 webViewImpl->setPageScaleFactor(2);
516
517 IntPoint pinchOffset(35, 60);
518 webViewImpl->page()->frameHost().pinchViewport().setLocation(pinchOffset);
519
520 FrameView* view = webViewImpl->page()->mainFrame()->view();
521
522 {
523 WebMouseEvent webMouseEvent;
524 webMouseEvent.type = WebInputEvent::MouseMove;
525 webMouseEvent.x = 10;
526 webMouseEvent.y = 10;
527 webMouseEvent.windowX = 10;
528 webMouseEvent.windowY = 10;
529 webMouseEvent.globalX = 10;
530 webMouseEvent.globalY = 10;
531
532 PlatformMouseEventBuilder platformMouseBuilder(view, webMouseEvent);
533 EXPECT_EQ(5 + pinchOffset.x(), platformMouseBuilder.position().x());
534 EXPECT_EQ(5 + pinchOffset.y(), platformMouseBuilder.position().y());
535 EXPECT_EQ(10, platformMouseBuilder.globalPosition().x());
536 EXPECT_EQ(10, platformMouseBuilder.globalPosition().y());
537 }
538
539 {
540 WebMouseWheelEvent webMouseWheelEvent;
541 webMouseWheelEvent.type = WebInputEvent::MouseWheel;
542 webMouseWheelEvent.x = 10;
543 webMouseWheelEvent.y = 10;
544 webMouseWheelEvent.windowX = 10;
545 webMouseWheelEvent.windowY = 10;
546 webMouseWheelEvent.globalX = 10;
547 webMouseWheelEvent.globalY = 10;
548
549 PlatformWheelEventBuilder platformWheelBuilder(view, webMouseWheelEvent) ;
550 EXPECT_EQ(5 + pinchOffset.x(), platformWheelBuilder.position().x());
551 EXPECT_EQ(5 + pinchOffset.y(), platformWheelBuilder.position().y());
552 EXPECT_EQ(10, platformWheelBuilder.globalPosition().x());
553 EXPECT_EQ(10, platformWheelBuilder.globalPosition().y());
554 }
555
556 {
557 WebGestureEvent webGestureEvent;
558 webGestureEvent.type = WebInputEvent::GestureScrollUpdate;
559 webGestureEvent.x = 10;
560 webGestureEvent.y = 10;
561 webGestureEvent.globalX = 10;
562 webGestureEvent.globalY = 10;
563
564 PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent );
565 EXPECT_EQ(5 + pinchOffset.x(), platformGestureBuilder.position().x());
566 EXPECT_EQ(5 + pinchOffset.y(), platformGestureBuilder.position().y());
567 EXPECT_EQ(10, platformGestureBuilder.globalPosition().x());
568 EXPECT_EQ(10, platformGestureBuilder.globalPosition().y());
569 }
570
571 {
572 WebTouchEvent webTouchEvent;
573 webTouchEvent.type = WebInputEvent::TouchMove;
574 webTouchEvent.touchesLength = 1;
575 webTouchEvent.touches[0].state = WebTouchPoint::StateMoved;
576 webTouchEvent.touches[0].screenPosition.x = 10.6f;
577 webTouchEvent.touches[0].screenPosition.y = 10.4f;
578 webTouchEvent.touches[0].position.x = 10.6f;
579 webTouchEvent.touches[0].position.y = 10.4f;
580
581 EXPECT_FLOAT_EQ(10.6f, webTouchEvent.touches[0].screenPosition.x);
582 EXPECT_FLOAT_EQ(10.4f, webTouchEvent.touches[0].screenPosition.y);
583 EXPECT_FLOAT_EQ(10.6f, webTouchEvent.touches[0].position.x);
584 EXPECT_FLOAT_EQ(10.4f, webTouchEvent.touches[0].position.y);
585
586 PlatformTouchEventBuilder platformTouchBuilder(view, webTouchEvent);
587 EXPECT_EQ(10, platformTouchBuilder.touchPoints()[0].screenPos().x());
588 EXPECT_EQ(10, platformTouchBuilder.touchPoints()[0].screenPos().y());
589 EXPECT_EQ(5 + pinchOffset.x(), platformTouchBuilder.touchPoints()[0].pos ().x());
590 EXPECT_EQ(5 + pinchOffset.y(), platformTouchBuilder.touchPoints()[0].pos ().y());
591 }
592 }
593
495 } // anonymous namespace 594 } // anonymous namespace
OLDNEW
« no previous file with comments | « Source/web/tests/WebFrameTest.cpp ('k') | Source/web/tests/WebViewTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698