DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (d1ed7de67f5a)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
<?xml version="1.0"?>

<!-- Any copyright is dedicated to the Public Domain.
   - http://creativecommons.org/publicdomain/zero/1.0/ -->

<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>

<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        title="Mozilla Bug 781379">
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
  <!-- test results are displayed in the html:body -->
  <body xmlns="http://www.w3.org/1999/xhtml">
  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=809213"
     target="_blank">Mozilla Bug 809213</a>
  </body>

<script type="application/javascript;version=1.8">

"use strict";

Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");

Services.prefs.setIntPref("dom.phonenumber.substringmatching.BR", 8);
Services.prefs.setCharPref("ril.lastKnownSimMcc", "724");

var pm = SpecialPowers.Cc["@mozilla.org/permissionmanager;1"]
                      .getService(SpecialPowers.Ci.nsIPermissionManager);

pm.addFromPrincipal(window.document.nodePrincipal, "phonenumberservice",
                    SpecialPowers.Ci.nsIPermissionManager.ALLOW_ACTION);

function onUnwantedSuccess() {
  ok(false, "onUnwantedSuccess: shouldn't get here");
}

function onFailure() {
  ok(false, "in on Failure!");
}

var req;
var index = 0;
var mozPhoneNumberService = window.navigator.mozPhoneNumberService;
ok(mozPhoneNumberService, "mozPhoneNumberService exists");
var steps = [
  function() {
    req = mozPhoneNumberService.fuzzyMatch("123", "123");
    req.onsuccess = function(e) {
      is(req.result, true, "same number");
      next();
    };
    req.onerror = onFailure;
  },
  function() {
    req = mozPhoneNumberService.fuzzyMatch("abcdef", "222333");
    req.onsuccess = function(e) {
      is(req.result, true, "normalize first number");
      next();
    };
    req.onerror = onFailure;
  },
  function() {
    req = mozPhoneNumberService.fuzzyMatch("abc333", "222def");
    req.onsuccess = function(e) {
      is(req.result, true, "normalize first and second number");
      next();
    };
    req.onerror = onFailure;
  },
  function() {
    req = mozPhoneNumberService.fuzzyMatch("1234567", "1234568");
    req.onsuccess = function(e) {
      is(req.result, false, "different numbers should not match");
      next();
    };
    req.onerror = onFailure;
  },
  function() {
    req = mozPhoneNumberService.fuzzyMatch("1234567", "123456");
    req.onsuccess = function(e) {
      is(req.result, false, "different length numbers should not match");
      next();
    };
    req.onerror = onFailure;
  },
  function() {
    req = mozPhoneNumberService.fuzzyMatch("1234567", "123456---");
    req.onsuccess = function(e) {
      is(req.result, false, "invalid number should not match valid number");
      next();
    };
    req.onerror = onFailure;
  },
  function() {
    req = mozPhoneNumberService.fuzzyMatch("111", undefined);
    req.onsuccess = function(e) {
      is(req.result, false, "missing second argument should not match");
      next();
    };
    req.onerror = onFailure;
  },
  function() {
    req = mozPhoneNumberService.fuzzyMatch(undefined, "111");
    req.onsuccess = function(e) {
      is(req.result, false, "missing first argument should not match");
      next();
    };
    req.onerror = onFailure;
  },
  function() {
    req = mozPhoneNumberService.fuzzyMatch(null, "");
    req.onsuccess = function(e) {
      is(req.result, true, "missing first argument should fuzzy match empty string");
      next();
    };
    req.onerror = onFailure;
  },
  function() {
    req = mozPhoneNumberService.fuzzyMatch("+552155555555", "2155555555");
    req.onsuccess = function(e) {
      is(req.result, true, "test internationalization of number");
      next();
    };
    req.onerror = onFailure;
  },
  function() {
    req = mozPhoneNumberService.fuzzyMatch("aaa123456789", "zzzzz123456789");
    req.onsuccess = function(e) {
      is(req.result, true, "substring matching should be in effect");
      next();
    };
    req.onerror = onFailure;
  },
  function () {
    ok(true, "all done!\n");
    SimpleTest.finish();
  }
];

function next() {
  ok(true, "Begin!");
  if (index >= steps.length) {
    ok(false, "Shouldn't get here!");
    return;
  }
  try {
    var i = index++;
    steps[i]();
  } catch(ex) {
    ok(false, "Caught exception", ex);
  }
}

SimpleTest.waitForExplicitFinish();
addLoadEvent(next);
</script>
</window>