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"
44 var differentProtocol
=
45 document
.location
.protocol
== "http:" ? "https:" : "http:";
47 (!document
.location
.port
|| document
.location
.port
== "80") ? ":81" : ":80";
50 document
.location
.protocol
+ "//" + document
.location
.host
+ "/";
51 var originWithDifferentProtocol
= differentProtocol
+ "//" +
52 document
.location
.host
+ "/";
53 var originWithDifferentPort
= document
.location
.protocol
+ "//" +
54 document
.location
.hostname
+ differentPort
+ "/";
56 // Verify existence of the api.
59 if (window
.external
.IsSearchProviderInstalled
)
64 logPassed("IsSearchProvider api exists.");
66 logFailed("IsSearchProvider api doesn't exist.");
71 // Verify the search provider state for the current page.
72 var installed
= window
.external
.IsSearchProviderInstalled(origin
)
73 var installedMessage
= "Search provider ("+ origin
+"): " + installed
+ ".";
74 if (installed
== document
.location
.hash
.substring(1)) {
75 logPassed(installedMessage
);
77 logFailed(installedMessage
+
78 " The expected result is passed as the hash.");
81 // Verify that cases that should result in exceptions.
82 verifyExceptionFor("different host", "http://example.org/");
83 verifyExceptionFor("different protocol", originWithDifferentProtocol
);
84 verifyExceptionFor("different port", originWithDifferentPort
);
88 logFailed("An exception occurred. Name: " + e
.name
+ " Message: " +