Bug 1400233 - Remove ContentWebElement.LegacyIdentifier key from Marionette; r?ato draft
authorwambui <wambui.dev@gmail.com>
Wed, 21 Mar 2018 07:26:19 +0300
changeset 770383 03e98994cc009311ed83b400a4fefbb91c26d9d3
parent 766749 1b0807f27f965487d1bc23b4a83f606e76028567
push id103396
push userbmo:wambui.dev@gmail.com
push dateWed, 21 Mar 2018 05:10:41 +0000
reviewersato
bugs1400233
milestone61.0a1
Bug 1400233 - Remove ContentWebElement.LegacyIdentifier key from Marionette; r?ato Marionette currently uses the ContentWebElement.Identifier key but also has the legacy key. The key is removed by making changes to testing/marionette/element.js, testing/marionette/test_element.js and testing/marionette/client/marionette_driver/marionette.py. MozReview-Commit-ID: J12uSJikQDY
moz.configure
testing/marionette/client/marionette_driver/marionette.py
testing/marionette/element.js
testing/marionette/test_element.js
--- a/moz.configure
+++ b/moz.configure
@@ -541,18 +541,16 @@ def nsis_binary_type(nsis):
 def nsis_flags(host):
     if host.kernel != 'WINNT':
         return '-nocd'
     return ''
 
 set_config('MAKENSISU_FLAGS', nsis_flags)
 
 check_prog('7Z', ('7z', '7za'), allow_missing=True, when=target_is_windows)
-# Automatically download and use compiled C++ components:
-ac_add_options --enable-artifact-builds
 
 # Fallthrough to autoconf-based configure
 include('build/moz.configure/old.configure')
 
 @imports('__sandbox__')
 def all_paths():
     return __sandbox__._all_paths
 
--- a/testing/marionette/client/marionette_driver/marionette.py
+++ b/testing/marionette/client/marionette_driver/marionette.py
@@ -20,18 +20,17 @@ from six import reraise
 
 from . import errors
 from . import transport
 from .decorators import do_process_check
 from .geckoinstance import GeckoInstance
 from .keys import Keys
 from .timeout import Timeouts
 
-
-W3C_WEBELEMENT_KEY = "element-6066-11e4-a52e-4f735466cecf"
+WEB_ELEMENT_KEY = "element-6066-11e4-a52e-4f735466cecf"
 
 
 class HTMLElement(object):
     """Represents a DOM Element."""
 
     def __init__(self, marionette, id):
         self.marionette = marionette
         assert(id is not None)
@@ -746,18 +745,18 @@ class Marionette(object):
             self._handle_error(err)
 
         if key is not None:
             return self._unwrap_response(res.get(key))
         else:
             return self._unwrap_response(res)
 
     def _unwrap_response(self, value):
-        if isinstance(value, dict) and W3C_WEBELEMENT_KEY in value:
-            return HTMLElement(self, value.get(W3C_WEBELEMENT_KEY))
+        if isinstance(value, dict) and WEB_ELEMENT_KEY in value:
+            return HTMLElement(self, value.get(WEB_ELEMENT_KEY))
         elif isinstance(value, list):
             return list(self._unwrap_response(item) for item in value)
         else:
             return value
 
     def _handle_error(self, obj):
         error = obj["error"]
         message = obj["message"]
@@ -1644,31 +1643,31 @@ class Marionette(object):
             wrapped = []
             for arg in args:
                 wrapped.append(self._to_json(arg))
         elif isinstance(args, dict):
             wrapped = {}
             for arg in args:
                 wrapped[arg] = self._to_json(args[arg])
         elif type(args) == HTMLElement:
-            wrapped = {W3C_WEBELEMENT_KEY: args.id}
+            wrapped = {WEB_ELEMENT_KEY: args.id}
         elif (isinstance(args, bool) or isinstance(args, basestring) or
               isinstance(args, int) or isinstance(args, float) or args is None):
             wrapped = args
         return wrapped
 
     def _from_json(self, value):
         if isinstance(value, list):
             unwrapped = []
             for item in value:
                 unwrapped.append(self._from_json(item))
         elif isinstance(value, dict):
             unwrapped = {}
             for key in value:
