dom/fmradio/test/marionette/test_one_seek_at_once.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:28722f807547
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 var request = FMRadio.seekUp();
25 ok(request);
26
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
31
32 request.onerror = function() {
33 ok(!firstSeekCompletes);
34 cleanUp();
35 };
36
37 var firstSeekCompletes = false;
38 request.onsuccess = function() {
39 firstSeekCompletes = true;
40 };
41
42 var seekAgainReq = FMRadio.seekUp();
43 ok(seekAgainReq);
44
45 seekAgainReq.onerror = function() {
46 log("Cancel the first seek to finish the test");
47 let cancelReq = FMRadio.cancelSeek();
48 ok(cancelReq);
49
50 // It's possible that the first seek completes when the
51 // cancel request is handled.
52 cancelReq.onerror = function() {
53 cleanUp();
54 };
55 };
56
57 seekAgainReq.onsuccess = function() {
58 ok(firstSeekCompletes);
59 cleanUp();
60 };
61 }
62
63 function cleanUp() {
64 FMRadio.disable();
65 FMRadio.ondisabled = function() {
66 FMRadio.ondisabled = null;
67 ok(!FMRadio.enabled);
68 finish();
69 };
70 }
71
72 verifyInitialState();
73

mercurial