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