summaryrefslogtreecommitdiffstats
path: root/mobile/android/tests/browser/chrome/test_about_logins.html
blob: 8e7b404fd014e8218f4b789d5175b0ec08a6968c (plain)
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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1136477
Migrated from Robocop: https://bugzilla.mozilla.org/show_bug.cgi?id=1184186
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 1136477</title>
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SpawnTask.js"></script>
  <link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
  <script type="application/javascript;version=1.8" src="head.js"></script>
  <script type="application/javascript;version=1.8">

  "use strict";

  const { interfaces: Ci, utils: Cu } = Components;

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

  const LOGIN_FIELDS = {
    hostname: "http://example.org/tests/robocop/robocop_blank_01.html",
    formSubmitUrl: "",
    realmAny: null,
    username: "username1",
    password: "password1",
    usernameField: "",
    passwordField: ""
  };

  const LoginInfo = Components.Constructor("@mozilla.org/login-manager/loginInfo;1", "nsILoginInfo", "init");

  function add_login(login) {
    let newLogin = new LoginInfo(login.hostname,
                                 login.formSubmitUrl,
                                 login.realmAny,
                                 login.username,
                                 login.password,
                                 login.usernameField,
                                 login.passwordField);

    Services.logins.addLogin(newLogin);
  }

  add_task(function* test_passwords_list() {
    add_login(LOGIN_FIELDS);

    // Load about:logins.
    let BrowserApp = Services.wm.getMostRecentWindow("navigator:browser").BrowserApp;
    let browser = BrowserApp.addTab("about:logins", { selected: true, parentId: BrowserApp.selectedTab.id }).browser;

    yield promiseBrowserEvent(browser, "load");

    let logins_list_parent = browser.contentDocument.getElementById("logins-list").parentNode;

    let waitForLoginToBeAdded = new Promise((resolve) => {
      let observer = new MutationObserver((mutations) => {
        for (let mutation of mutations) {
          for (let node of mutation.addedNodes) {
            if (node.id == 'logins-list') {
              info("Received mutation replacing 'logins-list'");
              resolve();
              return;
            }
          }
        }
        info("Skipping spurious mutation not replacing 'logins-list'");
      });
      observer.observe(logins_list_parent, {
        childList: true,
      });
      info("Now waiting for mutation to replace 'logins-list'");
    });

    yield waitForLoginToBeAdded;

    let logins_list = browser.contentDocument.getElementById("logins-list");

    // Test that the (single) entry added in setup is correct.
    let hostname = logins_list.querySelector(".hostname");
    is(hostname.textContent, LOGIN_FIELDS.hostname, "hostname is correct");

    let username = logins_list.querySelector(".username");
    is(username.textContent, LOGIN_FIELDS.username, "username is correct");

    // Cleanup: close about:logins, opened in password_setup()
    BrowserApp.closeTab(BrowserApp.selectedTab);
  });

  </script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1136477">Mozilla Bug 1136477</a>
<br>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1184186">Migrated from Robocop testAboutLogins</a>
<p id="display"></p>
<div id="content" style="display: none">

</div>
<pre id="test">
</pre>
</body>
</html>