dom/plugins/test/mochitest/test_getauthenticationinfo.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <title>Test for Login Manager</title>
michael@0 5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <script type="text/javascript" src="utils.js"></script>
michael@0 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 8 </head>
michael@0 9 <body>
michael@0 10 Test for NPN_GetAuthenticationInfo
michael@0 11 <p id="display"></p>
michael@0 12
michael@0 13 <div id="content">
michael@0 14 <iframe id="iframe"></iframe>
michael@0 15 </div>
michael@0 16
michael@0 17 <script class="testbody" type="text/javascript">
michael@0 18
michael@0 19 const Ci = SpecialPowers.Ci;
michael@0 20 const Cc = SpecialPowers.Cc;
michael@0 21
michael@0 22 function iframeLoad() {
michael@0 23 var plugin = iframe.contentDocument.getElementById("embedtest");
michael@0 24 // valid request
michael@0 25 is(plugin.getAuthInfo("http", "mochi.test", 8888, "basic", "testrealm"),
michael@0 26 "user1|password1",
michael@0 27 "correct user/pass retrieved");
michael@0 28 try {
michael@0 29 // invalid request -- wrong host
michael@0 30 is(plugin.getAuthInfo("http", "example.com", 8888, "basic", "testrealm"),
michael@0 31 "user1|password1",
michael@0 32 "correct user/pass retrieved");
michael@0 33 ok(false, "no exception was thrown");
michael@0 34 }
michael@0 35 catch (err) {
michael@0 36 ok(true, "expected exception caught");
michael@0 37 }
michael@0 38 try {
michael@0 39 // invalid request -- wrong port
michael@0 40 is(plugin.getAuthInfo("http", "mochi.test", 90, "basic", "testrealm"),
michael@0 41 "user1|password1",
michael@0 42 "correct user/pass retrieved");
michael@0 43 ok(false, "no exception was thrown");
michael@0 44 }
michael@0 45 catch (err) {
michael@0 46 ok(true, "expected exception caught");
michael@0 47 }
michael@0 48 try {
michael@0 49 // invalid request -- wrong realm
michael@0 50 is(plugin.getAuthInfo("http", "mochi.test", 8888, "basic", "wrongrealm"),
michael@0 51 "user1|password1",
michael@0 52 "correct user/pass retrieved");
michael@0 53 ok(false, "no exception was thrown");
michael@0 54 }
michael@0 55 catch (err) {
michael@0 56 ok(true, "expected exception caught");
michael@0 57 }
michael@0 58 SimpleTest.finish();
michael@0 59 }
michael@0 60
michael@0 61 SimpleTest.waitForExplicitFinish();
michael@0 62 setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
michael@0 63
michael@0 64 var iframe = document.getElementById("iframe");
michael@0 65 var am = Cc["@mozilla.org/network/http-auth-manager;1"].
michael@0 66 getService(Ci.nsIHttpAuthManager);
michael@0 67 am.setAuthIdentity("http", "mochi.test", 8888, "basic", "testrealm", "",
michael@0 68 "mochi.test", "user1", "password1");
michael@0 69 iframe.onload = iframeLoad;
michael@0 70 iframe.src = "http://mochi.test:8888/tests/toolkit/components/passwordmgr/" +
michael@0 71 "test/authenticate.sjs?user=user1&pass=password1&realm=testrealm&plugin=1";
michael@0 72
michael@0 73 </script>
michael@0 74 </body>
michael@0 75 </html>

mercurial