Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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);
14 setUp();
15 }
17 function setUp() {
18 let frequency = FMRadio.frequencyLowerBound + FMRadio.channelWidth;
19 FMRadio.enable(frequency);
20 FMRadio.onenabled = seek;
21 }
23 function seek() {
24 var request = FMRadio.seekUp();
25 ok(request);
27 // There are two possibilities which depends on the system
28 // process scheduling (bug 911063 comment 0):
29 // - the second seek fails
30 // - both seeks are executed
32 request.onerror = function() {
33 ok(!firstSeekCompletes);
34 cleanUp();
35 };
37 var firstSeekCompletes = false;
38 request.onsuccess = function() {
39 firstSeekCompletes = true;
40 };
42 var seekAgainReq = FMRadio.seekUp();
43 ok(seekAgainReq);
45 seekAgainReq.onerror = function() {
46 log("Cancel the first seek to finish the test");
47 let cancelReq = FMRadio.cancelSeek();
48 ok(cancelReq);
50 // It's possible that the first seek completes when the
51 // cancel request is handled.
52 cancelReq.onerror = function() {
53 cleanUp();
54 };
55 };
57 seekAgainReq.onsuccess = function() {
58 ok(firstSeekCompletes);
59 cleanUp();
60 };
61 }
63 function cleanUp() {
64 FMRadio.disable();
65 FMRadio.ondisabled = function() {
66 FMRadio.ondisabled = null;
67 ok(!FMRadio.enabled);
68 finish();
69 };
70 }
72 verifyInitialState();