Origin isolation: one more document.domain test

Inspired by the corresponding cross-origin isolation test in
https://chromium-review.googlesource.com/c/chromium/src/+/2417872.

Bug: 1042415
Change-Id: I490fc7a2f624b70d2e7fc71c3b45970c627b8835
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2427066
Reviewed-by: Yutaka Hirano <yhirano@chromium.org>
Commit-Queue: Domenic Denicola <domenic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812148}
diff --git a/origin-isolation/document-domain.sub.https.html b/origin-isolation/document-domain.sub.https.html
index 6910b02..48f9a99 100644
--- a/origin-isolation/document-domain.sub.https.html
+++ b/origin-isolation/document-domain.sub.https.html
@@ -11,6 +11,7 @@
 -->
 
 <iframe src="resources/frame.html"></iframe>
+<iframe src="//{{domains[www1]}}:{{location[port]}}/origin-isolation/resources/frame.html"></iframe>
 
 <script type="module">
 setup({ explicit_done: true });
@@ -33,6 +34,19 @@
     });
   }, "The registrable domain suffix check must happen before the bail-out");
 
+  async_test(t => {
+    frames[1].postMessage({
+      type: "set document.domain",
+      newValue: "{{host}}"
+    }, "*");
+
+    window.onmessage = t.step_func_done(e => {
+      assert_equals(e.data.type, "new document.domain");
+      assert_equals(e.data.result, "{{domains[www1]}}");
+    });
+  }, "Having an origin-isolated subdomain child try to set document.domain " +
+     "must not change the document.domain value it sees");
+
   done();
 };
 </script>
diff --git a/origin-isolation/resources/frame.html b/origin-isolation/resources/frame.html
index 8f35d27..537de07 100644
--- a/origin-isolation/resources/frame.html
+++ b/origin-isolation/resources/frame.html
@@ -1,3 +1,12 @@
 <!DOCTYPE html>
 <meta charset="utf-8">
 <title>A frame included by a test page</title>
+
+<script>
+window.onmessage = e => {
+  if (e.data.type === "set document.domain") {
+    document.domain = e.data.newValue;
+    e.source.postMessage({ type: "new document.domain", result: document.domain }, "*");
+  }
+};
+</script>