browsercms 3.1.4 → 3.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. data/app/controllers/cms/content_block_controller.rb +2 -2
  2. data/app/controllers/cms/section_nodes_controller.rb +6 -1
  3. data/app/controllers/cms/sections_controller.rb +1 -1
  4. data/app/helpers/cms/application_helper.rb +1 -1
  5. data/app/helpers/cms/content_block_helper.rb +27 -0
  6. data/app/helpers/cms/section_nodes_helper.rb +43 -5
  7. data/app/models/abstract_file_block.rb +16 -1
  8. data/app/models/attachment.rb +17 -35
  9. data/app/models/file_block.rb +0 -12
  10. data/app/models/image_block.rb +0 -12
  11. data/app/models/link.rb +4 -21
  12. data/app/models/page.rb +31 -34
  13. data/app/models/section.rb +82 -44
  14. data/app/models/section_node.rb +39 -24
  15. data/app/models/user.rb +5 -0
  16. data/app/views/cms/blocks/index.html.erb +4 -4
  17. data/app/views/cms/file_blocks/_form.html.erb +1 -1
  18. data/app/views/cms/image_blocks/_form.html.erb +1 -1
  19. data/app/views/cms/section_nodes/_link.html.erb +6 -3
  20. data/app/views/cms/section_nodes/_node.html.erb +11 -1
  21. data/app/views/cms/section_nodes/_page.html.erb +13 -7
  22. data/app/views/cms/section_nodes/_section.html.erb +24 -8
  23. data/app/views/cms/section_nodes/index.html.erb +28 -16
  24. data/app/views/layouts/templates/default.html.erb +17 -0
  25. data/browsercms.gemspec +28 -1413
  26. data/db/migrate/20120117144039_browsercms315.rb +94 -0
  27. data/db/migrate/{20081114172307_load_seed_data.rb → 20121114172307_load_seeds.rb} +8 -1
  28. data/lib/acts_as_list.rb +1 -1
  29. data/lib/browsercms.rb +2 -0
  30. data/lib/cms/addressable.rb +83 -0
  31. data/lib/cms/behaviors/attaching.rb +44 -24
  32. data/lib/cms/behaviors/connecting.rb +2 -1
  33. data/lib/cms/behaviors/publishing.rb +12 -3
  34. data/lib/cms/behaviors/versioning.rb +83 -53
  35. data/lib/cms/content_rendering_support.rb +3 -3
  36. data/lib/cms/error_pages.rb +8 -0
  37. data/lib/cms/init.rb +5 -3
  38. data/lib/cms/version.rb +1 -1
  39. data/templates/blank.rb +2 -0
  40. data/templates/demo.rb +2 -0
  41. data/templates/module.rb +2 -0
  42. data/test/custom_assertions.rb +7 -1
  43. data/test/factories.rb +3 -1
  44. data/test/factories/sitemap_factories.rb +28 -0
  45. data/test/fixtures/connectors.yml +97 -0
  46. data/test/fixtures/content_type_groups.yml +13 -0
  47. data/test/fixtures/content_types.yml +50 -0
  48. data/test/fixtures/dynamic_view_versions.yml +26 -0
  49. data/test/fixtures/dynamic_views.yml +26 -0
  50. data/test/fixtures/group_permissions.yml +16 -0
  51. data/test/fixtures/group_sections.yml +31 -0
  52. data/test/fixtures/group_type_permissions.yml +11 -0
  53. data/test/fixtures/group_types.yml +25 -0
  54. data/test/fixtures/groups.yml +25 -0
  55. data/test/fixtures/html_block_versions.yml +67 -0
  56. data/test/fixtures/html_blocks.yml +63 -0
  57. data/test/fixtures/page_versions.yml +265 -0
  58. data/test/fixtures/pages.yml +85 -0
  59. data/test/fixtures/permissions.yml +28 -0
  60. data/test/fixtures/section_nodes.yml +46 -0
  61. data/test/fixtures/sections.yml +19 -0
  62. data/test/fixtures/sites.yml +9 -0
  63. data/test/fixtures/user_group_memberships.yml +11 -0
  64. data/test/fixtures/users.yml +15 -0
  65. data/test/functional/cms/content_controller_test.rb +6 -1
  66. data/test/functional/cms/file_blocks_controller_test.rb +1 -0
  67. data/test/functional/cms/html_blocks_controller_test.rb +1 -0
  68. data/test/functional/cms/image_blocks_controller_test.rb +39 -32
  69. data/test/functional/cms/section_nodes_controller_test.rb +48 -20
  70. data/test/functional/cms/sections_controller_test.rb +3 -1
  71. data/test/functional/tests/pretend_controller_test.rb +6 -3
  72. data/test/integration/cms/ckeditor_test.rb +5 -2
  73. data/test/integration/sitemap_performance_test.rb +26 -0
  74. data/test/selenium-core/Blank.html +7 -0
  75. data/test/selenium-core/InjectedRemoteRunner.html +8 -0
  76. data/test/selenium-core/RemoteRunner.html +110 -0
  77. data/test/selenium-core/SeleniumLog.html +109 -0
  78. data/test/selenium-core/TestPrompt.html +145 -0
  79. data/test/selenium-core/TestRunner-splash.html +55 -0
  80. data/test/selenium-core/TestRunner.hta +176 -0
  81. data/test/selenium-core/TestRunner.html +176 -0
  82. data/test/selenium-core/domviewer/butmin.gif +0 -0
  83. data/test/selenium-core/domviewer/butplus.gif +0 -0
  84. data/test/selenium-core/domviewer/domviewer.css +298 -0
  85. data/test/selenium-core/domviewer/domviewer.html +16 -0
  86. data/test/selenium-core/domviewer/selenium-domviewer.js +205 -0
  87. data/test/selenium-core/icons/all.png +0 -0
  88. data/test/selenium-core/icons/continue.png +0 -0
  89. data/test/selenium-core/icons/continue_disabled.png +0 -0
  90. data/test/selenium-core/icons/pause.png +0 -0
  91. data/test/selenium-core/icons/pause_disabled.png +0 -0
  92. data/test/selenium-core/icons/selected.png +0 -0
  93. data/test/selenium-core/icons/step.png +0 -0
  94. data/test/selenium-core/icons/step_disabled.png +0 -0
  95. data/test/selenium-core/iedoc-core.xml +1515 -0
  96. data/test/selenium-core/iedoc.xml +1469 -0
  97. data/test/selenium-core/lib/cssQuery/cssQuery-p.js +6 -0
  98. data/test/selenium-core/lib/cssQuery/src/cssQuery-level2.js +142 -0
  99. data/test/selenium-core/lib/cssQuery/src/cssQuery-level3.js +150 -0
  100. data/test/selenium-core/lib/cssQuery/src/cssQuery-standard.js +53 -0
  101. data/test/selenium-core/lib/cssQuery/src/cssQuery.js +356 -0
  102. data/test/selenium-core/lib/prototype.js +2006 -0
  103. data/test/selenium-core/lib/scriptaculous/builder.js +101 -0
  104. data/test/selenium-core/lib/scriptaculous/controls.js +815 -0
  105. data/test/selenium-core/lib/scriptaculous/dragdrop.js +915 -0
  106. data/test/selenium-core/lib/scriptaculous/effects.js +958 -0
  107. data/test/selenium-core/lib/scriptaculous/scriptaculous.js +47 -0
  108. data/test/selenium-core/lib/scriptaculous/slider.js +283 -0
  109. data/test/selenium-core/lib/scriptaculous/unittest.js +383 -0
  110. data/test/selenium-core/scripts/find_matching_child.js +69 -0
  111. data/test/selenium-core/scripts/htmlutils.js +894 -0
  112. data/test/selenium-core/scripts/injection.html +72 -0
  113. data/test/selenium-core/scripts/js2html.js +70 -0
  114. data/test/selenium-core/scripts/narcissus-defs.js +175 -0
  115. data/test/selenium-core/scripts/narcissus-exec.js +1054 -0
  116. data/test/selenium-core/scripts/narcissus-parse.js +1003 -0
  117. data/test/selenium-core/scripts/se2html.js +63 -0
  118. data/test/selenium-core/scripts/selenium-api.js +2409 -0
  119. data/test/selenium-core/scripts/selenium-browserbot.js +2203 -0
  120. data/test/selenium-core/scripts/selenium-browserdetect.js +150 -0
  121. data/test/selenium-core/scripts/selenium-commandhandlers.js +377 -0
  122. data/test/selenium-core/scripts/selenium-executionloop.js +175 -0
  123. data/test/selenium-core/scripts/selenium-logging.js +147 -0
  124. data/test/selenium-core/scripts/selenium-remoterunner.js +571 -0
  125. data/test/selenium-core/scripts/selenium-testrunner.js +1333 -0
  126. data/test/selenium-core/scripts/selenium-version.js +5 -0
  127. data/test/selenium-core/scripts/user-extensions.js +3 -0
  128. data/test/selenium-core/scripts/user-extensions.js.sample +75 -0
  129. data/test/selenium-core/scripts/xmlextras.js +153 -0
  130. data/test/selenium-core/selenium-logo.png +0 -0
  131. data/test/selenium-core/selenium-test.css +43 -0
  132. data/test/selenium-core/selenium.css +299 -0
  133. data/test/selenium-core/xpath/dom.js +428 -0
  134. data/test/selenium-core/xpath/misc.js +252 -0
  135. data/test/selenium-core/xpath/xpath.js +2223 -0
  136. data/test/selenium/_login_as_cmsadmin.rsel +4 -0
  137. data/test/selenium/dashboard.rsel +5 -0
  138. data/test/selenium/html_blocks.rsel +4 -0
  139. data/test/selenium/login/failed_login.rsel +8 -0
  140. data/test/selenium/login/successful_login.rsel +9 -0
  141. data/test/selenium/page_templates.rsel +12 -0
  142. data/test/selenium/pages/edit_properties.rsel +5 -0
  143. data/test/selenium/site/view_home_page.rsel +4 -0
  144. data/test/selenium/sitemap/move_page.rsel +9 -0
  145. data/test/selenium/sitemap/open_section.rsel +6 -0
  146. data/test/selenium/sitemap/select_page.rsel +12 -0
  147. data/test/selenium/sitemap/select_section.rsel +17 -0
  148. data/test/test_helper.rb +30 -12
  149. data/test/unit/behaviors/attaching_test.rb +4 -6
  150. data/test/unit/behaviors/connectable_test.rb +29 -0
  151. data/test/unit/behaviors/publishable_test.rb +40 -9
  152. data/test/unit/behaviors/versioning_test.rb +36 -0
  153. data/test/unit/helpers/menu_helper_test.rb +5 -2
  154. data/test/unit/helpers/page_helper_test.rb +2 -0
  155. data/test/unit/lib/cms/sitemap_test.rb +206 -0
  156. data/test/unit/models/attachment_test.rb +51 -31
  157. data/test/unit/models/file_block_test.rb +74 -55
  158. data/test/unit/models/link_test.rb +44 -0
  159. data/test/unit/models/page_test.rb +290 -224
  160. data/test/unit/models/sections_test.rb +144 -44
  161. data/test/unit/models/user_test.rb +28 -18
  162. metadata +581 -350
  163. data/app/views/cms/section_nodes/_section_node.html.erb +0 -10
  164. data/test/unit/models/section_node_test.rb +0 -92
