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