Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: chrome/test/data/is_search_provider_installed.html

Issue 2823042: Implement IsSearchProviderInstalled and a test for it. (Closed)
Patch Set: Addressed feedback. Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <html>
2 <body>
3 <p>Test IsProviderInstalled.<p>
4 <div id=result>
5 </div>
6 <script>
7 var passedAll = true;
8
9 function log(message) {
10 document.getElementById("result").innerHTML += message + "<br>";
11 }
12
13 function logPassed(message) {
14 log("PASS: " + message);
15 }
16
17 function logFailed(message) {
18 passedAll = false;
19 log("FAIL: " + message);
20 }
21
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 + ").");
28 }
29 }
30
31 function writeResult() {
32 var result = "1";
33 if (passedAll)
34 logPassed("Everything passed.");
35 else {
36 logFailed("At least one test failed.");
37 result = " " + document.body.innerText; // Add a space to ensure that the
38 // result doesn't resemble success.
39 }
40 document.cookie = document.location.hostname + "testResult=" + escape(result);
41 }
42
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 ";
48
49 var origin = document.location.protocol + "//" + document.location.host + "/";
50 var originWithDifferentProtocol = differentProtocol + "//" +
51 document.location.host + "/";
52 var originWithDifferentPort = document.location.protocol + "//" +
53 document.location.hostname + differentPort + "/";
54
55 // Verify existance of the api.
56 var foundApi = false;
57 try {
58 if (window.external.IsSearchProviderInstalled)
59 foundApi = true;
60 } catch (e) {
61 }
62
63 if (foundApi)
64 logPassed("IsSearchProvider api exists.");
65 else {
66 logFailed("IsSearchProvider api doesn't exist.");
67 writeResult();
68 return;
69 }
70
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 + " The expected result is passed as the hash.");
78
79 // Verify that cases that should result in exceptions.
80 verifyExceptionFor("different host", "http://example.org/");
81 verifyExceptionFor("different protocol", originWithDifferentProtocol);
82 verifyExceptionFor("different port", originWithDifferentPort);
83
84 writeResult();
85 } catch (e) {
86 logFailed("An exception occurred. Name: " + e.name + " Message: " + e.message) ;
87 writeResult();
88 }
89 </script>
90 </body>
91 </html>
OLDNEW
« chrome/renderer/external_extension_uitest.cc ('K') | « chrome/renderer/render_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698