test_element.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  3. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. const {utils: Cu} = Components;
  5. Cu.import("chrome://marionette/content/element.js");
  6. let el = {
  7. getBoundingClientRect: function() {
  8. return {
  9. top: 0,
  10. left: 0,
  11. width: 100,
  12. height: 100,
  13. };
  14. }
  15. };
  16. add_test(function test_coordinates() {
  17. let p = element.coordinates(el);
  18. ok(p.hasOwnProperty("x"));
  19. ok(p.hasOwnProperty("y"));
  20. equal("number", typeof p.x);
  21. equal("number", typeof p.y);
  22. deepEqual({x: 50, y: 50}, element.coordinates(el));
  23. deepEqual({x: 10, y: 10}, element.coordinates(el, 10, 10));
  24. deepEqual({x: -5, y: -5}, element.coordinates(el, -5, -5));
  25. Assert.throws(() => element.coordinates(null));
  26. Assert.throws(() => element.coordinates(el, "string", undefined));
  27. Assert.throws(() => element.coordinates(el, undefined, "string"));
  28. Assert.throws(() => element.coordinates(el, "string", "string"));
  29. Assert.throws(() => element.coordinates(el, {}, undefined));
  30. Assert.throws(() => element.coordinates(el, undefined, {}));
  31. Assert.throws(() => element.coordinates(el, {}, {}));
  32. Assert.throws(() => element.coordinates(el, [], undefined));
  33. Assert.throws(() => element.coordinates(el, undefined, []));
  34. Assert.throws(() => element.coordinates(el, [], []));
  35. run_next_test();
  36. });
  37. add_test(function test_isWebElementReference() {
  38. strictEqual(element.isWebElementReference({[element.Key]: "some_id"}), true);
  39. strictEqual(element.isWebElementReference({[element.LegacyKey]: "some_id"}), true);
  40. strictEqual(element.isWebElementReference(
  41. {[element.LegacyKey]: "some_id", [element.Key]: "2"}), true);
  42. strictEqual(element.isWebElementReference({}), false);
  43. strictEqual(element.isWebElementReference({"key": "blah"}), false);
  44. run_next_test();
  45. });