summaryrefslogtreecommitdiffstats
path: root/netwerk/test/browser/browser_post_auth.js
blob: 1168cdabb1ccc0530e7d77644c8a89611ef0248d (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"use strict";

const { PromptTestUtils } = ChromeUtils.importESModule(
  "resource://testing-common/PromptTestUtils.sys.mjs"
);

const FOLDER = getRootDirectory(gTestPath).replace(
  "chrome://mochitests/content/",
  "http://mochi.test:8888/"
);

add_task(async function () {
  let tab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    "about:blank"
  );
  let browserLoadedPromise = BrowserTestUtils.browserLoaded(
    tab.linkedBrowser,
    true,
    `${FOLDER}post.html`
  );
  BrowserTestUtils.startLoadingURIString(
    tab.linkedBrowser,
    `${FOLDER}post.html`
  );
  await browserLoadedPromise;

  let finalLoadPromise = BrowserTestUtils.browserLoaded(
    tab.linkedBrowser,
    true,
    `${FOLDER}auth_post.sjs`
  );

  await SpecialPowers.spawn(tab.linkedBrowser, [], async function () {
    let file = new content.File(
      [new content.Blob(["1234".repeat(1024 * 500)], { type: "text/plain" })],
      "test-name"
    );
    content.document.getElementById("input_file").mozSetFileArray([file]);
    content.document.getElementById("form").submit();
  });

  let promptPromise = PromptTestUtils.handleNextPrompt(
    tab.linkedBrowser,
    {
      modalType: Ci.nsIPrompt.MODAL_TYPE_TAB,
      promptType: "promptUserAndPass",
    },
    { buttonNumClick: 0, loginInput: "user", passwordInput: "pass" }
  );

  await promptPromise;

  await finalLoadPromise;

  await SpecialPowers.spawn(tab.linkedBrowser, [], async function () {
    Assert.ok(content.location.href.includes("auth_post.sjs"));
    Assert.ok(content.document.body.innerHTML.includes("1234"));
  });

  BrowserTestUtils.removeTab(tab);

  // Clean up any active logins we added during the test.
  Services.obs.notifyObservers(null, "net:clear-active-logins");
});