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 = 'mmdb_head.js'; |
michael@0 | 6 | |
michael@0 | 7 | const DBNAME = "test_mmdb_foreachmatchedmmsdeliveryinfo:" + newUUID(); |
michael@0 | 8 | |
michael@0 | 9 | const PHONE_0 = "+15555215500"; |
michael@0 | 10 | const PHONE_1 = "+15555215501"; |
michael@0 | 11 | const PHONE_2 = "+15555215502"; |
michael@0 | 12 | const PHONE_2_NET = "5555215502"; |
michael@0 | 13 | const PHONE_3 = "+15555215503"; |
michael@0 | 14 | const PHONE_3_NET = "5555215503"; |
michael@0 | 15 | const EMAIL_1 = "foo@bar.com"; |
michael@0 | 16 | let deliveryInfo = [ |
michael@0 | 17 | { receiver: PHONE_1 }, |
michael@0 | 18 | { receiver: PHONE_2 }, |
michael@0 | 19 | { receiver: PHONE_1 }, |
michael@0 | 20 | { receiver: PHONE_2_NET }, |
michael@0 | 21 | { receiver: PHONE_3_NET }, |
michael@0 | 22 | { receiver: EMAIL_1 }, |
michael@0 | 23 | { receiver: PHONE_3 }, |
michael@0 | 24 | ]; |
michael@0 | 25 | |
michael@0 | 26 | function clearTraversed(aDeliveryInfo) { |
michael@0 | 27 | for (let element of aDeliveryInfo) { |
michael@0 | 28 | delete element.traversed; |
michael@0 | 29 | } |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | function doTest(aMmdb, aNeedle, aVerifyFunc, aCount) { |
michael@0 | 33 | log(" '" + aNeedle + "': " + aCount); |
michael@0 | 34 | |
michael@0 | 35 | clearTraversed(deliveryInfo); |
michael@0 | 36 | |
michael@0 | 37 | let count = 0; |
michael@0 | 38 | aMmdb.forEachMatchedMmsDeliveryInfo(deliveryInfo, aNeedle, function(aElement) { |
michael@0 | 39 | ok(true, "checking " + aElement.receiver); |
michael@0 | 40 | ok(!aElement.hasOwnProperty("traversed"), "element.traversed"); |
michael@0 | 41 | aVerifyFunc(aElement); |
michael@0 | 42 | |
michael@0 | 43 | aElement.traversed = true; |
michael@0 | 44 | ++count; |
michael@0 | 45 | }); |
michael@0 | 46 | is(count, aCount, "matched count"); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | function testNotFound(aMmdb) { |
michael@0 | 50 | log("Testing unavailable"); |
michael@0 | 51 | |
michael@0 | 52 | doTest(aMmdb, PHONE_0, function(aElement) { |
michael@0 | 53 | ok(false, "Should never have a match"); |
michael@0 | 54 | }, 0); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | function testDirectMatch(aMmdb) { |
michael@0 | 58 | log("Testing direct matching"); |
michael@0 | 59 | |
michael@0 | 60 | for (let needle of [PHONE_1, EMAIL_1]) { |
michael@0 | 61 | let count = deliveryInfo.reduce(function(aCount, aElement) { |
michael@0 | 62 | return aElement.receiver == needle ? aCount + 1 : aCount; |
michael@0 | 63 | }, 0); |
michael@0 | 64 | doTest(aMmdb, needle, function(aElement) { |
michael@0 | 65 | is(aElement.receiver, needle, "element.receiver"); |
michael@0 | 66 | }, count); |
michael@0 | 67 | } |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | function testPhoneMatch(aMmdb) { |
michael@0 | 71 | log("Testing phone matching"); |
michael@0 | 72 | |
michael@0 | 73 | let verifyFunc = function(aValid, aElement) { |
michael@0 | 74 | ok(aValid.indexOf(aElement.receiver) >= 0, "element.receiver"); |
michael@0 | 75 | }; |
michael@0 | 76 | |
michael@0 | 77 | let matchingGroups = [ |
michael@0 | 78 | [PHONE_2, PHONE_2_NET], |
michael@0 | 79 | [PHONE_3, PHONE_3_NET], |
michael@0 | 80 | ]; |
michael@0 | 81 | for (let group of matchingGroups) { |
michael@0 | 82 | for (let item of group) { |
michael@0 | 83 | doTest(aMmdb, item, verifyFunc.bind(null, group), group.length); |
michael@0 | 84 | } |
michael@0 | 85 | } |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | startTestBase(function testCaseMain() { |
michael@0 | 89 | let mmdb = newMobileMessageDB(); |
michael@0 | 90 | return initMobileMessageDB(mmdb, DBNAME, 0) |
michael@0 | 91 | .then(() => testNotFound(mmdb)) |
michael@0 | 92 | .then(() => testDirectMatch(mmdb)) |
michael@0 | 93 | .then(() => testPhoneMatch(mmdb)) |
michael@0 | 94 | .then(() => closeMobileMessageDB(mmdb)); |
michael@0 | 95 | }); |