tor-browser

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

canShare.https.html (4491B)


      1 <!DOCTYPE html>
      2 <html>
      3  <head>
      4    <meta charset="utf-8" />
      5    <title>WebShare Test: canShare method tests</title>
      6    <script src="/resources/testharness.js"></script>
      7    <script src="/resources/testharnessreport.js"></script>
      8  </head>
      9  <body>
     10    <script>
     11      test(() => {
     12        assert_false(
     13          navigator.canShare(),
     14          "no arguments (uses default argument value, which is empty dictionary)"
     15        );
     16 
     17        assert_false(navigator.canShare({}), "empty dictionary not allowed");
     18 
     19        assert_false(navigator.canShare(undefined), "empty dictionary not allowed");
     20 
     21        assert_false(navigator.canShare(null), "empty dictionary not allowed");
     22 
     23        assert_false(
     24          navigator.canShare({ unused: "unexpected field" }),
     25          "results in empty dictionary, which is not allowed"
     26        );
     27      }, "canShare() empty and default dictionary");
     28 
     29      test(() => {
     30        assert_true(navigator.canShare({ url: "http://a.b" }), "http URL is ok");
     31 
     32        assert_true(navigator.canShare({ url: "https://a.b" }), "https URL is ok");
     33 
     34        assert_false(
     35          navigator.canShare({ url: "http://a.b:65536" }),
     36          "URL is invalid"
     37        );
     38 
     39        assert_false(
     40          navigator.canShare({ url: "data:the url" }),
     41          "data URL is not allowed"
     42        );
     43 
     44        assert_false(
     45          navigator.canShare({ url: "file:///usr/" }),
     46          "file URL is not allowed"
     47        );
     48 
     49        assert_true(
     50          navigator.canShare({
     51            url: "https://a.b/path?query#fragment",
     52          }),
     53          "canShare with URL"
     54        );
     55 
     56        assert_true(
     57          navigator.canShare({
     58            url: {
     59              toString() {
     60                return "https://a.b/";
     61              },
     62            },
     63          }),
     64          "canShare URL as with object with stringifier"
     65        );
     66 
     67        assert_true(
     68          navigator.canShare(
     69            { url: "" },
     70            "canShare with empty URL, which resolves as the doc's base URL"
     71          )
     72        );
     73 
     74        assert_true(
     75          navigator.canShare({
     76            url: "//a.b/path?query#fragment",
     77          }),
     78          "canShare with URL having no scheme"
     79        );
     80 
     81        assert_true(
     82          navigator.canShare({
     83            url: "relative",
     84          }),
     85          "canShare relative URL, resolved against API base URL"
     86        );
     87      }, "canShare() url member");
     88 
     89      test(() => {
     90        assert_false(
     91          navigator.canShare({ title: undefined }),
     92          "canShare with attribute undefined is equivalent to omitting the attribute"
     93        );
     94 
     95        assert_true(navigator.canShare({ title: "subject" }), "canShare with title");
     96 
     97        assert_true(navigator.canShare({ title: null }), "stringified null");
     98      }, "canShare() title member");
     99 
    100      test(() => {
    101        assert_true(navigator.canShare({ text: "" }), "ok to share empty text");
    102 
    103        assert_true(
    104          navigator.canShare({ text: "some text 🤔" }),
    105          "ok to share unicode"
    106        );
    107 
    108        assert_true(navigator.canShare({ text: 123 }), "number is stringified");
    109      }, "canShare() text member");
    110 
    111      test(() => {
    112        const file = new File(["hello"], "file", { type: "text/plain" });
    113        const file2 = new File([], "file2");
    114 
    115        assert_false(navigator.canShare({ files: [] }), "empty list is not allowed");
    116 
    117        assert_false(
    118          navigator.canShare({
    119            url: "https://a.b:800000",
    120            files: [file, file2],
    121          }),
    122          "invalid URL invalidates the share"
    123        );
    124 
    125        assert_true(
    126          navigator.canShare({ files: [file] }),
    127          "single file is ok to share"
    128        );
    129 
    130        assert_true(
    131          navigator.canShare({ files: [file, file2, file] }),
    132          "repeated files is ok to share"
    133        );
    134 
    135        assert_true(
    136          navigator.canShare({
    137            files: [file, file2],
    138            text: "some texts",
    139            url: "https://example.com/",
    140          }),
    141          "is ok to share files, text, and url together"
    142        );
    143      }, "canShare() files member");
    144 
    145      test(() => {
    146        assert_true(
    147          navigator.canShare({
    148            title: "subject",
    149            text: "body",
    150            url: "https://a.b/",
    151            files: [new File([], "file")],
    152            unused: "unexpected field",
    153          }),
    154          "canShare with unexpected field"
    155        );
    156      }, "canShare() multiple members");
    157    </script>
    158  </body>
    159 </html>