OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 function sendTouchStart(touches) { |
| 6 var id = 0; |
| 7 let touchList = touches.map(function(xy) { |
| 8 var touchInit = { |
| 9 identifier: id++, |
| 10 target: viewer.plugin_, |
| 11 clientX: xy.x, |
| 12 clientY: xy.y, |
| 13 }; |
| 14 |
| 15 return new window.Touch(touchInit); |
| 16 }); |
| 17 |
| 18 viewer.plugin_.dispatchEvent(new TouchEvent('touchstart', { |
| 19 touches: touchList, |
| 20 targetTouches: touchList, |
| 21 changedtouches: touchList |
| 22 })); |
| 23 } |
| 24 |
| 25 function createContextMenuEvent() { |
| 26 return new MouseEvent('contextmenu', { |
| 27 cancelable: true, |
| 28 sourceCapabilities: new InputDeviceCapabilities({firesTouchEvents: true}) |
| 29 }); |
| 30 } |
| 31 |
| 32 var tests = [ |
| 33 // Test suppression of the context menu on single touch. |
| 34 function testContextMenuSingleTouch() { |
| 35 sendTouchStart([{x: 10, y: 10}]); |
| 36 |
| 37 let event = createContextMenuEvent(); |
| 38 // Dispatch event will be false if the event is cancellable and one of the |
| 39 // handlers called preventDefault. |
| 40 chrome.test.assertFalse(document.dispatchEvent(event), |
| 41 "Should have called preventDefault() for single touch."); |
| 42 chrome.test.succeed(); |
| 43 }, |
| 44 |
| 45 // Test allowing of context menu on double touch. |
| 46 function testContextMenuDoubleTouch() { |
| 47 sendTouchStart([{x: 10, y: 10}, {x: 15, y: 15}]); |
| 48 |
| 49 let event = createContextMenuEvent(); |
| 50 chrome.test.assertTrue(document.dispatchEvent(event), |
| 51 "Should not have called preventDefault() for double touch."); |
| 52 chrome.test.succeed(); |
| 53 }, |
| 54 |
| 55 // Test long press selects word. |
| 56 function testLongPressSelectsText() { |
| 57 var client = new PDFScriptingAPI(window, window); |
| 58 |
| 59 sendTouchStart([{x: 336, y: 163}]); |
| 60 window.setTimeout(function() { |
| 61 client.getSelectedText(chrome.test.callbackPass(function(selectedText) { |
| 62 chrome.test.assertEq('some', selectedText); |
| 63 })); |
| 64 chrome.test.succeed(); |
| 65 }, 350); |
| 66 } |
| 67 ]; |
| 68 |
| 69 var scriptingAPI = new PDFScriptingAPI(window, window); |
| 70 scriptingAPI.setLoadCallback(function() { |
| 71 chrome.test.runTests(tests); |
| 72 }); |
OLD | NEW |