Bug 1481836 [wpt PR 12355] - Introduced dictionary TrustedTypePolicyOptions, a=testonly
authorMaja Kabus <kabusm@google.com>
Mon, 20 Aug 2018 22:12:14 +0000
changeset 490452 a22032eb15789ebed9e72db4f62b6f19be1068a2
parent 490451 2d4c8ba18f28ffb2bf23a249764cee85bf06c8ef
child 490453 79b00799a592f445a7531abf9f324f4c9d86c6c2
push id1815
push userffxbld-merge
push dateMon, 15 Oct 2018 10:40:45 +0000
treeherdermozilla-release@18d4c09e9378 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1481836, 12355, 739170, 1167282, 584038
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1481836 [wpt PR 12355] - Introduced dictionary TrustedTypePolicyOptions, a=testonly Automatic update from web-platform-testsIntroduced dictionary TrustedTypePolicyOptions Created new dictionary TrustedTypePolicyOptions with callbacks and adjusted TrustedTypePolicyFactory and TrustedTypePolicy to accept the dictionary. Added createURL() and createScriptURL, and adjusted createHTML() in TrustedTypePolicyOptions. Bug: 739170 Change-Id: Ie63fdf90b5aac53188fcd8141c95d287c3e726fd Reviewed-on: https://chromium-review.googlesource.com/1167282 Reviewed-by: Mike West <mkwst@chromium.org> Reviewed-by: Yuki Shiino <yukishiino@chromium.org> Commit-Queue: Maja Kabus <kabusm@google.com> Cr-Commit-Position: refs/heads/master@{#584038} -- wpt-commits: fa06664dc85df3024762f5e082e05aa293f90d88 wpt-pr: 12355
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/trusted-types/TrustedTypePolicyFactory-createPolicy.tentative.html
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -643895,17 +643895,17 @@
    "a8d4e78b06d124b05aa640aad563b3d9e9003046",
    "testharness"
   ],
   "trusted-types/TrustedScriptURL.tentative.html": [
    "92bc87f1e1da3eec8a0d597687e04857ad079359",
    "testharness"
   ],
   "trusted-types/TrustedTypePolicyFactory-createPolicy.tentative.html": [
-   "863fe847141f9705bb5bc02fcb8f0b6f923c4aa8",
+   "a37b5a7197f264bb8f75e1582debff5a53cd8d5e",
    "testharness"
   ],
   "trusted-types/TrustedURL.tentative.html": [
    "5048326fad81af68915b9f83b56da375388fcbef",
    "testharness"
   ],
   "trusted-types/Window-trustedTypes.tentative.html": [
    "ef4487749dd0c12a00bd3ab42c1353467a6eeb8f",
--- a/testing/web-platform/tests/trusted-types/TrustedTypePolicyFactory-createPolicy.tentative.html
+++ b/testing/web-platform/tests/trusted-types/TrustedTypePolicyFactory-createPolicy.tentative.html
@@ -1,14 +1,229 @@
 <!DOCTYPE html>
 <script src="/resources/testharness.js" ></script>
 <script src="/resources/testharnessreport.js"></script>
 <script src="support/helper.sub.js"></script>
 <body>
 <script>
+  //Policy name test
   async_test(t => {
-    var policy = window.trustedTypes.createPolicy('SomeName')
+    let policy = window.trustedTypes.createPolicy('SomeName', { createHTML: s => s } )
         .then(t.step_func_done(policy => {
-           assert_true(policy instanceof TrustedTypePolicy);
-           assert_equals(policy.name, 'SomeName');
+            assert_true(policy instanceof TrustedTypePolicy);
+            assert_equals(policy.name, 'SomeName');
     }));
   }, "policy.name = name");
+
+  //HTML tests
+  function createHTMLTest(policy, expectedHTML, t) {
+    let p = window.trustedTypes.createPolicy('SomeName', policy)
+        .then(t.step_func_done(p => {
+            assert_true(p.createHTML('whatever') instanceof TrustedHTML);
+            assert_equals(p.createHTML('whatever') + "", expectedHTML);
+    }));
+  }
+
+  async_test(t => {
+    createHTMLTest( { createHTML: s => s }, 'whatever', t);
+  }, "html = identity function");
+
+  async_test(t => {
+    createHTMLTest( { createHTML: s => null }, "null", t);
+  }, "html = null");
+
+  var HTMLstr = 'well, ';
+  async_test(t => {
+    createHTMLTest( { createHTML: s => HTMLstr + s }, HTMLstr + 'whatever', t);
+  }, "html = string + global string");
+
+  var HTMLx = 'global';
+  async_test(t => {
+    let p = window.trustedTypes.createPolicy('SomeName', {
+        createHTML: s => { HTMLx = s; return s; }
+      })
+      .then(t.step_func_done(p => {
+        assert_true(p.createHTML('whatever') instanceof TrustedHTML);
+        assert_equals(p.createHTML('whatever') + "", 'whatever');
+        assert_equals(HTMLx, 'whatever');
+    }));
+  }, "html = identity function, global string changed");
+
+  async_test(t => {
+    let p = window.trustedTypes.createPolicy('SomeName', {
+        createHTML: s => { throw new Error(); }
+      })
+      .then(t.step_func_done(p => {
+        assert_throws(new Error(), _ => {
+          p.createHTML('whatever');
+        });
+    }));
+  }, "html = callback that throws");
+
+  var obj = {
+    "foo": "well,"
+  }
+
+  function getHTML(s) {
+    return this.foo + " " + s;
+  }
+
+  async_test(t => {
+    createHTMLTest( {
+      createHTML: getHTML.bind(obj)},
+      'well, whatever', t);
+  }, "html = this bound to an object");
+
+  var foo = "well,";
+  async_test(t => {
+    createHTMLTest( { createHTML: s => getHTML(s) }, 'well, whatever', t);
+  }, "html = this without bind");
+
+  async_test(t => {
+    let p = window.trustedTypes.createPolicy('SomeName', null)
+        .then(t.step_func_done(p => {
+            assert_equals(p.createHTML('whatever'), null);
+    }));
+  }, "html - calling undefined callback");
+
+  //ScriptURL tests
+  function createScriptURLTest(policy, expectedScriptURL, t) {
+    let p = window.trustedTypes.createPolicy('SomeName', policy)
+        .then(t.step_func_done(p => {
+            assert_true(p.createScriptURL(URLS.safe) instanceof TrustedScriptURL);
+            assert_equals(p.createScriptURL(URLS.safe) + "", expectedScriptURL);
+    }));
+  }
+
+  async_test(t => {
+    createScriptURLTest( { createScriptURL: s => s }, URLS.safe, t);
+  }, "script_url = identity function");
+
+  async_test(t => {
+    createScriptURLTest( { createScriptURL: s => null }, "", t);
+  }, "script_url = null");
+
+  var scriptURLstr = 'duck';
+  async_test(t => {
+    createScriptURLTest( { createScriptURL: s => s + scriptURLstr }, URLS.safe + scriptURLstr, t);
+  }, "script_url = string + global string");
+
+  var scriptURLx = 'global';
+  async_test(t => {
+    let p = window.trustedTypes.createPolicy('SomeName', {
+        createScriptURL: s => { ScriptURLx = s; return s; }
+      })
+      .then(t.step_func_done(p => {
+        assert_true(p.createScriptURL(URLS.safe) instanceof TrustedScriptURL);
+        assert_equals(p.createScriptURL(URLS.safe) + "", URLS.safe);
+        assert_equals(ScriptURLx, URLS.safe);
+    }));
+  }, "script_url = identity function, global string changed");
+
+  async_test(t => {
+    let p = window.trustedTypes.createPolicy('SomeName', {
+        createScriptURL: s => { throw new Error(); }
+      })
+      .then(t.step_func_done(p => {
+        assert_throws(new Error(), _ => {
+          p.createScriptURL(URLS.safe);
+        });
+    }));
+  }, "script_url = callback that throws");
+
+  function getScriptURL(s) {
+    return s + this.baz;
+  }
+
+  var obj = {
+    "baz": "duck"
+  }
+
+  async_test(t => {
+    createScriptURLTest( {
+      createScriptURL: getScriptURL.bind(obj)},
+      URLS.safe + "duck", t);
+  }, "script_url = this bound to an object");
+
+  var baz = "duck";
+
+  async_test(t => {
+    createScriptURLTest( { createScriptURL: s => getScriptURL(s) }, URLS.safe + baz, t);
+  }, "script_url = this without bind");
+
+  async_test(t => {
+    let p = window.trustedTypes.createPolicy('SomeName', null)
+        .then(t.step_func_done(p => {
+            assert_equals(p.createScriptURL('whatever'), null);
+    }));
+  }, "script_url - calling undefined callback");
+
+  //URL tests
+  function createURLTest(policy, expectedURL, t) {
+    let p = window.trustedTypes.createPolicy('SomeName', policy)
+        .then(t.step_func_done(p => {
+            assert_true(p.createURL(URLS.safe) instanceof TrustedURL);
+            assert_equals(p.createURL(URLS.safe) + "", expectedURL);
+    }));
+  }
+
+  async_test(t => {
+    createURLTest( { createURL: s => s }, URLS.safe, t);
+  }, "url = identity function");
+
+  async_test(t => {
+    createURLTest( { createURL: s => null }, "", t);
+  }, "url = null");
+
+  var URLstr = '#x';
+  async_test(t => {
+    createURLTest( { createURL: s => s + URLstr }, URLS.safe + URLstr, t);
+  }, "url = string + global string");
+
+  var URLx = 'global';
+  async_test(t => {
+    let p = window.trustedTypes.createPolicy('SomeName', {
+        createURL: s => { URLx = s; return s; }
+      })
+      .then(t.step_func_done(p => {
+        assert_true(p.createURL(URLS.safe) instanceof TrustedURL);
+        assert_equals(p.createURL(URLS.safe) + "", URLS.safe);
+        assert_equals(URLx, URLS.safe);
+    }));
+  }, "url = identity function, global string changed");
+
+  async_test(t => {
+    let p = window.trustedTypes.createPolicy('SomeName', {
+        createURL: s => { throw new Error(); }
+      })
+      .then(t.step_func_done(p => {
+        assert_throws(new Error(), _ => {
+          p.createURL(URLS.safe);
+        });
+    }));
+  }, "url = callback that throws");
+
+  function getURL(s) {
+    return s + this.bar;
+  }
+
+  var obj = {
+    "bar": "#x"
+  }
+
+  async_test(t => {
+    createURLTest( {
+      createURL: getURL.bind(obj)},
+      URLS.safe + "#x", t);
+  }, "url = this bound to an object");
+
+  var bar = "#x";
+  async_test(t => {
+    createURLTest( { createURL: s => getURL(s) }, URLS.safe + bar, t);
+  }, "url = this without bind");
+
+  async_test(t => {
+    let p = window.trustedTypes.createPolicy('SomeName', null)
+        .then(t.step_func_done(p => {
+            assert_equals(p.createURL('whatever'), null);
+    }));
+  }, "url - calling undefined callback");
 </script>