Bug 1587362 - Regression test. r=jaws
☠☠ backed out by 1c6ab26ee4cf ☠ ☠
authorMike Conley <mconley@mozilla.com>
Fri, 11 Oct 2019 21:00:27 +0000
changeset 497313 d3142d807c7f5a409a4fff4b94acf129f346786c
parent 497312 c71f9a59bdfeebc71144091b4ebd3c2e1c2bc74b
child 497314 5dad4aa34c7fede26690a0d4bbbd9b8614b09dfa
push id36682
push userncsoregi@mozilla.com
push dateSat, 12 Oct 2019 09:52:03 +0000
treeherdermozilla-central@06ea2371f897 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1587362
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 1587362 - Regression test. r=jaws Differential Revision: https://phabricator.services.mozilla.com/D48886
toolkit/components/pictureinpicture/tests/browser.ini
toolkit/components/pictureinpicture/tests/browser_toggleAfterTabTearOutIn.js
toolkit/components/pictureinpicture/tests/head.js
--- a/toolkit/components/pictureinpicture/tests/browser.ini
+++ b/toolkit/components/pictureinpicture/tests/browser.ini
@@ -1,40 +1,41 @@
-[DEFAULT]
-support-files =
-  click-event-helper.js
-  head.js
-  test-button-overlay.html
-  test-opaque-overlay.html
-  test-page.html
-  test-pointer-events-none.html
-  test-transparent-overlay-1.html
-  test-transparent-overlay-2.html
-  test-video.mp4
-
-prefs =
-  media.videocontrols.picture-in-picture.enabled=true
-  media.videocontrols.picture-in-picture.video-toggle.enabled=true
-  media.videocontrols.picture-in-picture.video-toggle.testing=true
-  media.videocontrols.picture-in-picture.video-toggle.always-show=true
-
-[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
-[browser_togglePointerEventsNone.js]
-[browser_toggleSimple.js]
-skip-if = os == 'linux' # Bug 1546455
-[browser_toggleTransparentOverlay-1.js]
-[browser_toggleTransparentOverlay-2.js]
-skip-if = os == 'linux' && (debug || asan) # Bug 1546930
+[DEFAULT]
+support-files =
+  click-event-helper.js
+  head.js
+  test-button-overlay.html
+  test-opaque-overlay.html
+  test-page.html
+  test-pointer-events-none.html
+  test-transparent-overlay-1.html
+  test-transparent-overlay-2.html
+  test-video.mp4
+
+prefs =
+  media.videocontrols.picture-in-picture.enabled=true
+  media.videocontrols.picture-in-picture.video-toggle.enabled=true
+  media.videocontrols.picture-in-picture.video-toggle.testing=true
+  media.videocontrols.picture-in-picture.video-toggle.always-show=true
+
+[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_toggleAfterTabTearOutIn.js]
+[browser_toggleButtonOverlay.js]
+skip-if = true # Bug 1546455
+[browser_toggleOnInsertedVideo.js]
+[browser_toggleOpaqueOverlay.js]
+skip-if = true # Bug 1546455
+[browser_togglePointerEventsNone.js]
+[browser_toggleSimple.js]
+skip-if = os == 'linux' # Bug 1546455
+[browser_toggleTransparentOverlay-1.js]
+[browser_toggleTransparentOverlay-2.js]
+skip-if = os == 'linux' && (debug || asan) # Bug 1546930
new file mode 100644
--- /dev/null
+++ b/toolkit/components/pictureinpicture/tests/browser_toggleAfterTabTearOutIn.js
@@ -0,0 +1,58 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Helper function that tries to use the mouse to open the Picture-in-Picture
+ * player window for a video with and without the built-in controls.
+ *
+ * @param {Element} tab The tab to be tested.
+ * @return Promise
+ * @resolves When the toggles for both the video-with-controls and
+ * video-without-controls have been tested.
+ */
+async function testToggleForTab(tab) {
+  for (let videoID of ["with-controls", "no-controls"]) {
+    let browser = tab.linkedBrowser;
+    info(`Testing ${videoID} case.`);
+
+    await testToggleHelper(browser, videoID, true);
+  }
+}
+
+/**
+ * Tests that the Picture-in-Picture toggle still works after tearing out the
+ * tab into a new window, or tearing in a tab from one window to another.
+ */
+add_task(async () => {
+  // The startingTab will be torn out and placed in the new window.
+  let startingTab = await BrowserTestUtils.openNewForegroundTab(
+    gBrowser,
+    TEST_PAGE
+  );
+
+  // Tear out the starting tab into its own window...
+  let newWinLoaded = BrowserTestUtils.waitForNewWindow();
+  let win2 = gBrowser.replaceTabWithWindow(startingTab);
+  await newWinLoaded;
+
+  // Let's maximize the newly opened window so we don't have to worry about
+  // the videos being visible.
+  if (win2.windowState != win2.STATE_MAXIMIZED) {
+    let resizePromise = BrowserTestUtils.waitForEvent(win2, "resize");
+    win2.maximize();
+    await resizePromise;
+  }
+
+  await SimpleTest.promiseFocus(win2);
+  await testToggleForTab(win2.gBrowser.selectedTab);
+
+  // Now bring the tab back to the original window.
+  let dragInTab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
+  gBrowser.swapBrowsersAndCloseOther(dragInTab, win2.gBrowser.selectedTab);
+  await SimpleTest.promiseFocus(window);
+  await testToggleForTab(dragInTab);
+
+  BrowserTestUtils.removeTab(dragInTab);
+});
--- a/toolkit/components/pictureinpicture/tests/head.js
+++ b/toolkit/components/pictureinpicture/tests/head.js
@@ -280,147 +280,156 @@ async function testToggle(testURL, expec
     async browser => {
       await prepFn(browser);
       await ensureVideosReady(browser);
 
       for (let [videoID, canToggle] of Object.entries(expectations)) {
         await SimpleTest.promiseFocus(browser);
         info(`Testing video with id: ${videoID}`);
 
-        let { toggleClientRect, controls } = await prepareForToggleClick(
-          browser,
-          videoID
-        );
-
-        // Hover the mouse over the video to reveal the toggle.
-        await BrowserTestUtils.synthesizeMouseAtCenter(
-          `#${videoID}`,
-          {
-            type: "mousemove",
-          },
-          browser
-        );
-        await BrowserTestUtils.synthesizeMouseAtCenter(
-          `#${videoID}`,
-          {
-            type: "mouseover",
-          },
-          browser
-        );
-
-        info("Waiting for toggle to become visible");
-        await toggleOpacityReachesThreshold(
-          browser,
-          videoID,
-          HOVER_VIDEO_OPACITY
-        );
-
-        info("Hovering the toggle rect now.");
-        // The toggle center, because of how it slides out, is actually outside
-        // of the bounds of a click event. For now, we move the mouse in by a
-        // hard-coded 2 pixels along the x and y axis to achieve the hover.
-        let toggleLeft = toggleClientRect.left + 2;
-        let toggleTop = toggleClientRect.top + 2;
-        await BrowserTestUtils.synthesizeMouseAtPoint(
-          toggleLeft,
-          toggleTop,
-          {
-            type: "mousemove",
-          },
-          browser
-        );
-        await BrowserTestUtils.synthesizeMouseAtPoint(
-          toggleLeft,
-          toggleTop,
-          {
-            type: "mouseover",
-          },
-          browser
-        );
-
-        await toggleOpacityReachesThreshold(
-          browser,
-          videoID,
-          HOVER_TOGGLE_OPACITY
-        );
-
-        // First, ensure that a non-primary mouse click is ignored.
-        info("Right-clicking on toggle.");
-
-        await BrowserTestUtils.synthesizeMouseAtPoint(
-          toggleLeft,
-          toggleTop,
-          { button: 1 },
-          browser
-        );
-
-        // For videos without the built-in controls, we expect that all mouse events
-        // should have fired - otherwise, the events are all suppressed.
-        await assertSawMouseEvents(browser, !controls, false);
-
-        // The message to open the Picture-in-Picture window would normally be sent
-        // immediately before this Promise resolved, so the window should have opened
-        // by now if it was going to happen.
-        for (let win of Services.wm.getEnumerator(WINDOW_TYPE)) {
-          if (!win.closed) {
-            ok(false, "Found a Picture-in-Picture window unexpectedly.");
-            return;
-          }
-        }
-
-        ok(true, "No Picture-in-Picture window found.");
-
-        // Okay, now test with the primary mouse button.
-
-        if (canToggle) {
-          info(
-            "Clicking on toggle, and expecting a Picture-in-Picture window to open"
-          );
-          let domWindowOpened = BrowserTestUtils.domWindowOpened(null);
-          await BrowserTestUtils.synthesizeMouseAtPoint(
-            toggleLeft,
-            toggleTop,
-            {},
-            browser
-          );
-          let win = await domWindowOpened;
-          ok(win, "A Picture-in-Picture window opened.");
-          await BrowserTestUtils.closeWindow(win);
-
-          // Make sure that clicking on the toggle resulted in no mouse button events
-          // being fired in content.
-          await assertSawMouseEvents(browser, false);
-        } else {
-          info(
-            "Clicking on toggle, and expecting no Picture-in-Picture window opens"
-          );
-          await BrowserTestUtils.synthesizeMouseAtPoint(
-            toggleLeft,
-            toggleTop,
-            {},
-            browser
-          );
-
-          // For videos without the built-in controls, we expect that all mouse events
-          // should have fired - otherwise, the events are all suppressed.
-          await assertSawMouseEvents(browser, !controls);
-
-          // The message to open the Picture-in-Picture window would normally be sent
-          // immediately before this Promise resolved, so the window should have opened
-          // by now if it was going to happen.
-          for (let win of Services.wm.getEnumerator(WINDOW_TYPE)) {
-            if (!win.closed) {
-              ok(false, "Found a Picture-in-Picture window unexpectedly.");
-              return;
-            }
-          }
-
-          ok(true, "No Picture-in-Picture window found.");
-        }
-
-        // Click on the very top-left pixel of the document and ensure that we
-        // see all of the mouse events for it.
-        await BrowserTestUtils.synthesizeMouseAtPoint(1, 1, {}, browser);
-        assertSawMouseEvents(browser, true);
+        await testToggleHelper(browser, videoID, canToggle);
       }
     }
   );
 }
