dom/mobilemessage/tests/marionette/test_smsc_address.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/mobilemessage/tests/marionette/test_smsc_address.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,78 @@
     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 = 60000;
     1.8 +
     1.9 +SpecialPowers.addPermission("sms", true, document);
    1.10 +
    1.11 +// Expected SMSC addresses of emulator
    1.12 +const SMSC = "\"+123456789\",145";
    1.13 +
    1.14 +let manager = window.navigator.mozMobileMessage;
    1.15 +
    1.16 +let tasks = {
    1.17 +  // List of test fuctions. Each of them should call |tasks.next()| when
    1.18 +  // completed or |tasks.finish()| to jump to the last one.
    1.19 +  _tasks: [],
    1.20 +  _nextTaskIndex: 0,
    1.21 +
    1.22 +  push: function(func) {
    1.23 +    this._tasks.push(func);
    1.24 +  },
    1.25 +
    1.26 +  next: function() {
    1.27 +    let index = this._nextTaskIndex++;
    1.28 +    let task = this._tasks[index];
    1.29 +    try {
    1.30 +      task();
    1.31 +    } catch (ex) {
    1.32 +      ok(false, "test task[" + index + "] throws: " + ex);
    1.33 +      // Run last task as clean up if possible.
    1.34 +      if (index != this._tasks.length - 1) {
    1.35 +        this.finish();
    1.36 +      }
    1.37 +    }
    1.38 +  },
    1.39 +
    1.40 +  finish: function() {
    1.41 +    this._tasks[this._tasks.length - 1]();
    1.42 +  },
    1.43 +
    1.44 +  run: function() {
    1.45 +    this.next();
    1.46 +  }
    1.47 +};
    1.48 +
    1.49 +tasks.push(function init() {
    1.50 +  log("Initialize test object.");
    1.51 +  ok(manager instanceof MozMobileMessageManager,
    1.52 +     "manager is instance of " + manager.constructor);
    1.53 +  tasks.next();
    1.54 +});
    1.55 +
    1.56 +tasks.push(function readSmscAddress() {
    1.57 +  log("read SMSC address");
    1.58 +
    1.59 +  let req = manager.getSmscAddress();
    1.60 +  ok(req, "DOMRequest object for getting smsc address");
    1.61 +
    1.62 +  req.onsuccess = function(e) {
    1.63 +    is(e.target.result, SMSC, "SMSC address");
    1.64 +    tasks.next();
    1.65 +  };
    1.66 +
    1.67 +  req.onerror = function(error) {
    1.68 +    ok(false, "readSmscAddress(): Received 'onerror'");
    1.69 +    tasks.finish();
    1.70 +  };
    1.71 +});
    1.72 +
    1.73 +// WARNING: All tasks should be pushed before this!!!
    1.74 +tasks.push(function cleanUp() {
    1.75 +  manager.onreceived = null;
    1.76 +  SpecialPowers.removePermission("sms", document);
    1.77 +  finish();
    1.78 +});
    1.79 +
    1.80 +// Start the test
    1.81 +tasks.run();

mercurial