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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/is_search_provider_installed.html
diff --git a/chrome/test/data/is_search_provider_installed.html b/chrome/test/data/is_search_provider_installed.html
new file mode 100644
index 0000000000000000000000000000000000000000..5e51c1793ede35d0971ea4b12e7d343c80eb02b5
--- /dev/null
+++ b/chrome/test/data/is_search_provider_installed.html
@@ -0,0 +1,91 @@
+<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 existance 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>
« 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