~bac/juju-gui/trunkcopy

« back to all changes in this revision

Viewing changes to lib/yui/tests/io/tests/js/globalevents-tests.js

  • Committer: kapil.foss at gmail
  • Date: 2012-07-13 18:45:59 UTC
  • Revision ID: kapil.foss@gmail.com-20120713184559-2xl7be17egsrz0c9
reshape

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
YUI.add('globalevents-tests', function(Y) {
2
 
 
3
 
    var suite = new Y.Test.Suite('IO Global Events Tests');
4
 
 
5
 
    suite.add(new Y.Test.Case({
6
 
        name: 'Success flow test',
7
 
        setUp: function() {
8
 
            var t = this;
9
 
            this.a0 = [];
10
 
            this.a1 = ['start', 'complete', 'success', 'end'];
11
 
 
12
 
            this.start = function(id, a) {
13
 
                t.a0.push(a);
14
 
            };
15
 
            this.complete = function(id, o, a) {
16
 
                t.a0.push(a);
17
 
            };
18
 
            this.success = function(id, o, a) {
19
 
                t.a0.push(a);
20
 
            };
21
 
            this.end = function(id, a) {
22
 
                t.a0.push(a);
23
 
                t.resume(t.resolve);
24
 
            };
25
 
            this.resolve = function() {
26
 
                for (var i=0; i < 4; i++) {
27
 
                    Y.Assert.areSame(t.a1[i], t.a0[i]);
28
 
                }
29
 
            };
30
 
            this.start = Y.on('io:start', t.start, t, 'start');
31
 
            this.complete = Y.on('io:complete', t.complete, t, 'complete');
32
 
            this.success = Y.on('io:success', t.success, t, 'success');
33
 
            this.end = Y.on('io:end', t.end, t, 'end');
34
 
        },
35
 
        tearDown: function() {
36
 
            this.start.detach();
37
 
            this.complete.detach();
38
 
            this.success.detach();
39
 
            this.end.detach();
40
 
        },
41
 
        testSuccessFlow: function() {
42
 
            Y.io(Y.IO.URLS.get);
43
 
            this.wait(null, 1000);
44
 
        }
45
 
    }));
46
 
 
47
 
    suite.add(new Y.Test.Case({
48
 
        name: 'Failure flow test',
49
 
        setUp: function() {
50
 
            var t = this;
51
 
            this.a0 = [];
52
 
            this.a2 = ['start', 'complete', 'failure', 'end'];
53
 
 
54
 
            this.start = function(id, a) {
55
 
                t.a0.push(a);
56
 
            };
57
 
            this.complete = function(id, o, a) {
58
 
                t.a0.push(a);
59
 
            };
60
 
            this.failure = function(id, o, a) {
61
 
                t.a0.push(a);
62
 
            };
63
 
            this.end = function(id, a) {
64
 
                t.a0.push(a);
65
 
                t.resume(t.resolve);
66
 
            };
67
 
            this.resolve = function() {
68
 
                for (var i=0; i < 4; i++) {
69
 
                    Y.Assert.areSame(t.a2[i], t.a0[i]);
70
 
                }
71
 
            };
72
 
            this.start = Y.on('io:start', t.start, t, 'start');
73
 
            this.complete = Y.on('io:complete', t.complete, t, 'complete');
74
 
            this.failure = Y.on('io:failure', t.failure, t, 'failure');
75
 
            this.end = Y.on('io:end', t.end, t, 'end');
76
 
        },
77
 
        tearDown: function() {
78
 
            this.start.detach();
79
 
            this.complete.detach();
80
 
            this.failure.detach();
81
 
            this.end.detach();
82
 
        },
83
 
        testFailureFlow: function() {
84
 
            Y.io(Y.IO.URLS.http + '?a=404');
85
 
            this.wait(null, 1000);
86
 
        }
87
 
    }));
88
 
 
89
 
    Y.Test.Runner.add(suite);
90
 
});