selenium-webdriver 0.0.24 → 0.0.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. data/{common/src/rb/CHANGES → CHANGES} +13 -0
  2. data/{common/src/rb/README → README} +1 -1
  3. data/{common/src/rb/lib → lib}/selenium-webdriver.rb +0 -0
  4. data/{common/src/rb/lib → lib}/selenium/webdriver.rb +2 -1
  5. data/{common/src/rb/lib → lib}/selenium/webdriver/bridge_helper.rb +0 -0
  6. data/{common/src/rb/lib → lib}/selenium/webdriver/child_process.rb +0 -0
  7. data/{chrome/src/rb/lib → lib}/selenium/webdriver/chrome.rb +0 -0
  8. data/{chrome/src/rb/lib → lib}/selenium/webdriver/chrome/bridge.rb +2 -2
  9. data/{chrome/src/rb/lib → lib}/selenium/webdriver/chrome/command_executor.rb +0 -0
  10. data/lib/selenium/webdriver/chrome/extension.zip +0 -0
  11. data/{chrome/src/rb/lib → lib}/selenium/webdriver/chrome/launcher.rb +26 -20
  12. data/{common/src/rb/lib → lib}/selenium/webdriver/core_ext/dir.rb +0 -0
  13. data/{common/src/rb/lib → lib}/selenium/webdriver/core_ext/string.rb +0 -0
  14. data/{common/src/rb/lib → lib}/selenium/webdriver/driver.rb +0 -0
  15. data/{common/src/rb/lib → lib}/selenium/webdriver/driver_extensions/takes_screenshot.rb +0 -0
  16. data/{common/src/rb/lib → lib}/selenium/webdriver/element.rb +0 -0
  17. data/{common/src/rb/lib → lib}/selenium/webdriver/error.rb +0 -0
  18. data/{common/src/rb/lib → lib}/selenium/webdriver/file_reaper.rb +2 -1
  19. data/{common/src/rb/lib → lib}/selenium/webdriver/find.rb +0 -0
  20. data/{firefox/src/rb/lib → lib}/selenium/webdriver/firefox.rb +2 -1
  21. data/{firefox/src/rb/lib → lib}/selenium/webdriver/firefox/binary.rb +32 -6
  22. data/{firefox/src/rb/lib → lib}/selenium/webdriver/firefox/bridge.rb +0 -0
  23. data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
  24. data/{firefox/src/rb/lib → lib}/selenium/webdriver/firefox/launcher.rb +0 -0
  25. data/lib/selenium/webdriver/firefox/native/linux/amd64/x_ignore_nofocus.so +0 -0
  26. data/lib/selenium/webdriver/firefox/native/linux/x86/x_ignore_nofocus.so +0 -0
  27. data/{firefox/src/rb/lib → lib}/selenium/webdriver/firefox/profile.rb +37 -72
  28. data/{firefox/src/rb/lib → lib}/selenium/webdriver/firefox/profiles_ini.rb +0 -0
  29. data/{firefox/src/rb/lib → lib}/selenium/webdriver/firefox/util.rb +0 -0
  30. data/{jobbie/src/rb/lib → lib}/selenium/webdriver/ie.rb +2 -2
  31. data/{jobbie/src/rb/lib → lib}/selenium/webdriver/ie/bridge.rb +7 -2
  32. data/{jobbie/src/rb/lib → lib}/selenium/webdriver/ie/lib.rb +0 -0
  33. data/{jobbie/prebuilt/Win32/Release → lib/selenium/webdriver/ie/native/win32}/InternetExplorerDriver.dll +0 -0
  34. data/lib/selenium/webdriver/ie/native/x64/InternetExplorerDriver.dll +0 -0
  35. data/{jobbie/src/rb/lib → lib}/selenium/webdriver/ie/util.rb +0 -0
  36. data/{common/src/rb/lib → lib}/selenium/webdriver/keys.rb +0 -0
  37. data/{common/src/rb/lib → lib}/selenium/webdriver/navigation.rb +0 -0
  38. data/{common/src/rb/lib → lib}/selenium/webdriver/options.rb +0 -0
  39. data/{common/src/rb/lib → lib}/selenium/webdriver/platform.rb +5 -1
  40. data/{remote/client/src/rb/lib → lib}/selenium/webdriver/remote.rb +0 -0
  41. data/{remote/client/src/rb/lib → lib}/selenium/webdriver/remote/bridge.rb +0 -0
  42. data/{remote/client/src/rb/lib → lib}/selenium/webdriver/remote/capabilities.rb +0 -0
  43. data/{remote/client/src/rb/lib → lib}/selenium/webdriver/remote/commands.rb +0 -0
  44. data/{remote/client/src/rb/lib → lib}/selenium/webdriver/remote/http/common.rb +0 -0
  45. data/{remote/client/src/rb/lib → lib}/selenium/webdriver/remote/http/curb.rb +0 -0
  46. data/{remote/client/src/rb/lib → lib}/selenium/webdriver/remote/http/default.rb +5 -1
  47. data/{remote/client/src/rb/lib → lib}/selenium/webdriver/remote/response.rb +0 -0
  48. data/{remote/client/src/rb/lib → lib}/selenium/webdriver/remote/server_error.rb +0 -0
  49. data/{common/src/rb/lib → lib}/selenium/webdriver/target_locator.rb +0 -0
  50. data/{common/src/rb/lib → lib}/selenium/webdriver/timeouts.rb +0 -0
  51. data/lib/selenium/webdriver/zip_helper.rb +30 -0
  52. metadata +73 -214
  53. data/COPYING +0 -204
  54. data/chrome/prebuilt/Win32/Release/npchromedriver.dll +0 -0
  55. data/chrome/prebuilt/x64/Release/npchromedriver.dll +0 -0
  56. data/chrome/src/extension/background.html +0 -9
  57. data/chrome/src/extension/background.js +0 -1029
  58. data/chrome/src/extension/content_script.js +0 -1488
  59. data/chrome/src/extension/icons/busy.png +0 -0
  60. data/chrome/src/extension/icons/free.png +0 -0
  61. data/chrome/src/extension/manifest-nonwin.json +0 -19
  62. data/chrome/src/extension/manifest-win.json +0 -20
  63. data/chrome/src/extension/utils.js +0 -231
  64. data/common/src/js/abstractcommandprocessor.js +0 -132
  65. data/common/src/js/asserts.js +0 -296
  66. data/common/src/js/by.js +0 -149
  67. data/common/src/js/command.js +0 -380
  68. data/common/src/js/core/Blank.html +0 -7
  69. data/common/src/js/core/InjectedRemoteRunner.html +0 -8
  70. data/common/src/js/core/RemoteRunner.html +0 -101
  71. data/common/src/js/core/SeleniumLog.html +0 -109
  72. data/common/src/js/core/TestPrompt.html +0 -145
  73. data/common/src/js/core/TestRunner-splash.html +0 -55
  74. data/common/src/js/core/TestRunner.html +0 -165
  75. data/common/src/js/core/icons/all.png +0 -0
  76. data/common/src/js/core/icons/continue.png +0 -0
  77. data/common/src/js/core/icons/continue_disabled.png +0 -0
  78. data/common/src/js/core/icons/pause.png +0 -0
  79. data/common/src/js/core/icons/pause_disabled.png +0 -0
  80. data/common/src/js/core/icons/selected.png +0 -0
  81. data/common/src/js/core/icons/step.png +0 -0
  82. data/common/src/js/core/icons/step_disabled.png +0 -0
  83. data/common/src/js/core/lib/cssQuery/cssQuery-p.js +0 -6
  84. data/common/src/js/core/lib/cssQuery/src/cssQuery-level2.js +0 -142
  85. data/common/src/js/core/lib/cssQuery/src/cssQuery-level3.js +0 -150
  86. data/common/src/js/core/lib/cssQuery/src/cssQuery-standard.js +0 -53
  87. data/common/src/js/core/lib/cssQuery/src/cssQuery.js +0 -356
  88. data/common/src/js/core/lib/prototype.js +0 -2006
  89. data/common/src/js/core/lib/scriptaculous/builder.js +0 -101
  90. data/common/src/js/core/lib/scriptaculous/controls.js +0 -815
  91. data/common/src/js/core/lib/scriptaculous/dragdrop.js +0 -915
  92. data/common/src/js/core/lib/scriptaculous/effects.js +0 -958
  93. data/common/src/js/core/lib/scriptaculous/scriptaculous.js +0 -47
  94. data/common/src/js/core/lib/scriptaculous/slider.js +0 -283
  95. data/common/src/js/core/lib/scriptaculous/unittest.js +0 -383
  96. data/common/src/js/core/lib/snapsie.js +0 -91
  97. data/common/src/js/core/scripts/find_matching_child.js +0 -69
  98. data/common/src/js/core/scripts/htmlutils.js +0 -8716
  99. data/common/src/js/core/scripts/injection.html +0 -72
  100. data/common/src/js/core/scripts/selenium-api.js +0 -3291
  101. data/common/src/js/core/scripts/selenium-browserbot.js +0 -2457
  102. data/common/src/js/core/scripts/selenium-browserdetect.js +0 -153
  103. data/common/src/js/core/scripts/selenium-commandhandlers.js +0 -379
  104. data/common/src/js/core/scripts/selenium-executionloop.js +0 -175
  105. data/common/src/js/core/scripts/selenium-logging.js +0 -148
  106. data/common/src/js/core/scripts/selenium-remoterunner.js +0 -695
  107. data/common/src/js/core/scripts/selenium-testrunner.js +0 -1362
  108. data/common/src/js/core/scripts/selenium-version.js +0 -5
  109. data/common/src/js/core/scripts/ui-doc.html +0 -808
  110. data/common/src/js/core/scripts/ui-element.js +0 -1644
  111. data/common/src/js/core/scripts/ui-map-sample.js +0 -979
  112. data/common/src/js/core/scripts/user-extensions.js +0 -3
  113. data/common/src/js/core/scripts/user-extensions.js.sample +0 -75
  114. data/common/src/js/core/scripts/xmlextras.js +0 -153
  115. data/common/src/js/core/selenium-logo.png +0 -0
  116. data/common/src/js/core/selenium-test.css +0 -43
  117. data/common/src/js/core/selenium.css +0 -316
  118. data/common/src/js/core/xpath/dom.js +0 -566
  119. data/common/src/js/core/xpath/javascript-xpath-0.1.11.js +0 -2816
  120. data/common/src/js/core/xpath/util.js +0 -549
  121. data/common/src/js/core/xpath/xmltoken.js +0 -149
  122. data/common/src/js/core/xpath/xpath.js +0 -2481
  123. data/common/src/js/extension/README +0 -2
  124. data/common/src/js/extension/dommessenger.js +0 -152
  125. data/common/src/js/factory.js +0 -55
  126. data/common/src/js/future.js +0 -141
  127. data/common/src/js/jsunit.js +0 -40
  128. data/common/src/js/jsunit/app/css/jsUnitStyle.css +0 -50
  129. data/common/src/js/jsunit/app/css/readme +0 -10
  130. data/common/src/js/jsunit/app/emptyPage.html +0 -11
  131. data/common/src/js/jsunit/app/jsUnitCore.js +0 -534
  132. data/common/src/js/jsunit/app/jsUnitMockTimeout.js +0 -81
  133. data/common/src/js/jsunit/app/jsUnitTestManager.js +0 -705
  134. data/common/src/js/jsunit/app/jsUnitTestSuite.js +0 -44
  135. data/common/src/js/jsunit/app/jsUnitTracer.js +0 -102
  136. data/common/src/js/jsunit/app/jsUnitVersionCheck.js +0 -59
  137. data/common/src/js/jsunit/app/main-counts-errors.html +0 -12
  138. data/common/src/js/jsunit/app/main-counts-failures.html +0 -13
  139. data/common/src/js/jsunit/app/main-counts-runs.html +0 -13
  140. data/common/src/js/jsunit/app/main-counts.html +0 -21
  141. data/common/src/js/jsunit/app/main-data.html +0 -178
  142. data/common/src/js/jsunit/app/main-errors.html +0 -23
  143. data/common/src/js/jsunit/app/main-frame.html +0 -19
  144. data/common/src/js/jsunit/app/main-loader.html +0 -45
  145. data/common/src/js/jsunit/app/main-progress.html +0 -25
  146. data/common/src/js/jsunit/app/main-results.html +0 -67
  147. data/common/src/js/jsunit/app/main-status.html +0 -13
  148. data/common/src/js/jsunit/app/testContainer.html +0 -16
  149. data/common/src/js/jsunit/app/testContainerController.html +0 -77
  150. data/common/src/js/jsunit/app/xbDebug.js +0 -306
  151. data/common/src/js/jsunit/changelog.txt +0 -60
  152. data/common/src/js/jsunit/css/jsUnitStyle.css +0 -83
  153. data/common/src/js/jsunit/images/green.gif +0 -0
  154. data/common/src/js/jsunit/images/logo_jsunit.gif +0 -0
  155. data/common/src/js/jsunit/images/powerby-transparent.gif +0 -0
  156. data/common/src/js/jsunit/images/red.gif +0 -0
  157. data/common/src/js/jsunit/licenses/JDOM_license.txt +0 -56
  158. data/common/src/js/jsunit/licenses/Jetty_license.html +0 -213
  159. data/common/src/js/jsunit/licenses/MPL-1.1.txt +0 -470
  160. data/common/src/js/jsunit/licenses/gpl-2.txt +0 -340
  161. data/common/src/js/jsunit/licenses/index.html +0 -141
  162. data/common/src/js/jsunit/licenses/lgpl-2.1.txt +0 -504
  163. data/common/src/js/jsunit/licenses/mpl-tri-license-c.txt +0 -35
  164. data/common/src/js/jsunit/licenses/mpl-tri-license-html.txt +0 -35
  165. data/common/src/js/jsunit/readme.txt +0 -19
  166. data/common/src/js/jsunit/testRunner.html +0 -167
  167. data/common/src/js/jsunit/version.txt +0 -1
  168. data/common/src/js/key.js +0 -117
  169. data/common/src/js/localcommandprocessor.js +0 -171
  170. data/common/src/js/testcase.js +0 -219
  171. data/common/src/js/timing.js +0 -89
  172. data/common/src/js/webdriver.js +0 -860
  173. data/common/src/js/webelement.js +0 -483
  174. data/firefox/prebuilt/Win32/Release/webdriver-firefox.dll +0 -0
  175. data/firefox/prebuilt/amd64/libnoblur64.so +0 -0
  176. data/firefox/prebuilt/i386/libnoblur.so +0 -0
  177. data/firefox/prebuilt/linux/Release/libwebdriver-firefox.so +0 -0
  178. data/firefox/prebuilt/linux64/Release/libwebdriver-firefox.so +0 -0
  179. data/firefox/prebuilt/nsICommandProcessor.xpt +0 -0
  180. data/firefox/prebuilt/nsINativeEvents.xpt +0 -0
  181. data/firefox/prebuilt/nsIResponseHandler.xpt +0 -0
  182. data/firefox/src/extension/chrome.manifest +0 -3
  183. data/firefox/src/extension/components/badCertListener.js +0 -295
  184. data/firefox/src/extension/components/dispatcher.js +0 -495
  185. data/firefox/src/extension/components/driver-component.js +0 -130
  186. data/firefox/src/extension/components/errorcode.js +0 -70
  187. data/firefox/src/extension/components/firefoxDriver.js +0 -831
  188. data/firefox/src/extension/components/json2.js +0 -273
  189. data/firefox/src/extension/components/keytest.html +0 -554
  190. data/firefox/src/extension/components/nsCommandProcessor.js +0 -684
  191. data/firefox/src/extension/components/promptService.js +0 -208
  192. data/firefox/src/extension/components/request.js +0 -219
  193. data/firefox/src/extension/components/response.js +0 -276
  194. data/firefox/src/extension/components/screenshooter.js +0 -81
  195. data/firefox/src/extension/components/session.js +0 -314
  196. data/firefox/src/extension/components/sessionstore.js +0 -226
  197. data/firefox/src/extension/components/socketListener.js +0 -435
  198. data/firefox/src/extension/components/utils.js +0 -1335
  199. data/firefox/src/extension/components/webLoadingListener.js +0 -57
  200. data/firefox/src/extension/components/webdriverserver.js +0 -110
  201. data/firefox/src/extension/components/wrappedElement.js +0 -706
  202. data/firefox/src/extension/content/fxdriver.xul +0 -30
  203. data/firefox/src/extension/content/server.js +0 -95
  204. data/firefox/src/extension/idl/nsICommandProcessor.idl +0 -38
  205. data/firefox/src/extension/idl/nsIResponseHandler.idl +0 -34
  206. data/firefox/src/extension/install.rdf +0 -29
  207. data/jobbie/prebuilt/x64/Release/InternetExplorerDriver.dll +0 -0
