Bug 1250102 - Turn element keys into constants; r=automatedtester
authorAndreas Tolfsen <ato@mozilla.com>
Tue, 23 Feb 2016 15:03:05 +0000
changeset 321767 9a57362d5fcaf0acc056f2e52576d695f8eccda6
parent 321766 c73978b005c82ad5673765fc200a34d5cffbdfa9
child 321768 2b7d91ef032698b52d2409a094362623d571f8ed
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersautomatedtester
bugs1250102
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1250102 - Turn element keys into constants; r=automatedtester MozReview-Commit-ID: 5r6MuIcTwbJ
testing/marionette/element.js
--- a/testing/marionette/element.js
+++ b/testing/marionette/element.js
@@ -55,18 +55,16 @@ this.PARTIAL_LINK_TEXT = "partial link t
 this.TAG = "tag name";
 this.XPATH = "xpath";
 this.ANON= "anon";
 this.ANON_ATTRIBUTE = "anon attribute";
 
 this.ElementManager = function ElementManager(notSupported) {
   this.seenItems = {};
   this.timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
-  this.elementKey = 'ELEMENT';
-  this.w3cElementKey = 'element-6066-11e4-a52e-4f735466cecf';
   this.elementStrategies = [CLASS_NAME, SELECTOR, ID, NAME, LINK_TEXT, PARTIAL_LINK_TEXT, TAG, XPATH, ANON, ANON_ATTRIBUTE];
   for (let i = 0; i < notSupported.length; i++) {
     this.elementStrategies.splice(this.elementStrategies.indexOf(notSupported[i]), 1);
   }
 }
 
 ElementManager.prototype = {
   /**
@@ -215,17 +213,17 @@ ElementManager.prototype = {
 
           }
         }
         else if (val == null) {
           result = null;
         }
         else if (val.nodeType == 1) {
           let elementId = this.addToKnownElements(val);
-          result = {[this.elementKey]: elementId, [this.w3cElementKey]: elementId};
+          result = {[element.LegacyKey]: elementId, [element.Key]: elementId};
         }
         else {
           result = {};
           for (let prop in val) {
             result[prop] = this.wrapValue(val[prop]);
           }
         }
         break;
@@ -259,20 +257,20 @@ ElementManager.prototype = {
           converted = null;
         }
         else if (Object.prototype.toString.call(args) == '[object Array]') {
           converted = [];
           for (let i in args) {
             converted.push(this.convertWrappedArguments(args[i], container));
           }
         }
-        else if (((typeof(args[this.elementKey]) === 'string') && args.hasOwnProperty(this.elementKey)) ||
-                 ((typeof(args[this.w3cElementKey]) === 'string') &&
-                     args.hasOwnProperty(this.w3cElementKey))) {
-          let elementUniqueIdentifier = args[this.w3cElementKey] ? args[this.w3cElementKey] : args[this.elementKey];
+        else if (((typeof(args[element.LegacyKey]) === 'string') && args.hasOwnProperty(element.LegacyKey)) ||
+                 ((typeof(args[element.Key]) === 'string') &&
+                     args.hasOwnProperty(element.Key))) {
+          let elementUniqueIdentifier = args[element.Key] ? args[element.Key] : args[element.LegacyKey];
           converted = this.getKnownElement(elementUniqueIdentifier, container);
           if (converted == null) {
             throw new WebDriverError(`Unknown element: ${elementUniqueIdentifier}`);
           }
         }
         else {
           converted = {};
           for (let prop in args) {
@@ -594,16 +592,18 @@ ElementManager.prototype = {
         throw new InvalidSelectorError(`No such strategy: ${using}`);
     }
     return elements;
   },
 };
 
 
 this.element = {};
+element.LegacyKey = "ELEMENT";
+element.Key = "element-6066-11e4-a52e-4f735466cecf";
 element.generateUUID = function() {
   let uuid = uuidGen.generateUUID().toString();
   return uuid.substring(1, uuid.length - 1);
 };
 
 /**
  * This function generates a pair of coordinates relative to the viewport
  * given a target element and coordinates relative to that element's
@@ -626,17 +626,17 @@ element.coordinates = function(node, x =
   }
   if (!y) {
     y = box.height / 2.0;
   }
   return {
     x: box.left + x,
     y: box.top + y,
   };
-}
+};
 
 /**
  * This function returns true if the node is in the viewport.
  *
  * @param {Element} element
  *     Target element.
  * @param {number=} x
  *     Horizontal offset relative to target.  Defaults to the centre of