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,175 @@
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
+ function TestLoop(commandFactory) {
18
+ this.commandFactory = commandFactory;
19
+ }
20
+
21
+ TestLoop.prototype = {
22
+
23
+ start : function() {
24
+ selenium.reset();
25
+ LOG.debug("currentTest.start()");
26
+ this.continueTest();
27
+ },
28
+
29
+ continueTest : function() {
30
+ /**
31
+ * Select the next command and continue the test.
32
+ */
33
+ LOG.debug("currentTest.continueTest() - acquire the next command");
34
+ if (! this.aborted) {
35
+ this.currentCommand = this.nextCommand();
36
+ }
37
+ if (! this.requiresCallBack) {
38
+ this.continueTestAtCurrentCommand();
39
+ } // otherwise, just finish and let the callback invoke continueTestAtCurrentCommand()
40
+ },
41
+
42
+ continueTestAtCurrentCommand : function() {
43
+ LOG.debug("currentTest.continueTestAtCurrentCommand()");
44
+ if (this.currentCommand) {
45
+ // TODO: rename commandStarted to commandSelected, OR roll it into nextCommand
46
+ this.commandStarted(this.currentCommand);
47
+ this._resumeAfterDelay();
48
+ } else {
49
+ this._testComplete();
50
+ }
51
+ },
52
+
53
+ _resumeAfterDelay : function() {
54
+ /**
55
+ * Pause, then execute the current command.
56
+ */
57
+
58
+ // Get the command delay. If a pauseInterval is set, use it once
59
+ // and reset it. Otherwise, use the defined command-interval.
60
+ var delay = this.pauseInterval || this.getCommandInterval();
61
+ this.pauseInterval = undefined;
62
+
63
+ if (this.currentCommand.isBreakpoint || delay < 0) {
64
+ // Pause: enable the "next/continue" button
65
+ this.pause();
66
+ } else {
67
+ window.setTimeout(fnBind(this.resume, this), delay);
68
+ }
69
+ },
70
+
71
+ resume: function() {
72
+ /**
73
+ * Select the next command and continue the test.
74
+ */
75
+ LOG.debug("currentTest.resume() - actually execute");
76
+ try {
77
+ selenium.browserbot.runScheduledPollers();
78
+ this._executeCurrentCommand();
79
+ this.continueTestWhenConditionIsTrue();
80
+ } catch (e) {
81
+ if (!this._handleCommandError(e)) {
82
+ this.testComplete();
83
+ } else {
84
+ this.continueTest();
85
+ }
86
+ }
87
+ },
88
+
89
+ _testComplete : function() {
90
+ selenium.ensureNoUnhandledPopups();
91
+ this.testComplete();
92
+ },
93
+
94
+ _executeCurrentCommand : function() {
95
+ /**
96
+ * Execute the current command.
97
+ *
98
+ * @return a function which will be used to determine when
99
+ * execution can continue, or null if we can continue immediately
100
+ */
101
+ var command = this.currentCommand;
102
+ LOG.info("Executing: |" + command.command + " | " + command.target + " | " + command.value + " |");
103
+
104
+ var handler = this.commandFactory.getCommandHandler(command.command);
105
+ if (handler == null) {
106
+ throw new SeleniumError("Unknown command: '" + command.command + "'");
107
+ }
108
+
109
+ command.target = selenium.preprocessParameter(command.target);
110
+ command.value = selenium.preprocessParameter(command.value);
111
+ LOG.debug("Command found, going to execute " + command.command);
112
+ this.result = handler.execute(selenium, command);
113
+
114
+
115
+ this.waitForCondition = this.result.terminationCondition;
116
+
117
+ },
118
+
119
+ _handleCommandError : function(e) {
120
+ if (!e.isSeleniumError) {
121
+ LOG.exception(e);
122
+ var msg = "Selenium failure. Please report to the Selenium Users forum at http://forums.openqa.org, with error details from the log window.";
123
+ msg += " The error message is: " + extractExceptionMessage(e);
124
+ return this.commandError(msg);
125
+ } else {
126
+ LOG.error(e.message);
127
+ return this.commandError(e.message);
128
+ }
129
+ },
130
+
131
+ continueTestWhenConditionIsTrue: function () {
132
+ /**
133
+ * Busy wait for waitForCondition() to become true, and then carry
134
+ * on with test. Fail the current test if there's a timeout or an
135
+ * exception.
136
+ */
137
+ //LOG.debug("currentTest.continueTestWhenConditionIsTrue()");
138
+ selenium.browserbot.runScheduledPollers();
139
+ try {
140
+ if (this.waitForCondition == null) {
141
+ LOG.debug("null condition; let's continueTest()");
142
+ LOG.debug("Command complete");
143
+ this.commandComplete(this.result);
144
+ this.continueTest();
145
+ } else if (this.waitForCondition()) {
146
+ LOG.debug("condition satisfied; let's continueTest()");
147
+ this.waitForCondition = null;
148
+ LOG.debug("Command complete");
149
+ this.commandComplete(this.result);
150
+ this.continueTest();
151
+ } else {
152
+ //LOG.debug("waitForCondition was false; keep waiting!");
153
+ window.setTimeout(fnBind(this.continueTestWhenConditionIsTrue, this), 10);
154
+ }
155
+ } catch (e) {
156
+ this.result = {};
157
+ this.result.failed = true;
158
+ this.result.failureMessage = extractExceptionMessage(e);
159
+ this.commandComplete(this.result);
160
+ this.continueTest();
161
+ }
162
+ },
163
+
164
+ pause : function() {},
165
+ nextCommand : function() {},
166
+ commandStarted : function() {},
167
+ commandComplete : function() {},
168
+ commandError : function() {},
169
+ testComplete : function() {},
170
+
171
+ getCommandInterval : function() {
172
+ return 0;
173
+ }
174
+
175
+ }
@@ -0,0 +1,147 @@
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
+ var Logger = function() {
18
+ this.logWindow = null;
19
+ }
20
+ Logger.prototype = {
21
+
22
+ logLevels: {
23
+ debug: 0,
24
+ info: 1,
25
+ warn: 2,
26
+ error: 3,
27
+ off: 999
28
+ },
29
+
30
+ pendingMessages: new Array(),
31
+
32
+ threshold: "info",
33
+
34
+ setLogLevelThreshold: function(logLevel) {
35
+ this.threshold = logLevel;
36
+ var logWindow = this.getLogWindow()
37
+ if (logWindow && logWindow.setThresholdLevel) {
38
+ logWindow.setThresholdLevel(logLevel);
39
+ }
40
+ // NOTE: log messages will be discarded until the log window is
41
+ // fully loaded.
42
+ },
43
+
44
+ getLogWindow: function() {
45
+ if (this.logWindow && this.logWindow.closed) {
46
+ this.logWindow = null;
47
+ }
48
+ return this.logWindow;
49
+ },
50
+
51
+ openLogWindow: function() {
52
+ this.logWindow = window.open(
53
+ getDocumentBase(document) + "SeleniumLog.html?startingThreshold="+this.threshold, "SeleniumLog",
54
+ "width=600,height=1000,bottom=0,right=0,status,scrollbars,resizable"
55
+ );
56
+ this.logWindow.moveTo(window.screenX + 1210, window.screenY + window.outerHeight - 1400);
57
+ if (browserVersion.appearsToBeBrokenInitialIE6) {
58
+ // I would really prefer for the message to immediately appear in the log window, the instant the user requests that the log window be
59
+ // visible. But when I initially coded it this way, thou message simply didn't appear unless I stepped through the code with a debugger.
60
+ // So obviously there is some timing issue here which I don't have the patience to figure out.
61
+ var pendingMessage = new LogMessage("warn", "You appear to be running an unpatched IE 6, which is not stable and can crash due to memory problems. We recommend you run Windows update to install a more stable version of IE.");
62
+ this.pendingMessages.push(pendingMessage);
63
+ }
64
+ return this.logWindow;
65
+ },
66
+
67
+ show: function() {
68
+ if (! this.getLogWindow()) {
69
+ this.openLogWindow();
70
+ }
71
+ setTimeout(function(){LOG.error("Log window displayed. Logging events will now be recorded to this window.");}, 500);
72
+ },
73
+
74
+ logHook: function(logLevel, message) {
75
+ },
76
+
77
+ log: function(logLevel, message) {
78
+ if (this.logLevels[logLevel] < this.logLevels[this.threshold]) {
79
+ return;
80
+ }
81
+ this.logHook(logLevel, message);
82
+ var logWindow = this.getLogWindow();
83
+ if (logWindow) {
84
+ if (logWindow.append) {
85
+ if (logWindow.disabled) {
86
+ logWindow.callBack = fnBind(this.setLogLevelThreshold, this);
87
+ logWindow.enableButtons();
88
+ }
89
+ if (this.pendingMessages.length > 0) {
90
+ logWindow.append("info: Appending missed logging messages", "info");
91
+ while (this.pendingMessages.length > 0) {
92
+ var msg = this.pendingMessages.shift();
93
+ logWindow.append(msg.type + ": " + msg.msg, msg.type);
94
+ }
95
+ logWindow.append("info: Done appending missed logging messages", "info");
96
+ }
97
+ logWindow.append(logLevel + ": " + message, logLevel);
98
+ }
99
+ } else {
100
+ // TODO these logging messages are never flushed, which creates
101
+ // an enormous array of strings that never stops growing.
102
+ // there should at least be a way to clear the messages!
103
+ this.pendingMessages.push(new LogMessage(logLevel, message));
104
+ }
105
+ },
106
+
107
+ close: function(message) {
108
+ if (this.logWindow != null) {
109
+ try {
110
+ this.logWindow.close();
111
+ } catch (e) {
112
+ // swallow exception
113
+ // the window is probably closed if we get an exception here
114
+ }
115
+ this.logWindow = null;
116
+ }
117
+ },
118
+
119
+ debug: function(message) {
120
+ this.log("debug", message);
121
+ },
122
+
123
+ info: function(message) {
124
+ this.log("info", message);
125
+ },
126
+
127
+ warn: function(message) {
128
+ this.log("warn", message);
129
+ },
130
+
131
+ error: function(message) {
132
+ this.log("error", message);
133
+ },
134
+
135
+ exception: function(exception) {
136
+ this.error("Unexpected Exception: " + extractExceptionMessage(exception));
137
+ this.error("Exception details: " + describe(exception, ', '));
138
+ }
139
+
140
+ };
141
+
142
+ var LOG = new Logger();
143
+
144
+ var LogMessage = function(type, msg) {
145
+ this.type = type;
146
+ this.msg = msg;
147
+ }
@@ -0,0 +1,571 @@
1
+ /*
2
+ * Copyright 2005 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
+ passColor = "#cfffcf";
19
+ failColor = "#ffcfcf";
20
+ errorColor = "#ffffff";
21
+ workingColor = "#DEE7EC";
22
+ doneColor = "#FFFFCC";
23
+
24
+ var injectedSessionId;
25
+ var cmd1 = document.createElement("div");
26
+ var cmd2 = document.createElement("div");
27
+ var cmd3 = document.createElement("div");
28
+ var cmd4 = document.createElement("div");
29
+
30
+ var postResult = "START";
31
+ var debugMode = false;
32
+ var relayToRC = null;
33
+ var proxyInjectionMode = false;
34
+ var uniqueId = 'sel_' + Math.round(100000 * Math.random());
35
+ var seleniumSequenceNumber = 0;
36
+
37
+ var RemoteRunnerOptions = classCreate();
38
+ objectExtend(RemoteRunnerOptions.prototype, URLConfiguration.prototype);
39
+ objectExtend(RemoteRunnerOptions.prototype, {
40
+ initialize: function() {
41
+ this._acquireQueryString();
42
+ },
43
+ isDebugMode: function() {
44
+ return this._isQueryParameterTrue("debugMode");
45
+ },
46
+
47
+ getContinue: function() {
48
+ return this._getQueryParameter("continue");
49
+ },
50
+
51
+ getDriverUrl: function() {
52
+ return this._getQueryParameter("driverUrl");
53
+ },
54
+
55
+ getSessionId: function() {
56
+ return this._getQueryParameter("sessionId");
57
+ },
58
+
59
+ _acquireQueryString: function () {
60
+ if (this.queryString) return;
61
+ if (browserVersion.isHTA) {
62
+ var args = this._extractArgs();
63
+ if (args.length < 2) return null;
64
+ this.queryString = args[1];
65
+ } else if (proxyInjectionMode) {
66
+ this.queryString = window.location.search.substr(1);
67
+ } else {
68
+ this.queryString = top.location.search.substr(1);
69
+ }
70
+ }
71
+
72
+ });
73
+ var runOptions;
74
+
75
+ function runSeleniumTest() {
76
+ runOptions = new RemoteRunnerOptions();
77
+ var testAppWindow;
78
+
79
+ if (runOptions.isMultiWindowMode()) {
80
+ testAppWindow = openSeparateApplicationWindow('Blank.html', true);
81
+ } else if (sel$('selenium_myiframe') != null) {
82
+ var myiframe = sel$('selenium_myiframe');
83
+ if (myiframe) {
84
+ testAppWindow = myiframe.contentWindow;
85
+ }
86
+ }
87
+ else {
88
+ proxyInjectionMode = true;
89
+ testAppWindow = window;
90
+ }
91
+ selenium = Selenium.createForWindow(testAppWindow, proxyInjectionMode);
92
+ if (runOptions.getBaseUrl()) {
93
+ selenium.browserbot.baseUrl = runOptions.getBaseUrl();
94
+ }
95
+ if (!debugMode) {
96
+ debugMode = runOptions.isDebugMode();
97
+ }
98
+ if (proxyInjectionMode) {
99
+ LOG.logHook = logToRc;
100
+ selenium.browserbot._modifyWindow(testAppWindow);
101
+ }
102
+ else if (debugMode) {
103
+ LOG.logHook = logToRc;
104
+ }
105
+ window.selenium = selenium;
106
+
107
+ commandFactory = new CommandHandlerFactory();
108
+ commandFactory.registerAll(selenium);
109
+
110
+ currentTest = new RemoteRunner(commandFactory);
111
+
112
+ if (document.getElementById("commandList") != null) {
113
+ document.getElementById("commandList").appendChild(cmd4);
114
+ document.getElementById("commandList").appendChild(cmd3);
115
+ document.getElementById("commandList").appendChild(cmd2);
116
+ document.getElementById("commandList").appendChild(cmd1);
117
+ }
118
+
119
+ var doContinue = runOptions.getContinue();
120
+ if (doContinue != null) postResult = "OK";
121
+
122
+ currentTest.start();
123
+ }
124
+
125
+ function buildDriverUrl() {
126
+ var driverUrl = runOptions.getDriverUrl();
127
+ if (driverUrl != null) {
128
+ return driverUrl;
129
+ }
130
+ var s = window.location.href
131
+ var slashPairOffset = s.indexOf("//") + "//".length
132
+ var pathSlashOffset = s.substring(slashPairOffset).indexOf("/")
133
+ return s.substring(0, slashPairOffset + pathSlashOffset) + "/selenium-server/driver/";
134
+ //return "http://localhost" + uniqueId + "/selenium-server/driver/";
135
+ }
136
+
137
+ function logToRc(logLevel, message) {
138
+ if (debugMode) {
139
+ if (logLevel == null) {
140
+ logLevel = "debug";
141
+ }
142
+ sendToRCAndForget("logLevel=" + logLevel + ":" + message.replace(/[\n\r\015]/g, " ") + "\n", "logging=true");
143
+ }
144
+ }
145
+
146
+ function serializeString(name, s) {
147
+ return name + "=unescape(\"" + escape(s) + "\");";
148
+ }
149
+
150
+ function serializeObject(name, x)
151
+ {
152
+ var s = '';
153
+
154
+ if (isArray(x))
155
+ {
156
+ s = name + "=new Array(); ";
157
+ var len = x["length"];
158
+ for (var j = 0; j < len; j++)
159
+ {
160
+ s += serializeString(name + "[" + j + "]", x[j]);
161
+ }
162
+ }
163
+ else if (typeof x == "string")
164
+ {
165
+ s = serializeString(name, x);
166
+ }
167
+ else
168
+ {
169
+ throw "unrecognized object not encoded: " + name + "(" + x + ")";
170
+ }
171
+ return s;
172
+ }
173
+
174
+ function relayBotToRC(s) {
175
+ }
176
+
177
+ // seems like no one uses this, but in fact it is called using eval from server-side PI mode code; however,
178
+ // because multiple names can map to the same popup, assigning a single name confuses matters sometimes;
179
+ // thus, I'm disabling this for now. -Nelson 10/21/06
180
+ function setSeleniumWindowName(seleniumWindowName) {
181
+ //selenium.browserbot.getCurrentWindow()['seleniumWindowName'] = seleniumWindowName;
182
+ }
183
+
184
+ RemoteRunner = classCreate();
185
+ objectExtend(RemoteRunner.prototype, new TestLoop());
186
+ objectExtend(RemoteRunner.prototype, {
187
+ initialize : function(commandFactory) {
188
+ this.commandFactory = commandFactory;
189
+ this.requiresCallBack = true;
190
+ this.commandNode = null;
191
+ this.xmlHttpForCommandsAndResults = null;
192
+ },
193
+
194
+ nextCommand : function() {
195
+ var urlParms = "";
196
+ if (postResult == "START") {
197
+ urlParms += "seleniumStart=true";
198
+ }
199
+ this.xmlHttpForCommandsAndResults = XmlHttp.create();
200
+ sendToRC(postResult, urlParms, fnBind(this._HandleHttpResponse, this), this.xmlHttpForCommandsAndResults);
201
+ },
202
+
203
+ commandStarted : function(command) {
204
+ this.commandNode = document.createElement("div");
205
+ var cmdText = command.command + '(';
206
+ if (command.target != null && command.target != "") {
207
+ cmdText += command.target;
208
+ if (command.value != null && command.value != "") {
209
+ cmdText += ', ' + command.value;
210
+ }
211
+ }
212
+ cmdText += ")";
213
+ if (cmdText.length >40) {
214
+ cmdText = cmdText.substring(0,40);
215
+ cmdText += "...";
216
+ }
217
+ this.commandNode.appendChild(document.createTextNode(cmdText));
218
+ this.commandNode.style.backgroundColor = workingColor;
219
+ if (document.getElementById("commandList") != null) {
220
+ document.getElementById("commandList").removeChild(cmd1);
221
+ document.getElementById("commandList").removeChild(cmd2);
222
+ document.getElementById("commandList").removeChild(cmd3);
223
+ document.getElementById("commandList").removeChild(cmd4);
224
+ cmd4 = cmd3;
225
+ cmd3 = cmd2;
226
+ cmd2 = cmd1;
227
+ cmd1 = this.commandNode;
228
+ document.getElementById("commandList").appendChild(cmd4);
229
+ document.getElementById("commandList").appendChild(cmd3);
230
+ document.getElementById("commandList").appendChild(cmd2);
231
+ document.getElementById("commandList").appendChild(cmd1);
232
+ }
233
+ },
234
+
235
+ commandComplete : function(result) {
236
+
237
+ if (result.failed) {
238
+ if (postResult == "CONTINUATION") {
239
+ currentTest.aborted = true;
240
+ }
241
+ postResult = result.failureMessage;
242
+ this.commandNode.title = result.failureMessage;
243
+ this.commandNode.style.backgroundColor = failColor;
244
+ } else if (result.passed) {
245
+ postResult = "OK";
246
+ this.commandNode.style.backgroundColor = passColor;
247
+ } else {
248
+ if (result.result == null) {
249
+ postResult = "OK";
250
+ } else {
251
+ var actualResult = result.result;
252
+ actualResult = selArrayToString(actualResult);
253
+ postResult = "OK," + actualResult;
254
+ }
255
+ this.commandNode.style.backgroundColor = doneColor;
256
+ }
257
+ },
258
+
259
+ commandError : function(message) {
260
+ postResult = "ERROR: " + message;
261
+ this.commandNode.style.backgroundColor = errorColor;
262
+ this.commandNode.title = message;
263
+ },
264
+
265
+ testComplete : function() {
266
+ window.status = "Selenium Tests Complete, for this Test"
267
+ // Continue checking for new results
268
+ this.continueTest();
269
+ postResult = "START";
270
+ },
271
+
272
+ _HandleHttpResponse : function() {
273
+ // When request is completed
274
+ if (this.xmlHttpForCommandsAndResults.readyState == 4) {
275
+ // OK
276
+ if (this.xmlHttpForCommandsAndResults.status == 200) {
277
+ if (this.xmlHttpForCommandsAndResults.responseText=="") {
278
+ LOG.error("saw blank string xmlHttpForCommandsAndResults.responseText");
279
+ return;
280
+ }
281
+ var command = this._extractCommand(this.xmlHttpForCommandsAndResults);
282
+ this.currentCommand = command;
283
+ this.continueTestAtCurrentCommand();
284
+ }
285
+ // Not OK
286
+ else {
287
+ var s = 'xmlHttp returned: ' + this.xmlHttpForCommandsAndResults.status + ": " + this.xmlHttpForCommandsAndResults.statusText;
288
+ LOG.error(s);
289
+ this.currentCommand = null;
290
+ setTimeout(fnBind(this.continueTestAtCurrentCommand, this), 2000);
291
+ }
292
+
293
+ }
294
+ },
295
+
296
+ _extractCommand : function(xmlHttp) {
297
+ var command;
298
+ try {
299
+ var re = new RegExp("^(.*?)\n((.|[\r\n])*)");
300
+ if (re.exec(xmlHttp.responseText)) {
301
+ command = RegExp.$1;
302
+ var rest = RegExp.$2;
303
+ rest = rest.trim();
304
+ if (rest) {
305
+ eval(rest);
306
+ }
307
+ }
308
+ else {
309
+ command = xmlHttp.responseText;
310
+ }
311
+ } catch (e) {
312
+ alert('could not get responseText: ' + e.message);
313
+ }
314
+ if (command.substr(0, '|testComplete'.length) == '|testComplete') {
315
+ return null;
316
+ }
317
+
318
+ return this._createCommandFromRequest(command);
319
+ },
320
+
321
+
322
+ _delay : function(millis) {
323
+ var startMillis = new Date();
324
+ while (true) {
325
+ milli = new Date();
326
+ if (milli - startMillis > millis) {
327
+ break;
328
+ }
329
+ }
330
+ },
331
+
332
+ // Parses a URI query string into a SeleniumCommand object
333
+ _createCommandFromRequest : function(commandRequest) {
334
+ //decodeURIComponent doesn't strip plus signs
335
+ var processed = commandRequest.replace(/\+/g, "%20");
336
+ // strip trailing spaces
337
+ var processed = processed.replace(/\s+$/, "");
338
+ var vars = processed.split("&");
339
+ var cmdArgs = new Object();
340
+ for (var i = 0; i < vars.length; i++) {
341
+ var pair = vars[i].split("=");
342
+ cmdArgs[pair[0]] = pair[1];
343
+ }
344
+ var cmd = cmdArgs['cmd'];
345
+ var arg1 = cmdArgs['1'];
346
+ if (null == arg1) arg1 = "";
347
+ arg1 = decodeURIComponent(arg1);
348
+ var arg2 = cmdArgs['2'];
349
+ if (null == arg2) arg2 = "";
350
+ arg2 = decodeURIComponent(arg2);
351
+ if (cmd == null) {
352
+ throw new Error("Bad command request: " + commandRequest);
353
+ }
354
+ return new SeleniumCommand(cmd, arg1, arg2);
355
+ }
356
+
357
+ })
358
+
359
+
360
+ function sendToRC(dataToBePosted, urlParms, callback, xmlHttpObject, async) {
361
+ if (async == null) {
362
+ async = true;
363
+ }
364
+ if (xmlHttpObject == null) {
365
+ xmlHttpObject = XmlHttp.create();
366
+ }
367
+ var url = buildDriverUrl() + "?"
368
+ if (urlParms) {
369
+ url += urlParms;
370
+ }
371
+ url = addUrlParams(url);
372
+ url += "&sequenceNumber=" + seleniumSequenceNumber++;
373
+
374
+ var wrappingCallback;
375
+ if (callback == null) {
376
+ callback = function() {};
377
+ wrappingCallback = callback;
378
+ } else {
379
+ wrappingCallback = function() {
380
+ if (xmlHttpObject.readyState == 4) {
381
+ if (xmlHttpObject.status == 200) {
382
+ var retry = false;
383
+ if (typeof currentTest != 'undefined') {
384
+ var command = currentTest._extractCommand(xmlHttpObject);
385
+ //console.log("*********** " + command.command + " | " + command.target + " | " + command.value);
386
+ if (command.command == 'retryLast') {
387
+ retry = true;
388
+ }
389
+ }
390
+ if (retry) {
391
+ setTimeout(fnBind(function() {
392
+ sendToRC("RETRY", "retry=true", callback, xmlHttpObject, async);
393
+ }, this), 1000);
394
+ } else {
395
+ callback();
396
+ }
397
+ }
398
+ }
399
+ }
400
+ }
401
+
402
+ var postedData = "postedData=" + encodeURIComponent(dataToBePosted);
403
+
404
+ //xmlHttpObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
405
+ xmlHttpObject.open("POST", url, async);
406
+ xmlHttpObject.onreadystatechange = wrappingCallback;
407
+ xmlHttpObject.send(postedData);
408
+ return null;
409
+ }
410
+
411
+ function addUrlParams(url) {
412
+ return url + "&localFrameAddress=" + (proxyInjectionMode ? makeAddressToAUTFrame() : "top")
413
+ + getSeleniumWindowNameURLparameters()
414
+ + "&uniqueId=" + uniqueId
415
+ + buildDriverParams() + preventBrowserCaching()
416
+ }
417
+
418
+ function sendToRCAndForget(dataToBePosted, urlParams) {
419
+ var url;
420
+ if (!(browserVersion.isChrome || browserVersion.isHTA)) {
421
+ // DGF we're behind a proxy, so we can send our logging message to literally any host, to avoid 2-connection limit
422
+ var protocol = "http:";
423
+ if (window.location.protocol == "https:") {
424
+ // DGF if we're in HTTPS, use another HTTPS url to avoid security warning
425
+ protocol = "https:";
426
+ }
427
+ // we don't choose a super large random value, but rather 1 - 16, because this matches with the pre-computed
428
+ // tunnels waiting on the Selenium Server side. This gives us higher throughput than the two-connection-per-host
429
+ // limitation, but doesn't require we generate an extremely large ammount of fake SSL certs either.
430
+ url = protocol + "//" + Math.floor(Math.random()* 16 + 1) + ".selenium.doesnotexist/selenium-server/driver/?" + urlParams;
431
+ } else {
432
+ url = buildDriverUrl() + "?" + urlParams;
433
+ }
434
+ url = addUrlParams(url);
435
+
436
+ var method = "GET";
437
+ if (method == "POST") {
438
+ // DGF submit a request using an iframe; we can't see the response, but we don't need to
439
+ // TODO not using this mechanism because it screws up back-button
440
+ var loggingForm = document.createElement("form");
441
+ loggingForm.method = "POST";
442
+ loggingForm.action = url;
443
+ loggingForm.target = "seleniumLoggingFrame";
444
+ var postedDataInput = document.createElement("input");
445
+ postedDataInput.type = "hidden";
446
+ postedDataInput.name = "postedData";
447
+ postedDataInput.value = dataToBePosted;
448
+ loggingForm.appendChild(postedDataInput);
449
+ document.body.appendChild(loggingForm);
450
+ loggingForm.submit();
451
+ document.body.removeChild(loggingForm);
452
+ } else {
453
+ var postedData = "&postedData=" + encodeURIComponent(dataToBePosted);
454
+ var scriptTag = document.createElement("script");
455
+ scriptTag.src = url + postedData;
456
+ document.body.appendChild(scriptTag);
457
+ document.body.removeChild(scriptTag);
458
+ }
459
+ }
460
+
461
+ function buildDriverParams() {
462
+ var params = "";
463
+
464
+ var sessionId = runOptions.getSessionId();
465
+ if (sessionId == undefined) {
466
+ sessionId = injectedSessionId;
467
+ }
468
+ if (sessionId != undefined) {
469
+ params = params + "&sessionId=" + sessionId;
470
+ }
471
+ return params;
472
+ }
473
+
474
+ function preventBrowserCaching() {
475
+ var t = (new Date()).getTime();
476
+ return "&counterToMakeURsUniqueAndSoStopPageCachingInTheBrowser=" + t;
477
+ }
478
+
479
+ //
480
+ // Return URL parameters pertaining to the name(s?) of the current window
481
+ //
482
+ // In selenium, the main (i.e., first) window's name is a blank string.
483
+ //
484
+ // Additional pop-ups are associated with either 1.) the name given by the 2nd parameter to window.open, or 2.) the name of a
485
+ // property on the opening window which points at the window.
486
+ //
487
+ // An example of #2: if window X contains JavaScript as follows:
488
+ //
489
+ // var windowABC = window.open(...)
490
+ //
491
+ // Note that the example JavaScript above is equivalent to
492
+ //
493
+ // window["windowABC"] = window.open(...)
494
+ //
495
+ function getSeleniumWindowNameURLparameters() {
496
+ var w = (proxyInjectionMode ? selenium.browserbot.getCurrentWindow() : window).top;
497
+ var s = "&seleniumWindowName=";
498
+ if (w.opener == null) {
499
+ return s;
500
+ }
501
+ if (w["seleniumWindowName"] == null) {
502
+ if (w.name) {
503
+ w["seleniumWindowName"] = w.name;
504
+ } else {
505
+ w["seleniumWindowName"] = 'generatedSeleniumWindowName_' + Math.round(100000 * Math.random());
506
+ }
507
+ }
508
+ s += w["seleniumWindowName"];
509
+ var windowOpener = w.opener;
510
+ for (key in windowOpener) {
511
+ var val = null;
512
+ try {
513
+ val = windowOpener[key];
514
+ }
515
+ catch(e) {
516
+ }
517
+ if (val==w) {
518
+ s += "&jsWindowNameVar=" + key; // found a js variable in the opener referring to this window
519
+ }
520
+ }
521
+ return s;
522
+ }
523
+
524
+ // construct a JavaScript expression which leads to my frame (i.e., the frame containing the window
525
+ // in which this code is operating)
526
+ function makeAddressToAUTFrame(w, frameNavigationalJSexpression)
527
+ {
528
+ if (w == null)
529
+ {
530
+ w = top;
531
+ frameNavigationalJSexpression = "top";
532
+ }
533
+
534
+ if (w == selenium.browserbot.getCurrentWindow())
535
+ {
536
+ return frameNavigationalJSexpression;
537
+ }
538
+ for (var j = 0; j < w.frames.length; j++)
539
+ {
540
+ var t = makeAddressToAUTFrame(w.frames[j], frameNavigationalJSexpression + ".frames[" + j + "]");
541
+ if (t != null)
542
+ {
543
+ return t;
544
+ }
545
+ }
546
+ return null;
547
+ }
548
+
549
+ Selenium.prototype.doSetContext = function(context) {
550
+ /**
551
+ * Writes a message to the status bar and adds a note to the browser-side
552
+ * log.
553
+ *
554
+ * @param context
555
+ * the message to be sent to the browser
556
+ */
557
+ //set the current test title
558
+ var ctx = document.getElementById("context");
559
+ if (ctx != null) {
560
+ ctx.innerHTML = context;
561
+ }
562
+ };
563
+
564
+ Selenium.prototype.doCaptureScreenshot = function(filename) {
565
+ /**
566
+ * Captures a PNG screenshot to the specified file.
567
+ *
568
+ * @param filename the absolute path to the file to be written, e.g. "c:\blah\screenshot.png"
569
+ */
570
+ // This doesn't really do anything on the JS side; we let the Selenium Server take care of this for us!
571
+ };