mirror of
https://github.com/classilla/tenfourfox.git
synced 2024-09-10 11:54:40 +00:00
275 lines
7.7 KiB
HTML
275 lines
7.7 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<!--
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=815833
|
|
-->
|
|
<head>
|
|
<title>Test for Bug 815833 WebContacts</title>
|
|
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
</head>
|
|
<body>
|
|
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=815833">Mozilla Bug 815833</a>
|
|
<p id="display"></p>
|
|
<div id="content" style="display: none">
|
|
|
|
</div>
|
|
<pre id="test">
|
|
<script type="text/javascript;version=1.8" src="http://mochi.test:8888/tests/dom/contacts/tests/shared.js"></script>
|
|
<script class="testbody" type="text/javascript">
|
|
"use strict";
|
|
|
|
var number1 = {
|
|
local: "7932012345",
|
|
international: "+557932012345"
|
|
};
|
|
|
|
var number2 = {
|
|
local: "7932012346",
|
|
international: "+557932012346"
|
|
};
|
|
|
|
var properties1 = {
|
|
name: ["Testname1"],
|
|
tel: [{type: ["work"], value: number1.local, carrier: "testCarrier"} , {type: ["home", "fax"], value: number2.local}],
|
|
};
|
|
|
|
var shortNumber = "888";
|
|
var properties2 = {
|
|
name: ["Testname2"],
|
|
tel: [{type: ["work"], value: shortNumber, carrier: "testCarrier"}]
|
|
};
|
|
|
|
var number3 = {
|
|
local: "7932012345",
|
|
international: "+557932012345"
|
|
};
|
|
|
|
var properties3 = {
|
|
name: ["Testname2"],
|
|
tel: [{value: number3.international}]
|
|
};
|
|
|
|
var req;
|
|
var createResult1;
|
|
var findResult1;
|
|
var sample_id1;
|
|
|
|
var steps = [
|
|
function () {
|
|
ok(true, "Deleting database");
|
|
req = mozContacts.clear();
|
|
req.onsuccess = function () {
|
|
ok(true, "Deleted the database");
|
|
next();
|
|
};
|
|
req.onerror = onFailure;
|
|
},
|
|
function () {
|
|
ok(true, "Adding a new contact1");
|
|
createResult1 = new mozContact(properties1);
|
|
req = navigator.mozContacts.save(createResult1);
|
|
req.onsuccess = function () {
|
|
ok(createResult1.id, "The contact now has an ID.");
|
|
sample_id1 = createResult1.id;
|
|
next();
|
|
};
|
|
req.onerror = onFailure;
|
|
},
|
|
function () {
|
|
ok(true, "Adding a new contact2");
|
|
var createResult2 = new mozContact(properties2);
|
|
req = navigator.mozContacts.save(createResult2);
|
|
req.onsuccess = function () {
|
|
ok(createResult2.id, "The contact now has an ID.");
|
|
next();
|
|
};
|
|
req.onerror = onFailure;
|
|
},
|
|
function () {
|
|
ok(true, "Searching for local number");
|
|
var options = {filterBy: ["tel"],
|
|
filterOp: "startsWith",
|
|
filterValue: number1.local};
|
|
req = mozContacts.find(options);
|
|
req.onsuccess = function () {
|
|
is(req.result.length, 1, "Found exactly 1 contact.");
|
|
findResult1 = req.result[0];
|
|
is(findResult1.id, sample_id1, "Same ID");
|
|
next();
|
|
};
|
|
req.onerror = onFailure;
|
|
},
|
|
function () {
|
|
ok(true, "Searching for international number");
|
|
var options = {filterBy: ["tel"],
|
|
filterOp: "startsWith",
|
|
filterValue: number1.international};
|
|
req = mozContacts.find(options);
|
|
req.onsuccess = function () {
|
|
is(req.result.length, 0, "Found exactly 0 contacts.");
|
|
next();
|
|
};
|
|
req.onerror = onFailure;
|
|
},
|
|
function () {
|
|
ok(true, "Searching for a short number matching the prefix");
|
|
var shortNumber = number1.local.substring(0, 3);
|
|
var options = {filterBy: ["tel"],
|
|
filterOp: "equals",
|
|
filterValue: shortNumber};
|
|
req = mozContacts.find(options);
|
|
req.onsuccess = function() {
|
|
is(req.result.length, 0, "The prefix short number should not match any contact.");
|
|
next();
|
|
};
|
|
req.onerror = onFailure;
|
|
},
|
|
function () {
|
|
ok(true, "Searching for a short number matching the suffix");
|
|
var shortNumber = number1.local.substring(number1.local.length - 3);
|
|
var options = {filterBy: ["tel"],
|
|
filterOp: "equals",
|
|
filterValue: shortNumber};
|
|
req = mozContacts.find(options);
|
|
req.onsuccess = function() {
|
|
is(req.result.length, 0, "The suffix short number should not match any contact.");
|
|
next();
|
|
};
|
|
req.onerror = onFailure;
|
|
},
|
|
function () {
|
|
ok(true, "Searching for a short number matching a contact");
|
|
var options = {filterBy: ["tel"],
|
|
filterOp: "equals",
|
|
filterValue: shortNumber};
|
|
req = mozContacts.find(options);
|
|
req.onsuccess = function() {
|
|
is(req.result.length, 1, "Found the contact equally matching the shortNumber.");
|
|
next();
|
|
};
|
|
req.onerror = onFailure;
|
|
},
|
|
function() {
|
|
ok(true, "Modifying number");
|
|
if (!findResult1) {
|
|
SpecialPowers.executeSoon(next);
|
|
} else {
|
|
findResult1.tel[0].value = number2.local;
|
|
req = mozContacts.save(findResult1);
|
|
req.onsuccess = function () {
|
|
next();
|
|
};
|
|
}
|
|
},
|
|
function () {
|
|
ok(true, "Searching for local number");
|
|
var options = {filterBy: ["tel"],
|
|
filterOp: "startsWith",
|
|
filterValue: number1.local};
|
|
req = mozContacts.find(options);
|
|
req.onsuccess = function () {
|
|
is(req.result.length, 0, "Found exactly 0 contact.");
|
|
next();
|
|
};
|
|
req.onerror = onFailure;
|
|
},
|
|
function () {
|
|
ok(true, "Searching for local number");
|
|
var options = {filterBy: ["tel"],
|
|
filterOp: "startsWith",
|
|
filterValue: number1.international};
|
|
req = mozContacts.find(options);
|
|
req.onsuccess = function () {
|
|
is(req.result.length, 0, "Found exactly 0 contact.");
|
|
next();
|
|
};
|
|
req.onerror = onFailure;
|
|
},
|
|
function () {
|
|
ok(true, "Searching for local number");
|
|
var options = {filterBy: ["tel"],
|
|
filterOp: "startsWith",
|
|
filterValue: number2.local};
|
|
req = mozContacts.find(options);
|
|
req.onsuccess = function () {
|
|
is(req.result.length, 1, "Found exactly 1 contact.");
|
|
findResult1 = req.result[0];
|
|
is(findResult1.id, sample_id1, "Same ID");
|
|
next();
|
|
};
|
|
req.onerror = onFailure;
|
|
},
|
|
function () {
|
|
ok(true, "Searching for local number");
|
|
var options = {filterBy: ["tel"],
|
|
filterOp: "startsWith",
|
|
filterValue: number2.international};
|
|
req = mozContacts.find(options);
|
|
req.onsuccess = function () {
|
|
is(req.result.length, 0, "Found exactly 1 contact.");
|
|
next();
|
|
};
|
|
req.onerror = onFailure;
|
|
},
|
|
function () {
|
|
ok(true, "Deleting database");
|
|
req = mozContacts.clear();
|
|
req.onsuccess = function () {
|
|
ok(true, "Deleted the database");
|
|
next();
|
|
}
|
|
req.onerror = onFailure;
|
|
},
|
|
function () {
|
|
ok(true, "Adding a contact with a Brazilian country code");
|
|
createResult1 = new mozContact(properties3);
|
|
req = navigator.mozContacts.save(createResult1);
|
|
req.onsuccess = function () {
|
|
ok(createResult1.id, "The contact now has an ID.");
|
|
sample_id1 = createResult1.id;
|
|
next();
|
|
};
|
|
req.onerror = onFailure;
|
|
},
|
|
function () {
|
|
ok(true, "Searching for Brazilian number using local number");
|
|
var options = {filterBy: ["tel"],
|
|
filterOp: "match",
|
|
filterValue: number3.local};
|
|
req = mozContacts.find(options);
|
|
req.onsuccess = function () {
|
|
is(req.result.length, 1, "Found exactly 1 contact.");
|
|
findResult1 = req.result[0];
|
|
is(findResult1.id, sample_id1, "Same ID");
|
|
next();
|
|
};
|
|
req.onerror = onFailure;
|
|
},
|
|
function () {
|
|
ok(true, "Deleting database");
|
|
req = mozContacts.clear();
|
|
req.onsuccess = function () {
|
|
ok(true, "Deleted the database");
|
|
next();
|
|
}
|
|
req.onerror = onFailure;
|
|
},
|
|
function () {
|
|
ok(true, "all done!\n");
|
|
SimpleTest.finish();
|
|
}
|
|
];
|
|
|
|
SpecialPowers.pushPrefEnv({
|
|
set: [
|
|
["ril.lastKnownSimMcc", "000"]
|
|
]
|
|
}, start_tests);
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|