tor-browser

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

browser_target_get-front.js (3183B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 add_task(async function () {
      5  const tab = await addTab("about:blank");
      6  const target = await createAndAttachTargetForTab(tab);
      7 
      8  const tab2 = await addTab("about:blank");
      9  const target2 = await createAndAttachTargetForTab(tab2);
     10 
     11  info("Test the targetFront attribute for the root");
     12  const { client } = target;
     13  is(
     14    client.mainRoot.targetFront,
     15    null,
     16    "got null from the targetFront attribute for the root"
     17  );
     18  is(
     19    client.mainRoot.parentFront,
     20    null,
     21    "got null from the parentFront attribute for the root"
     22  );
     23 
     24  info("Test getting a front twice");
     25  const getAccessibilityFront = await target.getFront("accessibility");
     26  const getAccessibilityFront2 = await target.getFront("accessibility");
     27  is(
     28    getAccessibilityFront,
     29    getAccessibilityFront2,
     30    "got the same front when calling getFront twice"
     31  );
     32  is(
     33    getAccessibilityFront.targetFront,
     34    target,
     35    "got the correct targetFront attribute from the front"
     36  );
     37  is(
     38    getAccessibilityFront2.targetFront,
     39    target,
     40    "got the correct targetFront attribute from the front"
     41  );
     42  is(
     43    getAccessibilityFront.parentFront,
     44    target,
     45    "got the correct parentFront attribute from the front"
     46  );
     47  is(
     48    getAccessibilityFront2.parentFront,
     49    target,
     50    "got the correct parentFront attribute from the front"
     51  );
     52 
     53  info("Test getting a front on different targets");
     54  const target1Front = await target.getFront("accessibility");
     55  const target2Front = await target2.getFront("accessibility");
     56  is(
     57    target1Front !== target2Front,
     58    true,
     59    "got different fronts when calling getFront on different targets"
     60  );
     61  is(
     62    target1Front.targetFront !== target2Front.targetFront,
     63    true,
     64    "got different targetFront from different fronts from different targets"
     65  );
     66  is(
     67    target2Front.targetFront,
     68    target2,
     69    "got the correct targetFront attribute from the front"
     70  );
     71 
     72  info("Test async front retrieval");
     73  // use two fronts that are initialized one after the other.
     74  const asyncFront1 = target.getFront("accessibility");
     75  const asyncFront2 = target.getFront("accessibility");
     76 
     77  info("waiting on async fronts returns a real front");
     78  const awaitedAsyncFront1 = await asyncFront1;
     79  const awaitedAsyncFront2 = await asyncFront2;
     80  is(
     81    awaitedAsyncFront1,
     82    awaitedAsyncFront2,
     83    "got the same front when requesting the front first async then sync"
     84  );
     85  await target.destroy();
     86  await target2.destroy();
     87 
     88  info("destroying a front immediately is possible");
     89  await testDestroy();
     90 });
     91 
     92 async function testDestroy() {
     93  // initialize a clean target
     94  const tab = await addTab("about:blank");
     95  const target = await createAndAttachTargetForTab(tab);
     96 
     97  // do not wait for the front to finish loading
     98  target.getFront("accessibility");
     99 
    100  try {
    101    await target.destroy();
    102    ok(
    103      true,
    104      "calling destroy on an async front instantiated with getFront does not throw"
    105    );
    106  } catch (e) {
    107    ok(
    108      false,
    109      "calling destroy on an async front instantiated with getFront does not throw"
    110    );
    111  }
    112 }