[Document Policy] Migrate document-write to document policy

Change-Id: Ice3b53cbce49c5989d5a45761fb15922bfe7ba21
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2359567
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Reviewed-by: Robert Sesek <rsesek@chromium.org>
Reviewed-by: Ian Clelland <iclelland@chromium.org>
Commit-Queue: Charlie Hu <chenleihu@google.com>
Cr-Commit-Position: refs/heads/master@{#801395}
diff --git a/feature-policy/experimental-features/document-write.tentative.html b/document-policy/experimental-features/document-write.tentative.html
similarity index 88%
rename from feature-policy/experimental-features/document-write.tentative.html
rename to document-policy/experimental-features/document-write.tentative.html
index 7e09ef7..551703c 100644
--- a/feature-policy/experimental-features/document-write.tentative.html
+++ b/document-policy/experimental-features/document-write.tentative.html
@@ -2,7 +2,7 @@
 <title>'document-write' tests</title>
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
-<script src="/feature-policy/experimental-features/resources/common.js"></script>
+<script src="/document-policy/experimental-features/resources/common.js"></script>
 <style>
 html, body {
   height: 100%;
@@ -20,7 +20,8 @@
   }
 
   let iframeElement = document.querySelector("iframe");
-  let url = url_base + "document-write.html";
+  const allowed_url = url_base + "document-write-allowed.html";
+  const disallowed_url = url_base + "document-write-disallowed.html";
 
   let text_to_write = "<div>FOO<\/div>";
   let test_cases = [{
@@ -49,7 +50,7 @@
   test_cases.forEach((tc) => {
     promise_test(async() => {
       let iframeElement = newIframe();
-      await loadUrlInIframe(iframeElement, url);
+      await loadUrlInIframe(iframeElement, allowed_url);
       await sendMessageAndGetResponse(iframeElement.contentWindow, tc).then((response) => {
         assert_false(
           response.did_throw_exception,
@@ -70,8 +71,7 @@
   test_cases.forEach((tc) => {
     promise_test(async() => {
       let iframeElement = newIframe();
-      setFeatureState(iframeElement, "document-write", "'none'");
-      await loadUrlInIframe(iframeElement, url);
+      await loadUrlInIframe(iframeElement, disallowed_url);
       await sendMessageAndGetResponse(iframeElement.contentWindow, tc).then((response) => {
         assert_true(
           response.did_throw_exception,
diff --git a/feature-policy/experimental-features/resources/document-write.html b/document-policy/experimental-features/resources/document-write-allowed.html
similarity index 100%
rename from feature-policy/experimental-features/resources/document-write.html
rename to document-policy/experimental-features/resources/document-write-allowed.html
diff --git a/feature-policy/experimental-features/resources/document-write.html b/document-policy/experimental-features/resources/document-write-disallowed.html
similarity index 100%
copy from feature-policy/experimental-features/resources/document-write.html
copy to document-policy/experimental-features/resources/document-write-disallowed.html
diff --git a/document-policy/experimental-features/resources/document-write-disallowed.html.headers b/document-policy/experimental-features/resources/document-write-disallowed.html.headers
new file mode 100644
index 0000000..32846f7
--- /dev/null
+++ b/document-policy/experimental-features/resources/document-write-disallowed.html.headers
@@ -0,0 +1 @@
+Document-Policy: document-write=?0
\ No newline at end of file
diff --git a/feature-policy/reporting/document-write-report-only.html b/document-policy/reporting/document-write-report-only-tentative.html
similarity index 83%
rename from feature-policy/reporting/document-write-report-only.html
rename to document-policy/reporting/document-write-report-only-tentative.html
index 69ce9f8..bf17807 100644
--- a/feature-policy/reporting/document-write-report-only.html
+++ b/document-policy/reporting/document-write-report-only-tentative.html
@@ -8,7 +8,7 @@
     <script>
 var check_report_format = ([reports, observer]) => {
   let report = reports[0];
-  assert_equals(report.type, "feature-policy-violation");
+  assert_equals(report.type, "document-policy-violation");
   assert_equals(report.body.featureId, "document-write");
   assert_equals(report.body.disposition, "report");
 };
@@ -16,7 +16,7 @@
 promise_test(async t => {
   const report = new Promise(resolve => {
     new ReportingObserver((reports, observer) => resolve([reports, observer]),
-                          {types: ['feature-policy-violation']}).observe();
+                          {types: ['document-policy-violation']}).observe();
   });
   document.write("This should be written into the document");
   check_report_format(await report);
diff --git a/document-policy/reporting/document-write-report-only-tentative.html.headers b/document-policy/reporting/document-write-report-only-tentative.html.headers
new file mode 100644
index 0000000..924dac8
--- /dev/null
+++ b/document-policy/reporting/document-write-report-only-tentative.html.headers
@@ -0,0 +1 @@
+Document-Policy-Report-Only: document-write=?0
diff --git a/feature-policy/reporting/document-write-reporting.html b/document-policy/reporting/document-write-reporting-tentative.html
similarity index 86%
rename from feature-policy/reporting/document-write-reporting.html
rename to document-policy/reporting/document-write-reporting-tentative.html
index 50af640..65a584c 100644
--- a/feature-policy/reporting/document-write-reporting.html
+++ b/document-policy/reporting/document-write-reporting-tentative.html
@@ -10,7 +10,7 @@
 
 var check_report_format = (reports, observer) => {
   let report = reports[0];
-  assert_equals(report.type, "feature-policy-violation");
+  assert_equals(report.type, "document-policy-violation");
   assert_equals(report.url, document.location.href);
   assert_equals(report.body.featureId, "document-write");
   assert_equals(report.body.sourceFile, document.location.href);
@@ -20,7 +20,7 @@
 };
 
 new ReportingObserver(t.step_func_done(check_report_format),
-                      {types: ['feature-policy-violation']}).observe();
+                      {types: ['document-policy-violation']}).observe();
 
 t.step_func(() => {
   assert_throws_dom('NotAllowedError',
diff --git a/document-policy/reporting/document-write-reporting-tentative.html.headers b/document-policy/reporting/document-write-reporting-tentative.html.headers
new file mode 100644
index 0000000..6d05e96
--- /dev/null
+++ b/document-policy/reporting/document-write-reporting-tentative.html.headers
@@ -0,0 +1 @@
+Document-Policy: document-write=?0
diff --git a/feature-policy/reporting/document-write-report-only.html.headers b/feature-policy/reporting/document-write-report-only.html.headers
deleted file mode 100644
index bd14187..0000000
--- a/feature-policy/reporting/document-write-report-only.html.headers
+++ /dev/null
@@ -1 +0,0 @@
-Feature-Policy-Report-Only: document-write 'none'
diff --git a/feature-policy/reporting/document-write-reporting.html.headers b/feature-policy/reporting/document-write-reporting.html.headers
deleted file mode 100644
index 57102d5..0000000
--- a/feature-policy/reporting/document-write-reporting.html.headers
+++ /dev/null
@@ -1 +0,0 @@
-Feature-Policy: document-write 'none'