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 = 60000;
5 MARIONETTE_HEAD_JS = 'head.js';
7 const AUDIO_MANAGER_CONTRACT_ID = "@mozilla.org/telephony/audiomanager;1";
9 // See nsIAudioManager
10 const PHONE_STATE_INVALID = -2;
11 const PHONE_STATE_CURRENT = -1;
12 const PHONE_STATE_NORMAL = 0;
13 const PHONE_STATE_RINGTONE = 1;
14 const PHONE_STATE_IN_CALL = 2;
15 const PHONE_STATE_IN_COMMUNICATION = 3;
17 let audioManager;
18 function checkStates(speakerEnabled, phoneState) {
19 if (!audioManager) {
20 audioManager = SpecialPowers.Cc[AUDIO_MANAGER_CONTRACT_ID]
21 .getService(SpecialPowers.Ci.nsIAudioManager);
22 ok(audioManager, "nsIAudioManager instance");
23 }
25 is(telephony.speakerEnabled, speakerEnabled, "telephony.speakerEnabled");
26 if (phoneState == PHONE_STATE_CURRENT) {
27 ok(audioManager.phoneState === PHONE_STATE_CURRENT ||
28 audioManager.phoneState === PHONE_STATE_NORMAL, "audioManager.phoneState");
29 } else {
30 is(audioManager.phoneState, phoneState, "audioManager.phoneState");
31 }
32 }
34 function check(phoneStateOrig, phoneStateEnabled, phoneStateDisabled) {
35 checkStates(false, phoneStateOrig);
37 let canEnableSpeaker = arguments.length > 1;
38 telephony.speakerEnabled = true;
39 if (canEnableSpeaker) {
40 checkStates(true, phoneStateEnabled);
41 } else {
42 checkStates(false, phoneStateOrig);
43 return;
44 }
46 telephony.speakerEnabled = false;
47 checkStates(false, arguments.length > 2 ? phoneStateDisabled : phoneStateOrig);
48 }
50 // Start the test
51 startTest(function() {
52 let outNumber = "5555550101";
53 let inNumber = "5555550201";
54 let outCall;
55 let inCall;
57 Promise.resolve()
58 .then(() => check(PHONE_STATE_CURRENT, PHONE_STATE_NORMAL, PHONE_STATE_NORMAL))
60 // Dial in
61 .then(() => gRemoteDial(inNumber))
62 .then(call => { inCall = call; })
63 // TODO - Bug 948860: should this be {RINGTONE, RINGTONE, RINGTONE}?
64 // From current UX spec, there is no chance that an user may enable speaker
65 // during alerting, so basically this 'set speaker enable' action can't
66 // happen in B2G.
67 .then(() => check(PHONE_STATE_RINGTONE, PHONE_STATE_NORMAL, PHONE_STATE_NORMAL))
68 .then(() => gAnswer(inCall))
69 .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL))
70 // Hang up all
71 .then(() => gRemoteHangUp(inCall))
72 .then(() => check(PHONE_STATE_NORMAL, PHONE_STATE_NORMAL))
74 // Dial out
75 .then(() => gDial(outNumber))
76 .then(call => { outCall = call; })
77 .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL))
78 .then(() => gRemoteAnswer(outCall))
79 .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL))
80 // Hang up all
81 .then(() => gRemoteHangUp(outCall))
82 .then(() => check(PHONE_STATE_NORMAL, PHONE_STATE_NORMAL))
84 // Dial out
85 .then(() => gDial(outNumber))
86 .then(call => { outCall = call; })
87 .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL))
88 .then(() => gRemoteAnswer(outCall))
89 .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL))
90 // Dial out and dial in
91 .then(() => gRemoteDial(inNumber))
92 .then(call => { inCall = call; })
93 .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL))
94 .then(() => gAnswer(inCall))
95 .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL))
96 // Conference
97 .then(() => gAddCallsToConference([outCall, inCall]))
98 .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL))
99 // Hang up all
100 .then(() => gRemoteHangUpCalls([outCall, inCall]))
101 .then(() => check(PHONE_STATE_NORMAL, PHONE_STATE_NORMAL))
103 // End
104 .then(null, error => {
105 ok(false, 'promise rejects during test.');
106 })
107 .then(finish);
108 });