tor-browser

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

event-constructor.html (3593B)


      1 <!doctype html>
      2 <script src="/resources/testharness.js"></script>
      3 <script src="/resources/testharnessreport.js"></script>
      4 <script>
      5 test(() => {
      6  assert_throws_js(TypeError, () => {
      7    new NavigateEvent("navigate");
      8  });
      9 }, "can't bypass required members by omitting the dictionary entirely");
     10 
     11 test(() => {
     12  assert_throws_js(TypeError, () => {
     13    new NavigateEvent("navigate", {
     14      navigationType: "push",
     15      canIntercept: false,
     16      userInitiated: false,
     17      hashChange: false,
     18      signal: (new AbortController()).signal,
     19      formData: null,
     20      downloadRequest: null,
     21      info: null,
     22      sourceElement: null
     23    });
     24  });
     25 }, "destination is required");
     26 
     27 async_test(t => {
     28  // We need to grab an NavigationDestination.
     29  navigation.onnavigate = t.step_func_done(e => {
     30    assert_throws_js(TypeError, () => {
     31      new NavigateEvent("navigate", {
     32        navigationType: "push",
     33        destination: e.destination,
     34        canIntercept: false,
     35        userInitiated: false,
     36        hashChange: false,
     37        formData: null,
     38        downloadRequest: null,
     39        info: null,
     40        sourceElement: null
     41      });
     42    });
     43  });
     44  history.pushState(1, null, "#1");
     45 }, "signal is required");
     46 
     47 async_test(t => {
     48  // We need to grab an NavigationDestination.
     49  navigation.onnavigate = t.step_func_done(e => {
     50    const info = { some: "object with identity" };
     51    const formData = new FormData();
     52    const signal = (new AbortController()).signal;
     53    const downloadRequest = "abc";
     54    const hasUAVisualTransition = true;
     55    const sourceElement = document.createElement("a");
     56 
     57    const event = new NavigateEvent("navigate", {
     58      navigationType: "replace",
     59      destination: e.destination,
     60      canIntercept: true,
     61      userInitiated: true,
     62      hashChange: true,
     63      signal,
     64      formData,
     65      downloadRequest,
     66      info,
     67      hasUAVisualTransition,
     68      sourceElement
     69    });
     70 
     71    assert_equals(event.navigationType, "replace");
     72    assert_equals(event.destination, e.destination);
     73    assert_equals(event.canIntercept, true);
     74    assert_equals(event.userInitiated, true);
     75    assert_equals(event.hashChange, true);
     76    assert_equals(event.signal, signal);
     77    assert_equals(event.formData, formData);
     78    assert_equals(event.downloadRequest, downloadRequest);
     79    assert_equals(event.info, info);
     80    assert_equals(event.hasUAVisualTransition, hasUAVisualTransition);
     81    assert_equals(event.sourceElement, sourceElement);
     82  });
     83  history.pushState(2, null, "#2");
     84 }, "all properties are reflected back");
     85 
     86 async_test(t => {
     87  // We need to grab an NavigationDestination.
     88  navigation.onnavigate = t.step_func_done(e => {
     89    const event = new NavigateEvent("navigate", {
     90      destination: e.destination,
     91      signal: (new AbortController()).signal
     92    });
     93 
     94    assert_equals(event.navigationType, "push");
     95    assert_equals(event.canIntercept, false);
     96    assert_equals(event.userInitiated, false);
     97    assert_equals(event.hashChange, false);
     98    assert_equals(event.formData, null);
     99    assert_equals(event.downloadRequest, null);
    100    assert_equals(event.info, undefined);
    101    assert_equals(event.sourceElement, null);
    102  });
    103  history.pushState(3, null, "#3");
    104 }, "defaults are as expected");
    105 
    106 async_test(t => {
    107  navigation.onnavigate = t.step_func_done(e => {
    108    const event = new NavigateEvent("navigate", {
    109      destination: e.destination,
    110      signal: (new AbortController()).signal
    111    });
    112 
    113    assert_false(event.hasUAVisualTransition);
    114  });
    115  history.pushState(3, null, "#3");
    116 }, "hasUAVisualTransition is default false");
    117 </script>