summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/general/browser_contextmenu_input.js
blob: cfc7b7529d197d157f598c815dc16a7e68e5d705 (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
"use strict";

let contextMenu;
let hasPocket = Services.prefs.getBoolPref("extensions.pocket.enabled");

add_task(function* test_setup() {
  const example_base = "http://example.com/browser/browser/base/content/test/general/";
  const url = example_base + "subtst_contextmenu_input.html";
  yield BrowserTestUtils.openNewForegroundTab(gBrowser, url);

  const chrome_base = "chrome://mochitests/content/browser/browser/base/content/test/general/";
  const contextmenu_common = chrome_base + "contextmenu_common.js";
  Services.scriptloader.loadSubScript(contextmenu_common, this);
});

add_task(function* test_text_input() {
  yield test_contextmenu("#input_text",
    ["context-undo",        false,
     "---",                 null,
     "context-cut",         true,
     "context-copy",        true,
     "context-paste",       null, // ignore clipboard state
     "context-delete",      false,
     "---",                 null,
     "context-selectall",   false,
     "---",                 null,
     "spell-check-enabled", true]);
});

add_task(function* test_text_input_spellcheck() {
  yield test_contextmenu("#input_spellcheck_no_value",
    ["context-undo",        false,
     "---",                 null,
     "context-cut",         true,
     "context-copy",        true,
     "context-paste",       null, // ignore clipboard state
     "context-delete",      false,
     "---",                 null,
     "context-selectall",   false,
     "---",                 null,
     "spell-check-enabled", true,
     "spell-dictionaries",  true,
         ["spell-check-dictionary-en-US", true,
          "---",                          null,
          "spell-add-dictionaries",       true], null],
    {
      waitForSpellCheck: true,
      // Need to dynamically add/remove the "password" type or LoginManager
      // will think that the form inputs on the page are part of a login
      // and will add fill-login context menu items.
      *preCheckContextMenuFn() {
        yield ContentTask.spawn(gBrowser.selectedBrowser, null, function*() {
          let doc = content.document;
          let input = doc.getElementById("input_spellcheck_no_value");
          input.setAttribute("spellcheck", "true");
          input.clientTop; // force layout flush
        });
      },
    }
  );
});

add_task(function* test_text_input_spellcheckwrong() {
  yield test_contextmenu("#input_spellcheck_incorrect",
    ["*prodigality",        true, // spelling suggestion
     "spell-add-to-dictionary", true,
     "---",                 null,
     "context-undo",        false,
     "---",                 null,
     "context-cut",         true,
     "context-copy",        true,
     "context-paste",       null, // ignore clipboard state
     "context-delete",      false,
     "---",                 null,
     "context-selectall",   true,
     "---",                 null,
     "spell-check-enabled", true,
     "spell-dictionaries",  true,
         ["spell-check-dictionary-en-US", true,
          "---",                          null,
          "spell-add-dictionaries",       true], null],
     {waitForSpellCheck: true}
   );
});

add_task(function* test_text_input_spellcheckcorrect() {
  yield test_contextmenu("#input_spellcheck_correct",
    ["context-undo",        false,
     "---",                 null,
     "context-cut",         true,
     "context-copy",        true,
     "context-paste",       null, // ignore clipboard state
     "context-delete",      false,
     "---",                 null,
     "context-selectall",   true,
     "---",                 null,
     "spell-check-enabled", true,
     "spell-dictionaries",  true,
         ["spell-check-dictionary-en-US", true,
          "---",                          null,
          "spell-add-dictionaries",       true], null],
     {waitForSpellCheck: true}
  );
});

add_task(function* test_text_input_disabled() {
  yield test_contextmenu("#input_disabled",
    ["context-undo",        false,
     "---",                 null,
     "context-cut",         true,
     "context-copy",        true,
     "context-paste",       null, // ignore clipboard state
     "context-delete",      false,
     "---",                 null,
     "context-selectall",   true,
     "---",                 null,
     "spell-check-enabled", true],
    {skipFocusChange: true}
  );
});

add_task(function* test_password_input() {
  todo(false, "context-selectall is enabled on osx-e10s, and windows when" +
              " it should be disabled");
  yield test_contextmenu("#input_password",
    ["context-undo",        false,
     "---",                 null,
     "context-cut",         true,
     "context-copy",        true,
     "context-paste",       null, // ignore clipboard state
     "context-delete",      false,
     "---",                 null,
     "context-selectall",   null,
     "---",                 null,
     "fill-login",          null,
       ["fill-login-no-logins",       false,
        "---",                        null,
        "fill-login-saved-passwords", true], null],
    {
      skipFocusChange: true,
      // Need to dynamically add/remove the "password" type or LoginManager
      // will think that the form inputs on the page are part of a login
      // and will add fill-login context menu items.
      *preCheckContextMenuFn() {
        yield ContentTask.spawn(gBrowser.selectedBrowser, null, function*() {
          let doc = content.document;
          let input = doc.getElementById("input_password");
          input.type = "password";
          input.clientTop; // force layout flush
        });
      },
      *postCheckContextMenuFn() {
        yield ContentTask.spawn(gBrowser.selectedBrowser, null, function*() {
          let doc = content.document;
          let input = doc.getElementById("input_password");
          input.type = "text";
          input.clientTop; // force layout flush
        });
      },
    }
  );
});

add_task(function* test_tel_email_url_number_input() {
  todo(false, "context-selectall is enabled on osx-e10s, and windows when" +
              " it should be disabled");
  for (let selector of ["#input_email", "#input_url", "#input_tel", "#input_number"]) {
    yield test_contextmenu(selector,
      ["context-undo",        false,
       "---",                 null,
       "context-cut",         true,
       "context-copy",        true,
       "context-paste",       null, // ignore clipboard state
       "context-delete",      false,
       "---",                 null,
       "context-selectall",   null],
      {skipFocusChange: true}
    );
  }
});

add_task(function* test_date_time_color_range_month_week_datetimelocal_input() {
  for (let selector of ["#input_date", "#input_time", "#input_color",
                        "#input_range", "#input_month", "#input_week",
                        "#input_datetime-local"]) {
    yield test_contextmenu(selector,
      ["context-navigation", null,
           ["context-back",         false,
            "context-forward",      false,
            "context-reload",       true,
            "context-bookmarkpage", true], null,
       "---",                  null,
       "context-savepage",     true,
       ...(hasPocket ? ["context-pocket", true] : []),
       "---",                  null,
       "context-viewbgimage",  false,
       "context-selectall",    null,
       "---",                  null,
       "context-viewsource",   true,
       "context-viewinfo",     true],
      {skipFocusChange: true}
    );
  }
});

add_task(function* test_search_input() {
  todo(false, "context-selectall is enabled on osx-e10s, and windows when" +
              " it should be disabled");
  yield test_contextmenu("#input_search",
    ["context-undo",        false,
     "---",                 null,
     "context-cut",         true,
     "context-copy",        true,
     "context-paste",       null, // ignore clipboard state
     "context-delete",      false,
     "---",                 null,
     "context-selectall",   null,
     "---",                 null,
     "spell-check-enabled", true],
    {skipFocusChange: true}
  );
});

add_task(function* test_text_input_readonly() {
  todo(false, "context-selectall is enabled on osx-e10s, and windows when" +
              " it should be disabled");
  todo(false, "spell-check should not be enabled for input[readonly]. see bug 1246296");
  yield test_contextmenu("#input_readonly",
    ["context-undo",        false,
     "---",                 null,
     "context-cut",         true,
     "context-copy",        true,
     "context-paste",       null, // ignore clipboard state
     "context-delete",      false,
     "---",                 null,
     "context-selectall",   null],
    {skipFocusChange: true}
  );
});

add_task(function* test_cleanup() {
  yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
});