Mercurial > bugzilla-dashboard
comparison js/black-box.js @ 108:3ad618d3370f
refactored new Automator class into js/black-box.js.
author | Atul Varma <avarma@mozilla.com> |
---|---|
date | Fri, 30 Apr 2010 04:52:17 -0700 |
parents | aad1c0a17ba4 |
children | 8335b1abc295 |
comparison
equal
deleted
inserted
replaced
107:9a524c01b0f1 | 108:3ad618d3370f |
---|---|
1 function testLoginWithCorrectPassword($) { | 1 function Automator(window, jQuery, onDone) { |
2 return [ | 2 this.jQuery = jQuery; |
3 function() { $("#login .username").val("john@doe.com"); | 3 this.onDone = onDone; |
4 $("#login .password").val("test"); }, | 4 this.queue = []; |
5 function() { $("#login form").submit(); } | 5 this.window = window; |
6 ]; | |
7 } | 6 } |
8 | 7 |
9 function testLoginWithNoPassword($) { | 8 Automator.prototype = { |
10 return [ | 9 COMMAND_DELAY: 500, |
11 function() { $("#login .username").val("john@doe.com"); | 10 queueNextCommand: function queueNextCommand() { |
12 $("#login .password").val(""); }, | 11 var self = this; |
13 function() { $("#login form").submit(); } | 12 function nextCommand() { |
14 ]; | 13 var cmd = self.queue.shift(); |
14 cmd.call(self); | |
15 self.queueNextCommand(); | |
16 } | |
17 | |
18 if (this.queue.length) | |
19 this.window.setTimeout(nextCommand, this.COMMAND_DELAY); | |
20 else | |
21 this.onDone(); | |
22 }, | |
23 _$: function _$(sel) { | |
24 var query = this.jQuery(sel); | |
25 if (query.length == 0) | |
26 throw new Error("selector yields no results: " + sel); | |
27 if (query.length > 1) | |
28 throw new Error("selector yields " + query.length + | |
29 " results instead of 1: " + sel); | |
30 return query; | |
31 }, | |
32 type: function type(field, value) { | |
33 this.queue.push(function() { this._$(field).val(value); }); | |
34 }, | |
35 submit: function submit(form) { | |
36 this.queue.push(function() { this._$(form).submit(); }); | |
37 } | |
38 }; | |
39 | |
40 function testLoginWithCorrectPassword(auto) { | |
41 auto.type("#login .username", "john@doe.com"); | |
42 auto.type("#login .password", "test"); | |
43 auto.submit("#login form"); | |
15 } | 44 } |
16 | 45 |
17 function testLoginWithIncorrectPassword($) { | 46 function testLoginWithNoPassword(auto) { |
18 return [ | 47 auto.type("#login .username", "john@doe.com"); |
19 function() { $("#login .username").val("john@doe.com"); | 48 auto.type("#login .password", ""); |
20 $("#login .password").val("wrong"); }, | 49 auto.submit("#login form"); |
21 function() { $("#login form").submit(); } | 50 } |
22 ]; | 51 |
52 function testLoginWithIncorrectPassword(auto) { | |
53 auto.type("#login .username", "john@doe.com"); | |
54 auto.type("#login .password", "u"); | |
55 auto.submit("#login form"); | |
23 } | 56 } |
24 | 57 |
25 function setDashboardLoaded(delegate, window) { | 58 function setDashboardLoaded(delegate, window) { |
26 window.onDashboardLoaded = function onDashboardLoaded(dashboard, options) { | 59 window.onDashboardLoaded = function onDashboardLoaded(dashboard, options) { |
27 $(dashboard).error( | 60 $(dashboard).error( |
65 function initialize() { | 98 function initialize() { |
66 $(".test-button").click( | 99 $(".test-button").click( |
67 function() { | 100 function() { |
68 var testButton = this; | 101 var testButton = this; |
69 var testFunc = window[testButton.id]; | 102 var testFunc = window[testButton.id]; |
70 var cmds = []; | 103 var auto; |
71 const COMMAND_DELAY = 500; | |
72 | 104 |
73 function queueNextCommand() { | 105 $(testButton).addClass("running"); |
74 if (cmds.length) | 106 function onDone() { |
75 window.setTimeout(nextCommand, COMMAND_DELAY); | 107 $(testButton).removeClass("running"); |
76 else { | |
77 $(testButton).removeClass("running"); | |
78 } | |
79 } | 108 } |
80 | 109 |
81 function nextCommand() { | |
82 var cmd = cmds.shift(); | |
83 cmd(); | |
84 queueNextCommand(); | |
85 } | |
86 | |
87 $(testButton).addClass("running"); | |
88 | |
89 resetDashboard( | 110 resetDashboard( |
90 function(method, args) { | 111 function(method, args) { |
91 switch (method) { | 112 switch (method) { |
92 case "blackBox.onDashboardLoaded": | 113 case "blackBox.onDashboardLoaded": |
93 var dashboard = args[0]; | 114 var dashboard = args[0]; |
94 var options = args[1]; | 115 var options = args[1]; |
95 cmds = testFunc(options.jQuery); | 116 auto = new Automator(window, options.jQuery, onDone); |
117 testFunc(auto); | |
96 break; | 118 break; |
97 case "blackBox.afterInit": | 119 case "blackBox.afterInit": |
98 queueNextCommand(); | 120 auto.queueNextCommand(); |
99 break; | 121 break; |
100 } | 122 } |
101 }); | 123 }); |
102 }); | 124 }); |
103 | 125 |