1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is JavaScript Engine testing utilities.
17 * The Initial Developer of the Original Code is
19 * Portions created by the Initial Developer are Copyright (C) 2005
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s): Bob Clary
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
39 * Spider hook function to check if an individual browser based JS test
40 * has completed executing.
43 var gCheckInterval = 1000;
46 var gCurrentTestStart;
48 var gCurrentTestValid;
52 function userOnStart()
57 registerDialogCloser();
61 cdump('Spider: FATAL ERROR: userOnStart: ' + ex);
65 function userOnBeforePage()
69 dlog('userOnBeforePage');
70 gPageStart = new Date();
72 gCurrentTestId = /test=(.*);language/.exec(gSpider.mCurrentUrl.mUrl)[1];
73 gCurrentTestValid = true;
74 gCurrentTestStart = new Date();
78 cdump('Spider: WARNING ERROR: userOnBeforePage: ' + ex);
79 gCurrentTestValid = false;
80 gPageCompleted = true;
84 function userOnAfterPage()
88 dlog('userOnAfterPage');
89 gPageStop = new Date();
95 cdump('Spider: WARNING ERROR: userOnAfterPage: ' + ex);
96 gCurrentTestValid = false;
97 gPageCompleted = true;
101 function userOnStop()
105 // close any pending dialogs
107 unregisterDialogCloser();
111 cdump('Spider: WARNING ERROR: userOnStop: ' + ex);
115 function userOnPageTimeout()
117 gPageStop = new Date();
118 if (typeof gSpider.mDocument != 'undefined')
122 var win = gSpider.mDocument.defaultView;
123 if (win.wrappedJSObject)
125 win = win.wrappedJSObject;
127 gPageCompleted = win.gPageCompleted = true;
128 checkTestCompleted();
132 cdump('Spider: WARNING ERROR: userOnPageTimeout: ' + ex);
137 function checkTestCompleted()
141 dlog('checkTestCompleted()');
143 var win = gSpider.mDocument.defaultView;
144 if (win.wrappedJSObject)
146 win = win.wrappedJSObject;
149 if (!gCurrentTestValid)
151 gPageCompleted = true;
153 else if (win.gPageCompleted)
155 gCurrentTestStop = new Date();
156 // gc to flush out issues quickly
159 dlog('Page Completed');
161 var gTestcases = win.gTestcases;
162 if (typeof gTestcases == 'undefined')
164 cdump('JavaScriptTest: ' + gCurrentTestId +
165 ' gTestcases array not defined. Possible test failure.');
166 throw 'gTestcases array not defined. Possible test failure.';
168 else if (gTestcases.length == 0)
170 cdump('JavaScriptTest: ' + gCurrentTestId +
171 ' gTestcases array is empty. Tests not run.');
172 new win.TestCase(win.gTestFile, win.summary, 'Unknown', 'gTestcases array is empty. Tests not run..');
177 cdump('JavaScriptTest: ' + gCurrentTestId + ' Elapsed time ' + ((gCurrentTestStop - gCurrentTestStart)/1000).toFixed(2) + ' seconds');
179 gPageCompleted = true;
183 dlog('page not completed, recheck');
184 setTimeout(checkTestCompleted, gCheckInterval);
189 cdump('Spider: WARNING ERROR: checkTestCompleted: ' + ex);
190 gPageCompleted = true;
194 gConsoleListener.onConsoleMessage =
195 function userOnConsoleMessage(s)