blob: 85de2a9c16802fa9e3d06a45d8813d571c0d20f1 (
plain)
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
|
<html>
<body>
<p>Test IsProviderInstalled.<p>
<div id=result>
</div>
<script>
var passedAll = true;
function log(message) {
document.getElementById("result").innerHTML += message + "<br>";
}
function logPassed(message) {
log("PASS: " + message);
}
function logFailed(message) {
passedAll = false;
log("FAIL: " + message);
}
function verifyExceptionFor(testName, origin) {
try {
window.external.IsSearchProviderInstalled(origin);
logFailed("No exception for a " + testName + " (" + origin + ").");
} catch (e) {
logPassed("Got an exception for a " + testName + " (" + origin + ").");
}
}
function writeResult() {
var result = "1";
if (passedAll)
logPassed("Everything passed.");
else {
logFailed("At least one test failed.");
result = " " + document.body.innerText; // Add a space to ensure that the
// result doesn't resemble success.
}
document.cookie = document.location.hostname + "testResult=" + escape(result);
}
try {
var differentProtocol =
document.location.protocol == "http:" ? "https:" : "http:";
var differentPort =
(!document.location.port || document.location.port == "80") ? ":81" : ":80";
var origin = document.location.protocol + "//" + document.location.host + "/";
var originWithDifferentProtocol = differentProtocol + "//" +
document.location.host + "/";
var originWithDifferentPort = document.location.protocol + "//" +
document.location.hostname + differentPort + "/";
// Verify existence of the api.
var foundApi = false;
try {
if (window.external.IsSearchProviderInstalled)
foundApi = true;
} catch (e) {
}
if (foundApi)
logPassed("IsSearchProvider api exists.");
else {
logFailed("IsSearchProvider api doesn't exist.");
writeResult();
return;
}
// Verify the search provider state for the current page.
var installed = window.external.IsSearchProviderInstalled(origin)
var installedMessage = "Search provider ("+ origin +"): " + installed + ".";
if (installed == document.location.hash.substring(1))
logPassed(installedMessage);
else
logFailed(installedMessage + " The expected result is passed as the hash.");
// Verify that cases that should result in exceptions.
verifyExceptionFor("different host", "http://example.org/");
verifyExceptionFor("different protocol", originWithDifferentProtocol);
verifyExceptionFor("different port", originWithDifferentPort);
writeResult();
} catch (e) {
logFailed("An exception occurred. Name: " + e.name + " Message: " +
e.message);
writeResult();
}
</script>
</body>
</html>
|