tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_navigate.js (2674B)


      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 
      5 const { navigate } = ChromeUtils.importESModule(
      6  "chrome://remote/content/marionette/navigate.sys.mjs"
      7 );
      8 
      9 const mockTopContext = {
     10  get children() {
     11    return [mockNestedContext];
     12  },
     13  id: 7,
     14  get top() {
     15    return this;
     16  },
     17 };
     18 
     19 const mockNestedContext = {
     20  id: 8,
     21  parent: mockTopContext,
     22  top: mockTopContext,
     23 };
     24 
     25 add_task(function test_isLoadEventExpectedForCurrent() {
     26  Assert.throws(
     27    () => navigate.isLoadEventExpected(undefined),
     28    /Expected at least one URL/
     29  );
     30 
     31  ok(navigate.isLoadEventExpected(new URL("http://a/")));
     32 });
     33 
     34 add_task(function test_isLoadEventExpectedForFuture() {
     35  const data = [
     36    { current: "http://a/", future: undefined, expected: true },
     37    { current: "http://a/", future: "http://a/", expected: true },
     38    { current: "http://a/", future: "http://a/#", expected: true },
     39    { current: "http://a/#", future: "http://a/", expected: true },
     40    { current: "http://a/#a", future: "http://a/#A", expected: true },
     41    { current: "http://a/#a", future: "http://a/#a", expected: false },
     42    { current: "http://a/", future: "javascript:whatever", expected: false },
     43  ];
     44 
     45  for (const entry of data) {
     46    const current = new URL(entry.current);
     47    const future = entry.future ? new URL(entry.future) : undefined;
     48    equal(navigate.isLoadEventExpected(current, { future }), entry.expected);
     49  }
     50 });
     51 
     52 add_task(function test_isLoadEventExpectedForTarget() {
     53  for (const target of ["_parent", "_top"]) {
     54    Assert.throws(
     55      () => navigate.isLoadEventExpected(new URL("http://a"), { target }),
     56      /Expected browsingContext when target is _parent or _top/
     57    );
     58  }
     59 
     60  const data = [
     61    { cur: "http://a/", target: "", expected: true },
     62    { cur: "http://a/", target: "_blank", expected: false },
     63    { cur: "http://a/", target: "_parent", bc: mockTopContext, expected: true },
     64    {
     65      cur: "http://a/",
     66      target: "_parent",
     67      bc: mockNestedContext,
     68      expected: false,
     69    },
     70    { cur: "http://a/", target: "_self", expected: true },
     71    { cur: "http://a/", target: "_top", bc: mockTopContext, expected: true },
     72    {
     73      cur: "http://a/",
     74      target: "_top",
     75      bc: mockNestedContext,
     76      expected: false,
     77    },
     78  ];
     79 
     80  for (const entry of data) {
     81    const current = entry.cur ? new URL(entry.cur) : undefined;
     82    equal(
     83      navigate.isLoadEventExpected(current, {
     84        target: entry.target,
     85        browsingContext: entry.bc,
     86      }),
     87      entry.expected
     88    );
     89  }
     90 });