tor-browser

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

window-scroll-arguments.html (2304B)


      1 <!DOCTYPE HTML>
      2 <link rel="help"
      3  href="https://drafts.csswg.org/cssom-view/#extensions-to-the-window-interface">
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <!--
      7  This test makes sure that calling the window scrolling methods with a single
      8  non-dictionary argument or with a dictionary whose 'behavior' field is invalid
      9  throws an exception.
     10 -->
     11 <div style="height: 1000px; width: 1000px; border: 1px solid black;">
     12  Scrollable area to test.
     13 </div>
     14 <script type="text/javascript">
     15  "use strict";
     16 
     17  const x = 25;
     18  const y = 50;
     19 
     20  function reset() {
     21    window.scrollTo(0, 0);
     22  }
     23 
     24  let scroll_methods = [window.scrollTo, window.scroll, window.scrollBy];
     25 
     26  for (const scroll_method of scroll_methods) {
     27    promise_test(async (test) => {
     28      reset();
     29      try {
     30        await scroll_method();
     31      } catch(e) {
     32        assert_unreached(e);
     33      }
     34    }, scroll_method.name + " with 0 arguments");
     35 
     36    promise_test(async (test) => {
     37      reset();
     38      await promise_rejects_js(test, TypeError, scroll_method(x));
     39    }, scroll_method.name + " with 1 non-dictionary argument");
     40 
     41    promise_test(async (test) => {
     42      reset();
     43      try {
     44        await scroll_method({ });
     45        await scroll_method({ left: x });
     46        await scroll_method({ top: y });
     47        await scroll_method({ behavior: "auto" });
     48        await scroll_method({ behavior: "instant" });
     49        await scroll_method({ behavior: "smooth" });
     50        await scroll_method({ left: x, top: y });
     51        await scroll_method({ left: x, top: y, behavior: "auto" });
     52        await scroll_method({ left: x, top: y, behavior: "instant" });
     53        await scroll_method({ left: x, top: y, behavior: "smooth" });
     54      } catch(e) {
     55        assert_unreached(e);
     56      }
     57    }, scroll_method.name + " with a valid ScrollToOptions argument");
     58 
     59    promise_test(async (test) => {
     60      reset();
     61      await promise_rejects_js(test, TypeError, scroll_method({ behavior: "" }));
     62      await promise_rejects_js(test, TypeError, scroll_method({ left: x, top: y, behavior: "abcd" }));
     63      await promise_rejects_js(test, TypeError, scroll_method({ left: x, top: y, behavior: 200 }));
     64    }, scroll_method.name + " with an invalid ScrollToOptions argument");
     65  }
     66 </script>