1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/mobileconnection/tests/marionette/test_mobile_mmi.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,107 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +MARIONETTE_TIMEOUT = 20000; 1.8 + 1.9 +SpecialPowers.addPermission("mobileconnection", true, document); 1.10 + 1.11 +// Permission changes can't change existing Navigator.prototype 1.12 +// objects, so grab our objects from a new Navigator 1.13 +let ifr = document.createElement("iframe"); 1.14 +let mobileConnection; 1.15 +ifr.onload = function() { 1.16 + mobileConnection = ifr.contentWindow.navigator.mozMobileConnections[0]; 1.17 + 1.18 + tasks.run(); 1.19 +}; 1.20 +document.body.appendChild(ifr); 1.21 + 1.22 +let tasks = { 1.23 + // List of test functions. Each of them should call |tasks.next()| when 1.24 + // completed or |tasks.abort()| to jump to the last one. 1.25 + _tasks: [], 1.26 + _nextTaskIndex: 0, 1.27 + 1.28 + push: function(func) { 1.29 + this._tasks.push(func); 1.30 + }, 1.31 + 1.32 + next: function() { 1.33 + let index = this._nextTaskIndex++; 1.34 + let task = this._tasks[index]; 1.35 + try { 1.36 + task(); 1.37 + } catch (ex) { 1.38 + ok(false, "test task[" + index + "] throws: " + ex); 1.39 + // Run last task as clean up if possible. 1.40 + if (index != this._tasks.length - 1) { 1.41 + this.abort(); 1.42 + } 1.43 + } 1.44 + }, 1.45 + 1.46 + abort: function() { 1.47 + this._tasks[this._tasks.length - 1](); 1.48 + }, 1.49 + 1.50 + run: function() { 1.51 + this.next(); 1.52 + } 1.53 +}; 1.54 + 1.55 +tasks.push(function verifyInitialState() { 1.56 + log("Verifying initial state."); 1.57 + 1.58 + ok(mobileConnection instanceof ifr.contentWindow.MozMobileConnection, 1.59 + "mobileConnection is instanceof " + mobileConnection.constructor); 1.60 + 1.61 + tasks.next(); 1.62 +}); 1.63 + 1.64 +tasks.push(function testGettingIMEI() { 1.65 + log("Test *#06# ..."); 1.66 + 1.67 + let request = mobileConnection.sendMMI("*#06#"); 1.68 + ok(request instanceof DOMRequest, 1.69 + "request is instanceof " + request.constructor); 1.70 + 1.71 + request.onsuccess = function onsuccess(event) { 1.72 + ok(true, "request success"); 1.73 + is(typeof event.target.result, "object", "typeof result object"); 1.74 + ok(event.target.result instanceof Object, "result instanceof Object"); 1.75 + is(event.target.result.statusMessage, "000000000000000", "Emulator IMEI"); 1.76 + is(event.target.result.serviceCode, "scImei", "Service code IMEI"); 1.77 + is(event.target.result.additionalInformation, undefined, 1.78 + "No additional information"); 1.79 + tasks.next(); 1.80 + } 1.81 + request.onerror = function onerror() { 1.82 + ok(false, "request should not error"); 1.83 + tasks.abort(); 1.84 + }; 1.85 +}); 1.86 + 1.87 +tasks.push(function testInvalidMMICode(){ 1.88 + log("Test invalid MMI code ..."); 1.89 + 1.90 + let request = mobileConnection.sendMMI("InvalidMMICode"); 1.91 + ok(request instanceof DOMRequest, 1.92 + "request is instanceof " + request.constructor); 1.93 + 1.94 + request.onsuccess = function onsuccess(event) { 1.95 + ok(false, "request should not success"); 1.96 + tasks.abort(); 1.97 + }; 1.98 + 1.99 + request.onerror = function onerror() { 1.100 + ok(true, "request error"); 1.101 + is(request.error.name, "emMmiError", "MMI error name"); 1.102 + tasks.next(); 1.103 + }; 1.104 +}); 1.105 + 1.106 +// WARNING: All tasks should be pushed before this!!! 1.107 +tasks.push(function cleanUp() { 1.108 + SpecialPowers.removePermission("mobileconnection", document); 1.109 + finish(); 1.110 +});