summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/chrome/test_clipboard_events_chrome.html
blob: 0c67d5e280aad2adcd8c2cbb0ec19af145070a75 (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
<html>
<body onload="runTest()">

<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>

<script>
// This test checks that the dom.event.clipboardevents.enabled does not apply to chrome shells.

SimpleTest.waitForExplicitFinish();
function runTest()
{
  SpecialPowers.pushPrefEnv({"set": [['dom.event.clipboardevents.enabled', false]]}, function() {
    window.openDialog("file_clipboard_events_chrome.html", "_blank", "chrome,width=200,height=200,noopener", window);
  });
}

var event_fired = false;

function doChecks(win)
{
  var windowFocused = function() {
    var textbox = win.document.getElementById("i");
    textbox.value = "Sample Text";

    textbox.oncut = function() { event_fired = true; };
    textbox.oncopy = function() { event_fired = true; };
    textbox.onpaste = function() { event_fired = true; };

    textbox.select();
    textbox.focus();

    textbox.setSelectionRange(1, 4);
    synthesizeKey("x", {accelKey: 1}, win);
    is(textbox.value, "Sle Text", "cut changed text when preference is disabled");
    ok(event_fired, "cut event fired when preference is disabled")

    event_fired = false;
    textbox.setSelectionRange(4, 6);
    synthesizeKey("c", {accelKey: 1}, win);
    is(textbox.value, "Sle Text", "cut changed text when preference is disabled");
    ok(event_fired, "copy event fired when preference is disabled")

    event_fired = false;
    textbox.setSelectionRange(1, 4);
    synthesizeKey("v", {accelKey: 1}, win);
    is(textbox.value, "STeText", "paste changed text when preference is disabled");
    ok(event_fired, "paste event fired when preference is disabled")

    win.close();
    SimpleTest.finish();
  }

  SimpleTest.waitForFocus(windowFocused, win);
}

</script>

<p id="display"></p>
</body></html>