summaryrefslogtreecommitdiffstats
path: root/comm/mail/test/browser/content-policy/browser_composeMailto.js
blob: ceac2b2b8ecaa4894489f3da4d685a45b31c72ee (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

var utils = ChromeUtils.import("resource://testing-common/mozmill/utils.jsm");
var { close_compose_window, wait_for_compose_window } = ChromeUtils.import(
  "resource://testing-common/mozmill/ComposeHelpers.jsm"
);
var { open_content_tab_with_url } = ChromeUtils.import(
  "resource://testing-common/mozmill/ContentTabHelpers.jsm"
);
var { mc } = ChromeUtils.import(
  "resource://testing-common/mozmill/FolderDisplayHelpers.jsm"
);
var { input_value } = ChromeUtils.import(
  "resource://testing-common/mozmill/KeyboardHelpers.jsm"
);
var {
  click_menus_in_sequence,
  plan_for_modal_dialog,
  plan_for_new_window,
  wait_for_modal_dialog,
  wait_for_window_close,
} = ChromeUtils.import("resource://testing-common/mozmill/WindowHelpers.jsm");

var folder = null;
var gMsgNo = 0;
var gCwc;
var gNewTab;
var gPreCount;

var url =
  "http://mochi.test:8888/browser/comm/mail/test/browser/content-policy/html/";

add_task(async function test_openComposeFromMailToLink() {
  let tabmail = mc.window.document.getElementById("tabmail");
  // Open a content tab with the mailto link in it.
  // To open a tab we're going to have to cheat and use tabmail so we can load
  // in the data of what we want.
  gPreCount = tabmail.tabContainer.allTabs.length;
  gNewTab = open_content_tab_with_url(url + "mailtolink.html");

  plan_for_new_window("msgcompose");
  await BrowserTestUtils.synthesizeMouseAtCenter(
    "#mailtolink",
    {},
    gNewTab.browser
  );
  gCwc = wait_for_compose_window();
});

add_task(async function test_checkInsertImage() {
  // First focus on the editor element
  gCwc.window.document.getElementById("messageEditor").focus();

  // Now open the image window
  plan_for_modal_dialog("Mail:image", async function insert_image(mwc) {
    // Insert the url of the image.
    let srcloc = mwc.window.document.getElementById("srcInput");
    srcloc.focus();

    input_value(mwc, url + "pass.png");
    await new Promise(resolve => setTimeout(resolve));

    let noAlt = mwc.window.document.getElementById("noAltTextRadio");
    // Don't add alternate text
    EventUtils.synthesizeMouseAtCenter(noAlt, {}, noAlt.ownerGlobal);

    // Accept the dialog
    mwc.window.document.querySelector("dialog").acceptDialog();
  });

  let insertMenu = gCwc.window.document.getElementById("InsertPopupButton");
  let insertMenuPopup = gCwc.window.document.getElementById("InsertPopup");
  EventUtils.synthesizeMouseAtCenter(insertMenu, {}, insertMenu.ownerGlobal);
  await click_menus_in_sequence(insertMenuPopup, [{ id: "InsertImageItem" }]);

  wait_for_modal_dialog();
  wait_for_window_close();

  // Test that the image load has not been denied
  let childImages = gCwc.window.document
    .getElementById("messageEditor")
    .contentDocument.getElementsByTagName("img");

  Assert.equal(childImages.length, 1, "Should be one image in the document");

  utils.waitFor(() => childImages[0].complete);

  // Should be the only image, so just check the first.
  Assert.ok(
    !childImages[0].matches(":-moz-broken"),
    "Loading of image in a mailto compose window should not be blocked"
  );
  Assert.ok(
    childImages[0].naturalWidth > 0,
    "Non blocked image should have naturalWidth"
  );
});

add_task(function test_closeComposeWindowAndTab() {
  close_compose_window(gCwc);
  let tabmail = mc.window.document.getElementById("tabmail");

  tabmail.closeTab(gNewTab);

  if (tabmail.tabContainer.allTabs.length != gPreCount) {
    throw new Error("The content tab didn't close");
  }

  Assert.report(
    false,
    undefined,
    undefined,
    "Test ran to completion successfully"
  );
});