summaryrefslogtreecommitdiffstats
path: root/browser/components/urlbar/tests/browser/browser_copy_during_load.js
blob: 4a81ff08be76a44e0a58473ed80ceb85e64aac9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test that copying from the urlbar page works correctly after a result is
// confirmed but takes a while to load.

add_task(async function () {
  const SLOW_PAGE =
    getRootDirectory(gTestPath).replace(
      "chrome://mochitests/content",
      "http://www.example.com"
    ) + "slow-page.sjs";

  await BrowserTestUtils.withNewTab(gBrowser, async tab => {
    gURLBar.focus();
    gURLBar.value = SLOW_PAGE;
    let promise = TestUtils.waitForCondition(
      () => gURLBar.getAttribute("pageproxystate") == "invalid"
    );
    EventUtils.synthesizeKey("KEY_Enter");
    info("wait for the initial conditions");
    await promise;

    info("Copy the whole url");
    await SimpleTest.promiseClipboardChange(SLOW_PAGE, () => {
      gURLBar.select();
      goDoCommand("cmd_copy");
    });

    info("Copy the initial part of the url, as a different valid url");
    await SimpleTest.promiseClipboardChange(
      SLOW_PAGE.substring(0, SLOW_PAGE.indexOf("slow-page.sjs")),
      () => {
        gURLBar.selectionStart = 0;
        gURLBar.selectionEnd = gURLBar.value.indexOf("slow-page.sjs");
        goDoCommand("cmd_copy");
      }
    );

    // This is apparently necessary to avoid a timeout on mochitest shutdown(!?)
    let browserStoppedPromise = BrowserTestUtils.browserStopped(
      gBrowser,
      null,
      true
    );
    BrowserStop();
    await browserStoppedPromise;
  });
});