-                if key == W3C_WEBELEMENT_KEY:
+                if key == WEB_ELEMENT_KEY:
                     unwrapped = HTMLElement(self, value[key])
                     break
                 else:
                     unwrapped[key] = self._from_json(value[key])
         else:
             unwrapped = value
         return unwrapped
 
--- a/testing/marionette/element.js
+++ b/testing/marionette/element.js
@@ -1545,17 +1545,17 @@ this.WebElement = WebElement;
 
 /**
  * DOM elements are represented as web elements when they are
  * transported over the wire protocol.
  */
 class ContentWebElement extends WebElement {
   toJSON() {
     return {
-      [ContentWebElement.Identifier]: this.uuid
+      [ContentWebElement.Identifier]: this.uuid,
     };
   }
 
   static fromJSON(json) {
     const {Identifier} = ContentWebElement;
 
     if (!(Identifier in json)) {
       throw new InvalidArgumentError(
@@ -1572,17 +1572,17 @@ this.ContentWebElement = ContentWebEleme
 /**
  * Top-level browsing contexts, such as <code>WindowProxy</code>
  * whose <code>opener</code> is null, are represented as web windows
  * over the wire protocol.
  */
 class ContentWebWindow extends WebElement {
   toJSON() {
     return {
-      [ContentWebWindow.Identifier]: this.uuid
+      [ContentWebWindow.Identifier]: this.uuid,
     };
   }
 
   static fromJSON(json) {
     if (!(ContentWebWindow.Identifier in json)) {
       throw new InvalidArgumentError(
           pprint`Expected web window reference, got: ${json}`);
     }
@@ -1596,17 +1596,17 @@ this.ContentWebWindow = ContentWebWindow
 /**
  * Nested browsing contexts, such as the <code>WindowProxy</code>
  * associated with <tt>&lt;frame&gt;</tt> and <tt>&lt;iframe&gt;</tt>,
  * are represented as web frames over the wire protocol.
  */
 class ContentWebFrame extends WebElement {
   toJSON() {
     return {
-      [ContentWebFrame.Identifier]: this.uuid
+      [ContentWebFrame.Identifier]: this.uuid,
     };
   }
 
   static fromJSON(json) {
     if (!(ContentWebFrame.Identifier in json)) {
       throw new InvalidArgumentError(
           pprint`Expected web frame reference, got: ${json}`);
     }
@@ -1619,17 +1619,17 @@ this.ContentWebFrame = ContentWebFrame;
 
 /**
  * XUL elements in chrome space are represented as chrome web elements
  * over the wire protocol.
  */
 class ChromeWebElement extends WebElement {
   toJSON() {
     return {
-      [ChromeWebElement.Identifier]: this.uuid
+      [ChromeWebElement.Identifier]: this.uuid,
     };
   }
 
   static fromJSON(json) {
     if (!(ChromeWebElement.Identifier in json)) {
       throw new InvalidArgumentError("Expected chrome element reference " +
           pprint`for XUL/XBL element, got: ${json}`);
     }
--- a/testing/marionette/test_element.js
+++ b/testing/marionette/test_element.js
@@ -353,47 +353,25 @@ add_test(function test_WebElement_from()
   ok(WebElement.from(xulEl) instanceof ChromeWebElement);
 
   Assert.throws(() => WebElement.from({}), InvalidArgumentError);
 
   run_next_test();
 });
 
 add_test(function test_WebElement_fromJSON_ContentWebElement() {
-  const {Identifier, LegacyIdentifier} = ContentWebElement;
-
-  let refNew = {[Identifier]: "foo"};
-  let webElNew = WebElement.fromJSON(refNew);
-  ok(webElNew instanceof ContentWebElement);
-  equal(webElNew.uuid, "foo");
-
-  let refOld = {[LegacyIdentifier]: "foo"};
-  let webElOld = WebElement.fromJSON(refOld);
-  ok(webElOld instanceof ContentWebElement);
-  equal(webElOld.uuid, "foo");
+  const {Identifier} = ContentWebElement;
 
-  ok(webElNew.is(webElOld));
-  ok(webElOld.is(webElNew));
-
-  let refBoth = {
-    [Identifier]: "foo",
-    [LegacyIdentifier]: "foo",
-  };
-  let webElBoth = WebElement.fromJSON(refBoth);
-  ok(webElBoth instanceof ContentWebElement);
-  equal(webElBoth.uuid, "foo");
-
-  ok(webElBoth.is(webElNew));
-  ok(webElBoth.is(webElOld));
-  ok(webElNew.is(webElBoth));
-  ok(webElOld.is(webElBoth));
+  let ref = {[Identifier]: "foo"};
+  let webEl = WebElement.fromJSON(ref);
+  ok(webEl instanceof ContentWebElement);
+  equal(webEl.uuid, "foo");
 
   let identifierPrecedence = {
     [Identifier]: "identifier-uuid",
-    [LegacyIdentifier]: "legacyidentifier-uuid",
   };
   let precedenceEl = WebElement.fromJSON(identifierPrecedence);
   ok(precedenceEl instanceof ContentWebElement);
   equal(precedenceEl.uuid, "identifier-uuid");
 
   run_next_test();
 });
 
@@ -445,61 +423,46 @@ add_test(function test_WebElement_fromUU
 });
 
 add_test(function test_WebElement_isReference() {
   for (let t of [42, true, "foo", [], {}]) {
     ok(!WebElement.isReference(t));
   }
 
   ok(WebElement.isReference({[ContentWebElement.Identifier]: "foo"}));
-  ok(WebElement.isReference({[ContentWebElement.LegacyIdentifier]: "foo"}));
   ok(WebElement.isReference({[ContentWebWindow.Identifier]: "foo"}));
   ok(WebElement.isReference({[ContentWebFrame.Identifier]: "foo"}));
   ok(WebElement.isReference({[ChromeWebElement.Identifier]: "foo"}));
 
   run_next_test();
 });
 
 add_test(function test_WebElement_generateUUID() {
   equal(typeof WebElement.generateUUID(), "string");
   run_next_test();
 });
 
 add_test(function test_ContentWebElement_toJSON() {
-  const {Identifier, LegacyIdentifier} = ContentWebElement;
+  const {Identifier} = ContentWebElement;
 
   let el = new ContentWebElement("foo");
   let json = el.toJSON();
 
   ok(Identifier in json);
-  ok(LegacyIdentifier in json);
   equal(json[Identifier], "foo");
-  equal(json[LegacyIdentifier], "foo");
 
   run_next_test();
 });
 
 add_test(function test_ContentWebElement_fromJSON() {
-  const {Identifier, LegacyIdentifier} = ContentWebElement;
-
-  let newEl = ContentWebElement.fromJSON({[Identifier]: "foo"});
-  ok(newEl instanceof ContentWebElement);
-  equal(newEl.uuid, "foo");
+  const {Identifier} = ContentWebElement;
 
-  let oldEl = ContentWebElement.fromJSON({[LegacyIdentifier]: "foo"});
-  ok(oldEl instanceof ContentWebElement);
-  equal(oldEl.uuid, "foo");
-
-  let bothRef = {
-    [Identifier]: "identifier-uuid",
-    [LegacyIdentifier]: "legacyidentifier-foo",
-  };
-  let bothEl = ContentWebElement.fromJSON(bothRef);
-  ok(bothEl instanceof ContentWebElement);
-  equal(bothEl.uuid, "identifier-uuid");
+  let el = ContentWebElement.fromJSON({[Identifier]: "foo"});
+  ok(el instanceof ContentWebElement);
+  equal(el.uuid, "foo");
 
   Assert.throws(() => ContentWebElement.fromJSON({}), InvalidArgumentError);
 
   run_next_test();
 });
 
 add_test(function test_ContentWebWindow_toJSON() {
   let win = new ContentWebWindow("foo");