mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
4d0d3e88a1
--HG-- extra : rebase_source : 9d7a645c0d2fb102d5d498fefebeb817a186720e
314 lines
8.8 KiB
HTML
314 lines
8.8 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 class="testbody" type="text/javascript">
|
|
|
|
"use strict";
|
|
|
|
if (SpecialPowers.isMainProcess()) {
|
|
SpecialPowers.Cu.import("resource://gre/modules/ContactService.jsm");
|
|
SpecialPowers.Cu.import("resource://gre/modules/PermissionPromptHelper.jsm");
|
|
}
|
|
|
|
SpecialPowers.addPermission("contacts-write", true, document);
|
|
SpecialPowers.addPermission("contacts-read", true, document);
|
|
SpecialPowers.addPermission("contacts-create", true, document);
|
|
|
|
var isAndroid = (navigator.userAgent.indexOf("Android") !== -1);
|
|
var androidVersion = SpecialPowers.Cc['@mozilla.org/system-info;1']
|
|
.getService(SpecialPowers.Ci.nsIPropertyBag2)
|
|
.getProperty('version');
|
|
|
|
function onFailure() {
|
|
ok(false, "in on Failure!");
|
|
next();
|
|
}
|
|
|
|
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 = {
|
|
international1: "0041557932012345",
|
|
international2: "+557932012345"
|
|
};
|
|
|
|
var properties3 = {
|
|
name: ["Testname2"],
|
|
tel: [{value: number3.international2}]
|
|
};
|
|
|
|
var req;
|
|
var index = 0;
|
|
var createResult1;
|
|
var findResult1;
|
|
var sample_id1;
|
|
|
|
var mozContacts = window.navigator.mozContacts;
|
|
|
|
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 () {
|
|
ok(req.result.length == 1, "Found exactly 1 contact.");
|
|
findResult1 = req.result[0];
|
|
ok(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 () {
|
|
ok(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() {
|
|
ok(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() {
|
|
ok(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() {
|
|
ok(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 () {
|
|
ok(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 () {
|
|
ok(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 () {
|
|
ok(req.result.length == 1, "Found exactly 1 contact.");
|
|
findResult1 = req.result[0];
|
|
ok(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 () {
|
|
ok(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 new contact with 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 international number with prefix");
|
|
var options = {filterBy: ["tel"],
|
|
filterOp: "match",
|
|
filterValue: number3.international1};
|
|
req = mozContacts.find(options);
|
|
req.onsuccess = function () {
|
|
ok(req.result.length == 1, "Found exactly 1 contact.");
|
|
findResult1 = req.result[0];
|
|
ok(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();
|
|
}
|
|
];
|
|
|
|
function next() {
|
|
ok(true, "Begin!");
|
|
if (index >= steps.length) {
|
|
ok(false, "Shouldn't get here!");
|
|
return;
|
|
}
|
|
try {
|
|
steps[index]();
|
|
} catch(ex) {
|
|
ok(false, "Caught exception", ex);
|
|
}
|
|
index += 1;
|
|
}
|
|
|
|
// Skip tests on Android < 4.0 due to test failures on tbpl (see bugs 897924 & 888891)
|
|
if (!isAndroid || androidVersion >= 14) {
|
|
SimpleTest.waitForExplicitFinish();
|
|
addLoadEvent(next);
|
|
} else {
|
|
ok(true, "Skip tests on Android < 4.0 (bugs 897924 & 888891");
|
|
}
|
|
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|