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

<script type="application/javascript"
        src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript"
        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.open("data:text/html,<body onload='window.opener.doChecks(this)'><input id='i' value='Sample Text'></body>",
                "_blank", "chrome,width=200,height=200");
  });
}

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>