Bug 850198, Fix null pointer checks on clipboardData when clipboard events preference is false, r=smaug

This commit is contained in:
Neil Deakin 2013-03-12 14:50:05 -04:00
Родитель 3338681f0a
Коммит 9315900726
2 изменённых файлов: 44 добавлений и 4 удалений

Просмотреть файл

@ -732,8 +732,11 @@ nsCopySupport::FireClipboardEvent(int32_t aType, nsIPresShell* aPresShell, nsISe
if (aType == NS_PASTE) {
// Clear and mark the clipboardData as readonly. This prevents someone
// from reading the clipboard contents after the paste event has fired.
if (clipboardData) {
clipboardData->ClearAll();
clipboardData->SetReadOnly();
}
return doDefault;
}
@ -758,7 +761,7 @@ nsCopySupport::FireClipboardEvent(int32_t aType, nsIPresShell* aPresShell, nsISe
if (NS_FAILED(rv)) {
return false;
}
} else {
} else if (clipboardData) {
// check to see if any data was put on the data transfer.
clipboardData->GetMozItemCount(&count);
if (count) {

Просмотреть файл

@ -66,7 +66,8 @@ window.onfocus = function()
test_input_paste_dataTransfer,
test_input_paste_abort_dataTransfer,
test_input_copypaste_dataTransfer_multiple,
test_input_copy_button_dataTransfer
test_input_copy_button_dataTransfer,
test_eventspref_disabled
];
// Run the main tests. This will also populate the delayedTests array
@ -571,6 +572,42 @@ function test_input_copy_button_dataTransfer() {
}
}
function test_eventspref_disabled() {
// Disable clipboard events
SpecialPowers.setBoolPref("dom.event.clipboardevents.enabled", false);
var event_fired = false;
contentInput.oncut = function() { event_fired = true; };
contentInput.oncopy = function() { event_fired = true; };
contentInput.onpaste = function() { event_fired = true; };
try {
selectContentInput();
contentInput.setSelectionRange(1, 4);
synthesizeKey("x", {accelKey: 1});
is(contentInput.value, "IT TEXT", "cut changed text when preference is disabled");
is(getClipboardText(), "NPU", "cut changed clipboard when preference is disabled");
ok(!event_fired, "cut event did not fire when preference is disabled")
event_fired = false;
contentInput.setSelectionRange(3, 6);
synthesizeKey("c", {accelKey: 1});
is(getClipboardText(), "TEX", "copy changed clipboard when preference is disabled");
ok(!event_fired, "copy event did not fire when preference is disabled")
event_fired = false;
contentInput.setSelectionRange(0, 2);
synthesizeKey("v", {accelKey: 1});
is(contentInput.value, "TEX TEXT", "paste changed text when preference is disabled");
ok(!event_fired, "paste event did not fire when preference is disabled")
} finally {
contentInput.oncut = null;
contentInput.oncopy = null;
contentInput.onpaste = null;
}
SpecialPowers.clearUserPref("dom.event.clipboardevents.enabled");
}
let expectedData = [];
// Check to make that synthetic events do not change the clipboard