Bug 1480738 - part2 : add test. draft
authoralwu <alwu@mozilla.com>
Fri, 03 Aug 2018 12:57:38 -0700
changeset 827065 fb8b8c8f51629b34903e630860d0f5ac53e16b92
parent 827064 4b8eb2488870f08ce363f9e4150884a59471debb
push id118453
push userbmo:alwu@mozilla.com
push dateMon, 06 Aug 2018 22:04:22 +0000
bugs1480738
milestone63.0a1
Bug 1480738 - part2 : add test. MozReview-Commit-ID: 8GwifOpAQNf
toolkit/content/tests/browser/browser_autoplay_videoDocument.js
--- a/toolkit/content/tests/browser/browser_autoplay_videoDocument.js
+++ b/toolkit/content/tests/browser/browser_autoplay_videoDocument.js
@@ -7,27 +7,61 @@ function setup_test_preference() {
     ["media.autoplay.default", SpecialPowers.Ci.nsIAutoplay.PROMPT],
     ["media.autoplay.enabled.user-gestures-needed", true],
     ["media.autoplay.ask-permission", true],
   ]});
 }
 
 function checkIsVideoDocumentAutoplay(browser) {
   return ContentTask.spawn(browser, null, async () => {
-    let video = content.document.getElementsByTagName("video")[0];
-    let played = video && await video.play().then(() => true, () => false);
+    const video = content.document.getElementsByTagName("video")[0];
+    const played = video && await video.play().then(() => true, () => false);
     ok(played, "Should be able to play in video document.");
   });
 }
 
+async function checkIsIframeVideoDocumentAutoplay(browser) {
+  info("- create iframe video document -");
+  await ContentTask.spawn(browser, PAGE, async (pageURL) => {
+    const iframe = content.document.createElement("iframe");
+    iframe.src = pageURL;
+    content.document.body.appendChild(iframe);
+    const iframeLoaded = new Promise((resolve, reject) => {
+      iframe.addEventListener("load", e => resolve(), {once: true});
+    });
+    await iframeLoaded;
+  });
+
+  info("- check whether iframe video document starts playing -");
+  await ContentTask.spawn(browser, null, async () => {
+    const iframe = content.document.querySelector("iframe");
+    const video = iframe.contentDocument.querySelector("video");
+    ok(video.paused, "Subdoc video should not have played");
+    is(video.played.length, 0, "Should have empty played ranges");
+  });
+}
+
 add_task(async () => {
   await BrowserTestUtils.withNewTab({
     gBrowser,
     url: PAGE,
   }, async (browser) => {
     info("- setup test preference -");
     await setup_test_preference();
 
     info(`- check whether video document is autoplay -`);
     await checkIsVideoDocumentAutoplay(browser);
   });
 });
 
+add_task(async () => {
+  await BrowserTestUtils.withNewTab({
+    gBrowser,
+    url: "about:blank",
+  }, async (browser) => {
+    info("- setup test preference -");
+    await setup_test_preference();
+
+    info(`- check whether video document in iframe is autoplay -`);
+    await checkIsIframeVideoDocumentAutoplay(browser);
+  });
+});
+