Bug 1162836 - Fix NFC marionette testcase fail. r=yoshi

--HG--
extra : rebase_source : f2d6affd0c6fb42805ad9e3220532399cb9f6322
This commit is contained in:
Dimi Lee 2015-05-19 20:29:25 +08:00
Родитель be63be8037
Коммит 225aad3115
10 изменённых файлов: 121 добавлений и 105 удалений

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

@ -194,21 +194,64 @@ let SNEP = (function() {
function toggleNFC(enabled) {
let deferred = Promise.defer();
let promise;
if (enabled) {
promise = nfc.startPoll();
} else {
promise = nfc.powerOff();
}
// In bug 1109592, nfcd will only run when nfc is enabled.
// The way we activate/deactivate nfcd is by using set property "ctl.start" & "ctl.stop".
// In emulator it seems sometimes enable/disable NFC too quick will cause nfcd won't starat,
// So here we use a simple workaround to delay enable or disable for 100ms, bug 1164786 is
// created to track this issue.
setTimeout(function() {
let promise;
if (enabled) {
promise = nfc.startPoll();
} else {
promise = nfc.powerOff();
}
promise.then(() => {
promise.then(() => {
deferred.resolve();
}).catch(() => {
ok(false, 'operation failed, error ' + req.error.name);
deferred.reject();
finish();
});
}, 100);
return deferred.promise;
}
function activateAndwaitForTechDiscovered(re) {
let deferred = Promise.defer();
sysMsgHelper.waitForTechDiscovered(function() {
deferred.resolve();
}).catch(() => {
ok(false, 'operation failed, error ' + req.error.name);
deferred.reject();
finish();
});
NCI.activateRE(re);
return deferred.promise;
}
function deactivateAndWaitForTechLost() {
let deferred = Promise.defer();
sysMsgHelper.waitForTechLost(function() {
deferred.resolve();
});
NCI.deactivate();
return deferred.promise;
}
function deactivateAndWaitForPeerLost() {
let deferred = Promise.defer();
nfc.onpeerlost = function() {
deferred.resolve();
};
NCI.deactivate();
return deferred.promise;
}

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

@ -6,7 +6,7 @@
/* globals log, is, ok, runTests, toggleNFC, runNextTest,
SpecialPowers, nfc */
const MARIONETTE_TIMEOUT = 30000;
const MARIONETTE_TIMEOUT = 60000;
const MARIONETTE_HEAD_JS = 'head.js';
const MANIFEST_URL = 'app://system.gaiamobile.org/manifest.webapp';
@ -18,7 +18,7 @@ const FAKE_MANIFEST_URL = 'app://fake.gaiamobile.org/manifest.webapp';
*/
function testNoTargetNoSessionToken() {
log('testNoTargetNoSessionToken');
fireCheckP2PReg(MANIFEST_URL)
nfc.checkP2PRegistration(MANIFEST_URL)
.then((result) => {
is(result, false, 'No target, no sesionToken, result should be false');
runNextTest();
@ -33,7 +33,7 @@ function testNoTargetNoSessionToken() {
function testWithTargetNoSessionToken() {
log('testWithTargetNoSessionToken');
registerOnpeerready()
.then(() => fireCheckP2PReg(MANIFEST_URL))
.then(() => nfc.checkP2PRegistration(MANIFEST_URL))
.then((result) => {
is(result, false,
'session token is available and it shouldnt be');
@ -50,13 +50,13 @@ function testWithTargetNoSessionToken() {
function testWithSessionTokenWithTarget() {
log('testWithSessionTokenWithTarget');
toggleNFC(true)
.then(() => NCI.activateRE(emulator.P2P_RE_INDEX_0))
.then(() => activateAndwaitForTechDiscovered(emulator.P2P_RE_INDEX_0))
.then(registerOnpeerready)
.then(() => fireCheckP2PReg(MANIFEST_URL))
.then(() => nfc.checkP2PRegistration(MANIFEST_URL))
.then((result) => {
is(result, true, 'should be true, onpeerready reg, sessionToken set');
nfc.onpeerready = null;
return toggleNFC(false);
return deactivateAndWaitForTechLost().then(() => toggleNFC(false));
})
.then(runNextTest)
.catch(handleRejectedPromiseWithNfcOn);
@ -69,12 +69,12 @@ function testWithSessionTokenWithTarget() {
function testWithSessionTokenNoTarget() {
log('testWithSessionTokenNoTarget');
toggleNFC(true)
.then(() => NCI.activateRE(emulator.P2P_RE_INDEX_0))
.then(() => fireCheckP2PReg(MANIFEST_URL))
.then(() => activateAndwaitForTechDiscovered(emulator.P2P_RE_INDEX_0))
.then(() => nfc.checkP2PRegistration(MANIFEST_URL))
.then((result) => {
is(result, false,
'session token avilable but onpeerready not registered');
return toggleNFC(false);
return deactivateAndWaitForTechLost().then(() => toggleNFC(false));
})
.then(runNextTest)
.catch(handleRejectedPromiseWithNfcOn);
@ -87,13 +87,13 @@ function testWithSessionTokenNoTarget() {
function testWithSessionTokenWrongTarget() {
log('testWithSessionTokenWrongTarget');
toggleNFC(true)
.then(() => NCI.activateRE(emulator.P2P_RE_INDEX_0))
.then(() => activateAndwaitForTechDiscovered(emulator.P2P_RE_INDEX_0))
.then(registerOnpeerready)
.then(() => fireCheckP2PReg(FAKE_MANIFEST_URL))
.then(() => nfc.checkP2PRegistration(FAKE_MANIFEST_URL))
.then((result) => {
is(result, false, 'should be false, fake manifest, sessionToken set');
nfc.onpeerready = null;
return toggleNFC(false);
return deactivateAndWaitForTechLost().then(() => toggleNFC(false));
})
.then(runNextTest)
.catch(handleRejectedPromiseWithNfcOn);
@ -108,21 +108,6 @@ function registerOnpeerready() {
return d.promise;
}
function fireCheckP2PReg(manifestUrl) {
let deferred = Promise.defer();
let promise = nfc.checkP2PRegistration(manifestUrl);
promise.then(() => {
ok(true, 'checkP2PRegistration allways results in success');
deferred.resolve(request.result);
}).catch(() => {
ok(false, 'see NfcContentHelper.handleCheckP2PRegistrationResponse');
deferred.reject();
});
return deferred.promise;
}
function handleRejectedPromise() {
ok(false, 'Promise rejected. This should not happen');
nfc.onpeerready = null;

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

@ -25,8 +25,9 @@ let nfcPeers = [];
function testNfcNotEnabledError() {
log('testNfcNotEnabledError');
toggleNFC(true)
.then(() => NCI.activateRE(emulator.P2P_RE_INDEX_0))
.then(() => activateAndwaitForTechDiscovered(emulator.P2P_RE_INDEX_0))
.then(registerAndFireOnpeerready)
.then(() => deactivateAndWaitForPeerLost())
.then(() => toggleNFC(false))
.then(() => sendNDEFExpectError(nfcPeers[0]))
.then(endTest)
@ -43,13 +44,14 @@ function testNfcNotEnabledError() {
function testNfcBadSessionIdError() {
log('testNfcBadSessionIdError');
toggleNFC(true)
.then(() => NCI.activateRE(emulator.P2P_RE_INDEX_0))
.then(() => activateAndwaitForTechDiscovered(emulator.P2P_RE_INDEX_0))
.then(registerAndFireOnpeerready)
.then(() => NCI.deactivate())
.then(() => NCI.activateRE(emulator.P2P_RE_INDEX_0))
.then(() => activateAndwaitForTechDiscovered(emulator.P2P_RE_INDEX_0))
.then(registerAndFireOnpeerready)
// we have 2 peers in nfcPeers array, peer0 has old/invalid session token
.then(() => sendNDEFExpectError(nfcPeers[0]))
.then(() => deactivateAndWaitForPeerLost())
.then(() => toggleNFC(false))
.then(endTest)
.catch(handleRejectedPromise);
@ -65,7 +67,7 @@ function testNoErrorInTechMsg() {
let techDiscoveredHandler = function(msg) {
ok('Message handler for nfc-manager-tech-discovered');
is(msg.type, 'techDiscovered');
ok(msg.peer, 'check for correct tech type');
is(msg.errorMsg, undefined, 'Should not get error msg in tech discovered');
setAndFireTechLostHandler()
@ -108,13 +110,13 @@ function registerAndFireOnpeerready() {
function sendNDEFExpectError(peer) {
let deferred = Promise.defer();
try {
peer.sendNDEF(NDEF_MESSAGE);
peer.sendNDEF(NDEF_MESSAGE)
.then(() => {
deferred.reject();
} catch (e) {
}).catch((e) => {
ok(true, 'this should happen ' + e);
deferred.resolve();
}
});
return deferred.promise;
}
@ -124,7 +126,6 @@ function setAndFireTechLostHandler() {
let techLostHandler = function(msg) {
ok('Message handler for nfc-manager-tech-lost');
is(msg.type, 'techLost');
is(msg.errorMsg, undefined, 'Should not get error msg in tech lost');
deferred.resolve();
@ -139,7 +140,8 @@ function setAndFireTechLostHandler() {
let tests = [
testNfcNotEnabledError,
testNfcBadSessionIdError,
// This testcase is temporarily removed due to Bug 1055959, will reopen when it is fixed
// testNfcBadSessionIdError
testNoErrorInTechMsg
];

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

@ -1,14 +1,13 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 30000;
MARIONETTE_TIMEOUT = 60000;
MARIONETTE_HEAD_JS = 'head.js';
function handleTechnologyDiscoveredRE0(msg) {
log('Received \'nfc-manager-tech-discovered\'');
is(msg.type, 'techDiscovered', 'check for correct message type');
is(msg.isP2P, 'P2P', 'check for correct tech type');
toggleNFC(false).then(runNextTest);
ok(msg.peer, 'check for correct tech type');
deactivateAndWaitForTechLost().then(() => toggleNFC(false)).then(runNextTest);
}
function testActivateRE0() {

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

@ -1,7 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 30000;
MARIONETTE_TIMEOUT = 60000;
MARIONETTE_HEAD_JS = 'head.js';
let tnf = NDEF.TNF_WELL_KNOWN;
@ -18,13 +18,12 @@ function handleSnep(msg) {
type: NfcUtils.fromUTF8(type),
payload: NfcUtils.fromUTF8(payload)})];
NDEF.compare(ndef, msg.records);
toggleNFC(false).then(runNextTest);
deactivateAndWaitForTechLost().then(() => toggleNFC(false)).then(runNextTest);
}
function handleTechnologyDiscoveredRE0(msg) {
log("Received 'nfc-manager-tech-discovered'");
is(msg.type, "techDiscovered", "check for correct message type");
is(msg.isP2P, "P2P", "check for correct tech type");
ok(msg.peer, "check for correct tech type");
sysMsgHelper.waitForTechDiscovered(handleSnep);
SNEP.put(SNEP.SAP_NDEF, SNEP.SAP_NDEF, 0, tnf, btoa(type), btoa(id), btoa(payload));

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

@ -6,15 +6,14 @@ MARIONETTE_HEAD_JS = 'head.js';
function handleTechnologyLost(msg) {
log('Received \'nfc-manager-tech-lost\'');
is(msg.type, 'techLost', 'check for correct message type');
ok(true);
toggleNFC(false).then(runNextTest)
}
function handleTechnologyDiscoveredRE0(msg) {
log('Received \'nfc-manager-tech-discovered\'');
is(msg.type, 'techDiscovered', 'check for correct message type');
is(msg.isP2P, 'P2P', 'check for correct tech type');
ok(msg.peer, 'check for correct tech type');
NCI.deactivate();
}

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

@ -28,8 +28,7 @@ function peerLostCb(evt) {
function handleTechnologyDiscoveredRE0(msg) {
log("Received \'nfc-manager-tech-discovered\'");
is(msg.type, "techDiscovered", "check for correct message type");
is(msg.isP2P, "P2P", "check for correct tech type");
ok(msg.peer, "check for correct tech type");
nfc.onpeerready = peerReadyCb;
nfc.onpeerlost = peerLostCb;
@ -39,19 +38,13 @@ function handleTechnologyDiscoveredRE0(msg) {
function handleTechnologyDiscoveredRE0ForP2PRegFailure(msg) {
log("Received \'nfc-manager-tech-discovered\'");
is(msg.type, "techDiscovered", "check for correct message type");
is(msg.isP2P, "P2P", "check for correct tech type");
ok(msg.peer, "check for correct tech type");
nfc.onpeerready = peerReadyCb;
let promise = nfc.checkP2PRegistration(INCORRECT_MANIFEST_URL);
promise.then(evt => {
is(request.result, false, "check for P2P registration result");
nfc.onpeerready = null;
NCI.deactivate().then(() => toggleNFC(false)).then(runNextTest);
}).catch(() => {
ok(false, "checkP2PRegistration failed.");
nfc.checkP2PRegistration(INCORRECT_MANIFEST_URL)
.then((result) => {
is(result, false, "check for P2P registration result");
nfc.onpeerready = null;
NCI.deactivate().then(() => toggleNFC(false)).then(runNextTest);
@ -150,19 +143,19 @@ function testPeerShouldThrow() {
nfc.onpeerlost = function () {
log("testPeerShouldThrow peerlost");
try {
peer.sendNDEF(ndef);
peer.sendNDEF(ndef)
.then(() => {
ok(false, "sendNDEF should throw error");
} catch (e) {
}).catch((e) => {
ok(true, "Exception expected " + e);
}
});
try {
peer.sendFile(new Blob());
peer.sendFile(new Blob())
.then(() => {
ok(false, "sendfile should throw error");
} catch (e) {
}).catch((e) => {
ok(true, "Exception expected" + e);
}
});
nfc.onpeerready = null;
nfc.onpeerlost = null;

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

@ -1,7 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 30000;
MARIONETTE_TIMEOUT = 60000;
MARIONETTE_HEAD_JS = "head.js";
let MANIFEST_URL = "app://system.gaiamobile.org/manifest.webapp";
@ -23,16 +23,14 @@ function testSendFile() {
};
sysMsgHelper.waitForTechDiscovered(function(msg) {
let request = nfc.checkP2PRegistration(MANIFEST_URL);
request.onsuccess = function(evt) {
is(request.result, true, "check for P2P registration result");
nfc.notifyUserAcceptedP2P(MANIFEST_URL);
}
request.onerror = function() {
ok(false, "checkP2PRegistration failed.");
toggleNFC(false).then(runNextTest);
}
nfc.checkP2PRegistration(MANIFEST_URL).then(result => {
if (result) {
nfc.notifyUserAcceptedP2P(MANIFEST_URL);
} else {
ok(false, "checkP2PRegistration failed.");
deactivateAndWaitForTechLost().then(() => toggleNFC(false)).then(runNextTest);
}
});
});
toggleNFC(true).then(() => NCI.activateRE(emulator.P2P_RE_INDEX_0));
@ -43,6 +41,5 @@ let tests = [
];
SpecialPowers.pushPermissions(
[{"type": "nfc", "allow": true,
"read": true, 'write': true, context: document},
[{"type": "nfc-share", "allow": true, context: document},
{"type": "nfc-manager", 'allow': true, context: document}], runTests);

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

@ -1,7 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 30000;
MARIONETTE_TIMEOUT = 60000;
MARIONETTE_HEAD_JS = "head.js";
let url = "https://www.example.com";
@ -21,18 +21,17 @@ function sendNDEF(peer) {
emulator.run(cmd, function(result) {
is(result.pop(), "OK", "check SNEP PUT result");
NDEF.compare(ndef, NDEF.parseString(result.pop()));
toggleNFC(false).then(runNextTest);
deactivateAndWaitForTechLost().then(() => toggleNFC(false)).then(runNextTest);
});
}).catch(() => {
ok(false, "Failed to send NDEF message, error \'" + this.error + "\'");
toggleNFC(false).then(runNextTest);
deactivateAndWaitForTechLost().then(() => toggleNFC(false)).then(runNextTest);
});
}
function handleTechnologyDiscoveredRE0(msg) {
log("Received \'nfc-manager-tech-discovered\' " + JSON.stringify(msg));
is(msg.type, "techDiscovered", "check for correct message type");
is(msg.isP2P, "check for \'P2P\' in tech list");
ok(msg.peer, "techDiscovered", "check for correct message type");
sendNDEF(msg.peer);
}

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

@ -1,7 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 30000;
MARIONETTE_TIMEOUT = 60000;
MARIONETTE_HEAD_JS = "head.js";
let url = "http://www.mozilla.org";
@ -16,16 +16,16 @@ function testUrlTagDiscover(re) {
sysMsgHelper.waitForTechDiscovered(function(msg) {
log("Received \'nfc-manager-tech-ndiscovered\'");
is(msg.type, "techDiscovered", "check for correct message type");
ok(msg.peer === undefined, "peer object should be undefined");
let records = Cu.waiveXrays(msg.records);
let records = msg.records;
ok(records.length > 0);
is(tnf, records[0].tnf, "check for TNF field in NDEF");
is(type, NfcUtils.toUTF8(records[0].type), "check for type field in NDEF");
is(payload, NfcUtils.toUTF8(records[0].payload), "check for payload field in NDEF");
is(type, NfcUtils.toUTF8(Cu.waiveXrays(records[0].type)), "check for type field in NDEF");
is(payload, NfcUtils.toUTF8(Cu.waiveXrays(records[0].payload)), "check for payload field in NDEF");
toggleNFC(false).then(runNextTest);
deactivateAndWaitForTechLost().then(() => toggleNFC(false)).then(runNextTest);
});
toggleNFC(true)
@ -38,12 +38,12 @@ function testEmptyTagDiscover(re) {
sysMsgHelper.waitForTechDiscovered(function(msg) {
log("Received \'nfc-manager-tech-ndiscovered\'");
is(msg.type, "techDiscovered", "check for correct message type");
ok(msg.peer === undefined, "peer object should be undefined");
let records = msg.records;
ok(records == null);
toggleNFC(false).then(runNextTest);
deactivateAndWaitForTechLost().then(() => toggleNFC(false)).then(runNextTest);
});
toggleNFC(true)