Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chrome / test / data / is_search_provider_installed.html
blobf23a14efdee1336011653b926f3888d5878df979
1 <html>
2 <body>
3 <p>Test IsProviderInstalled.<p>
4 <div id=result>
5 </div>
6 <script>
7 var passedAll = true;
9 function log(message) {
10 document.getElementById("result").innerHTML += message + "<br>";
13 function logPassed(message) {
14 log("PASS: " + message);
17 function logFailed(message) {
18 passedAll = false;
19 log("FAIL: " + message);
22 function verifyExceptionFor(testName, origin) {
23 try {
24 window.external.IsSearchProviderInstalled(origin);
25 logFailed("No exception for a " + testName + " (" + origin + ").");
26 } catch (e) {
27 logPassed("Got an exception for a " + testName + " (" + origin + ").");
31 function writeResult() {
32 var result = "1";
33 if (passedAll) {
34 logPassed("Everything passed.");
35 document.title = "OK";
36 } else {
37 logFailed("At least one test failed.");
38 document.title = "FAIL"
42 function main() {
43 try {
44 var differentProtocol =
45 document.location.protocol == "http:" ? "https:" : "http:";
46 var differentPort =
47 (!document.location.port || document.location.port == "80") ? ":81" : ":80";
49 var origin =
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.
57 var foundApi = false;
58 try {
59 if (window.external.IsSearchProviderInstalled)
60 foundApi = true;
61 } catch (e) {}
63 if (foundApi) {
64 logPassed("IsSearchProvider api exists.");
65 } else {
66 logFailed("IsSearchProvider api doesn't exist.");
67 writeResult();
68 return;
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);
76 } else {
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);
86 writeResult();
87 } catch (e) {
88 logFailed("An exception occurred. Name: " + e.name + " Message: " +
89 e.message);
90 writeResult();
93 main();
94 </script>
95 </body>
96 </html>