tor-browser

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

browser_bug1261299.js (3472B)


      1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 /**
      7 * Tests for Bug 1261299
      8 * Test that the service menu code path is called properly and the
      9 * current selection (transferable) is cached properly on the parent process.
     10 */
     11 
     12 add_setup(async function () {
     13  await SpecialPowers.pushPrefEnv({
     14    set: [["test.wait300msAfterTabSwitch", true]],
     15  });
     16 });
     17 
     18 add_task(async function test_content_and_chrome_selection() {
     19  let testPage =
     20    "data:text/html," +
     21    '<textarea id="textarea">Write something here</textarea>';
     22  let DOMWindowUtils = EventUtils._getDOMWindowUtils(window);
     23  let selectedText;
     24 
     25  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, testPage);
     26  await BrowserTestUtils.synthesizeMouse(
     27    "#textarea",
     28    0,
     29    0,
     30    {},
     31    gBrowser.selectedBrowser
     32  );
     33  await BrowserTestUtils.synthesizeKey(
     34    "KEY_ArrowRight",
     35    { shiftKey: true, ctrlKey: true },
     36    gBrowser.selectedBrowser
     37  );
     38  selectedText = DOMWindowUtils.GetSelectionAsPlaintext();
     39  is(
     40    selectedText,
     41    "Write something here",
     42    "The macOS services got the selected content text"
     43  );
     44  gURLBar.value = "test.mozilla.org";
     45  await gURLBar.editor.selectAll();
     46  selectedText = DOMWindowUtils.GetSelectionAsPlaintext();
     47  is(
     48    selectedText,
     49    "test.mozilla.org",
     50    "The macOS services got the selected chrome text"
     51  );
     52 
     53  BrowserTestUtils.removeTab(tab);
     54 });
     55 
     56 // Test switching active selection.
     57 // Each tab has a content selection and when you switch to that tab, its selection becomes
     58 // active aka the current selection.
     59 // Expect: The active selection is what is being sent to OSX service menu.
     60 
     61 add_task(async function test_active_selection_switches_properly() {
     62  let testPage1 =
     63    // eslint-disable-next-line no-useless-concat
     64    "data:text/html," +
     65    '<textarea id="textarea">Write something here</textarea>';
     66  let testPage2 =
     67    // eslint-disable-next-line no-useless-concat
     68    "data:text/html," + '<textarea id="textarea">Nothing available</textarea>';
     69  let DOMWindowUtils = EventUtils._getDOMWindowUtils(window);
     70  let selectedText;
     71 
     72  let tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, testPage1);
     73  await BrowserTestUtils.synthesizeMouse(
     74    "#textarea",
     75    0,
     76    0,
     77    {},
     78    gBrowser.selectedBrowser
     79  );
     80  await BrowserTestUtils.synthesizeKey(
     81    "KEY_ArrowRight",
     82    { shiftKey: true, ctrlKey: true },
     83    gBrowser.selectedBrowser
     84  );
     85 
     86  let tab2 = await BrowserTestUtils.openNewForegroundTab(gBrowser, testPage2);
     87  await BrowserTestUtils.synthesizeMouse(
     88    "#textarea",
     89    0,
     90    0,
     91    {},
     92    gBrowser.selectedBrowser
     93  );
     94  await BrowserTestUtils.synthesizeKey(
     95    "KEY_ArrowRight",
     96    { shiftKey: true, ctrlKey: true },
     97    gBrowser.selectedBrowser
     98  );
     99 
    100  await BrowserTestUtils.switchTab(gBrowser, tab1);
    101  selectedText = DOMWindowUtils.GetSelectionAsPlaintext();
    102  is(
    103    selectedText,
    104    "Write something here",
    105    "The macOS services got the selected content text"
    106  );
    107 
    108  await BrowserTestUtils.switchTab(gBrowser, tab2);
    109  selectedText = DOMWindowUtils.GetSelectionAsPlaintext();
    110  is(
    111    selectedText,
    112    "Nothing available",
    113    "The macOS services got the selected content text"
    114  );
    115 
    116  BrowserTestUtils.removeTab(tab1);
    117  BrowserTestUtils.removeTab(tab2);
    118 });