1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/mobileconnection/tests/marionette/mobile_header.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,60 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +SpecialPowers.addPermission("mobileconnection", true, document); 1.8 + 1.9 +// In single sim scenario, there is only one mobileConnection, we can always use 1.10 +// the first instance. 1.11 +let mobileConnection = window.navigator.mozMobileConnections[0]; 1.12 +ok(mobileConnection instanceof MozMobileConnection, 1.13 + "mobileConnection is instanceof " + mobileConnection.constructor); 1.14 + 1.15 +let _pendingEmulatorCmdCount = 0; 1.16 + 1.17 +/* Remove permission and execute finish() */ 1.18 +let cleanUp = function() { 1.19 + waitFor(function() { 1.20 + SpecialPowers.removePermission("mobileconnection", document); 1.21 + finish(); 1.22 + }, function() { 1.23 + return _pendingEmulatorCmdCount === 0; 1.24 + }); 1.25 +}; 1.26 + 1.27 +/* Helper for tasks */ 1.28 +let taskHelper = { 1.29 + tasks: [], 1.30 + 1.31 + push: function(task) { 1.32 + this.tasks.push(task); 1.33 + }, 1.34 + 1.35 + runNext: function() { 1.36 + let task = this.tasks.shift(); 1.37 + if (!task) { 1.38 + cleanUp(); 1.39 + return; 1.40 + } 1.41 + 1.42 + if (typeof task === "function") { 1.43 + task(); 1.44 + } 1.45 + }, 1.46 +}; 1.47 + 1.48 +/* Helper for emulator console command */ 1.49 +let emulatorHelper = { 1.50 + sendCommand: function(cmd, callback) { 1.51 + _pendingEmulatorCmdCount++; 1.52 + runEmulatorCmd(cmd, function(results) { 1.53 + _pendingEmulatorCmdCount--; 1.54 + 1.55 + let result = results[results.length - 1]; 1.56 + is(result, "OK", "'"+ cmd +"' returns '" + result + "'"); 1.57 + 1.58 + if (callback && typeof callback === "function") { 1.59 + callback(results); 1.60 + } 1.61 + }); 1.62 + }, 1.63 +};