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: enableThenDisable(); michael@0: } michael@0: michael@0: function enableThenDisable() { michael@0: log("Enable FM Radio and disable it immediately."); michael@0: var frequency = FMRadio.frequencyLowerBound + FMRadio.channelWidth; michael@0: var request = FMRadio.enable(frequency); michael@0: ok(request); michael@0: michael@0: var failedToEnable = false; michael@0: request.onerror = function() { michael@0: failedToEnable = true; michael@0: }; michael@0: michael@0: var enableCompleted = false; michael@0: request.onsuccess = function() { michael@0: ok(!failedToEnable); michael@0: enableCompleted = true; michael@0: }; michael@0: michael@0: var disableReq = FMRadio.disable(); michael@0: ok(disableReq); michael@0: michael@0: disableReq.onsuccess = function() { michael@0: // There are two possibilities which depends on the system michael@0: // process scheduling (bug 911063 comment 0): michael@0: // - enable fails michael@0: // - enable's onsuccess fires before disable's onsucess michael@0: ok(failedToEnable || enableCompleted); michael@0: ok(!FMRadio.enabled); michael@0: finish(); michael@0: }; michael@0: michael@0: disableReq.onerror = function() { michael@0: ok(false, "Disable request should not fail."); michael@0: }; michael@0: } michael@0: michael@0: verifyInitialState(); michael@0: