Bug 1583882 - Regression test. r=JSON_voorhees
authorMike Conley <mconley@mozilla.com>
Tue, 01 Oct 2019 16:21:08 +0000
changeset 495868 43c79d7f6b647c9bfee3a093f82bd4ad5f2daba2
parent 495867 6b4844ef3b2bcdc203b7c593d749b37294e1014f
child 495869 31d0469993bdecfcad267a2e0eaedc18e1199848
push id114140
push userdvarga@mozilla.com
push dateWed, 02 Oct 2019 18:04:51 +0000
treeherdermozilla-inbound@32eb0ea893f3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersJSON_voorhees
bugs1583882
milestone71.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 1583882 - Regression test. r=JSON_voorhees Differential Revision: https://phabricator.services.mozilla.com/D47614
toolkit/components/pictureinpicture/tests/browser.ini
toolkit/components/pictureinpicture/tests/browser_removeVideoElement.js
--- a/toolkit/components/pictureinpicture/tests/browser.ini
+++ b/toolkit/components/pictureinpicture/tests/browser.ini
@@ -18,16 +18,17 @@ prefs =
 
 [browser_cannotTriggerFromContent.js]
 [browser_contextMenu.js]
 [browser_closeTab.js]
 [browser_fullscreen.js]
 skip-if = (os == "mac" && debug) #Bug 1566173
 [browser_mouseButtonVariation.js]
 skip-if = debug
+[browser_removeVideoElement.js]
 [browser_rerequestPiP.js]
 [browser_showMessage.js]
 [browser_stripVideoStyles.js]
 [browser_toggleButtonOverlay.js]
 skip-if = true # Bug 1546455
 [browser_toggleOnInsertedVideo.js]
 [browser_toggleOpaqueOverlay.js]
 skip-if = true # Bug 1546455
new file mode 100644
--- /dev/null
+++ b/toolkit/components/pictureinpicture/tests/browser_removeVideoElement.js
@@ -0,0 +1,76 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Tests that if a <video> element is being displayed in a
+ * Picture-in-Picture window, that the window closes if that
+ * original <video> is ever removed from the DOM.
+ */
+add_task(async () => {
+  for (let videoID of ["with-controls", "no-controls"]) {
+    info(`Testing ${videoID} case.`);
+
+    await BrowserTestUtils.withNewTab(
+      {
+        url: TEST_PAGE,
+        gBrowser,
+      },
+      async browser => {
+        let pipWin = await triggerPictureInPicture(browser, videoID);
+        Assert.ok(pipWin, "Got PiP window.");
+
+        // First, let's make sure that removing the _other_ video doesn't cause
+        // the special event to fire, nor the PiP window to close.
+        await ContentTask.spawn(browser, videoID, async videoID => {
+          let doc = content.document;
+          let otherVideo = doc.querySelector(`video:not([id="${videoID}"])`);
+          let eventFired = false;
+
+          let listener = e => {
+            eventFired = true;
+          };
+
+          addEventListener("MozStopPictureInPicture", listener, {
+            capture: true,
+          });
+          otherVideo.remove();
+          Assert.ok(
+            !eventFired,
+            "Should not have seen MozStopPictureInPicture for other video"
+          );
+          removeEventListener("MozStopPictureInPicture", listener, {
+            capture: true,
+          });
+        });
+
+        Assert.ok(!pipWin.closed, "PiP window should still be open.");
+
+        await ContentTask.spawn(browser, videoID, async videoID => {
+          let doc = content.document;
+          let video = doc.querySelector(`#${videoID}`);
+
+          let promise = ContentTaskUtils.waitForEvent(
+            this,
+            "MozStopPictureInPicture",
+            { capture: true }
+          );
+          video.remove();
+          await promise;
+        });
+
+        try {
+          await BrowserTestUtils.waitForCondition(
+            () => pipWin.closed,
+            "Player window closed."
+          );
+        } finally {
+          if (!pipWin.closed) {
+            await BrowserTestUtils.closeWindow(pipWin);
+          }
+        }
+      }
+    );
+  }
+});