toolkit/components/passwordmgr/test/test_bug_242956.html
author sayrer@gmail.com
Sun, 22 Apr 2007 16:56:06 -0700
changeset 714 a5720d3cdbb6d54315a16e834db6f794890878d0
parent 688 d8c055007b8e36d1232ed23fdfe085260fd3c8eb
child 1511 8b4151470f6e0a6d0d4f7d2e4d80071029f6f6d2
permissions -rw-r--r--
bug 373253. Initial addition of test framework and tests for pwmgr. Patch by Justin Dolske <dolske@mozilla.com>. r=sayrer, sr=mconnor

<!DOCTYPE HTML>
<html>
<head>
  <title>Test for Password Manager</title>
  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
  <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>
Password Manager test: 242956
<p id="display"></p>
<div id="content" style="display: none">
  <!-- pword1 is not a type=password input -->
  <form action="formtest.js" method="get">
    <input  type="text" name="uname1" value="">
    <input  type="text" name="pword1" value="">

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

  <!-- uname2 is not a type=text input -->
  <form action="formtest.js" method="get">
    <input  type="password" name="uname2" value="">
    <input  type="password" name="pword2" value="">

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

  <!-- two "pword3" inputs, (text + password) -->
  <form action="formtest.js" method="get">
    <input  type="text"       name="uname3" value="">
    <input  type="text"       name="pword3" value="">
    <input  type="password"   name="pword3" value="">

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

  <!-- same thing, different order -->
  <form action="formtest.js" method="get">
    <input  type="text"       name="uname4" value="">
    <input  type="password"   name="pword4" value="">
    <input  type="text"       name="pword4" value="">

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

  <!-- two "uname5" inputs, (text + password) -->
  <form action="formtest.js" method="get">
    <input  type="text"       name="uname5" value="">
    <input  type="password"   name="uname5" value="">
    <input  type="password"   name="pword5" value="">

    <button type="submit">Submit</button>
    <button type="reset"> Reset </button>
  </form>
 
  <!-- same thing, different order -->
  <form action="formtest.js" method="get">
    <input  type="password"   name="uname6" value="">
    <input  type="text"       name="uname6" value="">
    <input  type="password"   name="pword6" value="">

    <button type="submit">Submit</button>
    <button type="reset"> Reset </button>
  </form>
  
  <!-- uname7 is not a type=text input (try a checkbox just for variety) -->
  <form action="formtest.js" method="get">
    <input  type="checkbox" name="uname7" value="">
    <input  type="password" name="pword7" value="">

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

  <!-- pword8 is not a type=password input (try a checkbox just for variety) -->
  <form action="formtest.js" method="get">
    <input  type="text"     name="uname8" value="">
    <input  type="checkbox" name="pword8" value="">

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

  <!-- pword9 is not a type=password input -->
  <form action="formtest.js" method="get">
    <input  type="text" name="uname9" value="testuser9">
    <input  type="text" name="pword9" value="">

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

  <!-- uname10 is not a type=text input -->
  <form action="formtest.js" method="get">
    <input  type="password" name="uname10" value="testuser10">
    <input  type="password" name="pword10" value="">

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

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

/** Test for Password Manger: 242956 (Stored password is inserted into a readable text input on a second page) **/

// Make sure that pwmgr only puts passwords into type=password <input>s.
// Might as well test the converse, too (username in password field).

function startTest() {
  for (var i = 1; i <= 8; i++) {
    if (i >= 3 && i <= 6) { continue; } // handle these below.
    // Check form i
    is($_("uname" + i).value, "", "Checking for unfilled username " + i);
    is($_("pword" + i).value, "", "Checking for unfilled password " + i);
  }

  // Forms 3 and 4 have two password inputs with the same name
  var form, input;

  form  = document.forms[2];
  input = form.elements[0];
  is(input.type,  "text",      "confirming user field 3 type");
  is(input.name,  "uname3",    "confirming user field 3 name");
  //is(input.value, "testuser3", "checking user field 3 value");
  todo(input.value == "testuser3", "ignore bogus <input> and fill testuser3");
  input = form.elements[1];
  is(input.type,  "text",      "confirming bogus password field 3 type");
  is(input.name,  "pword3",    "confirming bogus password field 3 name");
  is(input.value, "",    "checking bogus password field 3 value");
  input = form.elements[2];
  is(input.type,  "password",  "confirming legit password field 3 type");
  is(input.name,  "pword3",    "confirming legit password field 3 type");
  //is(input.value, "testpass3", "checking legit password field 3 value");
  todo(input.value == "testpass3", "ignore bogus <input> and fill testpass3");

  form  = document.forms[3];
  input = form.elements[0];
  is(input.type,  "text",      "confirming user field 4 type");
  is(input.name,  "uname4",    "confirming user field 4 name");
  //is(input.value, "testuser4", "checking user field 4 value");
  todo(input.value == "testuser4", "ignore bogus <input> and fill testuser4");
  input = form.elements[1];
  is(input.type,  "password",  "confirming legit password field 4 type");
  is(input.name,  "pword4",    "confirming legit password field 4 type");
  //is(input.value, "testpass4", "checking legit password field 4 value");
  todo(input.value == "testpass4", "ignore bogus <input> and fill testpass4");
  input = form.elements[2];
  is(input.type,  "text",      "confirming bogus password field 4 type");
  is(input.name,  "pword4",    "confirming bogus password field 4 name");
  is(input.value, "",    "checking bogus password field 4 value");

  // Forms 5 and 6 have two username inputs with the same name
  form  = document.forms[4];
  input = form.elements[0];
  is(input.type,  "text",      "confirming legit user field 5 type");
  is(input.name,  "uname5",    "confirming legit user field 5 name");
  //is(input.value, "testuser5", "checking legit user field 5 value");
  todo(input.value == "testuser5", "ignore bogus <input> and fill testuser5");
  input = form.elements[1];
  is(input.type,  "password",  "confirming bogus user field 5 type");
  is(input.name,  "uname5",    "confirming bogus user field 5 name");
  is(input.value, "",    "checking bogus user field 5 value");
  input = form.elements[2];
  is(input.type,  "password",  "confirming password field 5 ");
  is(input.name,  "pword5",    "confirming password field 5 ");
  //is(input.value, "testpass5", "checking password field 5 value");
  todo(input.value == "testpass5", "ignore bogus <input> and fill testpass5");

  form  = document.forms[5];
  input = form.elements[0];
  is(input.type,  "password",  "confirming bogus user field 6 type");
  is(input.name,  "uname6",    "confirming bogus user field 6 name");
  is(input.value, "",    "checking bogus user field 6 value");
  input = form.elements[1];
  is(input.type,  "text",      "confirming legit user field 6 type");
  is(input.name,  "uname6",    "confirming legit user field 6 name");
  //is(input.value, "testuser6", "checking legit user field 6 value");
  todo(input.value == "testuser6", "ignore bogus <input> and fill testuser6");
  input = form.elements[2];
  is(input.type,  "password",  "confirming password field 6 type");
  is(input.name,  "pword6",    "confirming password field 6 name");
  //is(input.value, "testpass6", "");
  todo(input.value == "testpass6", "ignore bogus <input> and fill testpass6");

  is($_("uname9").value, "testuser9", "Checking for unmodified username 9");
  is($_("pword9").value, "",    "Checking for unfilled password 9");

  is($_("uname10").value, "testuser10", "Checking for unmodified username 10");
  is($_("pword10").value, "",     "Checking for unfilled password 10");

  SimpleTest.finish();
}

window.onload = startTest;

SimpleTest.waitForExplicitFinish();

</script>
</pre>
</body>
</html>