@@ -1,130 +0,0 @@
1
- /*
2
- Copyright 2007-2009 WebDriver committers
3
- Copyright 2007-2009 Google Inc.
4
- Portions copyright 2007 ThoughtWorks, Inc
5
-
6
- Licensed under the Apache License, Version 2.0 (the "License");
7
- you may not use this file except in compliance with the License.
8
- You may obtain a copy of the License at
9
-
10
- http://www.apache.org/licenses/LICENSE-2.0
11
-
12
- Unless required by applicable law or agreed to in writing, software
13
- distributed under the License is distributed on an "AS IS" BASIS,
14
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- See the License for the specific language governing permissions and
16
- limitations under the License.
17
- */
18
-
19
- // constants
20
- const nsISupports = Components.interfaces.nsISupports;
21
- const CLASS_ID = Components.ID("{1C0E8D86-B661-40d0-AE3D-CA012FADF170}");
22
- const CLASS_NAME = "Firefox WebDriver";
23
- const CONTRACT_ID = "@googlecode.com/webdriver/fxdriver;1";
24
-
25
- // The following code is derived from https://addons.mozilla.org/en-US/firefox/files/browse/3682/
26
- // Its copyrights belong to its original author.
27
-
28
- var ExternalScripts = [
29
- "errorcode.js",
30
- "dispatcher.js",
31
- "firefoxDriver.js",
32
- "socketListener.js",
33
- "request.js",
34
- "response.js",
35
- "utils.js",
36
- "webdriverserver.js",
37
- "webLoadingListener.js",
38
- "wrappedElement.js",
39
- "screenshooter.js"
40
- ];
41
-
42
-
43
- (function() {
44
- var self;
45
- var fileProtocolHandler = Components.
46
- classes['@mozilla.org/network/protocol;1?name=file'].
47
- createInstance(Components.interfaces.nsIFileProtocolHandler);
48
- self = __LOCATION__;
49
-
50
- var parent = self.parent;
51
- // the directory this file is in
52
- var loader = Components.classes['@mozilla.org/moz/jssubscript-loader;1'].
53
- createInstance(Components.interfaces.mozIJSSubScriptLoader);
54
-
55
- // Firefox 3.5+ has native JSON support; prefer that over our script from
56
- // www.json.org, which may be slower.
57
- var appInfo = Components.classes['@mozilla.org/xre/app-info;1'].
58
- getService(Components.interfaces.nsIXULAppInfo);
59
- var versionChecker = Components.classes['@mozilla.org/xpcom/version-comparator;1'].
60
- getService(Components.interfaces.nsIVersionComparator);
61
- if (versionChecker.compare(appInfo.version, '3.5') < 0) {
62
- ExternalScripts.push('json2.js');
63
- }
64
-
65
- for (var index in ExternalScripts) {
66
- var child = parent.clone();
67
- child.append(ExternalScripts[index]);
68
- // child is a nsILocalFile of the file we want to load
69
- var childname = fileProtocolHandler.getURLSpecFromFile(child);
70
- loader.loadSubScript(childname);
71
- }
72
- })();
73
-
74
-
75
- // This code has been derived from the example code at
76
- // http://developer-stage.mozilla.org/en/docs/How_to_Build_an_XPCOM_Component_in_Javascript
77
- // Its copyrights belong to the original author
78
-
79
- var ServerFactory = {
80
- createInstance: function (aOuter, aIID) {
81
- if (aOuter != null)
82
- throw Components.results.NS_ERROR_NO_AGGREGATION;
83
- if (!this.server)
84
- this.server = new WebDriverServer();
85
- return (this.server).QueryInterface(aIID);
86
- }
87
- };
88
-
89
-
90
- //module definition (xpcom registration)
91
- var ServerModule = {
92
- firstTime_: true,
93
-
94
- registerSelf: function(aCompMgr, aFileSpec, aLocation, aType) {
95
- if (this.firstTime_) {
96
- this.firstTime_ = false;
97
- throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
98
- }
99
- aCompMgr =
100
- aCompMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
101
- aCompMgr.registerFactoryLocation(
102
- CLASS_ID, CLASS_NAME, CONTRACT_ID, aFileSpec, aLocation, aType);
103
- },
104
-
105
- unregisterSelf: function(aCompMgr, aLocation, aType) {
106
- aCompMgr =
107
- aCompMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
108
- aCompMgr.unregisterFactoryLocation(CLASS_ID, aLocation);
109
- },
110
-
111
- getClassObject: function(aCompMgr, aCID, aIID) {
112
- if (!aIID.equals(Components.interfaces.nsIFactory))
113
- throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
114
-
115
- if (aCID.equals(CLASS_ID))
116
- return ServerFactory;
117
-
118
- throw Components.results.NS_ERROR_NO_INTERFACE;
119
- },
120
-
121
- canUnload: function(aCompMgr) {
122
- return true;
123
- }
124
- };
125
-
126
-
127
- //module initialization
128
- function NSGetModule(aCompMgr, aFileSpec) {
129
- return ServerModule;
130
- }
@@ -1,70 +0,0 @@
1
- /*
2
- Copyright 2007-2010 WebDriver committers
3
- Copyright 2007-2010 Google Inc.
4
- Portions copyright 2007 ThoughtWorks, Inc
5
-
6
- Licensed under the Apache License, Version 2.0 (the "License");
7
- you may not use this file except in compliance with the License.
8
- You may obtain a copy of the License at
9
-
10
- http://www.apache.org/licenses/LICENSE-2.0
11
-
12
- Unless required by applicable law or agreed to in writing, software
13
- distributed under the License is distributed on an "AS IS" BASIS,
14
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- See the License for the specific language governing permissions and
16
- limitations under the License.
17
- */
18
-
19
-
20
- /**
21
- * Error codes used by the remote wire protocol.
22
- * @enum {number}
23
- */
24
- var ErrorCode = {
25
- // Keep in sync with codes in org.openqa.selenium.remote.ErrorCodes
26
-
27
- SUCCESS: 0,
28
- NO_SUCH_ELEMENT: 7,
29
- NO_SUCH_FRAME: 8,
30
- UNKNOWN_COMMAND: 9,
31
- STALE_ELEMENT_REFERENCE: 10,
32
- ELEMENT_NOT_VISIBLE: 11,
33
- INVALID_ELEMENT_STATE: 12,
34
- UNHANDLED_ERROR: 13,
35
- UNEXPECTED_JAVASCRIPT_ERROR: 17,
36
- XPATH_LOOKUP_ERROR: 19,
37
- NO_SUCH_WINDOW: 23,
38
- INVALID_COOKIE_DOMAIN: 24,
39
- UNABLE_TO_SET_COOKIE: 25
40
- };
41
-
42
-
43
- /**
44
- * Converts an Error object to a JSON object compatible with WebDriver's remote
45
- * wire protocol.
46
- * @param {Error} ex The thrown error to convert.
47
- * @return {Object} The converted object.
48
- */
49
- ErrorCode.toJSON = function(ex) {
50
- var stackFrames = [];
51
- var json = {
52
- 'message': ex.message ? ex.message : ex.toString(),
53
- 'stackTrace': stackFrames,
54
- };
55
-
56
- if (ex.stack) {
57
- var stack = ex.stack.replace(/\s*$/, '').split('\n');
58
-
59
- for (var frame = stack.shift(); frame; frame = stack.shift()) {
60
- var match = frame.match(/^([a-zA-Z_$][\w]*)?(?:\(.*\))?@(.+)?:(\d*)$/);
61
- stackFrames.push({
62
- 'methodName': match[1],
63
- 'fileName': match[2],
64
- 'lineNumber': Number(match[3])
65
- });
66
- }
67
- }
68
-
69
- return json;
70
- };
@@ -1,831 +0,0 @@
1
- /*
2
- Copyright 2007-2009 WebDriver committers
3
- Copyright 2007-2009 Google Inc.
4
- Portions copyright 2007 ThoughtWorks, Inc
5
-
6
- Licensed under the Apache License, Version 2.0 (the "License");
7
- you may not use this file except in compliance with the License.
8
- You may obtain a copy of the License at
9
-
10
- http://www.apache.org/licenses/LICENSE-2.0
11
-
12
- Unless required by applicable law or agreed to in writing, software
13
- distributed under the License is distributed on an "AS IS" BASIS,
14
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- See the License for the specific language governing permissions and
16
- limitations under the License.
17
- */
18
-
19
-
20
- function FirefoxDriver(server, enableNativeEvents, win) {
21
- this.server = server;
22
- this.enableNativeEvents = enableNativeEvents;
23
- this.window = win;
24
-
25
- this.currentX = 0;
26
- this.currentY = 0;
27
- }
28
-
29
-
30
- /**
31
- * Enumeration of supported speed values.
32
- * @enum {number}
33
- */
34
- FirefoxDriver.Speed = {
35
- SLOW: 1,
36
- MEDIUM: 10,
37
- FAST: 100
38
- };
39
-
40
-
41
- FirefoxDriver.prototype.__defineGetter__("id", function() {
42
- if (!this.id_) {
43
- this.id_ = this.server.getNextId();
44
- }
45
-
46
- return this.id_;
47
- });
48
-
49
-
50
- FirefoxDriver.prototype.getCurrentWindowHandle = function(respond) {
51
- respond.value = this.id;
52
- respond.send();
53
- };
54
-
55
-
56
- FirefoxDriver.prototype.get = function(respond, parameters) {
57
- var url = parameters.url;
58
- // Check to see if the given url is the same as the current one, but
59
- // with a different anchor tag.
60
- var current = respond.session.getWindow().location;
61
- var ioService =
62
- Utils.getService("@mozilla.org/network/io-service;1", "nsIIOService");
63
- var currentUri = ioService.newURI(current, "", null);
64
- var futureUri = ioService.newURI(url, "", currentUri);
65
-
66
- var loadEventExpected = true;
67
-
68
- if (currentUri && futureUri &&
69
- currentUri.prePath == futureUri.prePath &&
70
- currentUri.filePath == futureUri.filePath) {
71
- // Looks like we're at the same url with a ref
72
- // Being clever and checking the ref was causing me headaches.
73
- // Brute force for now
74
- loadEventExpected = futureUri.path.indexOf("#") == -1;
75
- }
76
-
77
- if (loadEventExpected) {
78
- new WebLoadingListener(respond.session.getBrowser(), function() {
79
- // TODO: Rescue the URI and response code from the event
80
- var responseText = "";
81
- // Focus on the top window.
82
- respond.session.setWindow(respond.session.getBrowser().contentWindow);
83
- respond.value = responseText;
84
- respond.send();
85
- });
86
- }
87
-
88
- respond.session.getBrowser().loadURI(url);
89
-
90
- if (!loadEventExpected) {
91
- respond.send();
92
- }
93
- };
94
-
95
-
96
- FirefoxDriver.prototype.close = function(respond) {
97
- // Grab all the references we'll need. Once we call close all this might go away
98
- var wm = Utils.getService(
99
- "@mozilla.org/appshell/window-mediator;1", "nsIWindowMediator");
100
- var appService = Utils.getService(
101
- "@mozilla.org/toolkit/app-startup;1", "nsIAppStartup");
102
- var forceQuit = Components.interfaces.nsIAppStartup.eForceQuit;
103
-
104
- // Here we go!
105
- try {
106
- var browser = respond.session.getBrowser();
107
- createSwitchFile("close:" + browser.id);
108
- browser.contentWindow.close();
109
- } catch(e) {
110
- dump(e);
111
- }
112
-
113
- // Send the response so the client doesn't get a connection refused socket
114
- // error.
115
- respond.send();
116
-
117
- // If we're on a Mac we might have closed all the windows but not quit, so
118
- // ensure that we do actually quit :)
119
- var allWindows = wm.getEnumerator("navigator:browser");
120
- if (!allWindows.hasMoreElements()) {
121
- appService.quit(forceQuit);
122
- return; // The client should catch the fact that the socket suddenly closes
123
- }
124
- };
125
-
126
-
127
- FirefoxDriver.prototype.executeScript = function(respond, parameters) {
128
- var window = respond.session.getWindow();
129
- var doc = window.document;
130
-
131
- var runScript;
132
-
133
- // Pre 2.0.0.15
134
- if (window['alert'] && !window.wrappedJSObject) {
135
- runScript = function(scriptSrc) {
136
- return window.eval(scriptSrc);
137
- };
138
- } else {
139
- runScript = function(scriptSrc, args) {
140
- window = window.wrappedJSObject;
141
- var sandbox = new Components.utils.Sandbox(window);
142
- sandbox.window = window;
143
- sandbox.__webdriverParams = args;
144
- sandbox.document = window.document;
145
- sandbox.unsafeWindow = window;
146
- sandbox.__proto__ = window;
147
-
148
- return Components.utils.evalInSandbox(scriptSrc, sandbox);
149
- };
150
- }
151
-
152
- var converted = Utils.unwrapParameters(
153
- parameters.args, respond.session.getDocument());
154
-
155
- try {
156
- var scriptSrc = "var __webdriverFunc = function(){" + parameters.script
157
- + "}; __webdriverFunc.apply(window, __webdriverParams);";
158
- var result = runScript(scriptSrc, converted);
159
- } catch (e) {
160
- Utils.dumpn(JSON.stringify(e));
161
- throw new WebDriverError(ErrorCode.UNEXPECTED_JAVASCRIPT_ERROR, e);
162
- }
163
-
164
- respond.value = Utils.wrapResult(result, respond.session.getDocument());
165
- respond.send();
166
- };
167
-
168
-
169
- FirefoxDriver.prototype.getCurrentUrl = function(respond) {
170
- var url = respond.session.getWindow().location;
171
- if (!url) {
172
- url = respond.session.getBrowser().contentWindow.location;
173
- }
174
- respond.value = "" + url;
175
- respond.send();
176
- };
177
-
178
-
179
- FirefoxDriver.prototype.getTitle = function(respond) {
180
- respond.value = respond.session.getBrowser().contentTitle;
181
- respond.send();
182
- };
183
-
184
-
185
- FirefoxDriver.prototype.getPageSource = function(respond) {
186
- var source = respond.session.getDocument().
187
- getElementsByTagName("html")[0].innerHTML;
188
-
189
- respond.value = "<html>" + source + "</html>";
190
- respond.send();
191
- };
192
-
193
- var normalizeXPath = function(xpath, opt_contextNode) {
194
- if (opt_contextNode && xpath) {
195
- var parentXPath = Utils.getXPathOfElement(opt_contextNode);
196
- if (parentXPath && parentXPath.length > 0) {
197
- if (xpath[0] != '/' && xpath[0] != '(') {
198
- return parentXPath + "/" + xpath;
199
- } else {
200
- return parentXPath + xpath;
201
- }
202
- }
203
- }
204
- return xpath;
205
- };
206
-
207
-
208
- /**
209
- * Searches for the first element in {@code theDocument} matching the given
210
- * {@code xpath} expression.
211
- * @param {nsIDOMDocument} theDocument The document to search in.
212
- * @param {string} xpath The XPath expression to evaluate.
213
- * @param {nsIDOMNode} opt_contextNode The context node for the query; defaults
214
- * to {@code theDocument}.
215
- * @return {nsIDOMNode} The first matching node.
216
- * @private
217
- */
218
- FirefoxDriver.prototype.findElementByXPath_ = function(theDocument, xpath,
219
- opt_contextNode) {
220
- var contextNode = theDocument;
221
- if (opt_contextNode) {
222
- contextNode = opt_contextNode;
223
- xpath = normalizeXPath(xpath, opt_contextNode);
224
- }
225
- return theDocument.evaluate(xpath, contextNode, null,
226
- Components.interfaces.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE, null).
227
- singleNodeValue;
228
- };
229
-
230
-
231
- /**
232
- * Searches for elements matching the given {@code xpath} expression in the
233
- * specified document.
234
- * @param {nsIDOMDocument} theDocument The document to search in.
235
- * @param {string} xpath The XPath expression to evaluate.
236
- * @param {nsIDOMNode} opt_contextNode The context node for the query; defaults
237
- * to {@code theDocument}.
238
- * @return {Array.<nsIDOMNode>} The matching nodes.
239
- * @private
240
- */
241
- FirefoxDriver.prototype.findElementsByXPath_ = function(theDocument, xpath,
242
- opt_contextNode) {
243
- var contextNode = theDocument;
244
- if (opt_contextNode) {
245
- contextNode = opt_contextNode;
246
- xpath = normalizeXPath(xpath, opt_contextNode);
247
- }
248
- var result = theDocument.evaluate(xpath, contextNode, null,
249
- Components.interfaces.nsIDOMXPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
250
- var elements = [];
251
- var element = result.iterateNext();
252
- while (element) {
253
- elements.push(element);
254
- element = result.iterateNext();
255
- }
256
- return elements;
257
- };
258
-
259
-
260
- /**
261
- * An enumeration of the supported element locator methods.
262
- * @enum {string}
263
- */
264
- FirefoxDriver.ElementLocator = {
265
- ID: 'id',
266
- NAME: 'name',
267
- CLASS_NAME: 'class name',
268
- CSS_SELECTOR: 'css selector',
269
- TAG_NAME: 'tag name',
270
- LINK_TEXT: 'link text',
271
- PARTIAL_LINK_TEXT: 'partial link text',
272
- XPATH: 'xpath'
273
- };
274
-
275
-
276
- /**
277
- * Finds an element on the current page. The response value will be the UUID of
278
- * the located element, or an error message if an element could not be found.
279
- * @param {Response} respond Object to send the command response with.
280
- * @param {FirefoxDriver.ElementLocator} method The locator method to use.
281
- * @param {string} selector What to search for; see {@code ElementLocator} for
282
- * details on what the selector should be for each element.
283
- * @param {string} opt_parentElementId If defined, the search will be restricted
284
- * to the corresponding element's subtree.
285
- * @param {number=} opt_startTime When this search operation started. Defaults
286
- * to the current time.
287
- * @private
288
- */
289
- FirefoxDriver.prototype.findElementInternal_ = function(respond, method,
290
- selector,
291
- opt_parentElementId,
292
- opt_startTime) {
293
- var startTime = typeof opt_startTime == 'number' ? opt_startTime :
294
- new Date().getTime();
295
- var theDocument = respond.session.getDocument();
296
- var rootNode = typeof opt_parentElementId == 'string' ?
297
- Utils.getElementAt(opt_parentElementId, theDocument) : theDocument;
298
-
299
- var element;
300
- switch (method) {
301
- case FirefoxDriver.ElementLocator.ID:
302
- element = rootNode === theDocument ?
303
- theDocument.getElementById(selector) :
304
- this.findElementByXPath_(
305
- theDocument, './/*[@id="' + selector + '"]', rootNode);
306
- break;
307
-
308
- case FirefoxDriver.ElementLocator.NAME:
309
- element = rootNode.getElementsByName ?
310
- rootNode.getElementsByName(selector)[0] :
311
- this.findElementByXPath_(
312
- theDocument, './/*[@name ="' + selector + '"]', rootNode);
313
- break;
314
-
315
- case FirefoxDriver.ElementLocator.CLASS_NAME:
316
- element = rootNode.getElementsByClassName ?
317
- rootNode.getElementsByClassName(selector)[0] : // FF 3+
318
- this.findElementByXPath_(theDocument, // FF 2
319
- '//*[contains(concat(" ",normalize-space(@class)," ")," ' +
320
- selector + ' ")]', rootNode);
321
- break;
322
-
323
- case FirefoxDriver.ElementLocator.CSS_SELECTOR:
324
- if (rootNode['querySelector']) {
325
- element = rootNode.querySelector(selector);
326
- } else {
327
- throw new WebDriverError(ErrorCode.UNKNOWN_COMMAND,
328
- "CSS Selectors not supported natively");
329
- }
330
- break;
331
-
332
- case FirefoxDriver.ElementLocator.TAG_NAME:
333
- element = rootNode.getElementsByTagName(selector)[0];
334
- break;
335
-
336
- case FirefoxDriver.ElementLocator.XPATH:
337
- element = this.findElementByXPath_(theDocument, selector, rootNode);
338
- break;
339
-
340
- case FirefoxDriver.ElementLocator.LINK_TEXT:
341
- case FirefoxDriver.ElementLocator.PARTIAL_LINK_TEXT:
342
- var allLinks = rootNode.getElementsByTagName('A');
343
- for (var i = 0; i < allLinks.length && !element; i++) {
344
- var text = Utils.getText(allLinks[i], true);
345
- if (FirefoxDriver.ElementLocator.PARTIAL_LINK_TEXT == method) {
346
- if (text.indexOf(selector) != -1) {
347
- element = allLinks[i];
348
- }
349
- } else if (text == selector) {
350
- element = allLinks[i];
351
- }
352
- }
353
- break;
354
-
355
- default:
356
- throw new WebDriverError(ErrorCode.UNKNOWN_COMMAND,
357
- 'Unsupported element locator method: ' + method);
358
- return;
359
- }
360
-
361
- if (element) {
362
- var id = Utils.addToKnownElements(element, respond.session.getDocument());
363
- respond.value = {'ELEMENT': id};
364
- respond.send();
365
- } else {
366
- var wait = respond.session.getImplicitWait();
367
- if (wait == 0 || new Date().getTime() - startTime > wait) {
368
- respond.sendError(new WebDriverError(ErrorCode.NO_SUCH_ELEMENT,
369
- 'Unable to locate element: ' + JSON.stringify({
370
- method: method,
371
- selector: selector
372
- })));
373
- } else {
374
- var self = this;
375
- var timer = Components.classes['@mozilla.org/timer;1'].
376
- createInstance(Components.interfaces.nsITimer);
377
- timer.initWithCallback({
378
- notify: function() {
379
- self.findElementInternal_(respond, method, selector,
380
- opt_parentElementId, startTime);
381
- }
382
- }, 10, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
383
- }
384
- }
385
- };
386
-
387
-
388
- /**
389
- * Finds an element on the current page. The response value will be the UUID of
390
- * the located element, or an error message if an element could not be found.
391
- * @param {Response} respond Object to send the command response with.
392
- * @param {{using: string, value: string}} parameters A JSON object
393
- * specifying the search parameters:
394
- * - using: A method to search with, as defined in the
395
- * {@code Firefox.ElementLocator} enum.
396
- * - value: What to search for.
397
- */
398
- FirefoxDriver.prototype.findElement = function(respond, parameters) {
399
- this.findElementInternal_(respond, parameters.using, parameters.value);
400
- };
401
-
402
-
403
- /**
404
- * Finds an element on the current page that is the child of a corresponding
405
- * search parameter. The response value will be the UUID of the located element,
406
- * or an error message if an element could not be found.
407
- * @param {Response} respond Object to send the command response with.
408
- * @param {{id: string, using: string, value: string}} parameters A JSON object
409
- * specifying the search parameters:
410
- * - id: UUID of the element to base the search from.
411
- * - using: A method to search with, as defined in the
412
- * {@code Firefox.ElementLocator} enum.
413
- * - value: What to search for.
414
- */
415
- FirefoxDriver.prototype.findChildElement = function(respond, parameters) {
416
- this.findElementInternal_(respond, parameters.using, parameters.value, parameters.id);
417
- };
418
-
419
-
420
- /**
421
- * Finds elements on the current page. The response value will an array of UUIDs
422
- * for the located elements.
423
- * @param {Response} respond Object to send the command response with.
424
- * @param {FirefoxDriver.ElementLocator} method The locator method to use.
425
- * @param {string} selector What to search for; see {@code ElementLocator} for
426
- * details on what the selector should be for each element.
427
- * @param {string} opt_parentElementId If defined, the search will be restricted
428
- * to the corresponding element's subtree.
429
- * @param {number=} opt_startTime When this search operation started. Defaults
430
- * to the current time.
431
- * @private
432
- */
433
- FirefoxDriver.prototype.findElementsInternal_ = function(respond, method,
434
- selector,
435
- opt_parentElementId,
436
- opt_startTime) {
437
- var startTime = typeof opt_startTime == 'number' ? opt_startTime :
438
- new Date().getTime();
439
- var theDocument = respond.session.getDocument();
440
- var rootNode = typeof opt_parentElementId == 'string' ?
441
- Utils.getElementAt(opt_parentElementId, theDocument) : theDocument;
442
-
443
- var elements;
444
- switch (method) {
445
- case FirefoxDriver.ElementLocator.ID:
446
- selector = './/*[@id="' + selector + '"]';
447
- // Fall-through
448
- case FirefoxDriver.ElementLocator.XPATH:
449
- elements = this.findElementsByXPath_(
450
- theDocument, selector, rootNode);
451
- break;
452
-
453
- case FirefoxDriver.ElementLocator.NAME:
454
- elements = rootNode.getElementsByName ?
455
- rootNode.getElementsByName(selector) :
456
- this.findElementsByXPath_(
457
- theDocument, './/*[@name="' + selector + '"]', rootNode);
458
- break;
459
-
460
- case FirefoxDriver.ElementLocator.CSS_SELECTOR:
461
- if (rootNode['querySelector']) {
462
- elements = rootNode.querySelectorAll(selector);
463
- } else {
464
- throw new WebDriverError(ErrorCode.UNKNOWN_COMMAND,
465
- "CSS Selectors not supported natively");
466
- }
467
- break;
468
-
469
- case FirefoxDriver.ElementLocator.TAG_NAME:
470
- elements = rootNode.getElementsByTagName(selector);
471
- break;
472
-
473
- case FirefoxDriver.ElementLocator.CLASS_NAME:
474
- elements = rootNode.getElementsByClassName ?
475
- rootNode.getElementsByClassName(selector) : // FF 3+
476
- this.findElementsByXPath_(theDocument, // FF 2
477
- './/*[contains(concat(" ",normalize-space(@class)," ")," ' +
478
- selector + ' ")]', rootNode);
479
- break;
480
-
481
- case FirefoxDriver.ElementLocator.LINK_TEXT:
482
- case FirefoxDriver.ElementLocator.PARTIAL_LINK_TEXT:
483
- elements = rootNode.getElementsByTagName('A');
484
- elements = Array.filter(elements, function(element) {
485
- var text = Utils.getText(element, true);
486
- if (FirefoxDriver.ElementLocator.PARTIAL_LINK_TEXT == method) {
487
- return text.indexOf(selector) != -1;
488
- } else {
489
- return text == selector;
490
- }
491
- });
492
- break;
493
-
494
- default:
495
- throw new WebDriverError(ErrorCode.UNKNOWN_COMMAND,
496
- 'Unsupported element locator method: ' + method);
497
- return;
498
- }
499
-
500
- var elementIds = [];
501
- for (var j = 0; j < elements.length; j++) {
502
- var element = elements[j];
503
- var elementId = Utils.addToKnownElements(
504
- element, respond.session.getDocument());
505
- elementIds.push({'ELEMENT': elementId});
506
- }
507
-
508
- var wait = respond.session.getImplicitWait();
509
- if (wait && !elementIds.length && new Date().getTime() - startTime <= wait) {
510
- var self = this;
511
- var timer = Components.classes['@mozilla.org/timer;1'].
512
- createInstance(Components.interfaces.nsITimer);
513
- timer.initWithCallback({
514
- notify: function() {
515
- self.findElementsInternal_(respond, method, selector,
516
- opt_parentElementId, startTime);
517
- }
518
- }, 10, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
519
- } else {
520
- respond.value = elementIds;
521
- respond.send();
522
- }
523
- };
524
-
525
-
526
- /**
527
- * Searches for multiple elements on the page. The response value will be an
528
- * array of UUIDs for the located elements.
529
- * @param {Response} respond Object to send the command response with.
530
- * @param {{using: string, value: string}} parameters A JSON object
531
- * specifying the search parameters:
532
- * - using: A method to search with, as defined in the
533
- * {@code Firefox.ElementLocator} enum.
534
- * - value: What to search for.
535
- */
536
- FirefoxDriver.prototype.findElements = function(respond, parameters) {
537
- this.findElementsInternal_(respond, parameters.using, parameters.value);
538
- };
539
-
540
-
541
- /**
542
- * Searches for multiple elements on the page that are children of the
543
- * corresponding search parameter. The response value will be an array of UUIDs
544
- * for the located elements.
545
- * @param {{id: string, using: string, value: string}} parameters A JSON object
546
- * specifying the search parameters:
547
- * - id: UUID of the element to base the search from.
548
- * - using: A method to search with, as defined in the
549
- * {@code Firefox.ElementLocator} enum.
550
- * - value: What to search for.
551
- */
552
- FirefoxDriver.prototype.findChildElements = function(respond, parameters) {
553
- this.findElementsInternal_(respond, parameters.using, parameters.value, parameters.id);
554
- };
555
-
556
-
557
- FirefoxDriver.prototype.switchToFrame = function(respond, parameters) {
558
- var browser = respond.session.getBrowser();
559
- if (parameters.id == null) {
560
- respond.session.setWindow(respond.session.getBrowser().contentWindow);
561
- } else {
562
- var frameDoc = Utils.findDocumentInFrame(browser, parameters.id);
563
- if (frameDoc) {
564
- respond.session.setWindow(frameDoc.defaultView);
565
- } else {
566
- throw new WebDriverError(ErrorCode.NO_SUCH_FRAME,
567
- "Cannot find frame with id: " + parameters.id);
568
- }
569
- }
570
- respond.send();
571
- };
572
-
573
-
574
- FirefoxDriver.prototype.getActiveElement = function(respond) {
575
- var element = Utils.getActiveElement(respond.session.getDocument());
576
- var id = Utils.addToKnownElements(element, respond.session.getDocument());
577
-
578
- respond.value = {'ELEMENT':id};
579
- respond.send();
580
- };
581
-
582
-
583
- FirefoxDriver.prototype.goBack = function(respond) {
584
- var browser = respond.session.getBrowser();
585
-
586
- if (browser.canGoBack) {
587
- browser.goBack();
588
- }
589
-
590
- respond.send();
591
- };
592
-
593
-
594
- FirefoxDriver.prototype.goForward = function(respond) {
595
- var browser = respond.session.getBrowser();
596
-
597
- if (browser.canGoForward) {
598
- browser.goForward();
599
- }
600
-
601
- respond.send();
602
- };
603
-
604
-
605
- FirefoxDriver.prototype.refresh = function(respond) {
606
- var browser = respond.session.getBrowser();
607
- browser.contentWindow.location.reload(true);
608
- // Wait for the reload to finish before sending the response.
609
- new WebLoadingListener(respond.session.getBrowser(), function() {
610
- // Reset to the top window.
611
- respond.session.setWindow(browser.contentWindow);
612
- respond.send();
613
- });
614
- };
615
-
616
-
617
- FirefoxDriver.prototype.addCookie = function(respond, parameters) {
618
- var cookie = parameters.cookie;
619
-
620
- if (cookie.expiry) {
621
- cookie.expiry = cookie.expiry.time ? new Date(cookie.expiry.time) :
622
- new Date(cookie.expiry);
623
- } else {
624
- var date = new Date();
625
- date.setYear(2030);
626
- cookie.expiry = date;
627
- }
628
-
629
- cookie.expiry = cookie.expiry.getTime() / 1000; // Stored in seconds
630
-
631
- if (!cookie.domain) {
632
- var location = respond.session.getBrowser().contentWindow.location;
633
- cookie.domain = location.hostname;
634
- } else {
635
- var currLocation = respond.session.getBrowser().contentWindow.location;
636
- var currDomain = currLocation.host;
637
- if (currDomain.indexOf(cookie.domain) == -1) { // Not quite right, but close enough
638
- throw new WebDriverError(ErrorCode.INVALID_COOKIE_DOMAIN,
639
- "You may only set cookies for the current domain");
640
- }
641
- }
642
-
643
- // The cookie's domain may include a port. Which is bad. Remove it
644
- // We'll catch ip6 addresses by mistake. Since no-one uses those
645
- // this will be okay for now.
646
- if (cookie.domain.match(/:\d+$/)) {
647
- cookie.domain = cookie.domain.replace(/:\d+$/, "");
648
- }
649
-
650
- var document = respond.session.getDocument();
651
- if (!document || !document.contentType.match(/html/i)) {
652
- throw new WebDriverError(ErrorCode.UNABLE_TO_SET_COOKIE,
653
- "You may only set cookies on html documents");
654
- }
655
-
656
- var cookieManager =
657
- Utils.getService("@mozilla.org/cookiemanager;1", "nsICookieManager2");
658
-
659
- // The signature for "add" is different in firefox 3 and 2. We should sniff
660
- // the browser version and call the right version of the method, but for now
661
- // we'll use brute-force.
662
- try {
663
- cookieManager.add(cookie.domain, cookie.path, cookie.name, cookie.value,
664
- cookie.secure, false, cookie.expiry);
665
- } catch(e) {
666
- cookieManager.add(cookie.domain, cookie.path, cookie.name, cookie.value,
667
- cookie.secure, false, false, cookie.expiry);
668
- }
669
-
670
- respond.send();
671
- };
672
-
673
- function getVisibleCookies(location) {
674
- var results = [];
675
-
676
- var currentPath = location.pathname;
677
- if (!currentPath) currentPath = "/";
678
- var isForCurrentPath = function(aPath) {
679
- return currentPath.indexOf(aPath) != -1;
680
- };
681
- var cm = Utils.getService("@mozilla.org/cookiemanager;1", "nsICookieManager");
682
- var e = cm.enumerator;
683
- while (e.hasMoreElements()) {
684
- var cookie = e.getNext().QueryInterface(Components.interfaces["nsICookie"]);
685
-
686
- // Take the hostname and progressively shorten it
687
- var hostname = location.hostname;
688
- do {
689
- if ((cookie.host == "." + hostname || cookie.host == hostname)
690
- && isForCurrentPath(cookie.path)) {
691
- results.push(cookie);
692
- break;
693
- }
694
- hostname = hostname.replace(/^.*?\./, "");
695
- } while (hostname.indexOf(".") != -1);
696
- }
697
-
698
- return results;
699
- };
700
-
701
- FirefoxDriver.prototype.getCookies = function(respond) {
702
- var toReturn = [];
703
- var cookies = getVisibleCookies(respond.session.getBrowser().
704
- contentWindow.location);
705
- for (var i = 0; i < cookies.length; i++) {
706
- var cookie = cookies[i];
707
- toReturn.push({
708
- 'name': cookie.name,
709
- 'value': cookie.value,
710
- 'path': cookie.path,
711
- 'domain': cookie.host,
712
- 'secure': cookie.isSecure
713
- });
714
- }
715
-
716
- respond.value = toReturn;
717
- respond.send();
718
- };
719
-
720
-
721
- // This is damn ugly, but it turns out that just deleting a cookie from the document
722
- // doesn't always do The Right Thing
723
- FirefoxDriver.prototype.deleteCookie = function(respond, parameters) {
724
- var toDelete = parameters.name;
725
- var cm = Utils.getService("@mozilla.org/cookiemanager;1", "nsICookieManager");
726
-
727
- var cookies = getVisibleCookies(respond.session.getBrowser().
728
- contentWindow.location);
729
- for (var i = 0; i < cookies.length; i++) {
730
- var cookie = cookies[i];
731
- if (cookie.name == toDelete) {
732
- cm.remove(cookie.host, cookie.name, cookie.path, false);
733
- }
734
- }
735
-
736
- respond.send();
737
- };
738
-
739
-
740
- FirefoxDriver.prototype.deleteAllCookies = function(respond) {
741
- var cm = Utils.getService("@mozilla.org/cookiemanager;1", "nsICookieManager");
742
- var cookies = getVisibleCookies(respond.session.getBrowser().
743
- contentWindow.location);
744
-
745
- for (var i = 0; i < cookies.length; i++) {
746
- var cookie = cookies[i];
747
- cm.remove(cookie.host, cookie.name, cookie.path, false);
748
- }
749
-
750
- respond.send();
751
- };
752
-
753
-
754
- FirefoxDriver.prototype.setSpeed = function(respond, parameters) {
755
- if (!(parameters.speed in FirefoxDriver.Speed)) {
756
- var validSpeeds = [];
757
- for (var prop in FirefoxDriver.Speed) {
758
- validSpeeds.push(prop);
759
- }
760
- throw new WebDriverError(ErrorCode.UNHANDLED_ERROR,
761
- 'Speed value expected to be one of ' + JSON.stringify(validSpeeds) +
762
- ', but was "' + parameters.speed + '"');
763
- }
764
- respond.session.setInputSpeed(FirefoxDriver.Speed[parameters.speed]);
765
- respond.send();
766
- };
767
-
768
-
769
- FirefoxDriver.prototype.getSpeed = function(respond) {
770
- var speed = respond.session.getInputSpeed();
771
- for (var prop in FirefoxDriver.Speed) {
772
- if (FirefoxDriver.Speed[prop] == speed) {
773
- respond.value = prop;
774
- }
775
- }
776
- respond.send();
777
- };
778
-
779
-
780
- FirefoxDriver.prototype.implicitlyWait = function(respond, parameters) {
781
- respond.session.setImplicitWait(parameters.ms);
782
- respond.send();
783
- };
784
-
785
-
786
- FirefoxDriver.prototype.saveScreenshot = function(respond, pngFile) {
787
- var window = respond.session.getBrowser().contentWindow;
788
- try {
789
- var canvas = Screenshooter.grab(window);
790
- try {
791
- Screenshooter.save(canvas, pngFile);
792
- } catch(e) {
793
- throw new WebDriverError(ErrorCode.UNHANDLED_ERROR,
794
- 'Could not save screenshot to ' + pngFile + ' - ' + e);
795
- }
796
- } catch(e) {
797
- throw new WebDriverError(ErrorCode.UNHANDLED_ERROR,
798
- 'Could not take screenshot of current page - ' + e);
799
- }
800
- respond.send();
801
- };
802
-
803
-
804
- FirefoxDriver.prototype.screenshot = function(respond) {
805
- var window = respond.session.getBrowser().contentWindow;
806
- try {
807
- var canvas = Screenshooter.grab(window);
808
- respond.value = Screenshooter.toBase64(canvas);
809
- } catch (e) {
810
- throw new WebDriverError(ErrorCode.UNHANDLED_ERROR,
811
- 'Could not take screenshot of current page - ' + e);
812
- }
813
- respond.send();
814
- };
815
-
816
- FirefoxDriver.prototype.dismissAlert = function(respond, parameters) {
817
- var alertText = parameters.text;
818
- // TODO(simon): Is there a type for alerts?
819
- var wm = Utils.getService("@mozilla.org/appshell/window-mediator;1", "nsIWindowMediator");
820
- var allWindows = wm.getEnumerator("");
821
- while (allWindows.hasMoreElements()) {
822
- var alert = allWindows.getNext();
823
- var doc = alert.document;
824
- if (doc && doc.documentURI == "chrome://global/content/commonDialog.xul") {
825
- var dialog = doc.getElementsByTagName("dialog")[0];
826
- dialog.getButton("accept").click();
827
- break;
828
- }
829
- }
830
- respond.send();
831
- };