Bug 945765 - Add some basic front end apzc tests to catch regressions. r=mbrubeck

This commit is contained in:
Jim Mathies 2013-12-14 14:40:56 -06:00
parent cb5c0faef6
commit 8f6c84ae13
4 changed files with 235 additions and 9 deletions

View File

@ -0,0 +1,117 @@
// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
function test() {
if (!isLandscapeMode()) {
todo(false, "browser_snapped_tests need landscape mode to run.");
return;
}
runTests();
}
let kTransformTimeout = 5000;
let gEdit = null;
let tabAdded = false;
function setUp() {
if (!tabAdded) {
yield addTab(chromeRoot + "res/textdivs01.html");
tabAdded = true;
}
yield hideContextUI();
}
/*
gTests.push({
desc: "soft keyboard reliability",
setUp: setUp,
run: function() {
yield waitForMs(3000);
let edit = Browser.selectedBrowser.contentDocument.getElementById("textinput");
// show the soft keyboard
let keyboardPromise = waitForObserver("metro_softkeyboard_shown", 20000);
sendNativeTap(edit);
yield waitForMs(5000);
sendNativeTap(edit);
yield keyboardPromise;
yield waitForMs(5000);
// hide the soft keyboard / navbar
keyboardPromise = waitForObserver("metro_softkeyboard_hidden", 20000);
sendNativeTap(Browser.selectedBrowser.contentDocument.getElementById("first"));
yield keyboardPromise;
yield waitForMs(5000);
},
tearDown: function () {
clearNativeTouchSequence();
}
});
*/
gTests.push({
desc: "native long tap works",
setUp: setUp,
run: function() {
let edit = Browser.selectedBrowser.contentDocument.getElementById("textinput");
let promise = waitForEvent(document, "popupshown");
sendNativeLongTap(edit);
yield promise;
ContextMenuUI.hide();
},
tearDown: function () {
clearNativeTouchSequence();
}
});
gTests.push({
desc: "double tap transforms",
setUp: setUp,
run: function() {
let beginPromise = waitForObserver("apzc-transform-begin", kTransformTimeout);
let endPromise = waitForObserver("apzc-transform-end", kTransformTimeout);
sendNativeDoubleTap(Browser.selectedBrowser.contentDocument.getElementById("second"));
yield beginPromise;
yield endPromise;
beginPromise = waitForObserver("apzc-transform-begin", kTransformTimeout);
endPromise = waitForObserver("apzc-transform-end", kTransformTimeout);
sendNativeDoubleTap(Browser.selectedBrowser.contentDocument.getElementById("second"));
yield beginPromise;
yield endPromise;
},
tearDown: function () {
clearNativeTouchSequence();
}
});
gTests.push({
desc: "scroll transforms",
setUp: setUp,
run: function() {
let beginPromise = waitForObserver("apzc-transform-begin", kTransformTimeout);
let endPromise = waitForObserver("apzc-transform-end", kTransformTimeout);
var touchdrag = new TouchDragAndHold();
touchdrag.useNativeEvents = true;
touchdrag.nativePointerId = 1;
yield touchdrag.start(Browser.selectedTab.browser.contentWindow,
10, 100, 10, 10);
touchdrag.end();
yield beginPromise;
yield endPromise;
},
tearDown: function () {
clearNativeTouchSequence();
}
});

View File

