Bug 987596 - B2G NFC: Marionette tests for onpeerready. r=dimi

From bfece1daa040d5e7e4ff965adea343831b2484c4 Mon Sep 17 00:00:00 2001
---
 dom/nfc/tests/marionette/head.js                   |  5 +-
 dom/nfc/tests/marionette/manifest.ini              |  1 +
 dom/nfc/tests/marionette/test_nfc_enabled.js       |  1 -
 .../marionette/test_nfc_manager_tech_discovered.js |  5 +-
 dom/nfc/tests/marionette/test_nfc_peer.js          | 64 ++++++++++++++++++++++
 5 files changed, 70 insertions(+), 6 deletions(-)
 create mode 100644 dom/nfc/tests/marionette/test_nfc_peer.js
This commit is contained in:
Yoshi Huang 2014-04-25 19:22:09 +08:00
Родитель e7cff5ac3a
Коммит cae3ce10c8
5 изменённых файлов: 70 добавлений и 6 удалений

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

@ -3,6 +3,10 @@
let pendingEmulatorCmdCount = 0;
let Promise =
SpecialPowers.Cu.import("resource://gre/modules/Promise.jsm").Promise;
let nfc = window.navigator.mozNfc;
SpecialPowers.addPermission("nfc-manager", true, document);
/**
@ -35,7 +39,6 @@ let emulator = (function() {
function toggleNFC(enabled, callback) {
isnot(callback, null);
let nfc = window.navigator.mozNfc;
let req;
if (enabled) {
req = nfc.startPoll();

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

@ -6,3 +6,4 @@ qemu=true
[test_ndef.js]
[test_nfc_enabled.js]
[test_nfc_manager_tech_discovered.js]
[test_nfc_peer.js]

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

@ -4,7 +4,6 @@
MARIONETTE_TIMEOUT = 30000;
MARIONETTE_HEAD_JS = 'head.js';
let nfc = window.navigator.mozNfc;
function testEnableNFC() {
log('Running \'testEnableNFC\'');
let req = nfc.startPoll();

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

@ -4,9 +4,6 @@
MARIONETTE_TIMEOUT = 30000;
MARIONETTE_HEAD_JS = 'head.js';
let Promise =
SpecialPowers.Cu.import("resource://gre/modules/Promise.jsm").Promise;
// See nfc-nci.h.
const NCI_LAST_NOTIFICATION = 0;
const NCI_LIMIT_NOTIFICATION = 1;
@ -24,7 +21,7 @@ function activateRE(re) {
let cmd = 'nfc ntf rf_intf_activated ' + re;
emulator.run(cmd, function(result) {
is(result.pop(), 'OK', 'check activation of RE0');
is(result.pop(), 'OK', 'check activation of RE' + re);
deferred.resolve();
});

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

@ -0,0 +1,64 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 30000;
MARIONETTE_HEAD_JS = 'head.js';
let MANIFEST_URL = "app://system.gaiamobile.org/manifest.webapp";
function peerReadyCb(evt) {
log("peerReadyCb called");
let peer = nfc.getNFCPeer(evt.detail);
ok(peer instanceof MozNFCPeer, "Should get a NFCPeer object.");
// reset callback and NFC Hardware.
nfc.onpeerready = null;
toggleNFC(false, runNextTest);
}
function handleTechnologyDiscoveredRE0(msg) {
log("Received \'nfc-manager-tech-discovered\'");
is(msg.type, "techDiscovered", "check for correct message type");
is(msg.techList[0], "P2P", "check for correct tech type");
nfc.onpeerready = peerReadyCb;
let request = nfc.checkP2PRegistration(MANIFEST_URL);
request.onsuccess = function (evt) {
nfc.notifyUserAcceptedP2P(MANIFEST_URL);
}
request.onerror = function () {
ok(false, "checkP2PRegistration failed.");
toggleNFC(false, runNextTest);
}
}
function activateRE(re) {
let deferred = Promise.defer();
let cmd = "nfc ntf rf_intf_activated " + re;
emulator.run(cmd, function(result) {
is(result.pop(), "OK", "check activation of RE" + re);
deferred.resolve();
});
return deferred.promise;
}
function testPeerReady() {
window.navigator.mozSetMessageHandler(
"nfc-manager-tech-discovered", handleTechnologyDiscoveredRE0);
toggleNFC(true, function() {
activateRE(0);
});
}
let tests = [
testPeerReady
];
SpecialPowers.pushPermissions(
[{"type": "nfc-manager", "allow": true, context: document},
{"type": "nfc-write", "allow": true, context: document}], runTests);