tor-browser

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

test_ManifestProcessor_scope.html (3345B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1079453
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for Bug 1079453</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     11  <script src="common.js"></script>
     12  <script>
     13 
     14 /**
     15 * Manifest scope
     16 * https://w3c.github.io/manifest/#scope-member
     17 */
     18 "use strict";
     19 
     20 var expected = "Expect non-string scope to be the default";
     21 typeTests.forEach((type) => {
     22  data.jsonText = JSON.stringify({
     23    scope: type,
     24  });
     25  var result = processor.process(data);
     26  is(result.scope, new URL(".", docURL).href, expected);
     27 });
     28 
     29 expected = "Expect different origin to be the default";
     30 data.jsonText = JSON.stringify({
     31  scope: "http://not-same-origin",
     32 });
     33 var result = processor.process(data);
     34 is(result.scope, new URL(".", docURL).href, expected);
     35 
     36 expected = "Expect the empty string to be the default";
     37 data.jsonText = JSON.stringify({
     38  scope: "",
     39 });
     40 result = processor.process(data);
     41 is(result.scope, new URL(".", docURL).href, expected);
     42 
     43 expected = "Resolve URLs relative to manifest.";
     44 var URLs = ["path", "/path", "../../path"];
     45 URLs.forEach((url) => {
     46  data.jsonText = JSON.stringify({
     47    scope: url,
     48    start_url: "/path",
     49  });
     50  var absURL = new URL(url, manifestURL).toString();
     51  result = processor.process(data);
     52  is(result.scope, absURL, expected);
     53 });
     54 
     55 expected = "If start URL is not in scope, return the default.";
     56 data.jsonText = JSON.stringify({
     57  scope: "foo",
     58  start_url: "bar",
     59 });
     60 result = processor.process(data);
     61 let expected_start = new URL("bar", docURL);
     62 is(result.scope, new URL(document.location.origin).href, expected);
     63 
     64 expected = "If start URL is in scope, use the scope.";
     65 data.jsonText = JSON.stringify({
     66  start_url: "foobar",
     67  scope: "foo",
     68 });
     69 result = processor.process(data);
     70 is(result.scope.toString(), new URL("foo", manifestURL).toString(), expected);
     71 
     72 expected = "Expect start_url to be " + new URL("foobar", manifestURL).toString();
     73 is(result.start_url.toString(), new URL("foobar", manifestURL).toString(), expected);
     74 
     75 expected = "If start URL is in scope, use the scope.";
     76 data.jsonText = JSON.stringify({
     77  start_url: "/foo/",
     78  scope: "/foo/",
     79 });
     80 result = processor.process(data);
     81 is(result.scope.toString(), new URL("/foo/", manifestURL).toString(), expected);
     82 
     83 expected = "If start URL is in scope, use the scope.";
     84 data.jsonText = JSON.stringify({
     85  start_url: ".././foo/",
     86  scope: "../foo/",
     87 });
     88 result = processor.process(data);
     89 is(result.scope.toString(), new URL("/foo/", manifestURL).toString(), expected);
     90 
     91 expected = "scope member has the URL's query removed.";
     92 data.jsonText = JSON.stringify({
     93  scope: "./test/?a=b&a=b&b=c&c=d&e",
     94 });
     95 result = processor.process(data);
     96 is(new URL(result.scope).search, "", expected);
     97 
     98 expected = "scope member has the URL's fragment removed.";
     99 data.jsonText = JSON.stringify({
    100  scope: "./test/#fragment"
    101 });
    102 result = processor.process(data);
    103 is(new URL(result.scope).hash, "", expected);
    104 
    105 expected = "scope member has the URL's query and fragment removed.";
    106 data.jsonText = JSON.stringify({
    107  scope: "./test/?a=b&a=b&b=c&c=d&e#fragment"
    108 });
    109 result = processor.process(data);
    110 is(new URL(result.scope).search, "", expected);
    111 is(new URL(result.scope).hash, "", expected);
    112  </script>
    113 </head>