1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/plugins/test/mochitest/test_getauthenticationinfo.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,75 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Test for Login Manager</title> 1.8 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.9 + <script type="text/javascript" src="utils.js"></script> 1.10 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.11 +</head> 1.12 +<body> 1.13 +Test for NPN_GetAuthenticationInfo 1.14 +<p id="display"></p> 1.15 + 1.16 +<div id="content"> 1.17 + <iframe id="iframe"></iframe> 1.18 +</div> 1.19 + 1.20 +<script class="testbody" type="text/javascript"> 1.21 + 1.22 +const Ci = SpecialPowers.Ci; 1.23 +const Cc = SpecialPowers.Cc; 1.24 + 1.25 +function iframeLoad() { 1.26 + var plugin = iframe.contentDocument.getElementById("embedtest"); 1.27 + // valid request 1.28 + is(plugin.getAuthInfo("http", "mochi.test", 8888, "basic", "testrealm"), 1.29 + "user1|password1", 1.30 + "correct user/pass retrieved"); 1.31 + try { 1.32 + // invalid request -- wrong host 1.33 + is(plugin.getAuthInfo("http", "example.com", 8888, "basic", "testrealm"), 1.34 + "user1|password1", 1.35 + "correct user/pass retrieved"); 1.36 + ok(false, "no exception was thrown"); 1.37 + } 1.38 + catch (err) { 1.39 + ok(true, "expected exception caught"); 1.40 + } 1.41 + try { 1.42 + // invalid request -- wrong port 1.43 + is(plugin.getAuthInfo("http", "mochi.test", 90, "basic", "testrealm"), 1.44 + "user1|password1", 1.45 + "correct user/pass retrieved"); 1.46 + ok(false, "no exception was thrown"); 1.47 + } 1.48 + catch (err) { 1.49 + ok(true, "expected exception caught"); 1.50 + } 1.51 + try { 1.52 + // invalid request -- wrong realm 1.53 + is(plugin.getAuthInfo("http", "mochi.test", 8888, "basic", "wrongrealm"), 1.54 + "user1|password1", 1.55 + "correct user/pass retrieved"); 1.56 + ok(false, "no exception was thrown"); 1.57 + } 1.58 + catch (err) { 1.59 + ok(true, "expected exception caught"); 1.60 + } 1.61 + SimpleTest.finish(); 1.62 +} 1.63 + 1.64 +SimpleTest.waitForExplicitFinish(); 1.65 +setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED); 1.66 + 1.67 +var iframe = document.getElementById("iframe"); 1.68 +var am = Cc["@mozilla.org/network/http-auth-manager;1"]. 1.69 + getService(Ci.nsIHttpAuthManager); 1.70 +am.setAuthIdentity("http", "mochi.test", 8888, "basic", "testrealm", "", 1.71 + "mochi.test", "user1", "password1"); 1.72 +iframe.onload = iframeLoad; 1.73 +iframe.src = "http://mochi.test:8888/tests/toolkit/components/passwordmgr/" + 1.74 + "test/authenticate.sjs?user=user1&pass=password1&realm=testrealm&plugin=1"; 1.75 + 1.76 +</script> 1.77 +</body> 1.78 +</html>