1 // Automatically add doNextStepButton to document for manual tests.
2 if (!window.testRunner) {
3 setTimeout(function () {
4 if (window.doNextStepButtonDisabled)
6 doNextStepButton = document.body.insertBefore(document.createElement("button"), document.body.firstChild);
7 doNextStepButton.onclick = doNextStep;
8 doNextStepButton.innerText = "doNextStep button for manual testing. Use keyboard to select button and press (TAB, then SPACE).";
12 function runOnKeyPress(fn)
14 function keypressHandler() {
15 document.removeEventListener('keypress', keypressHandler, false);
18 document.addEventListener('keypress', keypressHandler, false);
20 if (window.testRunner)
21 eventSender.keyDown(" ", []);
24 function doNextStep(args)
27 if (!window.testRunner && args.withUserGesture)
28 return; // Wait for human to press doNextStep button.
30 if (typeof(currentStep) == "undefined")
33 setTimeout(function () {
34 var thisStep = currentStep++;
35 if (thisStep < todo.length)
36 if (args.withUserGesture)
37 runOnKeyPress(todo[thisStep]);
40 else if (thisStep == todo.length)
41 setTimeout(function () { finishJSTest(); }, 0); // Deferred so that excessive doNextStep calls will be observed.
43 testFailed("doNextStep called too many times.");
47 function doNextStepWithUserGesture()
49 doNextStep({withUserGesture: true});
52 function eventExpected(eventHandlerName, message, expectedCalls, targetHanderNode)
54 targetHanderNode[eventHandlerName] = function () {
55 switch (expectedCalls--) {
57 testFailed(eventHandlerName + " received after: " + message);
63 testPassed(eventHandlerName + " received after: " + message);
68 function expectOnlyChangeEvent(message, targetDocument) {
70 targetDocument = targetDocument !== undefined ? targetDocument : document;
71 eventExpected("onpointerlockchange", message, 1, targetDocument);
72 eventExpected("onpointerlockerror", message, 0, targetDocument);
75 function expectOnlyErrorEvent(message, targetDocument) {
77 targetDocument = targetDocument !== undefined ? targetDocument : document;
78 eventExpected("onpointerlockchange", message, 0, targetDocument);
79 eventExpected("onpointerlockerror", message, 1, targetDocument);
82 function expectNoEvents(message, targetDocument) {
84 targetDocument = targetDocument !== undefined ? targetDocument : document;
85 eventExpected("onpointerlockchange", message, 0, targetDocument);
86 eventExpected("onpointerlockerror", message, 0, targetDocument);