dom/mobileconnection/tests/marionette/test_mobile_mmi.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/ */
     4 MARIONETTE_TIMEOUT = 20000;
     6 SpecialPowers.addPermission("mobileconnection", true, document);
     8 // Permission changes can't change existing Navigator.prototype
     9 // objects, so grab our objects from a new Navigator
    10 let ifr = document.createElement("iframe");
    11 let mobileConnection;
    12 ifr.onload = function() {
    13   mobileConnection = ifr.contentWindow.navigator.mozMobileConnections[0];
    15   tasks.run();
    16 };
    17 document.body.appendChild(ifr);
    19 let tasks = {
    20   // List of test functions. Each of them should call |tasks.next()| when
    21   // completed or |tasks.abort()| to jump to the last one.
    22   _tasks: [],
    23   _nextTaskIndex: 0,
    25   push: function(func) {
    26     this._tasks.push(func);
    27   },
    29   next: function() {
    30     let index = this._nextTaskIndex++;
    31     let task = this._tasks[index];
    32     try {
    33       task();
    34     } catch (ex) {
    35       ok(false, "test task[" + index + "] throws: " + ex);
    36       // Run last task as clean up if possible.
    37       if (index != this._tasks.length - 1) {
    38         this.abort();
    39       }
    40     }
    41   },
    43   abort: function() {
    44     this._tasks[this._tasks.length - 1]();
    45   },
    47   run: function() {
    48     this.next();
    49   }
    50 };
    52 tasks.push(function verifyInitialState() {
    53   log("Verifying initial state.");
    55   ok(mobileConnection instanceof ifr.contentWindow.MozMobileConnection,
    56       "mobileConnection is instanceof " + mobileConnection.constructor);
    58   tasks.next();
    59 });
    61 tasks.push(function testGettingIMEI() {
    62   log("Test *#06# ...");
    64   let request = mobileConnection.sendMMI("*#06#");
    65   ok(request instanceof DOMRequest,
    66      "request is instanceof " + request.constructor);
    68   request.onsuccess = function onsuccess(event) {
    69     ok(true, "request success");
    70     is(typeof event.target.result, "object", "typeof result object");
    71     ok(event.target.result instanceof Object, "result instanceof Object");
    72     is(event.target.result.statusMessage, "000000000000000", "Emulator IMEI");
    73     is(event.target.result.serviceCode, "scImei", "Service code IMEI");
    74     is(event.target.result.additionalInformation, undefined,
    75        "No additional information");
    76     tasks.next();
    77   }
    78   request.onerror = function onerror() {
    79     ok(false, "request should not error");
    80     tasks.abort();
    81   };
    82 });
    84 tasks.push(function testInvalidMMICode(){
    85   log("Test invalid MMI code ...");
    87   let request = mobileConnection.sendMMI("InvalidMMICode");
    88   ok(request instanceof DOMRequest,
    89      "request is instanceof " + request.constructor);
    91   request.onsuccess = function onsuccess(event) {
    92     ok(false, "request should not success");
    93     tasks.abort();
    94   };
    96   request.onerror = function onerror() {
    97     ok(true, "request error");
    98     is(request.error.name, "emMmiError", "MMI error name");
    99     tasks.next();
   100   };
   101 });
   103 // WARNING: All tasks should be pushed before this!!!
   104 tasks.push(function cleanUp() {
   105   SpecialPowers.removePermission("mobileconnection", document);
   106   finish();
   107 });

mercurial