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