tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_test_tab_drag_event_counts.js (3018B)


      1 /*
      2  Test for https://bugzilla.mozilla.org/show_bug.cgi?id=1683776
      3 */
      4 
      5 const EVENTUTILS_URL =
      6  "chrome://mochikit/content/tests/SimpleTest/EventUtils.js";
      7 var EventUtils = {};
      8 
      9 const NATIVEKEYCODES_URL =
     10  "chrome://mochikit/content/tests/SimpleTest/NativeKeyCodes.js";
     11 
     12 const APZNATIVEEVENTUTILS_URL =
     13  "chrome://mochitests/content/browser/gfx/layers/apz/test/mochitest/apz_test_native_event_utils.js";
     14 
     15 Services.scriptloader.loadSubScript(EVENTUTILS_URL, EventUtils);
     16 Services.scriptloader.loadSubScript(NATIVEKEYCODES_URL, this);
     17 Services.scriptloader.loadSubScript(APZNATIVEEVENTUTILS_URL, this);
     18 
     19 add_setup(async function () {
     20  await SpecialPowers.pushPrefEnv({
     21    set: [["test.wait300msAfterTabSwitch", true]],
     22  });
     23 });
     24 
     25 add_task(async function test_dragging_tabs_event_counts() {
     26  function httpURL(filename) {
     27    let chromeURL = getRootDirectory(gTestPath) + filename;
     28    return chromeURL.replace(
     29      "chrome://mochitests/content/",
     30      "http://mochi.test:8888/"
     31    );
     32  }
     33 
     34  async function sendKeyEvent(key) {
     35    await new Promise(resolve => {
     36      EventUtils.synthesizeNativeKey(
     37        EventUtils.KEYBOARD_LAYOUT_EN_US,
     38        key,
     39        {},
     40        "",
     41        "",
     42        resolve
     43      );
     44    });
     45  }
     46 
     47  const pageUrl = httpURL("helper_test_tab_drag_event_counts.html");
     48 
     49  // Open two windows:
     50  // window 1 with 1 tab
     51  // window 2 with 2 tabs
     52  let win1 = await BrowserTestUtils.openNewBrowserWindow();
     53  let win2 = await BrowserTestUtils.openNewBrowserWindow();
     54 
     55  let tab1 = await BrowserTestUtils.openNewForegroundTab(
     56    win1.gBrowser,
     57    pageUrl
     58  );
     59  let tab2 = await BrowserTestUtils.openNewForegroundTab(
     60    win2.gBrowser,
     61    pageUrl
     62  );
     63  let tab3 = await BrowserTestUtils.openNewForegroundTab(
     64    win2.gBrowser,
     65    pageUrl
     66  );
     67 
     68  await SpecialPowers.spawn(tab1.linkedBrowser, [], async () => {
     69    await content.wrappedJSObject.waitUntilApzStable();
     70  });
     71  await SpecialPowers.spawn(tab2.linkedBrowser, [], async () => {
     72    await content.wrappedJSObject.waitUntilApzStable();
     73  });
     74  await SpecialPowers.spawn(tab3.linkedBrowser, [], async () => {
     75    await content.wrappedJSObject.waitUntilApzStable();
     76  });
     77 
     78  // send numerous key events
     79  for (let i = 0; i < 100; i++) {
     80    await sendKeyEvent(nativeArrowUpKey());
     81    await sendKeyEvent(nativeArrowDownKey());
     82  }
     83 
     84  // drag and drop tab 3 from window 2 to window 1
     85  let dropPromise = BrowserTestUtils.waitForEvent(
     86    win1.gBrowser.tabContainer,
     87    "drop"
     88  );
     89  let effect = EventUtils.synthesizeDrop(
     90    tab3,
     91    tab1,
     92    [[{ type: TAB_DROP_TYPE, data: tab3 }]],
     93    null,
     94    win2,
     95    win1
     96  );
     97  is(effect, "move", "Tab should be moved from win2 to win1.");
     98  await dropPromise;
     99 
    100  // focus window 1
    101  await SimpleTest.promiseFocus(win1);
    102 
    103  // send another key event
    104  // when the bug occurs, an assertion is triggered when processing this event
    105  await sendKeyEvent(nativeArrowUpKey());
    106 
    107  await BrowserTestUtils.closeWindow(win1);
    108  await BrowserTestUtils.closeWindow(win2);
    109 
    110  ok(true);
    111 });