Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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="pwmgr_common.js"></script> |
michael@0 | 7 | <script type="text/javascript" src="prompt_common.js"></script> |
michael@0 | 8 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 9 | </head> |
michael@0 | 10 | <body> |
michael@0 | 11 | Login Manager test: XML prompt |
michael@0 | 12 | <p id="display"></p> |
michael@0 | 13 | |
michael@0 | 14 | <div id="content" style="display: none"> |
michael@0 | 15 | <iframe id="iframe"></iframe> |
michael@0 | 16 | </div> |
michael@0 | 17 | |
michael@0 | 18 | <pre id="test"> |
michael@0 | 19 | <script class="testbody" type="text/javascript"> |
michael@0 | 20 | |
michael@0 | 21 | /** Test for Login Manager: XML prompts. **/ |
michael@0 | 22 | var pwmgr, login1, login2; |
michael@0 | 23 | |
michael@0 | 24 | function initLogins() { |
michael@0 | 25 | pwmgr = SpecialPowers.Cc["@mozilla.org/login-manager;1"] |
michael@0 | 26 | .getService(Ci.nsILoginManager); |
michael@0 | 27 | |
michael@0 | 28 | login1 = SpecialPowers.Cc["@mozilla.org/login-manager/loginInfo;1"] |
michael@0 | 29 | .createInstance(Ci.nsILoginInfo); |
michael@0 | 30 | login2 = SpecialPowers.Cc["@mozilla.org/login-manager/loginInfo;1"] |
michael@0 | 31 | .createInstance(Ci.nsILoginInfo); |
michael@0 | 32 | |
michael@0 | 33 | login1.init("http://mochi.test:8888", null, "xml", |
michael@0 | 34 | "xmluser1", "xmlpass1", "", ""); |
michael@0 | 35 | login2.init("http://mochi.test:8888", null, "xml2", |
michael@0 | 36 | "xmluser2", "xmlpass2", "", ""); |
michael@0 | 37 | |
michael@0 | 38 | pwmgr.addLogin(login1); |
michael@0 | 39 | pwmgr.addLogin(login2); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | function finishTest() { |
michael@0 | 43 | ok(true, "finishTest removing testing logins..."); |
michael@0 | 44 | pwmgr.removeLogin(login1); |
michael@0 | 45 | pwmgr.removeLogin(login2); |
michael@0 | 46 | |
michael@0 | 47 | SimpleTest.finish(); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | function handleDialog(doc, testNum) { |
michael@0 | 51 | ok(true, "handleDialog running for test " + testNum); |
michael@0 | 52 | |
michael@0 | 53 | var clickOK = true; |
michael@0 | 54 | var userfield = doc.getElementById("loginTextbox"); |
michael@0 | 55 | var passfield = doc.getElementById("password1Textbox"); |
michael@0 | 56 | var username = userfield.getAttribute("value"); |
michael@0 | 57 | var password = passfield.getAttribute("value"); |
michael@0 | 58 | var dialog = doc.getElementById("commonDialog"); |
michael@0 | 59 | |
michael@0 | 60 | switch(testNum) { |
michael@0 | 61 | case 1: |
michael@0 | 62 | is(username, "xmluser1", "Checking provided username"); |
michael@0 | 63 | is(password, "xmlpass1", "Checking provided password"); |
michael@0 | 64 | break; |
michael@0 | 65 | |
michael@0 | 66 | case 2: |
michael@0 | 67 | is(username, "xmluser2", "Checking provided username"); |
michael@0 | 68 | is(password, "xmlpass2", "Checking provided password"); |
michael@0 | 69 | |
michael@0 | 70 | // Check that the dialog has the correct parent |
michael@0 | 71 | ok(doc.defaultView.opener, "dialog has opener"); |
michael@0 | 72 | // Not using is() because its "expected" text doesn't deal |
michael@0 | 73 | // with window objects very well |
michael@0 | 74 | // Disabled due to Bug 718543. |
michael@0 | 75 | // ok(doc.defaultView.opener == window, "dialog's opener is correct"); |
michael@0 | 76 | |
michael@0 | 77 | break; |
michael@0 | 78 | |
michael@0 | 79 | default: |
michael@0 | 80 | ok(false, "Uhh, unhandled switch for testNum #" + testNum); |
michael@0 | 81 | break; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | // Explicitly cancel the dialog and report a fail in this failure |
michael@0 | 85 | // case, rather than letting the dialog get stuck due to an auth |
michael@0 | 86 | // failure and having the test timeout. |
michael@0 | 87 | if (!username && !password) { |
michael@0 | 88 | ok(false, "No values prefilled"); |
michael@0 | 89 | clickOK = false; |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | if (clickOK) |
michael@0 | 93 | dialog.acceptDialog(); |
michael@0 | 94 | else |
michael@0 | 95 | dialog.cancelDialog(); |
michael@0 | 96 | |
michael@0 | 97 | ok(true, "handleDialog done"); |
michael@0 | 98 | didDialog = true; |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | var newWin; |
michael@0 | 102 | function xmlLoad(responseDoc) { |
michael@0 | 103 | ok(true, "xmlLoad running for test " + testNum); |
michael@0 | 104 | |
michael@0 | 105 | // The server echos back the user/pass it received. |
michael@0 | 106 | var username = responseDoc.getElementById("user").textContent; |
michael@0 | 107 | var password = responseDoc.getElementById("pass").textContent; |
michael@0 | 108 | var authok = responseDoc.getElementById("ok").textContent; |
michael@0 | 109 | |
michael@0 | 110 | switch(testNum) { |
michael@0 | 111 | case 1: |
michael@0 | 112 | is(username, "xmluser1", "Checking provided username"); |
michael@0 | 113 | is(password, "xmlpass1", "Checking provided password"); |
michael@0 | 114 | break; |
michael@0 | 115 | |
michael@0 | 116 | case 2: |
michael@0 | 117 | is(username, "xmluser2", "Checking provided username"); |
michael@0 | 118 | is(password, "xmlpass2", "Checking provided password"); |
michael@0 | 119 | |
michael@0 | 120 | newWin.close(); |
michael@0 | 121 | break; |
michael@0 | 122 | |
michael@0 | 123 | default: |
michael@0 | 124 | ok(false, "Uhh, unhandled switch for testNum #" + testNum); |
michael@0 | 125 | break; |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | doTest(); |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | function doTest() { |
michael@0 | 132 | switch(++testNum) { |
michael@0 | 133 | case 1: |
michael@0 | 134 | startCallbackTimer(); |
michael@0 | 135 | makeRequest("authenticate.sjs?user=xmluser1&pass=xmlpass1&realm=xml"); |
michael@0 | 136 | break; |
michael@0 | 137 | |
michael@0 | 138 | case 2: |
michael@0 | 139 | // Test correct parenting, by opening another window and |
michael@0 | 140 | // making sure the prompt's opener is correct |
michael@0 | 141 | newWin = window.open(); |
michael@0 | 142 | newWin.focus(); |
michael@0 | 143 | startCallbackTimer(); |
michael@0 | 144 | makeRequest("authenticate.sjs?user=xmluser2&pass=xmlpass2&realm=xml2"); |
michael@0 | 145 | break; |
michael@0 | 146 | |
michael@0 | 147 | default: |
michael@0 | 148 | finishTest(); |
michael@0 | 149 | } |
michael@0 | 150 | } |
michael@0 | 151 | |
michael@0 | 152 | function makeRequest(uri) { |
michael@0 | 153 | var xmlDoc = document.implementation.createDocument("", "test", null); |
michael@0 | 154 | |
michael@0 | 155 | function documentLoaded(e) { |
michael@0 | 156 | xmlLoad(xmlDoc); |
michael@0 | 157 | } |
michael@0 | 158 | xmlDoc.addEventListener("load", documentLoaded, false); |
michael@0 | 159 | xmlDoc.load(uri); |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | |
michael@0 | 163 | initLogins(); |
michael@0 | 164 | |
michael@0 | 165 | // clear plain HTTP auth sessions before the test, to allow |
michael@0 | 166 | // running them more than once. |
michael@0 | 167 | var authMgr = SpecialPowers.Cc['@mozilla.org/network/http-auth-manager;1'] |
michael@0 | 168 | .getService(SpecialPowers.Ci.nsIHttpAuthManager); |
michael@0 | 169 | authMgr.clearAll(); |
michael@0 | 170 | |
michael@0 | 171 | // start the tests |
michael@0 | 172 | testNum = 0; |
michael@0 | 173 | doTest(); |
michael@0 | 174 | |
michael@0 | 175 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 176 | </script> |
michael@0 | 177 | </pre> |
michael@0 | 178 | </body> |
michael@0 | 179 | </html> |