1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/fmradio/test/marionette/test_cancel_seek.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,69 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +MARIONETTE_TIMEOUT = 10000; 1.8 + 1.9 +SpecialPowers.addPermission("fmradio", true, document); 1.10 + 1.11 +let FMRadio = window.navigator.mozFMRadio; 1.12 + 1.13 +function verifyInitialState() { 1.14 + log("Verifying initial state."); 1.15 + ok(FMRadio); 1.16 + is(FMRadio.enabled, false); 1.17 + setUp(); 1.18 +} 1.19 + 1.20 +function setUp() { 1.21 + let frequency = FMRadio.frequencyLowerBound + FMRadio.channelWidth; 1.22 + FMRadio.enable(frequency); 1.23 + FMRadio.onenabled = seek; 1.24 +} 1.25 + 1.26 +function seek() { 1.27 + log("Seek up"); 1.28 + var request = FMRadio.seekUp(); 1.29 + ok(request); 1.30 + 1.31 + var seekUpIsCancelled = false; 1.32 + request.onerror = function() { 1.33 + seekUpIsCancelled = true; 1.34 + }; 1.35 + 1.36 + var seekUpCompleted = false; 1.37 + request.onsuccess = function() { 1.38 + ok(!seekUpIsCancelled); 1.39 + seekUpCompleted = true; 1.40 + }; 1.41 + 1.42 + log("Seek up"); 1.43 + var cancelSeekReq = FMRadio.cancelSeek(); 1.44 + ok(cancelSeekReq); 1.45 + 1.46 + // There are two possibilities which depends on the system 1.47 + // process scheduling (bug 911063 comment 0): 1.48 + // - seekup action is canceled 1.49 + // - seekup's onsuccess fires before cancelSeek's onerror 1.50 + 1.51 + cancelSeekReq.onsuccess = function() { 1.52 + ok(seekUpIsCancelled, "Seekup request failed."); 1.53 + cleanUp(); 1.54 + }; 1.55 + 1.56 + cancelSeekReq.onerror = function() { 1.57 + ok(seekUpCompleted); 1.58 + cleanUp(); 1.59 + }; 1.60 +} 1.61 + 1.62 +function cleanUp() { 1.63 + FMRadio.disable(); 1.64 + FMRadio.ondisabled = function() { 1.65 + FMRadio.ondisabled = null; 1.66 + ok(!FMRadio.enabled); 1.67 + finish(); 1.68 + }; 1.69 +} 1.70 + 1.71 +verifyInitialState(); 1.72 +