File: test_storage_legacy_4.js

package info (click to toggle)
wine-gecko-2.21 2.21%2Bdfsg2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 646,272 kB
  • ctags: 630,086
  • sloc: cpp: 2,895,786; ansic: 1,502,970; python: 156,675; asm: 115,373; java: 111,421; sh: 63,309; xml: 62,872; makefile: 58,685; perl: 19,182; objc: 3,461; yacc: 2,051; lex: 979; pascal: 929; exp: 449; php: 244; lisp: 228; awk: 211; sed: 26; csh: 21; ada: 16; ruby: 3
file content (166 lines) | stat: -rw-r--r-- 5,937 bytes parent folder | download | duplicates (8)
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
/*
 * Test suite for storage-Legacy.js -- mailnews specific tests.
 *
 * This test interfaces directly with the legacy login storage module,
 * bypassing the normal login manager usage.
 *
 */

const Cm = Components.manager;
const BASE_CONTRACTID = "@mozilla.org/network/protocol;1?name=";
const LDAPPH_CID = Components.ID("{08eebb58-8d1a-4ab5-9fca-e35372697828}");
const MAILBOXPH_CID = Components.ID("{edb1dea3-b226-405a-b93d-2a678a68a198}");
const NEWSBOXPH_CID = Components.ID("{939fe896-8961-49d0-b0e0-4ae779bdef36}");

const STORAGE_TYPE = "legacy";

function genericProtocolHandler(scheme, defaultPort) {
    this.scheme = scheme;
    this.defaultPort = defaultPort;
}

genericProtocolHandler.prototype = {
    scheme: "",
    defaultPort: 0,

    QueryInterface: function gph_QueryInterface(aIID) {
        if (!aIID.equals(Ci.nsISupports) &&
            !aIID.equals(Ci.nsIProtocolHandler)) {
            throw Cr.NS_ERROR_NO_INTERFACE;
        }
        return this;
    },

    get protocolFlags() {
        throw Cr.NS_ERROR_NOT_IMPLEMENTED;
    },

    newURI: function gph_newURI(aSpec, anOriginalCharset, aBaseURI) {
        var uri = Components.classes["@mozilla.org/network/standard-url;1"].
                             createInstance(Ci.nsIStandardURL);

        uri.init(Ci.nsIStandardURL.URLTYPE_STANDARD, this.defaultPort, aSpec,
                  anOriginalCharset, aBaseURI);

        return uri;
    },

    newChannel: function gph_newChannel(aUri) {
        throw Cr.NS_ERROR_NOT_IMPLEMENTED;
    },

    allowPort: function gph_allowPort(aPort, aScheme) {
        return false;
    }
}

function generateFactory(protocol, defaultPort)
{
    return {
        createInstance: function (outer, iid) {
            if (outer != null)
                throw Components.results.NS_ERROR_NO_AGGREGATION;

            return (new genericProtocolHandler(protocol, defaultPort)).
                    QueryInterface(iid);
        }
    };
}

function run_test() {
// News is set up as an external protocol in Firefox's prefs, for this test
// to work, we need it to be internal.
var prefBranch = Cc["@mozilla.org/preferences-service;1"].
                 getService(Ci.nsIPrefBranch);
prefBranch.setBoolPref("network.protocol-handler.external.news", false);

Cm.nsIComponentRegistrar.registerFactory(LDAPPH_CID, "LDAPProtocolFactory",
                                         BASE_CONTRACTID + "ldap",
                                         generateFactory("ldap", 389));
Cm.nsIComponentRegistrar.registerFactory(MAILBOXPH_CID,
                                         "MailboxProtocolFactory",
                                         BASE_CONTRACTID + "mailbox",
                                         generateFactory("mailbox", 0));
Cm.nsIComponentRegistrar.registerFactory(NEWSBOXPH_CID,
                                         "NewsProtocolFactory",
                                         BASE_CONTRACTID + "news",
                                         generateFactory("news", 119));

try {
/* ========== 0 ========== */
var testnum = 0;
var testdesc = "Initial connection to storage module";

var storage = Cc["@mozilla.org/login-manager/storage/legacy;1"].
              createInstance(Ci.nsILoginManagerStorage);
if (!storage)
    throw "Couldn't create storage instance.";

// Create a couple of dummy users to match what we expect to be translated
// from the input file.
var dummyuser1 = Cc["@mozilla.org/login-manager/loginInfo;1"].
                 createInstance(Ci.nsILoginInfo);
var dummyuser2 = Cc["@mozilla.org/login-manager/loginInfo;1"].
                 createInstance(Ci.nsILoginInfo);
var dummyuser3 = Cc["@mozilla.org/login-manager/loginInfo;1"].
                 createInstance(Ci.nsILoginInfo);
var dummyuser4 = Cc["@mozilla.org/login-manager/loginInfo;1"].
                 createInstance(Ci.nsILoginInfo);
var dummyuser5 = Cc["@mozilla.org/login-manager/loginInfo;1"].
                 createInstance(Ci.nsILoginInfo);
var dummyuser6 = Cc["@mozilla.org/login-manager/loginInfo;1"].
                 createInstance(Ci.nsILoginInfo);


dummyuser1.init("mailbox://localhost", null, "mailbox://localhost",
    "bugzilla", "testpass1", "", "");

dummyuser2.init("ldap://localhost1", null,
    "ldap://localhost1/dc=test",
    "", "testpass2", "", "");

dummyuser3.init("mailbox://localhost", null, "mailbox://localhost",
    "test+pop3", "pop3test", "", "");

dummyuser4.init("http://dummyhost.mozilla.org", "", null,
    "testuser1", "testpass1", "put_user_here", "put_pw_here");

dummyuser5.init("news://localhost", null, "news://localhost/#password",
    "", "newstest", "", "");

dummyuser6.init("news://localhost", null, "news://localhost/#username",
    "", "testnews", "", "");

/*
 * ---------------------- Bug 403790 ----------------------
 * Migrating mailnews style username/passwords
 */

/* ========== 1 ========== */
testnum++;

testdesc = "checking reading of mailnews-like old logins";
storage = LoginTest.initStorage(INDIR, "signons-403790.txt",
                               OUTDIR, "output-403790.txt");
// signons-403790.txt has one extra login that is invalid, and hence isn't
// shown here.
LoginTest.checkStorageData(storage, [], [dummyuser1, dummyuser2, dummyuser3,
                                         dummyuser5, dummyuser6]);

storage.addLogin(dummyuser4); // trigger a write
LoginTest.checkStorageData(storage, [],
                           [dummyuser1, dummyuser2, dummyuser3, dummyuser4,
                            dummyuser5, dummyuser6]);

testdesc = "[flush and reload for verification]";
storage = LoginTest.reloadStorage(OUTDIR, "output-403790.txt");
LoginTest.checkStorageData(storage, [],
                           [dummyuser1, dummyuser2, dummyuser3, dummyuser4,
                            dummyuser5, dummyuser6]);

/* ========== end ========== */
} catch (e) {
    throw ("FAILED in test #" + testnum + " -- " + testdesc + ": " + e);
}

};