@ -557,8 +557,11 @@ function waitForObserver(aObsEvent, aTimeoutMs) {
}
/*=============================================================================
Native input synthesis helpers
=============================================================================*/
* Native input helpers - these helpers send input directly to the os
* generating os level input events that get processed by widget and
* apzc logic.
*===========================================================================*/
// Keyboard layouts for use with synthesizeNativeKey
const usEnglish = 0x409;
const arSpanish = 0x2C0A;
@ -640,6 +643,36 @@ function synthesizeNativeMouseMUp(aElement, aOffsetX, aOffsetY) {
0x0040); // MOUSEEVENTF_MIDDLEUP
}
// WARNING: these calls can trigger the soft keyboard on tablets, but not
// on test slaves (bug 947428).
// WARNING: When testing the apzc, be careful of bug 933990. Events sent
// shortly after loading a page may get ignored.
function sendNativeLongTap(aElement, aX, aY) {
let coords = logicalCoordsForElement(aElement, aX, aY);
Browser.windowUtils.sendNativeTouchTap(coords.x, coords.y, true);
}
function sendNativeTap(aElement, aX, aY) {
let coords = logicalCoordsForElement(aElement, aX, aY);
Browser.windowUtils.sendNativeTouchTap(coords.x, coords.y, false);
}
function sendNativeDoubleTap(aElement, aX, aY) {
let coords = logicalCoordsForElement(aElement, aX, aY);
Browser.windowUtils.sendNativeTouchTap(coords.x, coords.y, false);
Browser.windowUtils.sendNativeTouchTap(coords.x, coords.y, false);
}
function clearNativeTouchSequence() {
Browser.windowUtils.clearNativeTouchSequence();
}
/*=============================================================================
* Synthesized event helpers - these helpers synthesize input events that get
* dispatched directly to the dom. As such widget and apzc logic is bypassed.
*===========================================================================*/
/*
* logicalCoordsForElement - given coordinates relative to top-left of
* given element, returns logical coordinates for window. If a non-numeric
@ -784,6 +817,17 @@ TouchDragAndHold.prototype = {
_numSteps: 50,
_debug: false,
_win: null,
_native: false,
_pointerId: 1,
_dui: Components.interfaces.nsIDOMWindowUtils,
set useNativeEvents(aValue) {
this._native = aValue;
},
set nativePointerId(aValue) {
this._pointerId = aValue;
},
callback: function callback() {
if (this._win == null)
@ -795,8 +839,14 @@ TouchDragAndHold.prototype = {
}
if (++this._step.steps >= this._numSteps) {
EventUtils.synthesizeTouchAtPoint(this._endPoint.xPos, this._endPoint.yPos,
{ type: "touchmove" }, this._win);
if (this._native) {
this._utils.sendNativeTouchPoint(this._pointerId, this._dui.TOUCH_CONTACT,
this._endPoint.xPos, this._endPoint.yPos,
1, 90);
} else {
EventUtils.synthesizeTouchAtPoint(this._endPoint.xPos, this._endPoint.yPos,
{ type: "touchmove" }, this._win);
}
this._defer.resolve();
return;
}
@ -805,8 +855,16 @@ TouchDragAndHold.prototype = {
if (this._debug) {
info("[" + this._step.steps + "] touchmove " + this._currentPoint.xPos + " x " + this._currentPoint.yPos);
}
EventUtils.synthesizeTouchAtPoint(this._currentPoint.xPos, this._currentPoint.yPos,
{ type: "touchmove" }, this._win);
if (this._native) {
this._utils.sendNativeTouchPoint(this._pointerId, this._dui.TOUCH_CONTACT,
this._currentPoint.xPos, this._currentPoint.yPos,
1, 90);
} else {
EventUtils.synthesizeTouchAtPoint(this._currentPoint.xPos, this._currentPoint.yPos,
{ type: "touchmove" }, this._win);
}
let self = this;
setTimeout(function () { self.callback(); }, this._timeoutStep);
},
@ -814,13 +872,20 @@ TouchDragAndHold.prototype = {
start: function start(aWindow, aStartX, aStartY, aEndX, aEndY) {
this._defer = Promise.defer();
this._win = aWindow;
this._utils = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
this._endPoint = { xPos: aEndX, yPos: aEndY };
this._currentPoint = { xPos: aStartX, yPos: aStartY };
this._step = { steps: 0, x: (aEndX - aStartX) / this._numSteps, y: (aEndY - aStartY) / this._numSteps };
if (this._debug) {
info("[0] touchstart " + aStartX + " x " + aStartY);
}
EventUtils.synthesizeTouchAtPoint(aStartX, aStartY, { type: "touchstart" }, aWindow);
if (this._native) {
this._utils.sendNativeTouchPoint(this._pointerId, this._dui.TOUCH_CONTACT,
aStartX, aStartY, 1, 90);
} else {
EventUtils.synthesizeTouchAtPoint(aStartX, aStartY, { type: "touchstart" }, aWindow);
}
let self = this;
setTimeout(function () { self.callback(); }, this._timeoutStep);
return this._defer.promise;
@ -847,8 +912,14 @@ TouchDragAndHold.prototype = {
info("[" + this._step.steps + "] touchend " + this._endPoint.xPos + " x " + this._endPoint.yPos);
SelectionHelperUI.debugClearDebugPoints();
}
EventUtils.synthesizeTouchAtPoint(this._endPoint.xPos, this._endPoint.yPos,
{ type: "touchend" }, this._win);
if (this._native) {
this._utils.sendNativeTouchPoint(this._pointerId, this._dui.TOUCH_REMOVE,
this._endPoint.xPos, this._endPoint.yPos,
1, 90);
} else {
EventUtils.synthesizeTouchAtPoint(this._endPoint.xPos, this._endPoint.yPos,
{ type: "touchend" }, this._win);
}
this._win = null;
},
};

View File

@ -24,6 +24,7 @@ support-files =
helpers/ViewStateHelper.js
res/image01.png
res/textblock01.html
res/textdivs01.html
res/textinput01.html
res/textarea01.html
res/testEngine.xml
@ -55,6 +56,7 @@ support-files =
[browser_urlbar.js]
[browser_urlbar_highlightURLs.js]
[browser_urlbar_trimURLs.js]
[browser_apzc_basic.js]
# These tests have known failures in debug builds
[browser_selection_basic.js]

View File

@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<style>
div
{
padding: 25px;
width: 300px;
display: block;
}
</style>
</head>
<body>
<br />
<input id="textinput" style="width:100px; height:25px;" value="The rabbit-hole went straight on like a tunnel for some way and then dipped suddenly down" type="text">
<div id="first">
Alice was beginning to get very tired of sitting by her sister on the bank, and of having
nothing to do: once or twice she had peeped into the book her sister was reading
but it had no pictures or conversations in it, `and what is the use of a book,' thought
Alice `without pictures or conversation?'
</div>
<div id="second">
Alice was beginning to get very tired of sitting by her sister on the bank, and of having
nothing to do: once or twice she had peeped into the book her sister was reading, but it
had no pictures or conversations in it, `and what is the use of a book,' thought Alice
`without pictures or conversation?'
</div>
<div id="third">
So she was considering in her own mind (as well as she could, for the hot day made her
feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth
the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink
eyes ran close by her.
</div>
<div style="height:1000px;"></div>
</body></html>