~alexlauni/webapps-applications/webapps-application-LibreFm

« back to all changes in this revision

Viewing changes to tests/LibreFm.js

  • Committer: Alex Launi
  • Date: 2013-02-13 16:54:50 UTC
  • Revision ID: alex.launi@canonical.com-20130213165450-qzpnwoptwcrba6if
initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function Test(browser) {
 
2
    this._init(browser);
 
3
}
 
4
 
 
5
Test.prototype = {
 
6
    _init: function (browser) {
 
7
        this._state = 0;
 
8
        this._url = browser.getUrl();
 
9
        this._browser = browser;
 
10
        browser.open(this._url);
 
11
    },
 
12
 
 
13
    onLoad: function () {
 
14
        if (this._state === 0) {
 
15
            setTimeout(function () {
 
16
                this._browser.invokeCallback('Unity.MediaPlayer.onNext');
 
17
                setTimeout(function () {
 
18
                    this._browser.finish();
 
19
                }.bind(this), 3000);
 
20
            }.bind(this), 3000);
 
21
        }
 
22
 
 
23
        this._state++;
 
24
    },
 
25
 
 
26
    validateCallLog: function (log) {
 
27
        assertEquals('Unity.init', log[0].func, 'Unity.init');
 
28
        assertEquals('Unity.MediaPlayer.init', log[1].func, 'Unity.MediaPlayer.init');
 
29
        assertEquals('Unity.MediaPlayer.setTrack', log[6].func, 'Unity.MediaPlayer.setTrack');
 
30
 
 
31
        var titles = {}, i;
 
32
        for (i = 0; i < log.length; i++) {
 
33
            if (log[i].func === 'Unity.MediaPlayer.setTrack') {
 
34
              var title = log[i].args[0].title;
 
35
              if (title && title.length !== 0)
 
36
                titles[log[i].args[0].title] = 1;
 
37
            }
 
38
        }
 
39
 
 
40
        var count = 0;
 
41
        for (i in titles) {
 
42
            if (titles.hasOwnProperty(i)) {
 
43
                count++;
 
44
            }
 
45
        }
 
46
        assertEquals('Unity.MediaPlayer.setTrack', count, 2);
 
47
    },
 
48
 
 
49
    scriptName: 'LibreFm/LibreFm.user.js'
 
50
};