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
<!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: simple form with autocomplete off and notifying observers & normal form
<p id="display"></p>

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

  <form id="form1" action="formtest.js" autocomplete="off">
    <p>This is form 1.</p>
    <input  type="text"       name="uname">
    <input  type="password"   name="pword">

    <button type="submit">Submit</button>
    <button type="reset"> Reset </button>
  </form>
  
  <form id="form2" action="formtest.js">
    <p>This is form 2.</p>
    <input  type="text"       name="uname">
    <input  type="password"   name="pword">

    <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: simple form with autocomplete off and notifying observers & normal form **/

commonInit();
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;

Cu.import("resource://gre/modules/XPCOMUtils.jsm");

var TestObserver = {
  receivedNotification1 : false,
  receivedNotification2 : false,
  data1 : "",
  data2 : "",
  QueryInterface : XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
  observe : function (subject, topic, data) {
    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
    var pwmgr = Cc["@mozilla.org/login-manager;1"].
                getService(Ci.nsILoginManager);
    if (topic == "passwordmgr-found-form") {
      if (subject.id == "form1") {
        this.receivedNotification1 = true;
        this.data1 = data;
      } else if (subject.id == "form2") {
        this.receivedNotification2 = true;
        this.data2 = data;
      }
      // Now fill the form
      pwmgr.fillForm(subject);
    }
  }
};

// Add the observer
var os = Cc["@mozilla.org/observer-service;1"].
         getService(Ci.nsIObserverService);
os.addObserver(TestObserver, "passwordmgr-found-form", false);

function startTest(){
  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
  // Test that observer is notified & got correct data
  is(TestObserver.receivedNotification1, true, "Checking observer was notified");
  is(TestObserver.data1, "autocompleteOff", "Checking observer got correct data");

  // Check that form1 was filled
  is($_(1, "uname").value, "testuser", "Checking for filled username 1");
  is($_(1, "pword").value, "testpass", "Checking for filled password 1");
  
  // Test that observer wasn't notified & didn't get data
  is(TestObserver.receivedNotification2, false, "Checking observer was not notified");
  is(TestObserver.data2, "", "Checking observer didn't get data");

  // Check that form2 was filled
  is($_(2, "uname").value, "testuser", "Checking for filled username 2");
  is($_(2, "pword").value, "testpass", "Checking for filled password 2");

  // Remove the observer
  os.removeObserver(TestObserver, "passwordmgr-found-form");

  SimpleTest.finish();
}

window.onload = startTest;

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