|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 MARIONETTE_TIMEOUT = 60000; |
|
5 MARIONETTE_HEAD_JS = "icc_header.js"; |
|
6 |
|
7 const EMULATOR_ICCID = "89014103211118510720"; |
|
8 |
|
9 function testReadContacts(type) { |
|
10 let request = icc.readContacts(type); |
|
11 request.onsuccess = function onsuccess() { |
|
12 let contacts = request.result; |
|
13 |
|
14 is(Array.isArray(contacts), true); |
|
15 |
|
16 is(contacts[0].name[0], "Mozilla"); |
|
17 is(contacts[0].tel[0].value, "15555218201"); |
|
18 is(contacts[0].id, EMULATOR_ICCID + "1"); |
|
19 |
|
20 is(contacts[1].name[0], "Saßê黃"); |
|
21 is(contacts[1].tel[0].value, "15555218202"); |
|
22 is(contacts[1].id, EMULATOR_ICCID + "2"); |
|
23 |
|
24 is(contacts[2].name[0], "Fire 火"); |
|
25 is(contacts[2].tel[0].value, "15555218203"); |
|
26 is(contacts[2].id, EMULATOR_ICCID + "3"); |
|
27 |
|
28 is(contacts[3].name[0], "Huang 黃"); |
|
29 is(contacts[3].tel[0].value, "15555218204"); |
|
30 is(contacts[3].id, EMULATOR_ICCID + "4"); |
|
31 |
|
32 taskHelper.runNext(); |
|
33 }; |
|
34 |
|
35 request.onerror = function onerror() { |
|
36 ok(false, "Cannot get " + type + " contacts"); |
|
37 taskHelper.runNext(); |
|
38 }; |
|
39 } |
|
40 |
|
41 function testAddContact(type, pin2) { |
|
42 let contact = new mozContact({ |
|
43 name: ["add"], |
|
44 tel: [{value: "0912345678"}], |
|
45 email:[] |
|
46 }); |
|
47 |
|
48 let updateRequest = icc.updateContact(type, contact, pin2); |
|
49 |
|
50 updateRequest.onsuccess = function onsuccess() { |
|
51 let updatedContact = updateRequest.result; |
|
52 ok(updatedContact, "updateContact should have retuend a mozContact."); |
|
53 ok(updatedContact.id.startsWith(EMULATOR_ICCID), |
|
54 "The returned mozContact has wrong id."); |
|
55 |
|
56 // Get ICC contact for checking new contact |
|
57 |
|
58 let getRequest = icc.readContacts(type); |
|
59 |
|
60 getRequest.onsuccess = function onsuccess() { |
|
61 let contacts = getRequest.result; |
|
62 |
|
63 // There are 4 SIM contacts which are harded in emulator |
|
64 is(contacts.length, 5); |
|
65 |
|
66 is(contacts[4].name[0], "add"); |
|
67 is(contacts[4].tel[0].value, "0912345678"); |
|
68 |
|
69 taskHelper.runNext(); |
|
70 }; |
|
71 |
|
72 getRequest.onerror = function onerror() { |
|
73 ok(false, "Cannot get " + type + " contacts: " + getRequest.error.name); |
|
74 taskHelper.runNext(); |
|
75 }; |
|
76 }; |
|
77 |
|
78 updateRequest.onerror = function onerror() { |
|
79 if (type === "fdn" && pin2 === undefined) { |
|
80 ok(updateRequest.error.name === "SimPin2", |
|
81 "expected error when pin2 is not provided"); |
|
82 } else { |
|
83 ok(false, "Cannot add " + type + " contact: " + updateRequest.error.name); |
|
84 } |
|
85 taskHelper.runNext(); |
|
86 }; |
|
87 } |
|
88 |
|
89 /* Test read adn contacts */ |
|
90 taskHelper.push(function testReadAdnContacts() { |
|
91 testReadContacts("adn"); |
|
92 }); |
|
93 |
|
94 /* Test add adn contacts */ |
|
95 taskHelper.push(function testAddAdnContact() { |
|
96 testAddContact("adn"); |
|
97 }); |
|
98 |
|
99 /* Test read fdn contacts */ |
|
100 taskHelper.push(function testReadAdnContacts() { |
|
101 testReadContacts("fdn"); |
|
102 }); |
|
103 |
|
104 /* Test add fdn contacts */ |
|
105 taskHelper.push(function testReadAdnContacts() { |
|
106 testAddContact("fdn", "0000"); |
|
107 }); |
|
108 |
|
109 /* Test add fdn contacts without passing pin2 */ |
|
110 taskHelper.push(function testReadAdnContacts() { |
|
111 testAddContact("fdn"); |
|
112 }); |
|
113 |
|
114 // Start test |
|
115 taskHelper.runNext(); |