michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: MARIONETTE_TIMEOUT = 10000; michael@0: michael@0: SpecialPowers.addPermission("fmradio", true, document); michael@0: michael@0: let FMRadio = window.navigator.mozFMRadio; michael@0: michael@0: function verifyInitialState() { michael@0: log("Verifying initial state."); michael@0: ok(FMRadio); michael@0: is(FMRadio.enabled, false); michael@0: setUp(); michael@0: } michael@0: michael@0: function setUp() { michael@0: let frequency = FMRadio.frequencyLowerBound + FMRadio.channelWidth; michael@0: FMRadio.enable(frequency); michael@0: FMRadio.onenabled = seek; michael@0: } michael@0: michael@0: function seek() { michael@0: var request = FMRadio.seekUp(); michael@0: ok(request); michael@0: michael@0: // There are two possibilities which depends on the system michael@0: // process scheduling (bug 911063 comment 0): michael@0: // - the second seek fails michael@0: // - both seeks are executed michael@0: michael@0: request.onerror = function() { michael@0: ok(!firstSeekCompletes); michael@0: cleanUp(); michael@0: }; michael@0: michael@0: var firstSeekCompletes = false; michael@0: request.onsuccess = function() { michael@0: firstSeekCompletes = true; michael@0: }; michael@0: michael@0: var seekAgainReq = FMRadio.seekUp(); michael@0: ok(seekAgainReq); michael@0: michael@0: seekAgainReq.onerror = function() { michael@0: log("Cancel the first seek to finish the test"); michael@0: let cancelReq = FMRadio.cancelSeek(); michael@0: ok(cancelReq); michael@0: michael@0: // It's possible that the first seek completes when the michael@0: // cancel request is handled. michael@0: cancelReq.onerror = function() { michael@0: cleanUp(); michael@0: }; michael@0: }; michael@0: michael@0: seekAgainReq.onsuccess = function() { michael@0: ok(firstSeekCompletes); michael@0: cleanUp(); michael@0: }; michael@0: } michael@0: michael@0: function cleanUp() { michael@0: FMRadio.disable(); michael@0: FMRadio.ondisabled = function() { michael@0: FMRadio.ondisabled = null; michael@0: ok(!FMRadio.enabled); michael@0: finish(); michael@0: }; michael@0: } michael@0: michael@0: verifyInitialState(); michael@0: