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.
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
4 MARIONETTE_TIMEOUT = 10000;
6 SpecialPowers.addPermission("fmradio", true, document);
8 let FMRadio = window.navigator.mozFMRadio;
10 function verifyInitialState() {
11 log("Verifying initial state.");
12 ok(FMRadio);
13 is(FMRadio.enabled, false);
15 log("Verifying attributes when disabled.");
16 is(FMRadio.frequency, null);
17 ok(FMRadio.frequencyLowerBound);
18 ok(FMRadio.frequencyUpperBound);
19 ok(FMRadio.frequencyUpperBound > FMRadio.frequencyLowerBound);
20 ok(FMRadio.channelWidth);
22 enableFMRadio();
23 }
25 function enableFMRadio() {
26 log("Verifying behaviors when enabled.");
27 var frequency = FMRadio.frequencyLowerBound + FMRadio.channelWidth;
28 var request = FMRadio.enable(frequency);
29 ok(request, "FMRadio.enable(r" + frequency + ") returns request");
31 request.onsuccess = function() {
32 ok(FMRadio.enabled);
33 ok(typeof FMRadio.frequency == "number");
34 ok(FMRadio.frequency > FMRadio.frequencyLowerBound);
35 };
37 request.onerror = function() {
38 ok(null, "Failed to enable");
39 };
41 var enabled = false;
42 FMRadio.onenabled = function() {
43 FMRadio.onenabled = null;
44 enabled = FMRadio.enabled;
45 };
47 FMRadio.onfrequencychange = function() {
48 log("Check if 'onfrequencychange' event is fired after the 'enabled' event");
49 FMRadio.onfrequencychange = null;
50 ok(enabled, "FMRadio is enabled when handling `onfrequencychange`");
51 disableFMRadio();
52 };
53 }
55 function disableFMRadio() {
56 log("Verify behaviors when disabled");
58 // There are two possibilities which depends on the system
59 // process scheduling (bug 911063 comment 0):
60 // - seek fails
61 // - seek's onsuccess fires before disable's onsucess
62 var seekRequest = FMRadio.seekUp();
63 var seekCompletes = false;
64 var failedToSeek = false;
65 seekRequest.onerror = function() {
66 ok(!seekCompletes);
67 failedToSeek = true;
68 };
70 seekRequest.onsuccess = function() {
71 ok(!failedToSeek);
72 seekCompletes = true;
73 };
75 FMRadio.disable();
76 FMRadio.ondisabled = function() {
77 FMRadio.ondisabled = null;
78 ok(seekCompletes || failedToSeek);
79 ok(!FMRadio.enabled);
80 finish();
81 };
82 }
84 verifyInitialState();