DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (5b81998bb7ab)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
<!DOCTYPE HTML>
<html>
<head>
  <title>Test for Login Manager</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>  
  <script type="text/javascript" src="pwmgr_common.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
Login Manager test: forms and logins without a username.
<p id="display"></p>

<div id="content" style="display: none">


<!-- simple form: no username field, 1 password field -->
<form id='form1' action='http://mochi.test:1111/formtest.js'> 1
    <input type='password' name='pname' value=''>

    <button type='submit'>Submit</button>
    <button type='reset'> Reset </button>
</form>

<!-- simple form: no username field, 2 password fields -->
<form id='form2' action='http://mochi.test:1111/formtest.js'> 2
    <input type='password' name='pname1' value=''>
    <input type='password' name='pname2' value=''>

    <button type='submit'>Submit</button>
    <button type='reset'> Reset </button>
</form>

<!-- simple form: no username field, 3 password fields -->
<form id='form3' action='http://mochi.test:1111/formtest.js'> 3
    <input type='password' name='pname1' value=''>
    <input type='password' name='pname2' value=''>
    <input type='password' name='pname3' value=''>

    <button type='submit'>Submit</button>
    <button type='reset'> Reset </button>
</form>

<!-- 4 password fields, should be ignored. -->
<form id='form4' action='http://mochi.test:1111/formtest.js'> 4
    <input type='password' name='pname1' value=''>
    <input type='password' name='pname2' value=''>
    <input type='password' name='pname3' value=''>
    <input type='password' name='pname4' value=''>

    <button type='submit'>Submit</button>
    <button type='reset'> Reset </button>
</form>



<!-- 1 username field -->
<form id='form5' action='http://mochi.test:1111/formtest.js'> 5
    <input type='text'     name='uname' value=''>
    <input type='password' name='pname' value=''>

    <button type='submit'>Submit</button>
    <button type='reset'> Reset </button>
</form>


<!-- 1 username field, with a value set -->
<form id='form6' action='http://mochi.test:1111/formtest.js'> 6
    <input type='text'     name='uname' value='someuser'>
    <input type='password' name='pname' value=''>

    <button type='submit'>Submit</button>
    <button type='reset'> Reset </button>
</form>



<!--
(The following forms have 2 potentially-matching logins, on is
password-only, the other is username+password)
-->



<!-- 1 username field, with value set. Fill in the matching U+P login -->
<form id='form7' action='formtest.js'> 7
    <input type='text'     name='uname' value='testuser'>
    <input type='password' name='pname' value=''>

    <button type='submit'>Submit</button>
    <button type='reset'> Reset </button>
</form>

<!-- 1 username field, with value set. Don't fill in U+P login-->
<form id='form8' action='formtest.js'> 8
    <input type='text'     name='uname' value='someuser'>
    <input type='password' name='pname' value=''>

    <button type='submit'>Submit</button>
    <button type='reset'> Reset </button>
</form>



<!-- 1 username field, too small for U+P login -->
<form id='form9' action='formtest.js'> 9
    <input type='text'     name='uname' value='' maxlength="4">
    <input type='password' name='pname' value=''>

    <button type='submit'>Submit</button>
    <button type='reset'> Reset </button>
</form>

<!-- 1 username field, too small for U+P login -->
<form id='form10' action='formtest.js'> 10
    <input type='text'     name='uname' value='' maxlength="0">
    <input type='password' name='pname' value=''>

    <button type='submit'>Submit</button>
    <button type='reset'> Reset </button>
</form>

<!-- 1 username field, too small for U+P login -->
<form id='form11' action='formtest.js'> 11
    <input type='text'     name='uname' value=''>
    <input type='password' name='pname' value='' maxlength="4">

    <button type='submit'>Submit</button>
    <button type='reset'> Reset </button>
</form>

<!-- 1 username field, too small for either login -->
<form id='form12' action='formtest.js'> 12
    <input type='text'     name='uname' value=''>
    <input type='password' name='pname' value='' maxlength="1">

    <button type='submit'>Submit</button>
    <button type='reset'> Reset </button>
</form>

<!-- 1 username field, too small for either login -->
<form id='form13' action='formtest.js'> 13
    <input type='text'     name='uname' value=''>
    <input type='password' name='pname' value='' maxlength="0">

    <button type='submit'>Submit</button>
    <button type='reset'> Reset </button>
</form>



</div>

<pre id="test">
<script class="testbody" type="text/javascript">

/** Test for Login Manager: password-only logins **/

commonInit();
function startTest() {

    checkForm(1, "1234");
    checkForm(2, "1234", "");
    checkForm(3, "1234", "", "");
    checkUnmodifiedForm(4);

    checkForm(5, "", "1234");
    checkForm(6, "someuser", "");

    checkForm(7, "testuser", "testpass");
    checkForm(8, "someuser", "");

    checkForm(9, "", "1234");
    checkForm(10, "", "1234");
    checkForm(11, "", "1234");

    checkUnmodifiedForm(12);
    checkUnmodifiedForm(13);

    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
    pwmgr.removeLogin(pwlogin2);
    SimpleTest.finish();
}


netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

// Get the pwmgr service
var Cc_pwmgr = Components.classes["@mozilla.org/login-manager;1"];
ok(Cc_pwmgr != null, "Access Cc[@mozilla.org/login-manager;1]");

var Ci_pwmgr = Components.interfaces.nsILoginManager;
ok(Ci_pwmgr != null, "Access Ci.nsILoginManager");

var pwmgr = Cc_pwmgr.getService(Ci_pwmgr);
ok(pwmgr != null, "pwmgr getService()");


var nsLoginInfo = new Components.Constructor("@mozilla.org/login-manager/loginInfo;1", Components.interfaces.nsILoginInfo);
ok(nsLoginInfo != null, "nsLoginInfo constructor");

// pwlogin1 uses a unique formSubmitURL, to check forms where no other logins
// will apply. pwlogin2 uses the normal formSubmitURL, so that we can test
// forms with a mix of username and non-username logins that might apply.
//
// Note: pwlogin2 is deleted at the end of the test.

pwlogin1 = new nsLoginInfo();
pwlogin2 = new nsLoginInfo();

pwlogin1.init("http://mochi.test:8888", "http://mochi.test:1111", null,
    "", "1234", "uname", "pword");

pwlogin2.init("http://mochi.test:8888", "http://mochi.test:8888", null,
    "", "1234", "uname", "pword");

try {
    pwmgr.addLogin(pwlogin1);
    pwmgr.addLogin(pwlogin2);
} catch (e) {
    ok(false, "addLogin threw: " + e);
}

window.onload = startTest;

SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>