|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 MARIONETTE_TIMEOUT = 10000; |
|
5 |
|
6 SpecialPowers.addPermission("fmradio", true, document); |
|
7 |
|
8 let FMRadio = window.navigator.mozFMRadio; |
|
9 |
|
10 function verifyInitialState() { |
|
11 log("Verifying initial state."); |
|
12 ok(FMRadio); |
|
13 is(FMRadio.enabled, false); |
|
14 setUp(); |
|
15 } |
|
16 |
|
17 function setUp() { |
|
18 let frequency = FMRadio.frequencyLowerBound + FMRadio.channelWidth; |
|
19 FMRadio.enable(frequency); |
|
20 FMRadio.onenabled = seek; |
|
21 } |
|
22 |
|
23 function seek() { |
|
24 log("Seek up"); |
|
25 var request = FMRadio.seekUp(); |
|
26 ok(request); |
|
27 |
|
28 var seekUpIsCancelled = false; |
|
29 request.onerror = function() { |
|
30 seekUpIsCancelled = true; |
|
31 }; |
|
32 |
|
33 var seekUpCompleted = false; |
|
34 request.onsuccess = function() { |
|
35 ok(!seekUpIsCancelled); |
|
36 seekUpCompleted = true; |
|
37 }; |
|
38 |
|
39 log("Seek up"); |
|
40 var cancelSeekReq = FMRadio.cancelSeek(); |
|
41 ok(cancelSeekReq); |
|
42 |
|
43 // There are two possibilities which depends on the system |
|
44 // process scheduling (bug 911063 comment 0): |
|
45 // - seekup action is canceled |
|
46 // - seekup's onsuccess fires before cancelSeek's onerror |
|
47 |
|
48 cancelSeekReq.onsuccess = function() { |
|
49 ok(seekUpIsCancelled, "Seekup request failed."); |
|
50 cleanUp(); |
|
51 }; |
|
52 |
|
53 cancelSeekReq.onerror = function() { |
|
54 ok(seekUpCompleted); |
|
55 cleanUp(); |
|
56 }; |
|
57 } |
|
58 |
|
59 function cleanUp() { |
|
60 FMRadio.disable(); |
|
61 FMRadio.ondisabled = function() { |
|
62 FMRadio.ondisabled = null; |
|
63 ok(!FMRadio.enabled); |
|
64 finish(); |
|
65 }; |
|
66 } |
|
67 |
|
68 verifyInitialState(); |
|
69 |