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 | |
michael@0 | 15 | log("Verifying attributes when disabled."); |
michael@0 | 16 | is(FMRadio.frequency, null); |
michael@0 | 17 | ok(FMRadio.frequencyLowerBound); |
michael@0 | 18 | ok(FMRadio.frequencyUpperBound); |
michael@0 | 19 | ok(FMRadio.frequencyUpperBound > FMRadio.frequencyLowerBound); |
michael@0 | 20 | ok(FMRadio.channelWidth); |
michael@0 | 21 | |
michael@0 | 22 | enableFMRadio(); |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | function enableFMRadio() { |
michael@0 | 26 | log("Verifying behaviors when enabled."); |
michael@0 | 27 | var frequency = FMRadio.frequencyLowerBound + FMRadio.channelWidth; |
michael@0 | 28 | var request = FMRadio.enable(frequency); |
michael@0 | 29 | ok(request, "FMRadio.enable(r" + frequency + ") returns request"); |
michael@0 | 30 | |
michael@0 | 31 | request.onsuccess = function() { |
michael@0 | 32 | ok(FMRadio.enabled); |
michael@0 | 33 | ok(typeof FMRadio.frequency == "number"); |
michael@0 | 34 | ok(FMRadio.frequency > FMRadio.frequencyLowerBound); |
michael@0 | 35 | }; |
michael@0 | 36 | |
michael@0 | 37 | request.onerror = function() { |
michael@0 | 38 | ok(null, "Failed to enable"); |
michael@0 | 39 | }; |
michael@0 | 40 | |
michael@0 | 41 | var enabled = false; |
michael@0 | 42 | FMRadio.onenabled = function() { |
michael@0 | 43 | FMRadio.onenabled = null; |
michael@0 | 44 | enabled = FMRadio.enabled; |
michael@0 | 45 | }; |
michael@0 | 46 | |
michael@0 | 47 | FMRadio.onfrequencychange = function() { |
michael@0 | 48 | log("Check if 'onfrequencychange' event is fired after the 'enabled' event"); |
michael@0 | 49 | FMRadio.onfrequencychange = null; |
michael@0 | 50 | ok(enabled, "FMRadio is enabled when handling `onfrequencychange`"); |
michael@0 | 51 | disableFMRadio(); |
michael@0 | 52 | }; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | function disableFMRadio() { |
michael@0 | 56 | log("Verify behaviors when disabled"); |
michael@0 | 57 | |
michael@0 | 58 | // There are two possibilities which depends on the system |
michael@0 | 59 | // process scheduling (bug 911063 comment 0): |
michael@0 | 60 | // - seek fails |
michael@0 | 61 | // - seek's onsuccess fires before disable's onsucess |
michael@0 | 62 | var seekRequest = FMRadio.seekUp(); |
michael@0 | 63 | var seekCompletes = false; |
michael@0 | 64 | var failedToSeek = false; |
michael@0 | 65 | seekRequest.onerror = function() { |
michael@0 | 66 | ok(!seekCompletes); |
michael@0 | 67 | failedToSeek = true; |
michael@0 | 68 | }; |
michael@0 | 69 | |
michael@0 | 70 | seekRequest.onsuccess = function() { |
michael@0 | 71 | ok(!failedToSeek); |
michael@0 | 72 | seekCompletes = true; |
michael@0 | 73 | }; |
michael@0 | 74 | |
michael@0 | 75 | FMRadio.disable(); |
michael@0 | 76 | FMRadio.ondisabled = function() { |
michael@0 | 77 | FMRadio.ondisabled = null; |
michael@0 | 78 | ok(seekCompletes || failedToSeek); |
michael@0 | 79 | ok(!FMRadio.enabled); |
michael@0 | 80 | finish(); |
michael@0 | 81 | }; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | verifyInitialState(); |
michael@0 | 85 |