Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | MARIONETTE_TIMEOUT = 10000; |
michael@0 | 5 | |
michael@0 | 6 | SpecialPowers.addPermission("fmradio", true, document); |
michael@0 | 7 | |
michael@0 | 8 | let FMRadio = window.navigator.mozFMRadio; |
michael@0 | 9 | |
michael@0 | 10 | function verifyInitialState() { |
michael@0 | 11 | log("Verifying initial state."); |
michael@0 | 12 | ok(FMRadio); |
michael@0 | 13 | is(FMRadio.enabled, false); |
michael@0 | 14 | setUp(); |
michael@0 | 15 | } |
michael@0 | 16 | |
michael@0 | 17 | function setUp() { |
michael@0 | 18 | let frequency = FMRadio.frequencyLowerBound + FMRadio.channelWidth; |
michael@0 | 19 | FMRadio.enable(frequency); |
michael@0 | 20 | FMRadio.onenabled = setFrequency; |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | function setFrequency() { |
michael@0 | 24 | log("Set Frequency"); |
michael@0 | 25 | let frequency = FMRadio.frequency + FMRadio.channelWidth; |
michael@0 | 26 | var request = FMRadio.setFrequency(frequency); |
michael@0 | 27 | ok(request); |
michael@0 | 28 | |
michael@0 | 29 | request.onsuccess = setOutOfRangeFrequency; |
michael@0 | 30 | request.onerror = function() { |
michael@0 | 31 | ok(false, "setFrequency request should not fail."); |
michael@0 | 32 | }; |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | function setOutOfRangeFrequency() { |
michael@0 | 36 | log("Set Frequency that out of the range"); |
michael@0 | 37 | var request = FMRadio.setFrequency(FMRadio.frequencyUpperBound + 1); |
michael@0 | 38 | ok(request); |
michael@0 | 39 | |
michael@0 | 40 | request.onsuccess = function() { |
michael@0 | 41 | ok(false, "The request of setting an out-of-range frequency should fail."); |
michael@0 | 42 | }; |
michael@0 | 43 | request.onerror = setFrequencyWhenSeeking; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | function setFrequencyWhenSeeking() { |
michael@0 | 47 | log("Set frequency when seeking"); |
michael@0 | 48 | var request = FMRadio.seekUp(); |
michael@0 | 49 | ok(request); |
michael@0 | 50 | |
michael@0 | 51 | // There are two possibilities which depends on the system |
michael@0 | 52 | // process scheduling (bug 911063 comment 0): |
michael@0 | 53 | // - seek fails |
michael@0 | 54 | // - seek's onsuccess fires before setFrequency's onsucess |
michael@0 | 55 | |
michael@0 | 56 | var failedToSeek = false; |
michael@0 | 57 | request.onerror = function() { |
michael@0 | 58 | failedToSeek = true; |
michael@0 | 59 | }; |
michael@0 | 60 | |
michael@0 | 61 | var seekCompletes = false; |
michael@0 | 62 | request.onsuccess = function() { |
michael@0 | 63 | ok(!failedToSeek); |
michael@0 | 64 | seekCompletes = true; |
michael@0 | 65 | }; |
michael@0 | 66 | |
michael@0 | 67 | var frequency = FMRadio.frequencyUpperBound - FMRadio.channelWidth; |
michael@0 | 68 | var setFreqRequest = FMRadio.setFrequency(frequency); |
michael@0 | 69 | ok(setFreqRequest); |
michael@0 | 70 | |
michael@0 | 71 | setFreqRequest.onsuccess = function() { |
michael@0 | 72 | ok(failedToSeek || seekCompletes); |
michael@0 | 73 | cleanUp(); |
michael@0 | 74 | }; |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | function cleanUp() { |
michael@0 | 78 | FMRadio.disable(); |
michael@0 | 79 | FMRadio.ondisabled = function() { |
michael@0 | 80 | FMRadio.ondisabled = null; |
michael@0 | 81 | ok(!FMRadio.enabled); |
michael@0 | 82 | finish(); |
michael@0 | 83 | }; |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | verifyInitialState(); |
michael@0 | 87 |