@@ -0,0 +1,1333 @@
1
+ /*
2
+ * Copyright 2004 ThoughtWorks, Inc
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ // An object representing the current test, used external
19
+ var currentTest = null; // TODO: get rid of this global, which mirrors the htmlTestRunner.currentTest
20
+ var selenium = null;
21
+
22
+ var htmlTestRunner;
23
+ var HtmlTestRunner = classCreate();
24
+ objectExtend(HtmlTestRunner.prototype, {
25
+ initialize: function() {
26
+ this.metrics = new Metrics();
27
+ this.controlPanel = new HtmlTestRunnerControlPanel();
28
+ this.testFailed = false;
29
+ this.currentTest = null;
30
+ this.runAllTests = false;
31
+ this.appWindow = null;
32
+ // we use a timeout here to make sure the LOG has loaded first, so we can see _every_ error
33
+ setTimeout(fnBind(function() {
34
+ this.loadSuiteFrame();
35
+ }, this), 500);
36
+ },
37
+
38
+ getTestSuite: function() {
39
+ return suiteFrame.getCurrentTestSuite();
40
+ },
41
+
42
+ markFailed: function() {
43
+ this.testFailed = true;
44
+ this.getTestSuite().markFailed();
45
+ },
46
+
47
+ loadSuiteFrame: function() {
48
+ var logLevel = this.controlPanel.getDefaultLogLevel();
49
+ if (logLevel) {
50
+ LOG.setLogLevelThreshold(logLevel);
51
+ }
52
+ if (selenium == null) {
53
+ var appWindow = this._getApplicationWindow();
54
+ try { appWindow.location; }
55
+ catch (e) {
56
+ // when reloading, we may be pointing at an old window (Perm Denied)
57
+ setTimeout(fnBind(function() {
58
+ this.loadSuiteFrame();
59
+ }, this), 50);
60
+ return;
61
+ }
62
+ selenium = Selenium.createForWindow(appWindow);
63
+ this._registerCommandHandlers();
64
+ }
65
+ this.controlPanel.setHighlightOption();
66
+ var testSuiteName = this.controlPanel.getTestSuiteName();
67
+ var self = this;
68
+ if (testSuiteName) {
69
+ suiteFrame.load(testSuiteName, function() {setTimeout(fnBind(self._onloadTestSuite, self), 50)} );
70
+ selenium.browserbot.baseUrl = absolutify(testSuiteName, window.location.href);
71
+ }
72
+ // DGF or should we use the old default?
73
+ // selenium.browserbot.baseUrl = window.location.href;
74
+ if (this.controlPanel.getBaseUrl()) {
75
+ selenium.browserbot.baseUrl = this.controlPanel.getBaseUrl();
76
+ }
77
+ },
78
+
79
+ _getApplicationWindow: function () {
80
+ if (this.controlPanel.isMultiWindowMode()) {
81
+ return this._getSeparateApplicationWindow();
82
+ }
83
+ return sel$('selenium_myiframe').contentWindow;
84
+ },
85
+
86
+ _getSeparateApplicationWindow: function () {
87
+ if (this.appWindow == null) {
88
+ this.appWindow = openSeparateApplicationWindow('TestRunner-splash.html', this.controlPanel.isAutomatedRun());
89
+ }
90
+ return this.appWindow;
91
+ },
92
+
93
+ _onloadTestSuite:function () {
94
+ if (! this.getTestSuite().isAvailable()) {
95
+ return;
96
+ }
97
+ if (this.controlPanel.isAutomatedRun()) {
98
+ this.startTestSuite();
99
+ } else if (this.controlPanel.getAutoUrl()) {
100
+ //todo what is the autourl doing, left to check it out
101
+ addLoadListener(this._getApplicationWindow(), fnBind(this._startSingleTest, this));
102
+ this._getApplicationWindow().src = this.controlPanel.getAutoUrl();
103
+ } else {
104
+ var testCaseLoaded = fnBind(function(){this.testCaseLoaded=true;},this);
105
+ this.getTestSuite().getSuiteRows()[0].loadTestCase(testCaseLoaded);
106
+ }
107
+ },
108
+
109
+ _startSingleTest:function () {
110
+ removeLoadListener(getApplicationWindow(), fnBind(this._startSingleTest, this));
111
+ var singleTestName = this.controlPanel.getSingleTestName();
112
+ testFrame.load(singleTestName, fnBind(this.startTest, this));
113
+ },
114
+
115
+ _registerCommandHandlers: function () {
116
+ this.commandFactory = new CommandHandlerFactory();
117
+ this.commandFactory.registerAll(selenium);
118
+ },
119
+
120
+ startTestSuite: function() {
121
+ this.controlPanel.reset();
122
+ this.metrics.resetMetrics();
123
+ this.getTestSuite().reset();
124
+ this.runAllTests = true;
125
+ this.runNextTest();
126
+ },
127
+
128
+ runNextTest: function () {
129
+ this.getTestSuite().updateSuiteWithResultOfPreviousTest();
130
+ if (!this.runAllTests) {
131
+ return;
132
+ }
133
+ this.getTestSuite().runNextTestInSuite();
134
+ },
135
+
136
+ startTest: function () {
137
+ this.controlPanel.reset();
138
+ testFrame.scrollToTop();
139
+ //todo: move testFailed and storedVars to TestCase
140
+ this.testFailed = false;
141
+ storedVars = new Object();
142
+ this.currentTest = new HtmlRunnerTestLoop(testFrame.getCurrentTestCase(), this.metrics, this.commandFactory);
143
+ currentTest = this.currentTest;
144
+ this.currentTest.start();
145
+ },
146
+
147
+ runSingleTest:function() {
148
+ this.runAllTests = false;
149
+ this.metrics.resetMetrics();
150
+ this.startTest();
151
+ }
152
+ });
153
+
154
+ var runInterval = 0;
155
+
156
+ /** SeleniumFrame encapsulates an iframe element */
157
+ var SeleniumFrame = classCreate();
158
+ objectExtend(SeleniumFrame.prototype, {
159
+
160
+ initialize : function(frame) {
161
+ this.frame = frame;
162
+ addLoadListener(this.frame, fnBind(this._handleLoad, this));
163
+ },
164
+
165
+ getDocument : function() {
166
+ return this.frame.contentWindow.document;
167
+ },
168
+
169
+ _handleLoad: function() {
170
+ this._attachStylesheet();
171
+ this._onLoad();
172
+ if (this.loadCallback) {
173
+ this.loadCallback();
174
+ this.loadCallback = null;
175
+ }
176
+ },
177
+
178
+ _attachStylesheet: function() {
179
+ var d = this.getDocument();
180
+ var head = d.getElementsByTagName('head').item(0);
181
+ var styleLink = d.createElement("link");
182
+ styleLink.rel = "stylesheet";
183
+ styleLink.type = "text/css";
184
+ if (browserVersion && browserVersion.isChrome) {
185
+ // DGF We have to play a clever trick to get the right absolute path.
186
+ // This trick works on most browsers, (not IE), but is only needed in
187
+ // chrome
188
+ var tempLink = window.document.createElement("link");
189
+ tempLink.href = "selenium-test.css"; // this will become an absolute href
190
+ styleLink.href = tempLink.href;
191
+ } else {
192
+ // this works in every browser (except Firefox in chrome mode)
193
+ var styleSheetPath = window.location.pathname.replace(/[^\/\\]+$/, "selenium-test.css");
194
+ if (browserVersion.isIE && window.location.protocol == "file:") {
195
+ styleSheetPath = "file:///" + styleSheetPath;
196
+ }
197
+ styleLink.href = styleSheetPath;
198
+ }
199
+ // DGF You're only going to see this log message if you set defaultLogLevel=debug
200
+ LOG.debug("styleLink.href="+styleLink.href);
201
+ head.appendChild(styleLink);
202
+ },
203
+
204
+ _onLoad: function() {
205
+ },
206
+
207
+ scrollToTop : function() {
208
+ this.frame.contentWindow.scrollTo(0, 0);
209
+ },
210
+
211
+ _setLocation: function(location) {
212
+ var isChrome = browserVersion.isChrome || false;
213
+ var isHTA = browserVersion.isHTA || false;
214
+ // DGF TODO multiWindow
215
+ location += (location.indexOf("?") == -1 ? "?" : "&");
216
+ location += "thisIsChrome=" + isChrome + "&thisIsHTA=" + isHTA;
217
+ if (browserVersion.isSafari) {
218
+ // safari doesn't reload the page when the location equals to current location.
219
+ // hence, set the location to blank so that the page will reload automatically.
220
+ this.frame.src = "about:blank";
221
+ this.frame.src = location;
222
+ } else {
223
+ this.frame.contentWindow.location.replace(location);
224
+ }
225
+ },
226
+
227
+ load: function(/* url, [callback] */) {
228
+ if (arguments.length > 1) {
229
+ this.loadCallback = arguments[1];
230
+
231
+ }
232
+ this._setLocation(arguments[0]);
233
+ }
234
+
235
+ });
236
+
237
+ /** HtmlTestSuiteFrame - encapsulates the suite iframe element */
238
+ var HtmlTestSuiteFrame = classCreate();
239
+ objectExtend(HtmlTestSuiteFrame.prototype, SeleniumFrame.prototype);
240
+ objectExtend(HtmlTestSuiteFrame.prototype, {
241
+
242
+ getCurrentTestSuite: function() {
243
+ if (!this.currentTestSuite) {
244
+ this.currentTestSuite = new HtmlTestSuite(this.getDocument());
245
+ }
246
+ return this.currentTestSuite;
247
+ }
248
+
249
+ });
250
+
251
+ /** HtmlTestFrame - encapsulates the test-case iframe element */
252
+ var HtmlTestFrame = classCreate();
253
+ objectExtend(HtmlTestFrame.prototype, SeleniumFrame.prototype);
254
+ objectExtend(HtmlTestFrame.prototype, {
255
+
256
+ _onLoad: function() {
257
+ this.currentTestCase = new HtmlTestCase(this.getDocument(), htmlTestRunner.getTestSuite().getCurrentRow());
258
+ },
259
+
260
+ getCurrentTestCase: function() {
261
+ return this.currentTestCase;
262
+ }
263
+
264
+ });
265
+
266
+ function onSeleniumLoad() {
267
+ suiteFrame = new HtmlTestSuiteFrame(getSuiteFrame());
268
+ testFrame = new HtmlTestFrame(getTestFrame());
269
+ htmlTestRunner = new HtmlTestRunner();
270
+ }
271
+
272
+ var suiteFrame;
273
+ var testFrame;
274
+
275
+ function getSuiteFrame() {
276
+ var f = sel$('testSuiteFrame');
277
+ if (f == null) {
278
+ f = top;
279
+ // proxyInjection mode does not set selenium_myiframe
280
+ }
281
+ return f;
282
+ }
283
+
284
+ function getTestFrame() {
285
+ var f = sel$('testFrame');
286
+ if (f == null) {
287
+ f = top;
288
+ // proxyInjection mode does not set selenium_myiframe
289
+ }
290
+ return f;
291
+ }
292
+
293
+ var HtmlTestRunnerControlPanel = classCreate();
294
+ objectExtend(HtmlTestRunnerControlPanel.prototype, URLConfiguration.prototype);
295
+ objectExtend(HtmlTestRunnerControlPanel.prototype, {
296
+ initialize: function() {
297
+ this._acquireQueryString();
298
+
299
+ this.runInterval = 0;
300
+
301
+ this.highlightOption = sel$('highlightOption');
302
+ this.pauseButton = sel$('pauseTest');
303
+ this.stepButton = sel$('stepTest');
304
+
305
+ this.highlightOption.onclick = fnBindAsEventListener((function() {
306
+ this.setHighlightOption();
307
+ }), this);
308
+ this.pauseButton.onclick = fnBindAsEventListener(this.pauseCurrentTest, this);
309
+ this.stepButton.onclick = fnBindAsEventListener(this.stepCurrentTest, this);
310
+
311
+
312
+ this.speedController = new Control.Slider('speedHandle', 'speedTrack', {
313
+ range: $R(0, 1000),
314
+ onSlide: fnBindAsEventListener(this.setRunInterval, this),
315
+ onChange: fnBindAsEventListener(this.setRunInterval, this)
316
+ });
317
+
318
+ this._parseQueryParameter();
319
+ },
320
+
321
+ setHighlightOption: function () {
322
+ var isHighlight = this.highlightOption.checked;
323
+ selenium.browserbot.setShouldHighlightElement(isHighlight);
324
+ },
325
+
326
+ _parseQueryParameter: function() {
327
+ var tempRunInterval = this._getQueryParameter("runInterval");
328
+ if (tempRunInterval) {
329
+ this.setRunInterval(tempRunInterval);
330
+ }
331
+ this.highlightOption.checked = this._getQueryParameter("highlight");
332
+ },
333
+
334
+ setRunInterval: function(runInterval) {
335
+ this.runInterval = runInterval;
336
+ },
337
+
338
+ setToPauseAtNextCommand: function() {
339
+ this.runInterval = -1;
340
+ },
341
+
342
+ pauseCurrentTest: function () {
343
+ this.setToPauseAtNextCommand();
344
+ this._switchPauseButtonToContinue();
345
+ },
346
+
347
+ continueCurrentTest: function () {
348
+ this.reset();
349
+ currentTest.resume();
350
+ },
351
+
352
+ reset: function() {
353
+ this.runInterval = this.speedController.value;
354
+ this._switchContinueButtonToPause();
355
+ },
356
+
357
+ _switchContinueButtonToPause: function() {
358
+ this.pauseButton.className = "cssPauseTest";
359
+ this.pauseButton.onclick = fnBindAsEventListener(this.pauseCurrentTest, this);
360
+ },
361
+
362
+ _switchPauseButtonToContinue: function() {
363
+ sel$('stepTest').disabled = false;
364
+ this.pauseButton.className = "cssContinueTest";
365
+ this.pauseButton.onclick = fnBindAsEventListener(this.continueCurrentTest, this);
366
+ },
367
+
368
+ stepCurrentTest: function () {
369
+ this.setToPauseAtNextCommand();
370
+ currentTest.resume();
371
+ },
372
+
373
+ isAutomatedRun: function() {
374
+ return this._isQueryParameterTrue("auto");
375
+ },
376
+
377
+ shouldSaveResultsToFile: function() {
378
+ return this._isQueryParameterTrue("save");
379
+ },
380
+
381
+ closeAfterTests: function() {
382
+ return this._isQueryParameterTrue("close");
383
+ },
384
+
385
+ getTestSuiteName: function() {
386
+ return this._getQueryParameter("test");
387
+ },
388
+
389
+ getSingleTestName: function() {
390
+ return this._getQueryParameter("singletest");
391
+ },
392
+
393
+ getAutoUrl: function() {
394
+ return this._getQueryParameter("autoURL");
395
+ },
396
+
397
+ getDefaultLogLevel: function() {
398
+ return this._getQueryParameter("defaultLogLevel");
399
+ },
400
+
401
+ getResultsUrl: function() {
402
+ return this._getQueryParameter("resultsUrl");
403
+ },
404
+
405
+ _acquireQueryString: function() {
406
+ if (this.queryString) return;
407
+ if (browserVersion.isHTA) {
408
+ var args = this._extractArgs();
409
+ if (args.length < 2) return null;
410
+ this.queryString = args[1];
411
+ } else {
412
+ this.queryString = location.search.substr(1);
413
+ }
414
+ }
415
+
416
+ });
417
+
418
+ var AbstractResultAwareRow = classCreate();
419
+ objectExtend(AbstractResultAwareRow.prototype, {
420
+
421
+ initialize: function(trElement) {
422
+ this.trElement = trElement;
423
+ },
424
+
425
+ setStatus: function(status) {
426
+ this.unselect();
427
+ this.trElement.className = this.trElement.className.replace(/status_[a-z]+/, "");
428
+ if (status) {
429
+ addClassName(this.trElement, "status_" + status);
430
+ }
431
+ },
432
+
433
+ select: function() {
434
+ addClassName(this.trElement, "selected");
435
+ safeScrollIntoView(this.trElement);
436
+ },
437
+
438
+ unselect: function() {
439
+ removeClassName(this.trElement, "selected");
440
+ },
441
+
442
+ markPassed: function() {
443
+ this.setStatus("passed");
444
+ },
445
+
446
+ markDone: function() {
447
+ this.setStatus("done");
448
+ },
449
+
450
+ markFailed: function() {
451
+ this.setStatus("failed");
452
+ }
453
+
454
+ });
455
+
456
+ var TitleRow = classCreate();
457
+ objectExtend(TitleRow.prototype, AbstractResultAwareRow.prototype);
458
+ objectExtend(TitleRow.prototype, {
459
+
460
+ initialize: function(trElement) {
461
+ this.trElement = trElement;
462
+ trElement.className = "title";
463
+ }
464
+
465
+ });
466
+
467
+ var HtmlTestCaseRow = classCreate();
468
+ objectExtend(HtmlTestCaseRow.prototype, AbstractResultAwareRow.prototype);
469
+ objectExtend(HtmlTestCaseRow.prototype, {
470
+
471
+ getCommand: function () {
472
+ return new SeleniumCommand(getText(this.trElement.cells[0]),
473
+ getText(this.trElement.cells[1]),
474
+ getText(this.trElement.cells[2]),
475
+ this.isBreakpoint());
476
+ },
477
+
478
+ markFailed: function(errorMsg) {
479
+ AbstractResultAwareRow.prototype.markFailed.call(this, errorMsg);
480
+ this.setMessage(errorMsg);
481
+ },
482
+
483
+ setMessage: function(message) {
484
+ setText(this.trElement.cells[2], message);
485
+ },
486
+
487
+ reset: function() {
488
+ this.setStatus(null);
489
+ var thirdCell = this.trElement.cells[2];
490
+ if (thirdCell) {
491
+ if (thirdCell.originalHTML) {
492
+ thirdCell.innerHTML = thirdCell.originalHTML;
493
+ } else {
494
+ thirdCell.originalHTML = thirdCell.innerHTML;
495
+ }
496
+ }
497
+ },
498
+
499
+ onClick: function() {
500
+ if (this.trElement.isBreakpoint == undefined) {
501
+ this.trElement.isBreakpoint = true;
502
+ addClassName(this.trElement, "breakpoint");
503
+ } else {
504
+ this.trElement.isBreakpoint = undefined;
505
+ removeClassName(this.trElement, "breakpoint");
506
+ }
507
+ },
508
+
509
+ addBreakpointSupport: function() {
510
+ elementSetStyle(this.trElement, {"cursor" : "pointer"});
511
+ this.trElement.onclick = fnBindAsEventListener(function() {
512
+ this.onClick();
513
+ }, this);
514
+ },
515
+
516
+ isBreakpoint: function() {
517
+ if (this.trElement.isBreakpoint == undefined || this.trElement.isBreakpoint == null) {
518
+ return false
519
+ }
520
+ return this.trElement.isBreakpoint;
521
+ }
522
+ });
523
+
524
+ var HtmlTestSuiteRow = classCreate();
525
+ objectExtend(HtmlTestSuiteRow.prototype, AbstractResultAwareRow.prototype);
526
+ objectExtend(HtmlTestSuiteRow.prototype, {
527
+
528
+ initialize: function(trElement, testFrame, htmlTestSuite) {
529
+ this.trElement = trElement;
530
+ this.testFrame = testFrame;
531
+ this.htmlTestSuite = htmlTestSuite;
532
+ this.link = trElement.getElementsByTagName("a")[0];
533
+ this.link.onclick = fnBindAsEventListener(this._onClick, this);
534
+ },
535
+
536
+ reset: function() {
537
+ this.setStatus(null);
538
+ },
539
+
540
+ _onClick: function() {
541
+ this.loadTestCase(null);
542
+ return false;
543
+ },
544
+
545
+ loadTestCase: function(onloadFunction) {
546
+ this.htmlTestSuite.unselectCurrentRow();
547
+ this.select();
548
+ this.htmlTestSuite.currentRowInSuite = this.trElement.rowIndex - 1;
549
+ // If the row has a stored results table, use that
550
+ var resultsFromPreviousRun = this.trElement.cells[1];
551
+ if (resultsFromPreviousRun) {
552
+ // todo: delegate to TestFrame, e.g.
553
+ // this.testFrame.restoreTestCase(resultsFromPreviousRun.innerHTML);
554
+ var testBody = this.testFrame.getDocument().body;
555
+ testBody.innerHTML = resultsFromPreviousRun.innerHTML;
556
+ this.testFrame._onLoad();
557
+ if (onloadFunction) {
558
+ onloadFunction();
559
+ }
560
+ } else {
561
+ this.testFrame.load(this.link.href, onloadFunction);
562
+ }
563
+ },
564
+
565
+ saveTestResults: function() {
566
+ // todo: GLOBAL ACCESS!
567
+ var resultHTML = this.testFrame.getDocument().body.innerHTML;
568
+ if (!resultHTML) return;
569
+
570
+ // todo: why create this div?
571
+ var divElement = this.trElement.ownerDocument.createElement("div");
572
+ divElement.innerHTML = resultHTML;
573
+
574
+ var hiddenCell = this.trElement.ownerDocument.createElement("td");
575
+ hiddenCell.appendChild(divElement);
576
+ hiddenCell.style.display = "none";
577
+
578
+ this.trElement.appendChild(hiddenCell);
579
+ }
580
+
581
+ });
582
+
583
+ var HtmlTestSuite = classCreate();
584
+ objectExtend(HtmlTestSuite.prototype, {
585
+
586
+ initialize: function(suiteDocument) {
587
+ this.suiteDocument = suiteDocument;
588
+ this.suiteRows = this._collectSuiteRows();
589
+ this.titleRow = new TitleRow(this.getTestTable().rows[0]);
590
+ this.reset();
591
+ },
592
+
593
+ reset: function() {
594
+ this.failed = false;
595
+ this.currentRowInSuite = -1;
596
+ this.titleRow.setStatus(null);
597
+ for (var i = 0; i < this.suiteRows.length; i++) {
598
+ var row = this.suiteRows[i];
599
+ row.reset();
600
+ }
601
+ },
602
+
603
+ getSuiteRows: function() {
604
+ return this.suiteRows;
605
+ },
606
+
607
+ getTestTable: function() {
608
+ var tables = sel$A(this.suiteDocument.getElementsByTagName("table"));
609
+ return tables[0];
610
+ },
611
+
612
+ isAvailable: function() {
613
+ return this.getTestTable() != null;
614
+ },
615
+
616
+ _collectSuiteRows: function () {
617
+ var result = [];
618
+ var tables = sel$A(this.suiteDocument.getElementsByTagName("table"));
619
+ var testTable = tables[0];
620
+ for (rowNum = 1; rowNum < testTable.rows.length; rowNum++) {
621
+ var rowElement = testTable.rows[rowNum];
622
+ result.push(new HtmlTestSuiteRow(rowElement, testFrame, this));
623
+ }
624
+
625
+ // process the unsuited rows as well
626
+ for (var tableNum = 1; tableNum < sel$A(this.suiteDocument.getElementsByTagName("table")).length; tableNum++) {
627
+ testTable = tables[tableNum];
628
+ for (rowNum = 1; rowNum < testTable.rows.length; rowNum++) {
629
+ var rowElement = testTable.rows[rowNum];
630
+ new HtmlTestSuiteRow(rowElement, testFrame, this);
631
+ }
632
+ }
633
+ return result;
634
+ },
635
+
636
+ getCurrentRow: function() {
637
+ if (this.currentRowInSuite == -1) {
638
+ return null;
639
+ }
640
+ return this.suiteRows[this.currentRowInSuite];
641
+ },
642
+
643
+ unselectCurrentRow: function() {
644
+ var currentRow = this.getCurrentRow()
645
+ if (currentRow) {
646
+ currentRow.unselect();
647
+ }
648
+ },
649
+
650
+ markFailed: function() {
651
+ this.failed = true;
652
+ this.titleRow.markFailed();
653
+ },
654
+
655
+ markDone: function() {
656
+ if (!this.failed) {
657
+ this.titleRow.markPassed();
658
+ }
659
+ },
660
+
661
+ _startCurrentTestCase: function() {
662
+ this.getCurrentRow().loadTestCase(fnBind(htmlTestRunner.startTest, htmlTestRunner));
663
+ },
664
+
665
+ _onTestSuiteComplete: function() {
666
+ this.markDone();
667
+ new TestResult(this.failed, this.getTestTable()).post();
668
+ },
669
+
670
+ updateSuiteWithResultOfPreviousTest: function() {
671
+ if (this.currentRowInSuite >= 0) {
672
+ this.getCurrentRow().saveTestResults();
673
+ }
674
+ },
675
+
676
+ runNextTestInSuite: function() {
677
+ this.currentRowInSuite++;
678
+
679
+ // If we are done with all of the tests, set the title bar as pass or fail
680
+ if (this.currentRowInSuite >= this.suiteRows.length) {
681
+ this._onTestSuiteComplete();
682
+ } else {
683
+ this._startCurrentTestCase();
684
+ }
685
+ }
686
+
687
+
688
+
689
+ });
690
+
691
+ var TestResult = classCreate();
692
+ objectExtend(TestResult.prototype, {
693
+
694
+ // Post the results to a servlet, CGI-script, etc. The URL of the
695
+ // results-handler defaults to "/postResults", but an alternative location
696
+ // can be specified by providing a "resultsUrl" query parameter.
697
+ //
698
+ // Parameters passed to the results-handler are:
699
+ // result: passed/failed depending on whether the suite passed or failed
700
+ // totalTime: the total running time in seconds for the suite.
701
+ //
702
+ // numTestPasses: the total number of tests which passed.
703
+ // numTestFailures: the total number of tests which failed.
704
+ //
705
+ // numCommandPasses: the total number of commands which passed.
706
+ // numCommandFailures: the total number of commands which failed.
707
+ // numCommandErrors: the total number of commands which errored.
708
+ //
709
+ // suite: the suite table, including the hidden column of test results
710
+ // testTable.1 to testTable.N: the individual test tables
711
+ //
712
+ initialize: function (suiteFailed, suiteTable) {
713
+ this.controlPanel = htmlTestRunner.controlPanel;
714
+ this.metrics = htmlTestRunner.metrics;
715
+ this.suiteFailed = suiteFailed;
716
+ this.suiteTable = suiteTable;
717
+ },
718
+
719
+ post: function () {
720
+ if (!this.controlPanel.isAutomatedRun()) {
721
+ return;
722
+ }
723
+ var form = document.createElement("form");
724
+ document.body.appendChild(form);
725
+
726
+ form.id = "resultsForm";
727
+ form.method = "post";
728
+ form.target = "selenium_myiframe";
729
+
730
+ var resultsUrl = this.controlPanel.getResultsUrl();
731
+ if (!resultsUrl) {
732
+ resultsUrl = "./postResults";
733
+ }
734
+
735
+ var actionAndParameters = resultsUrl.split('?', 2);
736
+ form.action = actionAndParameters[0];
737
+ var resultsUrlQueryString = actionAndParameters[1];
738
+
739
+ form.createHiddenField = function(name, value) {
740
+ input = document.createElement("input");
741
+ input.type = "hidden";
742
+ input.name = name;
743
+ input.value = value;
744
+ this.appendChild(input);
745
+ };
746
+
747
+ if (resultsUrlQueryString) {
748
+ var clauses = resultsUrlQueryString.split('&');
749
+ for (var i = 0; i < clauses.length; i++) {
750
+ var keyValuePair = clauses[i].split('=', 2);
751
+ var key = unescape(keyValuePair[0]);
752
+ var value = unescape(keyValuePair[1]);
753
+ form.createHiddenField(key, value);
754
+ }
755
+ }
756
+
757
+ form.createHiddenField("selenium.version", Selenium.version);
758
+ form.createHiddenField("selenium.revision", Selenium.revision);
759
+
760
+ form.createHiddenField("result", this.suiteFailed ? "failed" : "passed");
761
+
762
+ form.createHiddenField("totalTime", Math.floor((this.metrics.currentTime - this.metrics.startTime) / 1000));
763
+ form.createHiddenField("numTestPasses", this.metrics.numTestPasses);
764
+ form.createHiddenField("numTestFailures", this.metrics.numTestFailures);
765
+ form.createHiddenField("numCommandPasses", this.metrics.numCommandPasses);
766
+ form.createHiddenField("numCommandFailures", this.metrics.numCommandFailures);
767
+ form.createHiddenField("numCommandErrors", this.metrics.numCommandErrors);
768
+
769
+ // Create an input for each test table. The inputs are named
770
+ // testTable.1, testTable.2, etc.
771
+ for (rowNum = 1; rowNum < this.suiteTable.rows.length; rowNum++) {
772
+ // If there is a second column, then add a new input
773
+ if (this.suiteTable.rows[rowNum].cells.length > 1) {
774
+ var resultCell = this.suiteTable.rows[rowNum].cells[1];
775
+ form.createHiddenField("testTable." + rowNum, resultCell.innerHTML);
776
+ // remove the resultCell, so it's not included in the suite HTML
777
+ resultCell.parentNode.removeChild(resultCell);
778
+ }
779
+ }
780
+
781
+ form.createHiddenField("numTestTotal", rowNum-1);
782
+
783
+ // Add HTML for the suite itself
784
+ form.createHiddenField("suite", this.suiteTable.parentNode.innerHTML);
785
+
786
+ var logMessages = [];
787
+ while (LOG.pendingMessages.length > 0) {
788
+ var msg = LOG.pendingMessages.shift();
789
+ logMessages.push(msg.type);
790
+ logMessages.push(": ");
791
+ logMessages.push(msg.msg);
792
+ logMessages.push('\n');
793
+ }
794
+ var logOutput = logMessages.join("");
795
+ form.createHiddenField("log", logOutput);
796
+
797
+ if (this.controlPanel.shouldSaveResultsToFile()) {
798
+ this._saveToFile(resultsUrl, form);
799
+ } else {
800
+ form.submit();
801
+ }
802
+ document.body.removeChild(form);
803
+ if (this.controlPanel.closeAfterTests()) {
804
+ window.top.close();
805
+ }
806
+ },
807
+
808
+ _saveToFile: function (fileName, form) {
809
+ // This only works when run as an IE HTA
810
+ var inputs = new Object();
811
+ for (var i = 0; i < form.elements.length; i++) {
812
+ inputs[form.elements[i].name] = form.elements[i].value;
813
+ }
814
+
815
+ var objFSO = new ActiveXObject("Scripting.FileSystemObject")
816
+
817
+ // DGF get CSS
818
+ var styles = "";
819
+ try {
820
+ var styleSheetPath = window.location.pathname.replace(/[^\/\\]+$/, "selenium-test.css");
821
+ if (window.location.protocol == "file:") {
822
+ var stylesFile = objFSO.OpenTextFile(styleSheetPath, 1);
823
+ styles = stylesFile.ReadAll();
824
+ } else {
825
+ var xhr = XmlHttp.create();
826
+ xhr.open("GET", styleSheetPath, false);
827
+ xhr.send("");
828
+ styles = xhr.responseText;
829
+ }
830
+ } catch (e) {}
831
+
832
+ var scriptFile = objFSO.CreateTextFile(fileName);
833
+
834
+
835
+ scriptFile.WriteLine("<html><head><title>Test suite results</title><style>");
836
+ scriptFile.WriteLine(styles);
837
+ scriptFile.WriteLine("</style>");
838
+ scriptFile.WriteLine("<body>\n<h1>Test suite results</h1>" +
839
+ "\n\n<table>\n<tr>\n<td>result:</td>\n<td>" + inputs["result"] + "</td>\n" +
840
+ "</tr>\n<tr>\n<td>totalTime:</td>\n<td>" + inputs["totalTime"] + "</td>\n</tr>\n" +
841
+ "<tr>\n<td>numTestTotal:</td>\n<td>" + inputs["numTestTotal"] + "</td>\n</tr>\n" +
842
+ "<tr>\n<td>numTestPasses:</td>\n<td>" + inputs["numTestPasses"] + "</td>\n</tr>\n" +
843
+ "<tr>\n<td>numTestFailures:</td>\n<td>" + inputs["numTestFailures"] + "</td>\n</tr>\n" +
844
+ "<tr>\n<td>numCommandPasses:</td>\n<td>" + inputs["numCommandPasses"] + "</td>\n</tr>\n" +
845
+ "<tr>\n<td>numCommandFailures:</td>\n<td>" + inputs["numCommandFailures"] + "</td>\n</tr>\n" +
846
+ "<tr>\n<td>numCommandErrors:</td>\n<td>" + inputs["numCommandErrors"] + "</td>\n</tr>\n" +
847
+ "<tr>\n<td>" + inputs["suite"] + "</td>\n<td>&nbsp;</td>\n</tr></table><table>");
848
+ var testNum = inputs["numTestTotal"];
849
+
850
+ for (var rowNum = 1; rowNum <= testNum; rowNum++) {
851
+ scriptFile.WriteLine("<tr>\n<td>" + inputs["testTable." + rowNum] + "</td>\n<td>&nbsp;</td>\n</tr>");
852
+ }
853
+ scriptFile.WriteLine("</table><pre>");
854
+ var log = inputs["log"];
855
+ log=log.replace(/&/gm,"&amp;").replace(/</gm,"&lt;").replace(/>/gm,"&gt;").replace(/"/gm,"&quot;").replace(/'/gm,"&apos;");
856
+ scriptFile.WriteLine(log);
857
+ scriptFile.WriteLine("</pre></body></html>");
858
+ scriptFile.Close();
859
+ }
860
+ });
861
+
862
+ /** HtmlTestCase encapsulates an HTML test document */
863
+ var HtmlTestCase = classCreate();
864
+ objectExtend(HtmlTestCase.prototype, {
865
+
866
+ initialize: function(testDocument, htmlTestSuiteRow) {
867
+ if (testDocument == null) {
868
+ throw "testDocument should not be null";
869
+ }
870
+ if (htmlTestSuiteRow == null) {
871
+ throw "htmlTestSuiteRow should not be null";
872
+ }
873
+ this.testDocument = testDocument;
874
+ this.htmlTestSuiteRow = htmlTestSuiteRow;
875
+ this.headerRow = new TitleRow(this.testDocument.getElementsByTagName("tr")[0]);
876
+ this.commandRows = this._collectCommandRows();
877
+ this.nextCommandRowIndex = 0;
878
+ this._addBreakpointSupport();
879
+ },
880
+
881
+ _collectCommandRows: function () {
882
+ var commandRows = [];
883
+ var tables = sel$A(this.testDocument.getElementsByTagName("table"));
884
+ var self = this;
885
+ for (var i = 0; i < tables.length; i++) {
886
+ var table = tables[i];
887
+ var tableRows = sel$A(table.rows);
888
+ for (var j = 0; j < tableRows.length; j++) {
889
+ var candidateRow = tableRows[j];
890
+ if (self.isCommandRow(candidateRow)) {
891
+ commandRows.push(new HtmlTestCaseRow(candidateRow));
892
+ }
893
+ }
894
+ }
895
+ return commandRows;
896
+ },
897
+
898
+ isCommandRow: function (row) {
899
+ return row.cells.length >= 3;
900
+ },
901
+
902
+ reset: function() {
903
+ /**
904
+ * reset the test to runnable state
905
+ */
906
+ this.nextCommandRowIndex = 0;
907
+
908
+ this.setStatus('');
909
+ for (var i = 0; i < this.commandRows.length; i++) {
910
+ var row = this.commandRows[i];
911
+ row.reset();
912
+ }
913
+
914
+ // remove any additional fake "error" row added to the end of the document
915
+ var errorElement = this.testDocument.getElementById('error');
916
+ if (errorElement) {
917
+ errorElement.parentNode.removeChild(errorElement);
918
+ }
919
+ },
920
+
921
+ getCommandRows: function () {
922
+ return this.commandRows;
923
+ },
924
+
925
+ setStatus: function(status) {
926
+ this.headerRow.setStatus(status);
927
+ },
928
+
929
+ markFailed: function() {
930
+ this.setStatus("failed");
931
+ this.htmlTestSuiteRow.markFailed();
932
+ },
933
+
934
+ markPassed: function() {
935
+ this.setStatus("passed");
936
+ this.htmlTestSuiteRow.markPassed();
937
+ },
938
+
939
+ addErrorMessage: function(errorMsg, currentRow) {
940
+ errorMsg = errorMsg.replace(/ /g, String.fromCharCode(160)).replace("\n", '\\n');
941
+ if (currentRow) {
942
+ currentRow.markFailed(errorMsg);
943
+ } else {
944
+ var errorElement = this.testDocument.createElement("p");
945
+ errorElement.id = "error";
946
+ setText(errorElement, errorMsg);
947
+ this.testDocument.body.appendChild(errorElement);
948
+ errorElement.className = "status_failed";
949
+ }
950
+ },
951
+
952
+ _addBreakpointSupport: function() {
953
+ for (var i = 0; i < this.commandRows.length; i++) {
954
+ var row = this.commandRows[i];
955
+ row.addBreakpointSupport();
956
+ }
957
+ },
958
+
959
+ hasMoreCommandRows: function() {
960
+ return this.nextCommandRowIndex < this.commandRows.length;
961
+ },
962
+
963
+ getNextCommandRow: function() {
964
+ if (this.hasMoreCommandRows()) {
965
+ return this.commandRows[this.nextCommandRowIndex++];
966
+ }
967
+ return null;
968
+ }
969
+
970
+ });
971
+
972
+
973
+ // TODO: split out an JavascriptTestCase class to handle the "sejs" stuff
974
+
975
+ var get_new_rows = function() {
976
+ var row_array = new Array();
977
+ for (var i = 0; i < new_block.length; i++) {
978
+
979
+ var new_source = (new_block[i][0].tokenizer.source.slice(new_block[i][0].start,
980
+ new_block[i][0].end));
981
+
982
+ var row = '<td style="display:none;" class="js">getEval</td>' +
983
+ '<td style="display:none;">currentTest.doNextCommand()</td>' +
984
+ '<td style="white-space: pre;">' + new_source + '</td>' +
985
+ '<td></td>'
986
+
987
+ row_array.push(row);
988
+ }
989
+ return row_array;
990
+ };
991
+
992
+
993
+ var Metrics = classCreate();
994
+ objectExtend(Metrics.prototype, {
995
+ initialize: function() {
996
+ // The number of tests run
997
+ this.numTestPasses = 0;
998
+ // The number of tests that have failed
999
+ this.numTestFailures = 0;
1000
+ // The number of commands which have passed
1001
+ this.numCommandPasses = 0;
1002
+ // The number of commands which have failed
1003
+ this.numCommandFailures = 0;
1004
+ // The number of commands which have caused errors (element not found)
1005
+ this.numCommandErrors = 0;
1006
+ // The time that the test was started.
1007
+ this.startTime = null;
1008
+ // The current time.
1009
+ this.currentTime = null;
1010
+ },
1011
+
1012
+ printMetrics: function() {
1013
+ setText(sel$('commandPasses'), this.numCommandPasses);
1014
+ setText(sel$('commandFailures'), this.numCommandFailures);
1015
+ setText(sel$('commandErrors'), this.numCommandErrors);
1016
+ setText(sel$('testRuns'), this.numTestPasses + this.numTestFailures);
1017
+ setText(sel$('testFailures'), this.numTestFailures);
1018
+
1019
+ this.currentTime = new Date().getTime();
1020
+
1021
+ var timeDiff = this.currentTime - this.startTime;
1022
+ var totalSecs = Math.floor(timeDiff / 1000);
1023
+
1024
+ var minutes = Math.floor(totalSecs / 60);
1025
+ var seconds = totalSecs % 60;
1026
+
1027
+ setText(sel$('elapsedTime'), this._pad(minutes) + ":" + this._pad(seconds));
1028
+ },
1029
+
1030
+ // Puts a leading 0 on num if it is less than 10
1031
+ _pad: function(num) {
1032
+ return (num > 9) ? num : "0" + num;
1033
+ },
1034
+
1035
+ resetMetrics: function() {
1036
+ this.numTestPasses = 0;
1037
+ this.numTestFailures = 0;
1038
+ this.numCommandPasses = 0;
1039
+ this.numCommandFailures = 0;
1040
+ this.numCommandErrors = 0;
1041
+ this.startTime = new Date().getTime();
1042
+ }
1043
+
1044
+ });
1045
+
1046
+ var HtmlRunnerCommandFactory = classCreate();
1047
+ objectExtend(HtmlRunnerCommandFactory.prototype, {
1048
+
1049
+ initialize: function(seleniumCommandFactory, testLoop) {
1050
+ this.seleniumCommandFactory = seleniumCommandFactory;
1051
+ this.testLoop = testLoop;
1052
+ this.handlers = {};
1053
+ //todo: register commands
1054
+ },
1055
+
1056
+ getCommandHandler: function(command) {
1057
+ if (this.handlers[command]) {
1058
+ return this.handlers[command];
1059
+ }
1060
+ return this.seleniumCommandFactory.getCommandHandler(command);
1061
+ }
1062
+
1063
+ });
1064
+
1065
+ var HtmlRunnerTestLoop = classCreate();
1066
+ objectExtend(HtmlRunnerTestLoop.prototype, new TestLoop());
1067
+ objectExtend(HtmlRunnerTestLoop.prototype, {
1068
+ initialize: function(htmlTestCase, metrics, seleniumCommandFactory) {
1069
+
1070
+ this.commandFactory = new HtmlRunnerCommandFactory(seleniumCommandFactory, this);
1071
+ this.metrics = metrics;
1072
+
1073
+ this.htmlTestCase = htmlTestCase;
1074
+ LOG.info("Starting test " + htmlTestCase.testDocument.location.pathname);
1075
+
1076
+ se = selenium;
1077
+ global.se = selenium;
1078
+
1079
+ this.currentRow = null;
1080
+ this.currentRowIndex = 0;
1081
+
1082
+ // used for selenium tests in javascript
1083
+ this.currentItem = null;
1084
+ this.commandAgenda = new Array();
1085
+ this.expectedFailure = null;
1086
+ this.expectedFailureType = null;
1087
+
1088
+ this.htmlTestCase.reset();
1089
+
1090
+ this.sejsElement = this.htmlTestCase.testDocument.getElementById('sejs');
1091
+ if (this.sejsElement) {
1092
+ var fname = 'Selenium JavaScript';
1093
+ parse_result = parse(this.sejsElement.innerHTML, fname, 0);
1094
+
1095
+ var x2 = new ExecutionContext(GLOBAL_CODE);
1096
+ ExecutionContext.current = x2;
1097
+
1098
+ execute(parse_result, x2)
1099
+ }
1100
+ },
1101
+
1102
+ _advanceToNextRow: function() {
1103
+ if (this.htmlTestCase.hasMoreCommandRows()) {
1104
+ this.currentRow = this.htmlTestCase.getNextCommandRow();
1105
+ if (this.sejsElement) {
1106
+ this.currentItem = agenda.pop();
1107
+ this.currentRowIndex++;
1108
+ }
1109
+ } else {
1110
+ this.currentRow = null;
1111
+ this.currentItem = null;
1112
+ }
1113
+ },
1114
+
1115
+ nextCommand : function() {
1116
+ this._advanceToNextRow();
1117
+ if (this.currentRow == null) {
1118
+ return null;
1119
+ }
1120
+ return this.currentRow.getCommand();
1121
+ },
1122
+
1123
+ commandStarted : function() {
1124
+ sel$('pauseTest').disabled = false;
1125
+ this.currentRow.select();
1126
+ this.metrics.printMetrics();
1127
+ },
1128
+
1129
+ commandComplete : function(result) {
1130
+ this._checkExpectedFailure(result);
1131
+ if (result.failed) {
1132
+ this.metrics.numCommandFailures += 1;
1133
+ this._recordFailure(result.failureMessage);
1134
+ } else if (result.passed) {
1135
+ this.metrics.numCommandPasses += 1;
1136
+ this.currentRow.markPassed();
1137
+ } else {
1138
+ this.currentRow.markDone();
1139
+ }
1140
+ },
1141
+
1142
+ _checkExpectedFailure : function(result) {
1143
+ if (this.expectedFailure != null) {
1144
+ if (this.expectedFailureJustSet) {
1145
+ this.expectedFailureJustSet = false;
1146
+ return;
1147
+ }
1148
+ if (!result.failed) {
1149
+ result.passed = false;
1150
+ result.failed = true;
1151
+ result.failureMessage = "Expected " + this.expectedFailureType + " did not occur.";
1152
+ } else {
1153
+ if (PatternMatcher.matches(this.expectedFailure, result.failureMessage)) {
1154
+ var failureType = result.error ? "error" : "failure";
1155
+ if (failureType == this.expectedFailureType) {
1156
+ result.failed = false;
1157
+ result.passed = true;
1158
+ } else {
1159
+ result.failed = true;
1160
+ result.failureMessage = "Expected "+this.expectedFailureType+", but "+failureType+" occurred instead";
1161
+ }
1162
+ } else {
1163
+ result.failed = true;
1164
+ result.failureMessage = "Expected " + this.expectedFailureType + " message '" + this.expectedFailure
1165
+ + "' but was '" + result.failureMessage + "'";
1166
+ }
1167
+ }
1168
+ this.expectedFailure = null;
1169
+ this.expectedFailureType = null;
1170
+ }
1171
+ },
1172
+
1173
+ commandError : function(errorMessage) {
1174
+ var tempResult = {};
1175
+ tempResult.passed = false;
1176
+ tempResult.failed = true;
1177
+ tempResult.error = true;
1178
+ tempResult.failureMessage = errorMessage;
1179
+ this._checkExpectedFailure(tempResult);
1180
+ if (tempResult.passed) {
1181
+ this.currentRow.markDone();
1182
+ return true;
1183
+ }
1184
+ errorMessage = tempResult.failureMessage;
1185
+ this.metrics.numCommandErrors += 1;
1186
+ this._recordFailure(errorMessage);
1187
+ },
1188
+
1189
+ _recordFailure : function(errorMsg) {
1190
+ LOG.warn("currentTest.recordFailure: " + errorMsg);
1191
+ htmlTestRunner.markFailed();
1192
+ this.htmlTestCase.addErrorMessage(errorMsg, this.currentRow);
1193
+ },
1194
+
1195
+ testComplete : function() {
1196
+ sel$('pauseTest').disabled = true;
1197
+ sel$('stepTest').disabled = true;
1198
+ if (htmlTestRunner.testFailed) {
1199
+ this.htmlTestCase.markFailed();
1200
+ this.metrics.numTestFailures += 1;
1201
+ } else {
1202
+ this.htmlTestCase.markPassed();
1203
+ this.metrics.numTestPasses += 1;
1204
+ }
1205
+
1206
+ this.metrics.printMetrics();
1207
+
1208
+ window.setTimeout(function() {
1209
+ htmlTestRunner.runNextTest();
1210
+ }, 1);
1211
+ },
1212
+
1213
+ getCommandInterval : function() {
1214
+ return htmlTestRunner.controlPanel.runInterval;
1215
+ },
1216
+
1217
+ pause : function() {
1218
+ htmlTestRunner.controlPanel.pauseCurrentTest();
1219
+ },
1220
+
1221
+ doNextCommand: function() {
1222
+ var _n = this.currentItem[0];
1223
+ var _x = this.currentItem[1];
1224
+
1225
+ new_block = new Array()
1226
+ execute(_n, _x);
1227
+ if (new_block.length > 0) {
1228
+ var the_table = this.htmlTestCase.testDocument.getElementById("se-js-table")
1229
+ var loc = this.currentRowIndex
1230
+ var new_rows = get_new_rows()
1231
+
1232
+ // make the new statements visible on screen...
1233
+ for (var i = 0; i < new_rows.length; i++) {
1234
+ the_table.insertRow(loc + 1);
1235
+ the_table.rows[loc + 1].innerHTML = new_rows[i];
1236
+ this.commandRows.unshift(the_table.rows[loc + 1])
1237
+ }
1238
+
1239
+ }
1240
+ }
1241
+
1242
+ });
1243
+
1244
+ Selenium.prototype.doPause = function(waitTime) {
1245
+ /** Wait for the specified amount of time (in milliseconds)
1246
+ * @param waitTime the amount of time to sleep (in milliseconds)
1247
+ */
1248
+ // todo: should not refer to currentTest directly
1249
+ currentTest.pauseInterval = waitTime;
1250
+ };
1251
+
1252
+ Selenium.prototype.doBreak = function() {
1253
+ /** Halt the currently running test, and wait for the user to press the Continue button.
1254
+ * This command is useful for debugging, but be careful when using it, because it will
1255
+ * force automated tests to hang until a user intervenes manually.
1256
+ */
1257
+ // todo: should not refer to controlPanel directly
1258
+ htmlTestRunner.controlPanel.setToPauseAtNextCommand();
1259
+ };
1260
+
1261
+ Selenium.prototype.doStore = function(expression, variableName) {
1262
+ /** This command is a synonym for storeExpression.
1263
+ * @param expression the value to store
1264
+ * @param variableName the name of a <a href="#storedVars">variable</a> in which the result is to be stored.
1265
+ */
1266
+ storedVars[variableName] = expression;
1267
+ }
1268
+
1269
+ /*
1270
+ * Click on the located element, and attach a callback to notify
1271
+ * when the page is reloaded.
1272
+ */
1273
+ // DGF TODO this code has been broken for some time... what is it trying to accomplish?
1274
+ Selenium.prototype.XXXdoModalDialogTest = function(returnValue) {
1275
+ this.browserbot.doModalDialogTest(returnValue);
1276
+ };
1277
+
1278
+ Selenium.prototype.doEcho = function(message) {
1279
+ /** Prints the specified message into the third table cell in your Selenese tables.
1280
+ * Useful for debugging.
1281
+ * @param message the message to print
1282
+ */
1283
+ currentTest.currentRow.setMessage(message);
1284
+ }
1285
+
1286
+ Selenium.prototype.assertSelected = function(selectLocator, optionLocator) {
1287
+ /**
1288
+ * Verifies that the selected option of a drop-down satisfies the optionSpecifier. <i>Note that this command is deprecated; you should use assertSelectedLabel, assertSelectedValue, assertSelectedIndex, or assertSelectedId instead.</i>
1289
+ *
1290
+ * <p>See the select command for more information about option locators.</p>
1291
+ *
1292
+ * @param selectLocator an <a href="#locators">element locator</a> identifying a drop-down menu
1293
+ * @param optionLocator an option locator, typically just an option label (e.g. "John Smith")
1294
+ */
1295
+ var element = this.page().findElement(selectLocator);
1296
+ var locator = this.optionLocatorFactory.fromLocatorString(optionLocator);
1297
+ if (element.selectedIndex == -1)
1298
+ {
1299
+ Assert.fail("No option selected");
1300
+ }
1301
+ locator.assertSelected(element);
1302
+ };
1303
+
1304
+ Selenium.prototype.assertFailureOnNext = function(message) {
1305
+ /**
1306
+ * Tell Selenium to expect a failure on the next command execution.
1307
+ * @param message The failure message we should expect. This command will fail if the wrong failure message appears.
1308
+ */
1309
+ if (!message) {
1310
+ throw new SeleniumError("Message must be provided");
1311
+ }
1312
+
1313
+ currentTest.expectedFailure = message;
1314
+ currentTest.expectedFailureType = "failure";
1315
+ currentTest.expectedFailureJustSet = true;
1316
+ };
1317
+
1318
+ Selenium.prototype.assertErrorOnNext = function(message) {
1319
+ /**
1320
+ * Tell Selenium to expect an error on the next command execution.
1321
+ * @param message The error message we should expect. This command will fail if the wrong error message appears.
1322
+ */
1323
+ // This command temporarily installs a CommandFactory that generates
1324
+ // CommandHandlers that expect an error.
1325
+ if (!message) {
1326
+ throw new SeleniumError("Message must be provided");
1327
+ }
1328
+
1329
+ currentTest.expectedFailure = message;
1330
+ currentTest.expectedFailureType = "error";
1331
+ currentTest.expectedFailureJustSet = true;
1332
+ };
1333
+