3 <p>Test IsProviderInstalled.
<p>
9 function log(message
) {
10 document
.getElementById("result").innerHTML
+= message
+ "<br>";
13 function logPassed(message
) {
14 log("PASS: " + message
);
17 function logFailed(message
) {
19 log("FAIL: " + message
);
22 function verifyExceptionFor(testName
, origin
) {
24 window
.external
.IsSearchProviderInstalled(origin
);
25 logFailed("No exception for a " + testName
+ " (" + origin
+ ").");
27 logPassed("Got an exception for a " + testName
+ " (" + origin
+ ").");
31 function writeResult() {
34 logPassed("Everything passed.");
35 document
.title
= "OK";
37 logFailed("At least one test failed.");
38 document
.title
= "FAIL"
43 var differentProtocol
=
44 document
.location
.protocol
== "http:" ? "https:" : "http:";
46 (!document
.location
.port
|| document
.location
.port
== "80") ? ":81" : ":80";
48 var origin
= document
.location
.protocol
+ "//" + document
.location
.host
+ "/";
49 var originWithDifferentProtocol
= differentProtocol
+ "//" +
50 document
.location
.host
+ "/";
51 var originWithDifferentPort
= document
.location
.protocol
+ "//" +
52 document
.location
.hostname
+ differentPort
+ "/";
54 // Verify existence of the api.
57 if (window
.external
.IsSearchProviderInstalled
)
63 logPassed("IsSearchProvider api exists.");
65 logFailed("IsSearchProvider api doesn't exist.");
70 // Verify the search provider state for the current page.
71 var installed
= window
.external
.IsSearchProviderInstalled(origin
)
72 var installedMessage
= "Search provider ("+ origin
+"): " + installed
+ ".";
73 if (installed
== document
.location
.hash
.substring(1))
74 logPassed(installedMessage
);
76 logFailed(installedMessage
+ " The expected result is passed as the hash.");
78 // Verify that cases that should result in exceptions.
79 verifyExceptionFor("different host", "http://example.org/");
80 verifyExceptionFor("different protocol", originWithDifferentProtocol
);
81 verifyExceptionFor("different port", originWithDifferentPort
);
85 logFailed("An exception occurred. Name: " + e
.name
+ " Message: " +