1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/phonenumberutils/tests/test_phonenumberservice.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,158 @@ 1.4 +<?xml version="1.0"?> 1.5 + 1.6 +<!-- Any copyright is dedicated to the Public Domain. 1.7 + - http://creativecommons.org/publicdomain/zero/1.0/ --> 1.8 + 1.9 +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> 1.10 +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> 1.11 + 1.12 +<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 1.13 + title="Mozilla Bug 781379"> 1.14 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 1.15 + <!-- test results are displayed in the html:body --> 1.16 + <body xmlns="http://www.w3.org/1999/xhtml"> 1.17 + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=809213" 1.18 + target="_blank">Mozilla Bug 809213</a> 1.19 + </body> 1.20 + 1.21 +<script type="application/javascript;version=1.8"> 1.22 + 1.23 +"use strict"; 1.24 + 1.25 +Components.utils.import("resource://gre/modules/Services.jsm"); 1.26 +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); 1.27 + 1.28 +Services.prefs.setIntPref("dom.phonenumber.substringmatching.BR", 8); 1.29 +Services.prefs.setCharPref("ril.lastKnownSimMcc", "724"); 1.30 + 1.31 +var pm = SpecialPowers.Cc["@mozilla.org/permissionmanager;1"] 1.32 + .getService(SpecialPowers.Ci.nsIPermissionManager); 1.33 + 1.34 +pm.addFromPrincipal(window.document.nodePrincipal, "phonenumberservice", 1.35 + SpecialPowers.Ci.nsIPermissionManager.ALLOW_ACTION); 1.36 + 1.37 +function onUnwantedSuccess() { 1.38 + ok(false, "onUnwantedSuccess: shouldn't get here"); 1.39 +} 1.40 + 1.41 +function onFailure() { 1.42 + ok(false, "in on Failure!"); 1.43 +} 1.44 + 1.45 +var req; 1.46 +var index = 0; 1.47 +var mozPhoneNumberService = window.navigator.mozPhoneNumberService; 1.48 +ok(mozPhoneNumberService, "mozPhoneNumberService exists"); 1.49 +var steps = [ 1.50 + function() { 1.51 + req = mozPhoneNumberService.fuzzyMatch("123", "123"); 1.52 + req.onsuccess = function(e) { 1.53 + is(req.result, true, "same number"); 1.54 + next(); 1.55 + }; 1.56 + req.onerror = onFailure; 1.57 + }, 1.58 + function() { 1.59 + req = mozPhoneNumberService.fuzzyMatch("abcdef", "222333"); 1.60 + req.onsuccess = function(e) { 1.61 + is(req.result, true, "normalize first number"); 1.62 + next(); 1.63 + }; 1.64 + req.onerror = onFailure; 1.65 + }, 1.66 + function() { 1.67 + req = mozPhoneNumberService.fuzzyMatch("abc333", "222def"); 1.68 + req.onsuccess = function(e) { 1.69 + is(req.result, true, "normalize first and second number"); 1.70 + next(); 1.71 + }; 1.72 + req.onerror = onFailure; 1.73 + }, 1.74 + function() { 1.75 + req = mozPhoneNumberService.fuzzyMatch("1234567", "1234568"); 1.76 + req.onsuccess = function(e) { 1.77 + is(req.result, false, "different numbers should not match"); 1.78 + next(); 1.79 + }; 1.80 + req.onerror = onFailure; 1.81 + }, 1.82 + function() { 1.83 + req = mozPhoneNumberService.fuzzyMatch("1234567", "123456"); 1.84 + req.onsuccess = function(e) { 1.85 + is(req.result, false, "different length numbers should not match"); 1.86 + next(); 1.87 + }; 1.88 + req.onerror = onFailure; 1.89 + }, 1.90 + function() { 1.91 + req = mozPhoneNumberService.fuzzyMatch("1234567", "123456---"); 1.92 + req.onsuccess = function(e) { 1.93 + is(req.result, false, "invalid number should not match valid number"); 1.94 + next(); 1.95 + }; 1.96 + req.onerror = onFailure; 1.97 + }, 1.98 + function() { 1.99 + req = mozPhoneNumberService.fuzzyMatch("111", undefined); 1.100 + req.onsuccess = function(e) { 1.101 + is(req.result, false, "missing second argument should not match"); 1.102 + next(); 1.103 + }; 1.104 + req.onerror = onFailure; 1.105 + }, 1.106 + function() { 1.107 + req = mozPhoneNumberService.fuzzyMatch(undefined, "111"); 1.108 + req.onsuccess = function(e) { 1.109 + is(req.result, false, "missing first argument should not match"); 1.110 + next(); 1.111 + }; 1.112 + req.onerror = onFailure; 1.113 + }, 1.114 + function() { 1.115 + req = mozPhoneNumberService.fuzzyMatch(null, ""); 1.116 + req.onsuccess = function(e) { 1.117 + is(req.result, true, "missing first argument should fuzzy match empty string"); 1.118 + next(); 1.119 + }; 1.120 + req.onerror = onFailure; 1.121 + }, 1.122 + function() { 1.123 + req = mozPhoneNumberService.fuzzyMatch("+552155555555", "2155555555"); 1.124 + req.onsuccess = function(e) { 1.125 + is(req.result, true, "test internationalization of number"); 1.126 + next(); 1.127 + }; 1.128 + req.onerror = onFailure; 1.129 + }, 1.130 + function() { 1.131 + req = mozPhoneNumberService.fuzzyMatch("aaa123456789", "zzzzz123456789"); 1.132 + req.onsuccess = function(e) { 1.133 + is(req.result, true, "substring matching should be in effect"); 1.134 + next(); 1.135 + }; 1.136 + req.onerror = onFailure; 1.137 + }, 1.138 + function () { 1.139 + ok(true, "all done!\n"); 1.140 + SimpleTest.finish(); 1.141 + } 1.142 +]; 1.143 + 1.144 +function next() { 1.145 + ok(true, "Begin!"); 1.146 + if (index >= steps.length) { 1.147 + ok(false, "Shouldn't get here!"); 1.148 + return; 1.149 + } 1.150 + try { 1.151 + var i = index++; 1.152 + steps[i](); 1.153 + } catch(ex) { 1.154 + ok(false, "Caught exception", ex); 1.155 + } 1.156 +} 1.157 + 1.158 +SimpleTest.waitForExplicitFinish(); 1.159 +addLoadEvent(next); 1.160 +</script> 1.161 +</window>