Bug 1221730 - Update mochitest. r=qdot

--HG--
extra : rebase_source : 981798b3dc3020ad4c4fea717e6dba4ec67fe57f
This commit is contained in:
Chih-Yi Leu 2016-06-28 00:27:00 +02:00
Родитель 810f0727b1
Коммит c2c58e120e
7 изменённых файлов: 135 добавлений и 101 удалений

Просмотреть файл

@ -3,11 +3,10 @@
var GamepadService;
GamepadService = SpecialPowers.Cc["@mozilla.org/gamepad-test;1"].getService(SpecialPowers.Ci.nsIGamepadServiceTest);
var addGamepad = function(name, mapping, buttons, axes) {
return new Promise((resolve, reject) => {
resolve(GamepadService.addGamepad(name, mapping, buttons, axes));
});
}
function runGamepadTest (callback) {
SpecialPowers.pushPrefEnv({"set" : [["dom.gamepad.test.enabled", true]]},
() => {
GamepadService = navigator.requestGamepadServiceTest();
callback();
});
}

Просмотреть файл

@ -10,25 +10,31 @@
<body>
<script type="text/javascript" src="mock_gamepad.js"></script>
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
window.addEventListener("gamepadbuttondown", buttonpresshandler);
var index;
addGamepad("test gamepad 1", // id
SpecialPowers.Ci.nsIGamepadServiceTest.NO_MAPPING,
4, // buttons
2).then(function(i) {
index = i;
// Press a button to make the gamepad visible to the page.
GamepadService.newButtonEvent(index, 0, true);
GamepadService.newButtonEvent(index, 0, true);
});
var timea=0;
var firstPress = true;
var testOver = false;
SimpleTest.waitForExplicitFinish();
runGamepadTest(checkTimestamp);
function checkTimestamp(){
GamepadService.addGamepad("test gamepad 1",
GamepadService.standardMapping,
4,
2).then(function(i) {
index = i;
// Press a button to make the gamepad visible
// to the page.
GamepadService.newButtonEvent(index, 0, true);
GamepadService.newButtonEvent(index, 0, true);
ok(true, "test");
});
}
function cleanup(){
SpecialPowers.executeSoon(function() {
GamepadService.removeGamepad(index);

Просмотреть файл

@ -17,16 +17,29 @@ SimpleTest.waitForExplicitFinish();
// we account for timing before checking values.
window.addEventListener("gamepadconnected", connecthandler);
var index;
// Add a gamepad
addGamepad("test gamepad", // id
SpecialPowers.Ci.nsIGamepadServiceTest.STANDARD_MAPPING,
4,
2).then(function(i) {
index = i;
// Simulate button events on the gamepad we added
GamepadService.newButtonEvent(index, 0, true);
GamepadService.newButtonValueEvent(index, 1, true, 0.5);
});
var testNum = 0;
window.addEventListener("gamepadbuttondown", () => {
SpecialPowers.executeSoon(buttontest1);
});
window.addEventListener("gamepadbuttonup", () => {
SpecialPowers.executeSoon(buttontest2);
});
runGamepadTest(startTest);
function startTest() {
// Add a gamepad
GamepadService.addGamepad("test gamepad", // id
GamepadService.standardMapping,
4,
2).then(function(i) {
index = i;
// Simulate button events on the gamepad we added
GamepadService.newButtonEvent(index, 0, true);
});
}
function connecthandler(e) {
ok(e.gamepad.timestamp <= performance.now(),
@ -36,17 +49,22 @@ function connecthandler(e) {
is(e.gamepad.mapping, "standard", "standard mapping");
is(e.gamepad.buttons.length, 4, "correct number of buttons");
is(e.gamepad.axes.length, 2, "correct number of axes");
// Execute button event tests later, since we need to make sure button
// event updates executed on the parent process first.
SimpleTest.executeSoon(function() {
gamepads = navigator.getGamepads();
is(gamepads[0].buttons[0].pressed, true, "gamepad button should register as pressed");
is(gamepads[0].buttons[1].pressed, true, "gamepad button should register as pressed");
is(gamepads[0].buttons[1].value, 0.5, "gamepad button value should be 0.5");
GamepadService.removeGamepad(index);
SimpleTest.finish();
});
}
function buttontest1() {
var gamepads = navigator.getGamepads();
is(gamepads[0].buttons[0].pressed, true, "gamepad button should register as pressed");
GamepadService.newButtonValueEvent(index, 1, true, 0.5);
}
function buttontest2() {
var gamepads = navigator.getGamepads();
is(gamepads[0].buttons[1].pressed, true, "gamepad button should register as pressed");
is(gamepads[0].buttons[1].value, 0.5, "gamepad button value should be 0.5");
GamepadService.removeGamepad(index);
SimpleTest.finish();
}
</script>
</body>
</html>

Просмотреть файл

@ -24,13 +24,13 @@ function pressButton() {
// Add a gamepad
function startTests() {
addGamepad("test gamepad", // id
SpecialPowers.Ci.nsIGamepadServiceTest.STANDARD_MAPPING,
4, // buttons
2).then(function(i) {
gamepad_index = i;
gamepad_connected()
});
GamepadService.addGamepad("test gamepad", // id
GamepadService.standardMapping,
4, // buttons
2).then(function(i) {
gamepad_index = i;
gamepad_connected()
});
}
var f1, f2;
@ -71,6 +71,6 @@ function test2() {
}
</script>
<iframe id="f1" src="gamepad_frame.html" onload="startTests()"></iframe>
<iframe id="f1" src="gamepad_frame.html" onload="runGamepadTest(startTests)"></iframe>
</body>
</html>

Просмотреть файл

@ -24,19 +24,33 @@ var frames_loaded = 0;
function startTest() {
frames_loaded++;
if (frames_loaded == 2) {
addGamepad("test gamepad", // id
SpecialPowers.Ci.nsIGamepadServiceTest.STANDARD_MAPPING,
4, // buttons
2).then(function(i) {
index = i;
gamepad_loaded();
});
GamepadService.addGamepad("test gamepad", // id
GamepadService.standardMapping,
4, // buttons
2).then(function(i) {
index = i;
gamepad_loaded();
});
}
}
var f1, f2;
function gamepad_loaded() {
f1 = document.getElementById('f1');
f2 = document.getElementById('f2');
let w1 = f1.contentWindow;
let w2 = f2.contentWindow;
w1.addEventListener("gamepadbuttonup", () => {
ok(!f1.contentWindow.gamepad.buttons[0].pressed,
"frame 1 no button pressed");
});
w2.addEventListener("gamepadbuttonup", () => {
ok(!f2.contentWindow.gamepad.buttons[0].pressed,
"frame 2 no button pressed");
setFrameVisible(f2, false);
SpecialPowers.executeSoon(function() {
GamepadService.newButtonEvent(index, 0, true);
});
})
// Now press the button, but don't release it.
GamepadService.newButtonEvent(index, 0, true);
}
@ -59,15 +73,6 @@ function check_button_pressed() {
// Now release the button, then hide the second frame.
GamepadService.newButtonEvent(index, 0, false);
SpecialPowers.executeSoon(function() {
// Now press the button, but don't release it.
ok(!f1.contentWindow.gamepad.buttons[0].pressed, "frame 1 no button pressed");
ok(!f2.contentWindow.gamepad.buttons[0].pressed, "frame 2 no button pressed");
setFrameVisible(f2, false);
SpecialPowers.executeSoon(function() {
GamepadService.newButtonEvent(index, 0, true);
});
});
}
function check_second_frame_no_button_press () {
@ -91,7 +96,7 @@ function check_second_frame_no_button_press () {
}
</script>
<iframe id="f1" src="gamepad_frame_state.html" onload="startTest()"></iframe>
<iframe id="f2" src="gamepad_frame_state.html" onload="startTest()"></iframe>
<iframe id="f1" src="gamepad_frame_state.html" onload="runGamepadTest(startTest)"></iframe>
<iframe id="f2" src="gamepad_frame_state.html" onload="runGamepadTest(startTest)"></iframe>
</body>
</html>

Просмотреть файл

@ -12,6 +12,11 @@
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
window.addEventListener("gamepadbuttondown", function() {
// Wait to ensure that all frames received the button press as well.
SpecialPowers.executeSoon(tests[testNum++]);
});
function pressButton() {
GamepadService.newButtonEvent(index, 0, true);
GamepadService.newButtonEvent(index, 0, false);
@ -26,14 +31,14 @@ function setFrameVisible(f, visible) {
var frames_loaded = 0;
function startTest() {
frames_loaded++;
if (frames_loaded == 2) {
addGamepad("test gamepad", // id
SpecialPowers.Ci.nsIGamepadServiceTest.STANDARD_MAPPING,
4, // buttons
2).then(function(i) {
index = i;
gamepad_loaded();
});
if (frames_loaded == 2) {
GamepadService.addGamepad("test gamepad", // id
GamepadService.standardMapping,
4, // buttons
2).then(function(i) {
index = i;
gamepad_loaded();
});
}
}
var f1, f2;
@ -43,10 +48,7 @@ function gamepad_loaded() {
pressButton();
}
window.addEventListener("gamepadbuttondown", function() {
// Wait to ensure that all frames received the button press as well.
SpecialPowers.executeSoon(tests[testNum++]);
});
var testNum = 0;
var tests = [
@ -60,7 +62,7 @@ function test1() {
// Now hide the second frame and send another button press.
setFrameVisible(f2, false);
SpecialPowers.executeSoon(function() { pressButton(); });
SpecialPowers.executeSoon( () => { pressButton(); });
}
function test2() {
@ -71,7 +73,7 @@ function test2() {
}
</script>
<iframe id="f1" src="gamepad_frame.html" onload="startTest()"></iframe>
<iframe id="f2" src="gamepad_frame.html" onload="startTest()"></iframe>
<iframe id="f1" src="gamepad_frame.html" onload="runGamepadTest(startTest)"></iframe>
<iframe id="f2" src="gamepad_frame.html" onload="runGamepadTest(startTest)"></iframe>
</body>
</html>

Просмотреть файл

@ -24,9 +24,6 @@ function run_next_test(event) {
SpecialPowers.executeSoon(function() { tests[testNum++](event); });
}
// gamepads should be empty first
is(navigator.getGamepads().length, 0, "should be zero gamepads exposed");
function buttonhandler(e) {
run_next_test(e);
}
@ -36,15 +33,22 @@ function disconnecthandler(e) {
}
window.addEventListener("gamepadbuttondown", buttonhandler);
window.addEventListener("gamepaddisconnected", disconnecthandler);
// Add a gamepad
addGamepad("test gamepad 1", // id
SpecialPowers.Ci.nsIGamepadServiceTest.NO_MAPPING,
4, // buttons
2).then(function(index) {
internal_index1 = index;
// Press a button to make the gamepad visible to the page.
GamepadService.newButtonEvent(internal_index1, 0, true);
});
runGamepadTest(startTest)
function startTest() {
// gamepads should be empty first
is(navigator.getGamepads().length, 0, "should be zero gamepads exposed");
// Add a gamepad
GamepadService.addGamepad("test gamepad 1", // id
GamepadService.standardMapping,
4, // buttons
2).then(function(index) {
internal_index1 = index;
// Press a button to make the gamepad visible to the page.
GamepadService.newButtonEvent(internal_index1, 0, true);
});
}
var content_index1 = 0;
var internal_index2;
@ -59,13 +63,13 @@ function check_first_gamepad(e) {
is(gamepads[e.gamepad.index], e.gamepad, "right gamepad exposed at index");
is(gamepads[content_index1], e.gamepad, "gamepad counter working correctly");
// Add a second gamepad, should automatically show up.
addGamepad("test gamepad 2", // id
SpecialPowers.Ci.nsIGamepadServiceTest.NO_MAPPING,
4, // buttons
2).then(function(index) {
internal_index2 = index;
GamepadService.newButtonEvent(internal_index2, 0, true);
});
GamepadService.addGamepad("test gamepad 2", // id
GamepadService.standardMapping,
4, // buttons
2).then(function(index) {
internal_index2 = index;
GamepadService.newButtonEvent(internal_index2, 0, true);
});
ok(true, "Done checking first gamepad");
}