Bug 792494 - Develop WebTelephony tests to verify onstatechange events, and redundant operations, update manifiest; r=jgriffin, DONTBUILD (NPOTB)
authorRob Wood <rwood@mozilla.com>
Sat, 22 Sep 2012 14:51:43 -0400
changeset 108029 e0d18c79d5d08e7f6cd0edfac0450adeda27861d
parent 108028 702fd21579a5a9477b6ffab6e59b275c22330087
child 108030 584119bf249d3280a471cc2f516d193ac2766216
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersjgriffin, DONTBUILD
bugs792494
milestone18.0a1
Bug 792494 - Develop WebTelephony tests to verify onstatechange events, and redundant operations, update manifiest; r=jgriffin, DONTBUILD (NPOTB)
dom/telephony/test/marionette/manifest.ini
dom/telephony/test/marionette/test_incoming_onstatechange.js
dom/telephony/test/marionette/test_outgoing_onstatechange.js
dom/telephony/test/marionette/test_redundant_operations.js
--- a/dom/telephony/test/marionette/manifest.ini
+++ b/dom/telephony/test/marionette/manifest.ini
@@ -28,9 +28,12 @@ qemu = true
 [test_incoming_hangup_held.js]
 [test_incoming_remote_cancel.js]
 [test_incoming_remote_hangup_held.js]
 [test_outgoing_already_held.js]
 [test_outgoing_answer_local_hangup.js]
 [test_outgoing_remote_hangup_held.js]
 [test_incoming_already_held.js]
 [test_swap_held_and_active.js]
+[test_incoming_onstatechange.js]
+[test_outgoing_onstatechange.js]
+[test_redundant_operations.js]
 
