dom/fmradio/test/marionette/test_one_seek_at_once.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/fmradio/test/marionette/test_one_seek_at_once.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,73 @@
     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 +  setUp();
    1.18 +}
    1.19 +
    1.20 +function setUp() {
    1.21 +  let frequency = FMRadio.frequencyLowerBound + FMRadio.channelWidth;
    1.22 +  FMRadio.enable(frequency);
    1.23 +  FMRadio.onenabled = seek;
    1.24 +}
    1.25 +
    1.26 +function seek() {
    1.27 +  var request = FMRadio.seekUp();
    1.28 +  ok(request);
    1.29 +
    1.30 +  // There are two possibilities which depends on the system
    1.31 +  // process scheduling (bug 911063 comment 0):
    1.32 +  //   - the second seek fails
    1.33 +  //   - both seeks are executed
    1.34 +
    1.35 +  request.onerror = function() {
    1.36 +    ok(!firstSeekCompletes);
    1.37 +    cleanUp();
    1.38 +  };
    1.39 +
    1.40 +  var firstSeekCompletes = false;
    1.41 +  request.onsuccess = function() {
    1.42 +    firstSeekCompletes = true;
    1.43 +  };
    1.44 +
    1.45 +  var seekAgainReq = FMRadio.seekUp();
    1.46 +  ok(seekAgainReq);
    1.47 +
    1.48 +  seekAgainReq.onerror = function() {
    1.49 +    log("Cancel the first seek to finish the test");
    1.50 +    let cancelReq = FMRadio.cancelSeek();
    1.51 +    ok(cancelReq);
    1.52 +
    1.53 +    // It's possible that the first seek completes when the
    1.54 +    // cancel request is handled.
    1.55 +    cancelReq.onerror = function() {
    1.56 +      cleanUp();
    1.57 +    };
    1.58 +  };
    1.59 +
    1.60 +  seekAgainReq.onsuccess = function() {
    1.61 +    ok(firstSeekCompletes);
    1.62 +    cleanUp();
    1.63 +  };
    1.64 +}
    1.65 +
    1.66 +function cleanUp() {
    1.67 +  FMRadio.disable();
    1.68 +  FMRadio.ondisabled = function() {
    1.69 +    FMRadio.ondisabled = null;
    1.70 +    ok(!FMRadio.enabled);
    1.71 +    finish();
    1.72 +  };
    1.73 +}
    1.74 +
    1.75 +verifyInitialState();
    1.76 +

mercurial