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

Unified Diff: LayoutTests/fast/dom/navigatorcontentutils/unregister-protocol-handler.html

Issue 293403002: Introduce mock test system for navigator content utils (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 7 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: LayoutTests/fast/dom/navigatorcontentutils/unregister-protocol-handler.html
diff --git a/LayoutTests/fast/dom/navigatorcontentutils/unregister-protocol-handler.html b/LayoutTests/fast/dom/navigatorcontentutils/unregister-protocol-handler.html
index d930fd2c56f75a89e4f4a7f5e4b8bc0b44cdb372..16475e6f8605b65dd9ff040660094d6e1c42cd4d 100644
--- a/LayoutTests/fast/dom/navigatorcontentutils/unregister-protocol-handler.html
+++ b/LayoutTests/fast/dom/navigatorcontentutils/unregister-protocol-handler.html
@@ -1,4 +1,7 @@
<html>
+<head>
+<script src="../../../resources/js-test.js"></script>
+</head>
<body>
<p>This test makes sure that navigator.unregisterProtocolHandler throws the proper exceptions and has no-op default implementation.</p>
<pre id="console"></pre>
@@ -6,16 +9,13 @@
if (window.testRunner)
testRunner.dumpAsText();
-function debug(str)
-{
- var c = document.getElementById('console')
- c.appendChild(document.createTextNode(str + '\n'));
-}
+if (window.internals)
+ internals.setNavigatorContentUtilsClientMock(document);
if (window.navigator.unregisterProtocolHandler)
- debug('Pass: window.navigator.unregisterProtocolHandler is defined.');
+ debug('PASS window.navigator.unregisterProtocolHandler is defined.');
else
- debug('Fail: window.navigator.unregisterProtocolHandler is not defined.');
+ debug('FAIL window.navigator.unregisterProtocolHandler is not defined.');
var invalid_protocols = ['http', 'https', 'file', 'web+'];
invalid_protocols.forEach(function (protocol) {
@@ -28,9 +28,9 @@ invalid_protocols.forEach(function (protocol) {
}
if (succeeded)
- debug('Pass: Invalid protocol "' + protocol + '" threw SecurityError exception: "' + errorMessage + '".');
+ debug('PASS Invalid protocol "' + protocol + '" threw SecurityError exception: "' + errorMessage + '".');
else
- debug('Fail: Invalid protocol "' + protocol + '" allowed.');
+ debug('FAIL Invalid protocol "' + protocol + '" allowed.');
});
var valid_protocols = ['bitcoin', 'geo', 'im', 'irc', 'ircs', 'magnet', 'mailto', 'mms', 'news', 'nntp', 'sip', 'sms', 'smsto', 'ssh', 'tel', 'urn', 'webcal', 'wtai', 'xmpp'];
@@ -44,9 +44,9 @@ valid_protocols.forEach(function (protocol) {
}
if (succeeded)
- debug('Pass: Valid protocol "' + protocol + '" allowed.');
+ debug('PASS Valid protocol "' + protocol + '" allowed.');
else
- debug('Fail: Valid protocol "' + protocol + '" failed.');
+ debug('FAIL Valid protocol "' + protocol + '" failed.');
});
var invalid_schemes = ['mailto:', 'ssh:/', 'magnet:+', 'tel:sip'];
@@ -60,7 +60,7 @@ invalid_schemes.forEach(function (scheme) {
}
if (succeeded)
- debug('Pass: Invalid scheme "' + scheme + '" falied.');
+ debug('PASS Invalid scheme "' + scheme + '" falied.');
else
debug('Fail: Invalid scheme "' + scheme + '" allowed. Threw exception: "' + errorMessage + '".');
});
@@ -76,9 +76,9 @@ invalid_urls.forEach(function (url) {
}
if (succeeded)
- debug('Pass: Invalid url "' + url + '" threw SyntaxError exception.' + errorMessage + '".');
+ debug('PASS Invalid url "' + url + '" threw SyntaxError exception.' + errorMessage + '".');
else
- debug('Fail: Invalid url "' + url + '" allowed.');
+ debug('FAIL Invalid url "' + url + '" allowed.');
});
// Test that the API has default no-op implementation.
@@ -90,9 +90,37 @@ try {
}
if (succeeded)
- debug('Pass: Valid call succeeded.');
+ debug('PASS Valid call succeeded.');
else
- debug('Fail: Invalid call did not succeed.');
+ debug('FAIL Invalid call did not succeed.');
+
+// Check if unregisterProtocolHandler can unregister protocol.
+debug("\nCheck if unregisterProtocolHandler can unregister protocol correctly. If isProtocolHandlerRegistered() returns 'new' state, unregisterProtoclHandler() works well.");
+debug("'bitcoin' protocol will be registered and unregistered for testing.\n");
+try {
+ // Register 'bitcoin' protocol for testing.
+ window.navigator.registerProtocolHandler('bitcoin', 'invalid scheme uri=%s', 'title');
+ var state = window.navigator.isProtocolHandlerRegistered('bitcoin', 'valid protocol %s');
+ if (state == "registered")
+ debug("PASS window.navigator.isProtocolHandlerRegistered returns 'registered' state. 'bitcoin' is registered successfully.");
+ else if (state == "new")
+ debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'new' state. Fail to register 'bitcoin' protocol.");
+ else if (state == "declined")
+ debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'declined' state. Fail to register 'bitcoin' protocol.");
+
+ window.navigator.unregisterProtocolHandler('bitcoin', 'invalid scheme uri=%s');
+ var state = window.navigator.isProtocolHandlerRegistered('bitcoin', 'valid protocol %s');
+ if (state == "new")
+ debug("PASS window.navigator.isProtocolHandlerRegistered returns 'new' state. 'bitcoin' is unregistered successfully.");
+ else if (state == "registered")
+ debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'registered' state. Fail to unregister 'bitcoin' protocol.");
+ else if (state == "declined")
+ debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'declined' state. Fail to unregister 'bitcoin' protocol.");
+} catch (e) {
+ debug('FAIL window.navigator.isProtocolHandlerRegistered call is failed: "' + e.message + '".');
+}
+debug("\n");
+
</script>
</body>
</html>

Powered by Google App Engine
This is Rietveld 408576698