new file mode 100644
--- /dev/null
+++ b/dom/telephony/test/marionette/test_incoming_onstatechange.js
@@ -0,0 +1,161 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+MARIONETTE_TIMEOUT = 10000;
+
+SpecialPowers.addPermission("telephony", true, document);
+
+let telephony = window.navigator.mozTelephony;
+let incomingCall;
+let inNumber = "5555551111";
+
+function verifyInitialState() {
+  log("Verifying initial state.");
+  ok(telephony);
+  is(telephony.active, null);
+  ok(telephony.calls);
+  is(telephony.calls.length, 0);
+
+  runEmulatorCmd("gsm list", function(result) {
+    log("Initial call list: " + result);
+    is(result[0], "OK");
+    simulateIncoming();
+  });
+}
+
+function simulateIncoming() {
+  log("Simulating an incoming call.");
+
+  telephony.onincoming = function onincoming(event) {
+    log("Received 'incoming' call event.");
+    incomingCall = event.call;
+    ok(incomingCall);
+    is(incomingCall.number, inNumber);
+    is(incomingCall.state, "incoming");
+
+    is(telephony.calls.length, 1);
+    is(telephony.calls[0], incomingCall);
+
+    runEmulatorCmd("gsm list", function(result) {
+      log("Call list is now: " + result);
+      is(result[0], "inbound from " + inNumber + " : incoming");
+      is(result[1], "OK");
+      answerIncoming();
+    });
+  };
+  runEmulatorCmd("gsm call " + inNumber);
+}
+
+function answerIncoming() {
+  log("Answering the incoming call.");
+
+  gotConnecting = false;
+  incomingCall.onstatechange = function statechangeconnect(event) {
+    log("Received 'onstatechange' call event.");
+    is(incomingCall, event.call);
+    if(!gotConnecting){
+      is(incomingCall.state, "connecting");
+      gotConnecting = true;
+    } else {
+      is(incomingCall.state, "connected");
+      is(telephony.active, incomingCall);
+      is(telephony.calls.length, 1);
+      is(telephony.calls[0], incomingCall);
+
+      runEmulatorCmd("gsm list", function(result) {
+        log("Call list is now: " + result);
+        is(result[0], "inbound from " + inNumber + " : active");
+        is(result[1], "OK");
+        hold();
+      });
+    };
+  };
+  incomingCall.answer();
+};
+
+function hold() {
+  log("Putting the call on hold.");
+
+  let gotHolding = false;
+  incomingCall.onstatechange = function onstatechangehold(event) {
+    log("Received 'onstatechange' call event.");
+    is(incomingCall, event.call);
+    if(!gotHolding){
+      is(incomingCall.state, "holding");
+      gotHolding = true;
+    } else {
+      is(incomingCall.state, "held");
+      is(telephony.active, null);
+      is(telephony.calls.length, 1);
+      is(telephony.calls[0], incomingCall);
+
+      runEmulatorCmd("gsm list", function(result) {
+        log("Call list is now: " + result);
+        is(result[0], "inbound from " + inNumber + " : held");
+        is(result[1], "OK");
+        resume();
+      });
+    };
+  };
+  incomingCall.hold();
+}
+
+function resume() {
+  log("Resuming the held call.");
+
+  let gotResuming = false;
+  incomingCall.onstatechange = function onstatechangeresume(event) {
+    log("Received 'onstatechange' call event.");
+    is(incomingCall, event.call);
+    if(!gotResuming){
+      is(incomingCall.state, "resuming");
+      gotResuming = true;
+    } else {
+      is(incomingCall.state, "connected");
+      is(telephony.active, incomingCall);
+      is(telephony.calls.length, 1);
+      is(telephony.calls[0], incomingCall);
+
+      runEmulatorCmd("gsm list", function(result) {
+        log("Call list is now: " + result);
+        is(result[0], "inbound from " + inNumber + " : active");
+        is(result[1], "OK");
+        hangUp();
+      });
+    };
+  };
+  incomingCall.resume();
+}
+
+function hangUp() {
+  log("Hanging up the incoming call (local hang-up).");
+
+  let gotDisconnecting = false;
+  incomingCall.onstatechange = function onstatechangedisconnect(event) {
+    log("Received 'onstatechange' call event.");
+    is(incomingCall, event.call);
+    if(!gotDisconnecting){
+      is(incomingCall.state, "disconnecting");
+      gotDisconnecting = true;
+    } else {
+      is(incomingCall.state, "disconnected");
+      is(telephony.active, null);
+      is(telephony.calls.length, 0);
+
+      runEmulatorCmd("gsm list", function(result) {
+        log("Call list is now: " + result);
+        is(result[0], "OK");
+        cleanUp();
+      });
+    };
+  };
+  incomingCall.hangUp();
+}
+
+function cleanUp() {
+  SpecialPowers.removePermission("telephony", document);
+  finish();
+}
+
+// Start the test
+verifyInitialState();
new file mode 100644
--- /dev/null
+++ b/dom/telephony/test/marionette/test_outgoing_onstatechange.js
@@ -0,0 +1,159 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+MARIONETTE_TIMEOUT = 10000;
+
+SpecialPowers.addPermission("telephony", true, document);
+
+let telephony = window.navigator.mozTelephony;
+let outgoingCall;
+let outNumber = "5555551111";
+
+function verifyInitialState() {
+  log("Verifying initial state.");
+  ok(telephony);
+  is(telephony.active, null);
+  ok(telephony.calls);
+  is(telephony.calls.length, 0);
+
+  runEmulatorCmd("gsm list", function(result) {
+    log("Initial call list: " + result);
+    is(result[0], "OK");
+    dial();
+  });
+}
+
+function dial() {
+  log("Make an outgoing call.");
+
+  outgoingCall = telephony.dial(outNumber);
+  ok(outgoingCall);
+  is(outgoingCall.number, outNumber);
+  is(outgoingCall.state, "dialing");
+
+  is(outgoingCall, telephony.active);
+  is(telephony.calls.length, 1);
+  is(telephony.calls[0], outgoingCall);
+
+  outgoingCall.onstatechange = function statechangering(event) {
+    log("Received 'onstatechange' call event.");
+
+    is(outgoingCall, event.call);
+    is(outgoingCall.state, "alerting");
+
+    runEmulatorCmd("gsm list", function(result) {
+      log("Call list is now: " + result);
+      is(result[0], "outbound to  " + outNumber + " : ringing");
+      is(result[1], "OK");
+      answer();
+    });
+  };
+}
+
+function answer() {
+  log("Answering the outgoing call.");
+
+  // We get no "connecting" event when the remote party answers the call.
+
+  outgoingCall.onstatechange = function onstatechangeanswer(event) {
+    log("Received 'onstatechange' call event.");
+    is(outgoingCall, event.call);
+    is(outgoingCall.state, "connected");
+    is(outgoingCall, telephony.active);
+
+    runEmulatorCmd("gsm list", function(result) {
+      log("Call list is now: " + result);
+      is(result[0], "outbound to  " + outNumber + " : active");
+      is(result[1], "OK");
+      hold();
+    });
+  };
+  runEmulatorCmd("gsm accept " + outNumber);
+};
+
+function hold() {
+  log("Putting the call on hold.");
+
+  let gotHolding = false;
+  outgoingCall.onstatechange = function onstatechangehold(event) {
+    log("Received 'onstatechange' call event.");
+    is(outgoingCall, event.call);
+    if(!gotHolding){
+      is(outgoingCall.state, "holding");
+      gotHolding = true;
+    } else {
+      is(outgoingCall.state, "held");
+      is(telephony.active, null);
+      is(telephony.calls.length, 1);
+      is(telephony.calls[0], outgoingCall);
+
+      runEmulatorCmd("gsm list", function(result) {
+        log("Call list is now: " + result);
+        is(result[0], "outbound to  " + outNumber + " : held");
+        is(result[1], "OK");
+        resume();
+      });
+    };
+  };
+  outgoingCall.hold();
+}
+
+function resume() {
+  log("Resuming the held call.");
+
+  let gotResuming = false;
+  outgoingCall.onstatechange = function onstatechangeresume(event) {
+    log("Received 'onstatechange' call event.");
+    is(outgoingCall, event.call);
+    if(!gotResuming){
+      is(outgoingCall.state, "resuming");
+      gotResuming = true;
+    } else {
+      is(outgoingCall.state, "connected");
+      is(telephony.active, outgoingCall);
+      is(telephony.calls.length, 1);
+      is(telephony.calls[0], outgoingCall);
+
+      runEmulatorCmd("gsm list", function(result) {
+        log("Call list is now: " + result);
+        is(result[0], "outbound to  " + outNumber + " : active");
+        is(result[1], "OK");
+        hangUp();
+      });
+    };
+  };
+  outgoingCall.resume();
+}
+
+function hangUp() {
+  log("Hanging up the outgoing call (local hang-up).");
+
+  let gotDisconnecting = false;
+  outgoingCall.onstatechange = function onstatechangedisconnect(event) {
+    log("Received 'onstatechange' call event.");
+    is(outgoingCall, event.call);
+    if(!gotDisconnecting){
+      is(outgoingCall.state, "disconnecting");
+      gotDisconnecting = true;
+    } else {
+      is(outgoingCall.state, "disconnected");
+      is(telephony.active, null);
+      is(telephony.calls.length, 0);
+
+      runEmulatorCmd("gsm list", function(result) {
+        log("Call list is now: " + result);
+        is(result[0], "OK");
+        cleanUp();
+      });
+    };
+  };
+  outgoingCall.hangUp();
+}
+
+function cleanUp() {
+  SpecialPowers.removePermission("telephony", document);
+  finish();
+}
+
+// Start the test
+verifyInitialState();
new file mode 100644
--- /dev/null
+++ b/dom/telephony/test/marionette/test_redundant_operations.js
@@ -0,0 +1,346 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+MARIONETTE_TIMEOUT = 10000;
+
+SpecialPowers.addPermission("telephony", true, document);
+
+let telephony = window.navigator.mozTelephony;
+let inNumber = "5555551111";
+let incomingCall;
+
+function verifyInitialState() {
+  log("Verifying initial state.");
+  ok(telephony);
+  is(telephony.active, null);
+  ok(telephony.calls);
+  is(telephony.calls.length, 0);
+
+  runEmulatorCmd("gsm list", function(result) {
+    log("Initial call list: " + result);
+    is(result[0], "OK");
+    simulateIncoming();
+  });
+}
+
+function simulateIncoming() {
+  log("Simulating an incoming call.");
+
+  telephony.onincoming = function onincoming(event) {
+    log("Received 'incoming' call event.");
+    incomingCall = event.call;
+    ok(incomingCall);
+    is(incomingCall.number, inNumber);
+    is(incomingCall.state, "incoming");
+
+    is(telephony.calls.length, 1);
+    is(telephony.calls[0], incomingCall);
+
+    runEmulatorCmd("gsm list", function(result) {
+      log("Call list is now: " + result);
+      is(result[0], "inbound from " + inNumber + " : incoming");
+      is(result[1], "OK");
+      answerIncoming();
+    });
+  };
+  runEmulatorCmd("gsm call " + inNumber);
+}
+
+function answerIncoming() {
+  log("Answering the incoming call.");
+
+  let gotConnecting = false;
+  incomingCall.onconnecting = function onconnectingIn(event) { 
+    log("Received 'connecting' call event for incoming call.");
+    is(incomingCall, event.call);
+    is(incomingCall.state, "connecting");
+    gotConnecting = true;
+  };
+
+  incomingCall.onconnected = function onconnectedIn(event) {
+    log("Received 'connected' call event for incoming call.");
+    is(incomingCall, event.call);
+    is(incomingCall.state, "connected");
+    ok(gotConnecting);
+
+    is(incomingCall, telephony.active);
+
+    runEmulatorCmd("gsm list", function(result) {
+      log("Call list is now: " + result);
+      is(result[0], "inbound from " + inNumber + " : active");
+      is(result[1], "OK");
+      answerAlreadyConnected();
+    });
+  };
+  incomingCall.answer();
+}
+
+function answerAlreadyConnected() {
+  log("Attempting to answer already connected call, should be ignored.");
+
+  incomingCall.onconnecting = function onconnectingErr(event) {
+    log("Received 'connecting' call event, but should not have.");
+    ok(false, "Received 'connecting' event when answered already active call");
+  }
+
+  incomingCall.onconnected = function onconnectedErr(event) {
+    log("Received 'connected' call event, but should not have.");
+    ok(false, "Received 'connected' event when answered already active call");
+  }
+
+  incomingCall.answer();
+
+  is(incomingCall.state, "connected");
+  is(telephony.calls.length, 1);
+  is(telephony.calls[0], incomingCall);
+  is(incomingCall, telephony.active);
+  hold();
+}
+
+function hold() {
+  log("Putting the call on hold.");
+
+  let gotHolding = false;
+  incomingCall.onholding = function onholding(event) {
+    log("Received 'holding' call event.");
+    is(incomingCall, event.call);
+    is(incomingCall.state, "holding");
+    gotHolding = true;
+  };
+
+  incomingCall.onheld = function onheld(event) {
+    log("Received 'held' call event.");
+    is(incomingCall, event.call);
+    is(incomingCall.state, "held");
+    ok(gotHolding);
+
+    is(telephony.active, null);
+    is(telephony.calls.length, 1);
+    is(telephony.calls[0], incomingCall);
+
+    runEmulatorCmd("gsm list", function(result) {
+      log("Call list is now: " + result);
+      is(result[0], "inbound from " + inNumber + " : held");
+      is(result[1], "OK");
+      holdAlreadyHeld();
+    });
+  };
+  incomingCall.hold();
+}
+
+function holdAlreadyHeld() {
+  log("Attempting to hold an already held call, should be ignored.");
+
+  incomingCall.onholding = function onholding(event) {
+    log("Received 'holding' call event, but should not have.");
+    ok(false, "Received 'holding' event when held an already held call");
+  }
+
+  incomingCall.onheld = function onheldErr(event) {
+    log("Received 'held' call event, but should not have.");
+    ok(false, "Received 'held' event when held an already held call");
+  }
+
+  incomingCall.hold();
+
+  is(incomingCall.state, "held");
+  is(telephony.active, null);
+  is(telephony.calls.length, 1);
+  is(telephony.calls[0], incomingCall);
+
+  answerHeld();
+}
+
+function answerHeld() {
+  log("Attempting to answer a held call, should be ignored.");
+
+  incomingCall.onconnecting = function onconnectingErr(event) {
+    log("Received 'connecting' call event, but should not have.");
+    ok(false, "Received 'connecting' event when answered a held call");
+  }
+
+  incomingCall.onconnected = function onconnectedErr(event) {
+    log("Received 'connected' call event, but should not have.");
+    ok(false, "Received 'connected' event when answered a held call");
+  }
+
+  incomingCall.answer();
+
+  is(incomingCall.state, "held");
+  is(telephony.active, null);
+  is(telephony.calls.length, 1);
+  is(telephony.calls[0], incomingCall);
+
+  resume();
+}
+
+function resume() {
+  log("Resuming the held call.");
+
+  let gotResuming = false;
+  incomingCall.onresuming = function onresuming(event) {
+    log("Received 'resuming' call event.");
+    is(incomingCall, event.call);
+    is(incomingCall.state, "resuming");
+    gotResuming = true;
+  };
+
+  incomingCall.onconnected = function onconnected(event) {
+    log("Received 'connected' call event.");
+    is(incomingCall, event.call);
+    is(incomingCall.state, "connected");
+    ok(gotResuming);
+
+    is(incomingCall, telephony.active);
+    is(telephony.calls.length, 1);
+    is(telephony.calls[0], incomingCall);
+
+    runEmulatorCmd("gsm list", function(result) {
+      log("Call list is now: " + result);
+      is(result[0], "inbound from " + inNumber + " : active");
+      is(result[1], "OK");
+      resumeNonHeld();
+    });
+  };
+  incomingCall.resume();
+}
+
+function resumeNonHeld() {
+  log("Attempting to resume non-held call, should be ignored.");
+
+  incomingCall.onresuming = function onresumingErr(event) {
+    log("Received 'resuming' call event, but should not have.");
+    ok(false, "Received 'resuming' event when resumed non-held call");
+  }
+
+  incomingCall.onconnected = function onconnectedErr(event) {
+    log("Received 'connected' call event, but should not have.");
+    ok(false, "Received 'connected' event when resumed non-held call");
+  }
+
+  incomingCall.resume();
+
+  is(incomingCall.state, "connected");
+  is(telephony.calls.length, 1);
+  is(telephony.calls[0], incomingCall);
+  is(incomingCall, telephony.active);
+  hangUp();
+}
+
+function hangUp() {
+  log("Hanging up the call (local hang-up).");
+
+  let gotDisconnecting = false;
+  incomingCall.ondisconnecting = function ondisconnecting(event) {
+    log("Received 'disconnecting' call event.");
+    is(incomingCall, event.call);
+    is(incomingCall.state, "disconnecting");
+    gotDisconnecting = true;
+  };
+
+  incomingCall.ondisconnected = function ondisconnectedOut(event) {
+    log("Received 'disconnected' call event.");
+    is(incomingCall, event.call);
+    is(incomingCall.state, "disconnected");
+    ok(gotDisconnecting);
+
+    is(telephony.active, null);
+    is(telephony.calls.length, 0);
+
+    runEmulatorCmd("gsm list", function(result) {
+      log("Call list is now: " + result);
+      is(result[0], "OK");
+      answerDisconnected();
+    });
+  };
+  incomingCall.hangUp();
+}
+
+function answerDisconnected() {
+  log("Attempting to answer disconnected call, should be ignored.");
+
+  incomingCall.onconnecting = function onconnectingErr(event) {
+    log("Received 'connecting' call event, but should not have.");
+    ok(false, "Received 'connecting' event when answered disconnected call");
+  }
+
+  incomingCall.onconnected = function onconnectedErr(event) {
+    log("Received 'connected' call event, but should not have.");
+    ok(false, "Received 'connected' event when answered disconnected call");
+  }
+
+  incomingCall.answer();
+
+  is(telephony.active, null);
+  is(telephony.calls.length, 0);
+  holdDisconnected();
+}
+
+function holdDisconnected() {
+  log("Attempting to hold disconnected call, should be ignored.");
+
+  incomingCall.onholding = function onholdingErr(event) {
+    log("Received 'holding' call event, but should not have.");
+    ok(false, "Received 'holding' event when held a disconnected call");
+  }
+
+  incomingCall.onheld = function onheldErr(event) {
+    log("Received 'held' call event, but should not have.");
+    ok(false, "Received 'held' event when held a disconnected call");
+  }
+
+  incomingCall.hold();
+
+  is(telephony.active, null);
+  is(telephony.calls.length, 0);
+  resumeDisconnected();
+}
+
+function resumeDisconnected() {
+  log("Attempting to resume disconnected call, should be ignored.");
+
+  incomingCall.onresuming = function onresumingErr(event) {
+    log("Received 'resuming' call event, but should not have.");
+    ok(false, "Received 'resuming' event when resumed disconnected call");
+  }
+
+  incomingCall.onconnected = function onconnectedErr(event) {
+    log("Received 'connected' call event, but should not have.");
+    ok(false, "Received 'connected' event when resumed disconnected call");
+  }
+
+  incomingCall.resume();
+
+  is(telephony.active, null);
+  is(telephony.calls.length, 0);
+  hangUpNonConnected();
+}
+
+function hangUpNonConnected() {
+  log("Attempting to hang-up disconnected call, should be ignored.");
+
+  incomingCall.ondisconnecting = function ondisconnectingErr(event) {
+    log("Received 'disconnecting' call event, but should not have.");
+    ok(false, "Received 'disconnecting' event when hung-up non-active call");
+  }
+
+  incomingCall.ondisconnected = function ondisconnectedErr(event) {
+    log("Received 'disconnected' call event, but should not have.");
+    ok(false, "Received 'disconnected' event when hung-up non-active call");
+  }
+
+  incomingCall.hangUp();
+
+  is(telephony.active, null);
+  is(telephony.calls.length, 0);
+  cleanUp();
+}
+
+function cleanUp() {
+  telephony.onincoming = null;
+  SpecialPowers.removePermission("telephony", document);
+  finish();
+}
+
+// Start the test
+verifyInitialState();