test_navigate.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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.importGlobalProperties(["URL"]);
  6. Cu.import("chrome://marionette/content/navigate.js");
  7. add_test(function test_isLoadEventExpected() {
  8. Assert.throws(() => navigate.isLoadEventExpected(undefined),
  9. /Expected at least one URL/);
  10. equal(true, navigate.isLoadEventExpected("http://a/"));
  11. equal(true, navigate.isLoadEventExpected("http://a/", "http://a/"));
  12. equal(true, navigate.isLoadEventExpected("http://a/", "http://a/b"));
  13. equal(true, navigate.isLoadEventExpected("http://a/", "http://b"));
  14. equal(true, navigate.isLoadEventExpected("http://a/", "data:text/html;charset=utf-8,foo"));
  15. equal(true, navigate.isLoadEventExpected("about:blank", "http://a/"));
  16. equal(true, navigate.isLoadEventExpected("http://a/", "about:blank"));
  17. equal(true, navigate.isLoadEventExpected("http://a/", "https://a/"));
  18. equal(false, navigate.isLoadEventExpected("http://a/", "javascript:whatever"));
  19. equal(false, navigate.isLoadEventExpected("http://a/", "http://a/#"));
  20. equal(false, navigate.isLoadEventExpected("http://a/", "http://a/#b"));
  21. equal(false, navigate.isLoadEventExpected("http://a/#b", "http://a/#b"));
  22. equal(false, navigate.isLoadEventExpected("http://a/#b", "http://a/#c"));
  23. equal(false, navigate.isLoadEventExpected("data:text/html;charset=utf-8,foo", "data:text/html;charset=utf-8,foo#bar"));
  24. equal(false, navigate.isLoadEventExpected("data:text/html;charset=utf-8,foo", "data:text/html;charset=utf-8,foo#"));
  25. run_next_test();
  26. });
  27. add_test(function test_IdempotentURL() {
  28. Assert.throws(() => new navigate.IdempotentURL(undefined));
  29. Assert.throws(() => new navigate.IdempotentURL(true));
  30. Assert.throws(() => new navigate.IdempotentURL({}));
  31. Assert.throws(() => new navigate.IdempotentURL(42));
  32. // propagated URL properties
  33. let u1 = new URL("http://a/b");
  34. let u2 = new navigate.IdempotentURL(u1);
  35. equal(u1.host, u2.host);
  36. equal(u1.hostname, u2.hostname);
  37. equal(u1.href, u2.href);
  38. equal(u1.origin, u2.origin);
  39. equal(u1.password, u2.password);
  40. equal(u1.port, u2.port);
  41. equal(u1.protocol, u2.protocol);
  42. equal(u1.search, u2.search);
  43. equal(u1.username, u2.username);
  44. // specialisations
  45. equal("#b", new navigate.IdempotentURL("http://a/#b").hash);
  46. equal("#", new navigate.IdempotentURL("http://a/#").hash);
  47. equal("", new navigate.IdempotentURL("http://a/").hash);
  48. equal("#bar", new navigate.IdempotentURL("data:text/html;charset=utf-8,foo#bar").hash);
  49. equal("#", new navigate.IdempotentURL("data:text/html;charset=utf-8,foo#").hash);
  50. equal("", new navigate.IdempotentURL("data:text/html;charset=utf-8,foo").hash);
  51. equal("/", new navigate.IdempotentURL("http://a/").pathname);
  52. equal("/", new navigate.IdempotentURL("http://a/#b").pathname);
  53. equal("text/html;charset=utf-8,foo", new navigate.IdempotentURL("data:text/html;charset=utf-8,foo#bar").pathname);
  54. run_next_test();
  55. });