dom/contacts/tests/test_contacts_substringmatching.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <!DOCTYPE html>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=877302
     5 -->
     6 <head>
     7   <title>Test for Bug 877302 substring matching for WebContacts</title>
     8   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
     9   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    10   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    11 </head>
    12 <body>
    14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=877302">Mozilla Bug 877302</a>
    15 <p id="display"></p>
    16 <div id="content" style="display: none">
    18 </div>
    19 <pre id="test">
    20 <script type="text/javascript;version=1.8" src="http://mochi.test:8888/tests/dom/contacts/tests/shared.js"></script>
    21 <script class="testbody" type="text/javascript">
    22 "use strict";
    24 var substringLength = 8;
    26 var prop = {
    27   tel: [{value: "7932012345" }, {value: "7932012346"}]
    28 };
    30 var prop2 = {
    31   tel: [{value: "01187654321" }]
    32 };
    34 var prop3 = {
    35   tel: [{ value: "+43332112346" }]
    36 };
    38 var prop4 = {
    39   tel: [{ value: "(0414) 233-9888" }]
    40 };
    42 var brazilianNumber = {
    43   international1: "0041557932012345",
    44   international2: "+557932012345"
    45 };
    47 var prop5 = {
    48   tel: [{value: brazilianNumber.international2}]
    49 };
    51 var req;
    52 var steps = [
    53   function () {
    54     ok(true, "Deleting database");
    55     req = mozContacts.clear()
    56     req.onsuccess = function () {
    57       ok(true, "Deleted the database");
    58       next();
    59     }
    60     req.onerror = onFailure;
    61   },
    62   function () {
    63     ok(true, "Adding contact");
    64     createResult1 = new mozContact(prop);
    65     req = navigator.mozContacts.save(createResult1);
    66     req.onsuccess = function () {
    67       ok(createResult1.id, "The contact now has an ID.");
    68       sample_id1 = createResult1.id;
    69       next();
    70     };
    71     req.onerror = onFailure;
    72   },
    73   function () {
    74     ok(true, "Retrieving all contacts");
    75     req = mozContacts.find({});
    76     req.onsuccess = function () {
    77       is(req.result.length, 1, "One contact.");
    78       findResult1 = req.result[0];
    79       next();
    80     };
    81     req.onerror = onFailure;
    82   },
    83   function () {
    84     ok(true, "Retrieving by substring 1");
    85     var length = prop.tel[0].value.length;
    86     var num = prop.tel[0].value.substring(length - substringLength, length);
    87     var options = {filterBy: ["tel"],
    88                    filterOp: "match",
    89                    filterValue: num};
    90     req = mozContacts.find(options);
    91     req.onsuccess = function () {
    92       is(req.result.length, 1, "Found exactly 1 contact.");
    93       findResult1 = req.result[0];
    94       ok(findResult1.id == sample_id1, "Same ID");
    95       is(findResult1.tel[0].value, "7932012345", "Same Value");
    96       next();
    97     };
    98     req.onerror = onFailure;
    99   },
   100   function () {
   101     ok(true, "Retrieving by substring 2");
   102     var length = prop.tel[1].value.length;
   103     var num = prop.tel[1].value.substring(length - substringLength, length);
   104     var options = {filterBy: ["tel"],
   105                    filterOp: "match",
   106                    filterValue: num};
   107     req = mozContacts.find(options);
   108     req.onsuccess = function () {
   109       is(req.result.length, 1, "Found exactly 1 contact.");
   110       findResult1 = req.result[0];
   111       ok(findResult1.id == sample_id1, "Same ID");
   112       is(findResult1.tel[0].value, "7932012345", "Same Value");
   113       next();
   114     };
   115     req.onerror = onFailure;
   116   },
   117   function () {
   118     ok(true, "Retrieving by substring 3");
   119     var length = prop.tel[0].value.length;
   120     var num = prop.tel[0].value.substring(length - substringLength + 1, length);
   121     var options = {filterBy: ["tel"],
   122                    filterOp: "match",
   123                    filterValue: num};
   124     req = mozContacts.find(options);
   125     req.onsuccess = function () {
   126       is(req.result.length, 0, "Found exactly 0 contacts.");
   127       next();
   128     };
   129     req.onerror = onFailure;
   130   },
   131   function () {
   132     ok(true, "Retrieving by substring 4");
   133     var length = prop.tel[0].value.length;
   134     var num = prop.tel[0].value.substring(length - substringLength - 1, length);
   135     var options = {filterBy: ["tel"],
   136                    filterOp: "match",
   137                    filterValue: num};
   138     req = mozContacts.find(options);
   139     req.onsuccess = function () {
   140       is(req.result.length, 1, "Found exactly 1 contacts.");
   141       next();
   142     };
   143     req.onerror = onFailure;
   144   },
   145   function () {
   146     ok(true, "Adding contact");
   147     createResult1 = new mozContact(prop2);
   148     req = navigator.mozContacts.save(createResult1);
   149     req.onsuccess = function () {
   150       ok(createResult1.id, "The contact now has an ID.");
   151       sample_id1 = createResult1.id;
   152       next();
   153     };
   154     req.onerror = onFailure;
   155   },
   156   function () {
   157     ok(true, "Retrieving by substring 5");
   158     var options = {filterBy: ["tel"],
   159                    filterOp: "match",
   160                    filterValue: "87654321"};
   161     req = mozContacts.find(options);
   162     req.onsuccess = function () {
   163       is(req.result.length, 1, "Found exactly 1 contacts.");
   164       next();
   165     };
   166     req.onerror = onFailure;
   167   },
   168   function () {
   169     ok(true, "Retrieving by substring 6");
   170     var options = {filterBy: ["tel"],
   171                    filterOp: "match",
   172                    filterValue: "01187654321"};
   173     req = mozContacts.find(options);
   174     req.onsuccess = function () {
   175       is(req.result.length, 1, "Found exactly 1 contacts.");
   176       next();
   177     };
   178     req.onerror = onFailure;
   179   },
   180   function () {
   181     ok(true, "Retrieving by substring 7");
   182     var options = {filterBy: ["tel"],
   183                    filterOp: "match",
   184                    filterValue: "909087654321"};
   185     req = mozContacts.find(options);
   186     req.onsuccess = function () {
   187       is(req.result.length, 1, "Found exactly 1 contacts.");
   188       next();
   189     };
   190     req.onerror = onFailure;
   191   },
   192   function () {
   193     ok(true, "Retrieving by substring 8");
   194     var options = {filterBy: ["tel"],
   195                    filterOp: "match",
   196                    filterValue: "0411187654321"};
   197     req = mozContacts.find(options);
   198     req.onsuccess = function () {
   199       is(req.result.length, 1, "Found exactly 1 contacts.");
   200       next();
   201     };
   202     req.onerror = onFailure;
   203   },
   204   function () {
   205     ok(true, "Retrieving by substring 9");
   206     var options = {filterBy: ["tel"],
   207                    filterOp: "match",
   208                    filterValue: "90411187654321"};
   209     req = mozContacts.find(options);
   210     req.onsuccess = function () {
   211       is(req.result.length, 1, "Found exactly 1 contacts.");
   212       next();
   213     };
   214     req.onerror = onFailure;
   215   },
   216   function () {
   217     ok(true, "Retrieving by substring 10");
   218     var options = {filterBy: ["tel"],
   219                    filterOp: "match",
   220                    filterValue: "+551187654321"};
   221     req = mozContacts.find(options);
   222     req.onsuccess = function () {
   223       is(req.result.length, 1, "Found exactly 1 contacts.");
   224       next();
   225     };
   226     req.onerror = onFailure;
   227   },
   228   function () {
   229     ok(true, "Deleting database");
   230     req = mozContacts.clear()
   231     req.onsuccess = function () {
   232       ok(true, "Deleted the database");
   233       next();
   234     }
   235     req.onerror = onFailure;
   236   },
   237   function () {
   238     ok(true, "Adding contact");
   239     createResult1 = new mozContact(prop3);
   240     req = navigator.mozContacts.save(createResult1);
   241     req.onsuccess = function () {
   242       ok(createResult1.id, "The contact now has an ID.");
   243       sample_id1 = createResult1.id;
   244       next();
   245     };
   246     req.onerror = onFailure;
   247   },
   248   function () {
   249     if (!isAndroid) { // Bug 905927
   250       ok(true, "Retrieving by substring 1");
   251       var length = prop3.tel[0].value.length;
   252       var num = prop3.tel[0].value.substring(length - substringLength, length);
   253       var options = {filterBy: ["tel"],
   254                      filterOp: "match",
   255                      filterValue: num};
   256       req = mozContacts.find(options);
   257       req.onsuccess = function () {
   258         is(req.result.length, 0, "Found exactly 0 contacts.");
   259         next();
   260       };
   261       req.onerror = onFailure;
   262     } else {
   263       SpecialPowers.executeSoon(next);
   264     }
   265   },
   266   function () {
   267     ok(true, "Adding contact");
   268     createResult1 = new mozContact(prop4);
   269     req = navigator.mozContacts.save(createResult1);
   270     req.onsuccess = function () {
   271       ok(createResult1.id, "The contact now has an ID.");
   272       sample_id1 = createResult1.id;
   273       next();
   274     };
   275     req.onerror = onFailure;
   276   },
   277   function () {
   278     ok(true, "Retrieving by substring 1");
   279     var num = "(0424) 233-9888"
   280     var options = {filterBy: ["tel"],
   281                    filterOp: "match",
   282                    filterValue: num};
   283     req = mozContacts.find(options);
   284     req.onsuccess = function () {
   285       is(req.result.length, 1, "Found exactly 1 contacts.");
   286       next();
   287     };
   288     req.onerror = onFailure;
   289   },
   290   function () {
   291     ok(true, "Deleting database");
   292     req = mozContacts.clear()
   293     req.onsuccess = function () {
   294       ok(true, "Deleted the database");
   295       next();
   296     }
   297     req.onerror = onFailure;
   298   },
   299   function () {
   300     ok(true, "Adding a new contact with a Brazilian country code");
   301     createResult1 = new mozContact(prop5);
   302     req = navigator.mozContacts.save(createResult1);
   303     req.onsuccess = function () {
   304       ok(createResult1.id, "The contact now has an ID.");
   305       sample_id1 = createResult1.id;
   306       next();
   307     };
   308     req.onerror = onFailure;
   309   },
   310   function () {
   311     ok(true, "Searching for international number with prefix");
   312     var options = {filterBy: ["tel"],
   313                    filterOp: "match",
   314                    filterValue: brazilianNumber.international1};
   315     req = mozContacts.find(options);
   316     req.onsuccess = function () {
   317       ok(req.result.length == 1, "Found exactly 1 contact.");
   318       findResult1 = req.result[0];
   319       ok(findResult1.id == sample_id1, "Same ID");
   320       next();
   321     };
   322     req.onerror = onFailure;
   323   },
   324   function () {
   325     ok(true, "Deleting database");
   326     req = mozContacts.clear()
   327     req.onsuccess = function () {
   328       ok(true, "Deleted the database");
   329       next();
   330     }
   331     req.onerror = onFailure;
   332   },
   333   function () {
   334     ok(true, "all done!\n");
   335     SimpleTest.finish();
   336   }
   337 ];
   339 SpecialPowers.pushPrefEnv({
   340   set: [
   341     ["dom.phonenumber.substringmatching.BR", substringLength],
   342     ["ril.lastKnownSimMcc", "724"]
   343   ]
   344 }, start_tests);
   345 </script>
   346 </pre>
   347 </body>
   348 </html>

mercurial