dom/phonenumberutils/tests/test_phonenumberutils.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/phonenumberutils/tests/test_phonenumberutils.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,68 @@
     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 +  <script type="application/javascript" src="head.js"/>
    1.16 +  <!-- test results are displayed in the html:body -->
    1.17 +  <body xmlns="http://www.w3.org/1999/xhtml">
    1.18 +  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=809213"
    1.19 +     target="_blank">Mozilla Bug 809213</a>
    1.20 +  </body>
    1.21 +
    1.22 +<script type="application/javascript;version=1.8">
    1.23 +
    1.24 +"use strict";
    1.25 +
    1.26 +Components.utils.import("resource://gre/modules/Services.jsm");
    1.27 +Components.utils.import("resource://gre/modules/PhoneNumberUtils.jsm");
    1.28 +
    1.29 +Services.prefs.setIntPref("dom.phonenumber.substringmatching.BR", 8);
    1.30 +Services.prefs.setCharPref("ril.lastKnownSimMcc", "724");
    1.31 +
    1.32 +function CantParseWithMcc(dial, mcc) {
    1.33 +  var result = PhoneNumberUtils.parseWithMCC(dial, mcc);
    1.34 +  if (result) {
    1.35 +    ok(false, "Shouldn't parse!\n");
    1.36 +    dump("expected: does not parse");
    1.37 +    dump("got: " + dial + " " + mcc);
    1.38 +  } else {
    1.39 +    ok(true, "Parses");
    1.40 +  }
    1.41 +}
    1.42 +
    1.43 +function ParseWithMcc(dial, mcc) {
    1.44 +  var result = PhoneNumberUtils.parseWithMCC(dial, mcc);
    1.45 +  if (result) {
    1.46 +    ok(true, "Parses!\n");
    1.47 +  } else {
    1.48 +    ok(false, "Should Parse");
    1.49 +    dump("expected: parses");
    1.50 +  }
    1.51 +}
    1.52 +
    1.53 +function FuzzyMatch(number1, number2, expect) {
    1.54 +  var result = PhoneNumberUtils.fuzzyMatch(number1, number2);
    1.55 +  is(result, expect, "FuzzyMatch OK!");
    1.56 +}
    1.57 +
    1.58 +// Unknown mcc
    1.59 +CantParseWithMcc("1234", 123);
    1.60 +ParseWithMcc("4165555555", 302);
    1.61 +
    1.62 +is(PhoneNumberUtils.normalize("123abc", true), "123", "NumbersOnly");
    1.63 +is(PhoneNumberUtils.normalize("123abc", false), "123222", "NumbersOnly");
    1.64 +
    1.65 +FuzzyMatch("123abc", "123222", true);
    1.66 +FuzzyMatch("123456789", "123456789", true);
    1.67 +FuzzyMatch("111", null, false);
    1.68 +FuzzyMatch("+552155555555", "2155555555", true);
    1.69 +FuzzyMatch("aaa123456789", "zzzzz123456789", true);
    1.70 +</script>
    1.71 +</window>

mercurial