# HG changeset patch # User Atul Varma # Date 1272562106 25200 # Node ID a994fc89f341eaf1a88fb579756881ebcfb44062 # Parent 00b02ba5236c2440cd8c085f2057a490a38c8a50 added semi-automated system tests to black box. diff -r 00b02ba5236c -r a994fc89f341 black-box.html --- a/black-box.html Wed Apr 28 20:06:26 2010 -0700 +++ b/black-box.html Thu Apr 29 10:28:26 2010 -0700 @@ -1,14 +1,33 @@ - Bugzilla Dashboard - Black Box + + Bugzilla Dashboard - Black Box - +

Bugzilla Dashboard - Black Box

-
- +

+ This page contains a Bugzilla Dashboard plugged-in to a + toy Bugzilla database. You can log into it with the + username "john@doe.com" and password "test". +

+

+ You can also click on a test that automates some + common UI actions for you. +

+
+
+ + Login without Password + + + Login with Correct Password + + + Login with Incorrect Password + diff -r 00b02ba5236c -r a994fc89f341 css/black-box.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/css/black-box.css Thu Apr 29 10:28:26 2010 -0700 @@ -0,0 +1,35 @@ +body { + background: black; + color: white; + font-family: Monaco, monospace; + font-size: 9pt; +} + +#dashboard-container { + float: left; +} + +#dashboard { + width: 640px; + height: 480px; + border: none; + margin-right: 1em; +} + +.test-button:before { + content: "Test "; +} + +.test-button { + display: block; + margin: 1em; + cursor: pointer; +} + +.running:after { + content: " (now running)"; +} + +span.test-button:hover { + background: #404040; +} diff -r 00b02ba5236c -r a994fc89f341 js/black-box.js --- a/js/black-box.js Wed Apr 28 20:06:26 2010 -0700 +++ b/js/black-box.js Thu Apr 29 10:28:26 2010 -0700 @@ -1,36 +1,105 @@ -function onDashboardLoaded(dashboard, options) { - var require = Require.build(Require.modules, {window: window}); +function testLoginWithCorrectPassword($) { + return [ + function() { $("#login .username").val("john@doe.com"); + $("#login .password").val("test"); }, + function() { $("#login form").submit(); } + ]; +} - // Needed for Firebug, which won't log iframe errors to the console. - $(dashboard).error( - function(event) { - console.warn("An error occurred in the dashboard iframe."); - }); +function testLoginWithNoPassword($) { + return [ + function() { $("#login .username").val("john@doe.com"); + $("#login .password").val(""); }, + function() { $("#login form").submit(); } + ]; +} - var moduleExports = {}; - var dbrequire = dashboard.Require.build(dashboard.Require.modules, - moduleExports); +function testLoginWithIncorrectPassword($) { + return [ + function() { $("#login .username").val("john@doe.com"); + $("#login .password").val("wrong"); }, + function() { $("#login form").submit(); } + ]; +} - function delegate(method, args) { - console.log(method, args); - } +function setDashboardLoaded(delegate, window) { + window.onDashboardLoaded = function onDashboardLoaded(dashboard, options) { + $(dashboard).error( + function(event) { + if (window.console) + window.console.warn("An error occurred in the dashboard iframe."); + }); - // Get rid of any form values cached by the browser. - options.jQuery("input[type=text], input[type=password]").val(""); + delegate("blackBox.onDashboardLoaded", [dashboard, options]); + + var require = Require.build(Require.modules, {window: window}); + + var moduleExports = {}; + var dbrequire = dashboard.Require.build(dashboard.Require.modules, + moduleExports); + + // Get rid of any form values cached by the browser. + options.jQuery("input[type=text], input[type=password]").val(""); - var ajaxImpl = require("mocks/bugzilla/trivial").makeAjaxImpl(); - options.cache = require("mocks/cache").create(delegate); - options.Bugzilla = require("mocks/bugzilla").create(options.Bugzilla, - ajaxImpl, - delegate); - dbrequire("date-utils").now = function() { - return new Date("Tue Apr 27 2010 09:00:00 GMT"); + var ajaxImpl = require("mocks/bugzilla/trivial").makeAjaxImpl(); + options.cache = require("mocks/cache").create(delegate); + options.Bugzilla = require("mocks/bugzilla").create(options.Bugzilla, + ajaxImpl, + delegate); + dbrequire("date-utils").now = function() { + return new Date("Tue Apr 27 2010 09:00:00 GMT"); + }; + + delegate("blackBox.beforeInit", []); + dbrequire("app/loader").init(moduleExports, options); + delegate("blackBox.afterInit", []); }; - dbrequire("app/loader").init(moduleExports, options); +} + +function resetDashboard(delegate) { + setDashboardLoaded(delegate, window); + var iframe = $("#dashboard").get(0); + iframe.src = "index.html?testing=1"; } $(window).ready( function() { - var iframe = $("#dashboard").get(0); - iframe.src = "index.html?testing=1"; + $(".test-button").click( + function() { + var testButton = this; + var testFunc = window[testButton.id]; + var cmds = []; + const COMMAND_DELAY = 500; + + function queueNextCommand() { + if (cmds.length) + window.setTimeout(nextCommand, COMMAND_DELAY); + else { + $(testButton).removeClass("running"); + } + } + + function nextCommand() { + var cmd = cmds.shift(); + cmd(); + queueNextCommand(); + } + + $(testButton).addClass("running"); + + resetDashboard( + function(method, args) { + switch (method) { + case "blackBox.onDashboardLoaded": + var dashboard = args[0]; + var options = args[1]; + cmds = testFunc(options.jQuery); + break; + case "blackBox.afterInit": + queueNextCommand(); + break; + } + }); + }); + resetDashboard(function() {}); });