Chromium Code Reviews| Index: chrome/test/data/pdf/touch_handling_test.js |
| diff --git a/chrome/test/data/pdf/touch_handling_test.js b/chrome/test/data/pdf/touch_handling_test.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..dea713efcb035fd4cf050712965034b06985939e |
| --- /dev/null |
| +++ b/chrome/test/data/pdf/touch_handling_test.js |
| @@ -0,0 +1,71 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +function sendTouchStart(touches) { |
| + var id = 0; |
| + 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.
|
| + var touchInit = { |
| + identifier: id++, |
| + target: viewer.plugin_, |
| + clientX: xy.x, |
| + clientY: xy.y, |
| + }; |
| + |
| + return new window.Touch(touchInit); |
| + }); |
| + |
| + viewer.plugin_.dispatchEvent(new TouchEvent('touchstart', { |
| + touches: touch_list, |
| + targetTouches: touch_list, |
| + 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.
|
| +} |
| + |
| +function createContextMenuEvent() { |
| + return new MouseEvent('contextmenu', { |
| + cancelable: true, |
|
Kevin McNee
2017/05/04 15:38:55
nit: formatting
dsinclair
2017/05/04 17:55:54
Done.
|
| + sourceCapabilities: new InputDeviceCapabilities({firesTouchEvents: true}) |
| + }); |
| +} |
| + |
| +var tests = [ |
| + // Test suppression of the context menu on single touch. |
| + function testContextMenuSingleTouch() { |
| + sendTouchStart([{x: 10, y: 10}]); |
| + |
| + let event = createContextMenuEvent(); |
| + // Dispatch event will be false if the event is cancellable and one of the |
| + // handlers called preventDefault. |
| + chrome.test.assertFalse(document.dispatchEvent(event), |
| + "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.
|
| + chrome.test.succeed(); |
| + }, |
| + |
| + // Test allowing of context menu on double touch. |
| + function testContextMenuDoubleTouch() { |
| + sendTouchStart([{x: 10, y: 10}, {x: 15, y: 15}]); |
| + |
| + let event = createContextMenuEvent(); |
| + chrome.test.assertTrue(document.dispatchEvent(event), |
| + "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.
|
| + chrome.test.succeed(); |
| + }, |
| + |
| + // Test long press selects word. |
| + function testLongPressSelectsText() { |
| + var client = new PDFScriptingAPI(window, window); |
| + |
| + sendTouchStart([{x: 336, y: 163}]); |
| + window.setTimeout(function() { |
| + client.getSelectedText(chrome.test.callbackPass(function(selectedText) { |
| + chrome.test.assertEq('some', selectedText); |
| + })); |
| + chrome.test.succeed(); |
| + }, 350); |
| + } |
| +]; |
| + |
| +var scriptingAPI = new PDFScriptingAPI(window, window); |
| +scriptingAPI.setLoadCallback(function() { |
| + chrome.test.runTests(tests); |
| +}); |