dom/fmradio/test/marionette/test_bug862672.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/fmradio/test/marionette/test_bug862672.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,53 @@
     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 = 10000;
     1.8 +
     1.9 +SpecialPowers.addPermission("fmradio", true, document);
    1.10 +
    1.11 +let FMRadio = window.navigator.mozFMRadio;
    1.12 +
    1.13 +function verifyInitialState() {
    1.14 +  log("Verifying initial state.");
    1.15 +  ok(FMRadio);
    1.16 +  is(FMRadio.enabled, false);
    1.17 +  enableThenDisable();
    1.18 +}
    1.19 +
    1.20 +function enableThenDisable() {
    1.21 +  log("Enable FM Radio and disable it immediately.");
    1.22 +  var frequency = FMRadio.frequencyLowerBound + FMRadio.channelWidth;
    1.23 +  var request = FMRadio.enable(frequency);
    1.24 +  ok(request);
    1.25 +
    1.26 +  var failedToEnable = false;
    1.27 +  request.onerror = function() {
    1.28 +    failedToEnable = true;
    1.29 +  };
    1.30 +
    1.31 +  var enableCompleted = false;
    1.32 +  request.onsuccess = function() {
    1.33 +    ok(!failedToEnable);
    1.34 +    enableCompleted = true;
    1.35 +  };
    1.36 +
    1.37 +  var disableReq = FMRadio.disable();
    1.38 +  ok(disableReq);
    1.39 +
    1.40 +  disableReq.onsuccess = function() {
    1.41 +    // There are two possibilities which depends on the system
    1.42 +    // process scheduling (bug 911063 comment 0):
    1.43 +    //   - enable fails
    1.44 +    //   - enable's onsuccess fires before disable's onsucess
    1.45 +    ok(failedToEnable || enableCompleted);
    1.46 +    ok(!FMRadio.enabled);
    1.47 +    finish();
    1.48 +  };
    1.49 +
    1.50 +  disableReq.onerror = function() {
    1.51 +    ok(false, "Disable request should not fail.");
    1.52 +  };
    1.53 +}
    1.54 +
    1.55 +verifyInitialState();
    1.56 +

mercurial