comparison js/black-box.js @ 103:a994fc89f341

added semi-automated system tests to black box.
author Atul Varma <avarma@mozilla.com>
date Thu, 29 Apr 2010 10:28:26 -0700
parents 00b02ba5236c
children aad1c0a17ba4
comparison
equal deleted inserted replaced
102:00b02ba5236c 103:a994fc89f341
1 function onDashboardLoaded(dashboard, options) { 1 function testLoginWithCorrectPassword($) {
2 var require = Require.build(Require.modules, {window: window}); 2 return [
3 function() { $("#login .username").val("john@doe.com");
4 $("#login .password").val("test"); },
5 function() { $("#login form").submit(); }
6 ];
7 }
3 8
4 // Needed for Firebug, which won't log iframe errors to the console. 9 function testLoginWithNoPassword($) {
5 $(dashboard).error( 10 return [
6 function(event) { 11 function() { $("#login .username").val("john@doe.com");
7 console.warn("An error occurred in the dashboard iframe."); 12 $("#login .password").val(""); },
8 }); 13 function() { $("#login form").submit(); }
14 ];
15 }
9 16
10 var moduleExports = {}; 17 function testLoginWithIncorrectPassword($) {
11 var dbrequire = dashboard.Require.build(dashboard.Require.modules, 18 return [
12 moduleExports); 19 function() { $("#login .username").val("john@doe.com");
20 $("#login .password").val("wrong"); },
21 function() { $("#login form").submit(); }
22 ];
23 }
13 24
14 function delegate(method, args) { 25 function setDashboardLoaded(delegate, window) {
15 console.log(method, args); 26 window.onDashboardLoaded = function onDashboardLoaded(dashboard, options) {
16 } 27 $(dashboard).error(
28 function(event) {
29 if (window.console)
30 window.console.warn("An error occurred in the dashboard iframe.");
31 });
17 32
18 // Get rid of any form values cached by the browser. 33 delegate("blackBox.onDashboardLoaded", [dashboard, options]);
19 options.jQuery("input[type=text], input[type=password]").val("");
20 34
21 var ajaxImpl = require("mocks/bugzilla/trivial").makeAjaxImpl(); 35 var require = Require.build(Require.modules, {window: window});
22 options.cache = require("mocks/cache").create(delegate); 36
23 options.Bugzilla = require("mocks/bugzilla").create(options.Bugzilla, 37 var moduleExports = {};
24 ajaxImpl, 38 var dbrequire = dashboard.Require.build(dashboard.Require.modules,
25 delegate); 39 moduleExports);
26 dbrequire("date-utils").now = function() { 40
27 return new Date("Tue Apr 27 2010 09:00:00 GMT"); 41 // Get rid of any form values cached by the browser.
42 options.jQuery("input[type=text], input[type=password]").val("");
43
44 var ajaxImpl = require("mocks/bugzilla/trivial").makeAjaxImpl();
45 options.cache = require("mocks/cache").create(delegate);
46 options.Bugzilla = require("mocks/bugzilla").create(options.Bugzilla,
47 ajaxImpl,
48 delegate);
49 dbrequire("date-utils").now = function() {
50 return new Date("Tue Apr 27 2010 09:00:00 GMT");
51 };
52
53 delegate("blackBox.beforeInit", []);
54 dbrequire("app/loader").init(moduleExports, options);
55 delegate("blackBox.afterInit", []);
28 }; 56 };
29 dbrequire("app/loader").init(moduleExports, options); 57 }
58
59 function resetDashboard(delegate) {
60 setDashboardLoaded(delegate, window);
61 var iframe = $("#dashboard").get(0);
62 iframe.src = "index.html?testing=1";
30 } 63 }
31 64
32 $(window).ready( 65 $(window).ready(
33 function() { 66 function() {
34 var iframe = $("#dashboard").get(0); 67 $(".test-button").click(
35 iframe.src = "index.html?testing=1"; 68 function() {
69 var testButton = this;
70 var testFunc = window[testButton.id];
71 var cmds = [];
72 const COMMAND_DELAY = 500;
73
74 function queueNextCommand() {
75 if (cmds.length)
76 window.setTimeout(nextCommand, COMMAND_DELAY);
77 else {
78 $(testButton).removeClass("running");
79 }
80 }
81
82 function nextCommand() {
83 var cmd = cmds.shift();
84 cmd();
85 queueNextCommand();
86 }
87
88 $(testButton).addClass("running");
89
90 resetDashboard(
91 function(method, args) {
92 switch (method) {
93 case "blackBox.onDashboardLoaded":
94 var dashboard = args[0];
95 var options = args[1];
96 cmds = testFunc(options.jQuery);
97 break;
98 case "blackBox.afterInit":
99 queueNextCommand();
100 break;
101 }
102 });
103 });
104 resetDashboard(function() {});
36 }); 105 });