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
<!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: (placeholder)
<p id="display"></p>

<div id="content" style="display: none">
  <form id="form1" onsubmit="return checkSubmit(1)" action="http://newuser.com">
    <input  type="text"     name="uname">
    <input  type="password" name="pword">
    <input  type="password" name="qword">

    <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: form fill, 2 password fields **/

/*
 * If a form has two password fields, other things may be going on....
 *
 * 1 - The user might be creating a new login (2nd field for typo checking)
 * 2 - The user is changing a password (old and new password each have field)
 *
 * This test is for case #1.
 */

var numSubmittedForms = 0;
var numStartingLogins = 0;

function startTest() {
  // Check for unfilled forms
  is($_(1, "uname").value, "", "Checking username 1");
  is($_(1, "pword").value, "", "Checking password 1A");
  is($_(1, "qword").value, "", "Checking password 1B");

  // Fill in the username and password fields, for account creation.
  // Form 1
  $_(1, "uname").value = "newuser1";
  $_(1, "pword").value = "newpass1";
  $_(1, "qword").value = "newpass1";

  var button = getFormSubmitButton(1);
  //button.click();

  todo(false, "form submission disabled, can't auto-accept dialog yet");
  SimpleTest.finish();
}


// Called by each form's onsubmit handler.
function checkSubmit(formNum) {
  numSubmittedForms++;

  // End the test at the last form.
  if (formNum == 999) {
    is(numSubmittedForms, 999, "Ensuring all forms submitted for testing.");

    var numEndingLogins = countLogins();

    ok(numEndingLogins > 0, "counting logins at end");
    is(numStartingLogins, numEndingLogins + 222, "counting logins at end");

    SimpleTest.finish();
    return false; // return false to cancel current form submission
  }

  // submit the next form.
  var button = getFormSubmitButton(formNum + 1);
  button.click();

  return false; // return false to cancel current form submission
}


function getFormSubmitButton(formNum) {
  var form = $("form" + formNum); // by id, not name
  ok(form != null, "getting form " + formNum);

  // we can't just call form.submit(), because that doesn't seem to
  // invoke the form onsubmit handler.
  var button = form.firstChild;
  while (button && button.type != "submit") { button = button.nextSibling; }
  ok(button != null, "getting form submit button");

  return button;
}


// Counts the number of logins currently stored by password manager.
function countLogins() {
  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

  var logins = pwmgr.getAllLogins();

  return logins.length;
}

commonInit();

// Get the pwmgr service
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

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()");


window.onload = startTest;

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