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 touch_list = touches.map(function(xy) { | |
Kevin McNee
2017/05/04 15:38:55
nit: touchList
dsinclair
2017/05/04 17:55:54
Done.
| |
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: touch_list, | |
20 targetTouches: touch_list, | |
21 changedtouches: touch_list})); | |
Kevin McNee
2017/05/04 15:38:55
nit: formatting https://google.github.io/styleguid
dsinclair
2017/05/04 17:55:54
Done.
| |
22 } | |
23 | |
24 function createContextMenuEvent() { | |
25 return new MouseEvent('contextmenu', { | |
26 cancelable: true, | |
Kevin McNee
2017/05/04 15:38:55
nit: formatting
dsinclair
2017/05/04 17:55:54
Done.
| |
27 sourceCapabilities: new InputDeviceCapabilities({firesTouchEvents: true}) | |
28 }); | |
29 } | |
30 | |
31 var tests = [ | |
32 // Test suppression of the context menu on single touch. | |
33 function testContextMenuSingleTouch() { | |
34 sendTouchStart([{x: 10, y: 10}]); | |
35 | |
36 let event = createContextMenuEvent(); | |
37 // Dispatch event will be false if the event is cancellable and one of the | |
38 // handlers called preventDefault. | |
39 chrome.test.assertFalse(document.dispatchEvent(event), | |
40 "Should have called preventDefault() for single touch."); | |
Kevin McNee
2017/05/04 15:38:55
nit: formatting
dsinclair
2017/05/04 17:55:54
Done.
| |
41 chrome.test.succeed(); | |
42 }, | |
43 | |
44 // Test allowing of context menu on double touch. | |
45 function testContextMenuDoubleTouch() { | |
46 sendTouchStart([{x: 10, y: 10}, {x: 15, y: 15}]); | |
47 | |
48 let event = createContextMenuEvent(); | |
49 chrome.test.assertTrue(document.dispatchEvent(event), | |
50 "Should not have called preventDefault() for double touch."); | |
Kevin McNee
2017/05/04 15:38:55
nit: formatting
dsinclair
2017/05/04 17:55:54
Done.
| |
51 chrome.test.succeed(); | |
52 }, | |
53 | |
54 // Test long press selects word. | |
55 function testLongPressSelectsText() { | |
56 var client = new PDFScriptingAPI(window, window); | |
57 | |
58 sendTouchStart([{x: 336, y: 163}]); | |
59 window.setTimeout(function() { | |
60 client.getSelectedText(chrome.test.callbackPass(function(selectedText) { | |
61 chrome.test.assertEq('some', selectedText); | |
62 })); | |
63 chrome.test.succeed(); | |
64 }, 350); | |
65 } | |
66 ]; | |
67 | |
68 var scriptingAPI = new PDFScriptingAPI(window, window); | |
69 scriptingAPI.setLoadCallback(function() { | |
70 chrome.test.runTests(tests); | |
71 }); | |
OLD | NEW |