~ps-jenkins/unity-webapps-twitter/latestsnapshot-2.4.16+13.10.20130917.1-0ubuntu1

1 by Robert Bruce Park
Initial commit.
1
function Test(browser) {
2
    this._init(browser);
3
}
4
5
Test.prototype = {
6
    _init: function (browser) {
7
        this._state = 0;
8
        this._login = browser.getLogin();
9
        this._password = browser.getPassword();
10
        this._url = browser.getUrl();
11
        this._browser = browser;
12
        browser.open(this._url);
13
    },
14
15
    onLoad: function () {
16
        function authorize(login, pass) {
17
            var name = document.evaluate('//input[@name=\"session[username_or_email]\"]', document, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue;
18
            var password = document.evaluate('//input[@name=\"session[password]\"]', document, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue;
19
            name.value = login;
20
            password.value = pass;
21
            password.form.submit();
22
        }
23
        if (!this._login) {
24
            this._browser.skipTest();
25
        }
26
        if (this._state === 0) {
27
            this._browser.injectScript("(function(){var authorize = " + authorize + "; authorize('" + this._login + "', '" + this._password + "');})();");
28
        } else if (this._state >= 1) {
29
            setTimeout(this._browser.finish.bind(this._browser), 10000);
30
        }
31
        this._state++;
32
    },
33
34
    validateCallLog: function (log, out) {
35
        assertEquals('Unity.init', log[0].func, 'Unity.init');
36
        assertEquals('Twitter', log[0].args[0].name, 'Twitter');
37
        assertFalse('Login', !log[3].args[0].login);
38
39
        var found = false, i;
40
        for (i = 0; i < out.length; i++) {
41
            if (out[i] === 'PASS SELF TEST') {
42
                found = true;
43
            }
44
        }
45
        assertTrue('PASS SELF TEST', found);
46
    },
47
48
    scriptName: 'Twitter.user.js'
49
};