+
+/**
+ * Test helper for the Picture-in-Picture toggle. Given a loaded page with some
+ * videos on it, tests that the toggle behaves as expected when interacted
+ * with by the mouse.
+ *
+ * @param {Element} browser The <xul:browser> that has the <video> loaded in it.
+ * @param {String} videoID The ID of the video that has the toggle.
+ * @param {Boolean} canToggle True if we expect the toggle to be visible and
+ * clickable by the mouse for the associated video.
+ *
+ * @return Promise
+ * @resolves When the check for the toggle is complete.
+ */
+async function testToggleHelper(browser, videoID, canToggle) {
+  let { toggleClientRect, controls } = await prepareForToggleClick(
+    browser,
+    videoID
+  );
+
+  // Hover the mouse over the video to reveal the toggle.
+  await BrowserTestUtils.synthesizeMouseAtCenter(
+    `#${videoID}`,
+    {
+      type: "mousemove",
+    },
+    browser
+  );
+  await BrowserTestUtils.synthesizeMouseAtCenter(
+    `#${videoID}`,
+    {
+      type: "mouseover",
+    },
+    browser
+  );
+
+  info("Waiting for toggle to become visible");
+  await toggleOpacityReachesThreshold(browser, videoID, HOVER_VIDEO_OPACITY);
+
+  info("Hovering the toggle rect now.");
+  // The toggle center, because of how it slides out, is actually outside
+  // of the bounds of a click event. For now, we move the mouse in by a
+  // hard-coded 2 pixels along the x and y axis to achieve the hover.
+  let toggleLeft = toggleClientRect.left + 2;
+  let toggleTop = toggleClientRect.top + 2;
+  await BrowserTestUtils.synthesizeMouseAtPoint(
+    toggleLeft,
+    toggleTop,
+    {
+      type: "mousemove",
+    },
+    browser
+  );
+  await BrowserTestUtils.synthesizeMouseAtPoint(
+    toggleLeft,
+    toggleTop,
+    {
+      type: "mouseover",
+    },
+    browser
+  );
+
+  await toggleOpacityReachesThreshold(browser, videoID, HOVER_TOGGLE_OPACITY);
+
+  // First, ensure that a non-primary mouse click is ignored.
+  info("Right-clicking on toggle.");
+
+  await BrowserTestUtils.synthesizeMouseAtPoint(
+    toggleLeft,
+    toggleTop,
+    { button: 2 },
+    browser
+  );
+
+  // For videos without the built-in controls, we expect that all mouse events
+  // should have fired - otherwise, the events are all suppressed.
+  await assertSawMouseEvents(browser, !controls, false);
+
+  // The message to open the Picture-in-Picture window would normally be sent
+  // immediately before this Promise resolved, so the window should have opened
+  // by now if it was going to happen.
+  for (let win of Services.wm.getEnumerator(WINDOW_TYPE)) {
+    if (!win.closed) {
+      ok(false, "Found a Picture-in-Picture window unexpectedly.");
+      return;
+    }
+  }
+
+  ok(true, "No Picture-in-Picture window found.");
+
+  // Okay, now test with the primary mouse button.
+
+  if (canToggle) {
+    info(
+      "Clicking on toggle, and expecting a Picture-in-Picture window to open"
+    );
+    let domWindowOpened = BrowserTestUtils.domWindowOpened(null);
+    await BrowserTestUtils.synthesizeMouseAtPoint(
+      toggleLeft,
+      toggleTop,
+      {},
+      browser
+    );
+    let win = await domWindowOpened;
+    ok(win, "A Picture-in-Picture window opened.");
+    await BrowserTestUtils.closeWindow(win);
+
+    // Make sure that clicking on the toggle resulted in no mouse button events
+    // being fired in content.
+    await assertSawMouseEvents(browser, false);
+  } else {
+    info(
+      "Clicking on toggle, and expecting no Picture-in-Picture window opens"
+    );
+    await BrowserTestUtils.synthesizeMouseAtPoint(
+      toggleLeft,
+      toggleTop,
+      {},
+      browser
+    );
+
+    // For videos without the built-in controls, we expect that all mouse events
+    // should have fired - otherwise, the events are all suppressed.
+    await assertSawMouseEvents(browser, !controls);
+
+    // The message to open the Picture-in-Picture window would normally be sent
+    // immediately before this Promise resolved, so the window should have opened
+    // by now if it was going to happen.
+    for (let win of Services.wm.getEnumerator(WINDOW_TYPE)) {
+      if (!win.closed) {
+        ok(false, "Found a Picture-in-Picture window unexpectedly.");
+        return;
+      }
+    }
+
+    ok(true, "No Picture-in-Picture window found.");
+  }
+
+  // Click on the very top-left pixel of the document and ensure that we
+  // see all of the mouse events for it.
+  await BrowserTestUtils.synthesizeMouseAtPoint(1, 1, {}, browser);
+  assertSawMouseEvents(browser, true);
+}