Bug 1026350 - Part 2: Test Case. r=baku

This commit is contained in:
James Cheng 2015-04-08 03:08:00 -04:00
parent d7b40ea760
commit 9e884ae2e6
5 changed files with 207 additions and 0 deletions

View File

@ -0,0 +1,5 @@
[DEFAULT]
skip-if = buildapp != 'b2g'
[test_inputport_get_inputports.html]
[test_inputport_connection_event.html]

View File

@ -0,0 +1,72 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1026350
-->
<head>
<meta charset="utf-8">
<title>Test Inputport Connection Event</title>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1026350">Test Inputport Connection Event
</a>
<script type="application/javascript;version=1.8">
'use strict';
SimpleTest.waitForExplicitFinish();
function testInputportConnectionEvent() {
return new Promise(function(resolve, reject) {
var inputPortMgr = navigator.inputPortManager;
inputPortMgr.getInputPorts().then(
function(aPorts) {
ok(aPorts.length > 0, "Got at least 1 inputport.");
var port0 = aPorts[0];
var port0_isConnected = port0.connected;
port0.onconnect = function(aEvent) {
var port = aEvent.target;
is(port.id, port0.id, "The inputport ID should be the same");
ok(port.connected, "The connected value matches the connect evnet purpose");
is(port.connected, !port0_isConnected, "The connected value should change");
resolve();
}
port0.ondisconnect = function (aEvent) {
var port = aEvent.target;
is(port.id, port0.id, "The inputport ID should be the same");
ok(!port.connected, "The connected value matches the disconnect evnet purpose");
is(port.connected, !port0_isConnected, "The connected value should change");
resolve();
}
},
function(aError) {
ok(false, "Fail to get input ports: " + aError);
resolve();
}
);
});
}
function runTest() {
ok(navigator.inputPortManager, 'should have navigator.inputPortManager');
testInputportConnectionEvent()
.then(function() {
info('test finished');
SimpleTest.finish();
});
}
SpecialPowers.pushPrefEnv({"set": [["dom.inputport.enabled", true],
//to ignore app scope check.
["dom.ignore_webidl_scope_checks", true]]}, function() {
SpecialPowers.pushPermissions(
[{'type': 'inputport', 'allow': true, 'context': document}], runTest);
});
</script>
</pre>
</body>
</html>

View File

@ -0,0 +1,63 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1026350
-->
<head>
<meta charset="utf-8">
<title>Inputport API Test</title>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1026350">Test Inputport API</a>
<script type="application/javascript;version=1.8">
'use strict';
SimpleTest.waitForExplicitFinish();
function testGetInputports() {
return new Promise(function(resolve, reject) {
var inputPortMgr = navigator.inputPortManager;
inputPortMgr.getInputPorts().then(
function(aPorts) {
ok(aPorts.length > 0, "Got at least 1 inputport.");
for (var i=0; i < aPorts.length; ++i) {
var port = aPorts[i];
ok(port instanceof InputPort, "Inputport " + i + " should be in the right type.");
ok('id' in port, "Inputport " + i + " should have an ID.");
ok('connected' in port, "Inputport " + i + " should have a connected property.");
ok(port.stream, "Inputport " + i + " should have non null stream.");
resolve();
}
},
function(aError) {
ok(false, "Fail to get input ports: " + aError);
resolve();
}
);
});
}
function runTest() {
ok(navigator.inputPortManager, 'should have navigator.inputPortManager');
testGetInputports()
.then(function() {
info('test finished');
SimpleTest.finish();
});
}
SpecialPowers.pushPrefEnv({"set": [["dom.inputport.enabled", true],
//to ignore app scope check.
["dom.ignore_webidl_scope_checks", true]]}, function() {
SpecialPowers.pushPermissions(
[{'type': 'inputport', 'allow': true, 'context': document}], runTest);
});
</script>
</pre>
</body>
</html>

View File

@ -0,0 +1,61 @@
"use strict";
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
function run_test() {
run_next_test();
}
add_test(function test_valid_inputport_id() {
var inputportId = "inputportId";
var data = Cc["@mozilla.org/inputport/inputportdata;1"].
createInstance(Ci.nsIInputPortData);
data.id = inputportId;
equal(data.id, inputportId);
run_next_test();
});
add_test(function test_empty_inputport_id() {
var data = Cc["@mozilla.org/inputport/inputportdata;1"].
createInstance(Ci.nsIInputPortData);
Assert.throws(function() {
data.id = "";
}, /NS_ERROR_ILLEGAL_VALUE/i);
run_next_test();
});
add_test(function test_valid_type() {
var inputportType = "hdmi";
var data = Cc["@mozilla.org/inputport/inputportdata;1"].
createInstance(Ci.nsIInputPortData);
data.type = inputportType;
equal(data.type, inputportType);
run_next_test();
});
add_test(function test_empty_type() {
var data = Cc["@mozilla.org/inputport/inputportdata;1"].
createInstance(Ci.nsIInputPortData);
Assert.throws(function() {
data.type = "";
}, /NS_ERROR_ILLEGAL_VALUE/i);
run_next_test();
});
add_test(function test_is_connected() {
var data = Cc["@mozilla.org/inputport/inputportdata;1"].
createInstance(Ci.nsIInputPortData);
data.connected = true;
ok(data.connected);
run_next_test();
});

View File

@ -0,0 +1,6 @@
[DEFAULT]
skip-if = buildapp != 'b2g'
head =
tail =
[test_inputport_data.js]