<!DOCTYPE html>
<script src="../../resources/js-test.js"></script>
<form id="test-form">
<input id="test-input">
</form>
<script>
description('Tests the lookup in inline event handlers');
function dispatchClick(element)
{
var clickEvent = document.createEvent('MouseEvent');
clickEvent.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
element.dispatchEvent(clickEvent);
}
var result;
var testForm = document.getElementById('test-form');
var testInput = document.getElementById('test-input');
document.a = 'document-a';
testForm.a = 'test-form-a';
testInput.a = 'test-input-a';
document.b = 'document-b';
testForm.b = 'test-form-b';
document.c = 'document-c';
testInput.setAttribute('onclick', 'result = a');
dispatchClick(testInput);
shouldBeEqualToString('result', 'test-input-a');
testInput.setAttribute('onclick', 'result = b');
dispatchClick(testInput);
shouldBeEqualToString('result', 'test-form-b');
testInput.setAttribute('onclick', 'result = c');
dispatchClick(testInput);
shouldBeEqualToString('result', 'document-c');
var div = document.createElement('div');
div.a = 'div-a';
div.setAttribute('onclick', 'result = a');
dispatchClick(div);
shouldBeEqualToString('result', 'div-a');
div.form = {b: 'fake-b'};
div.setAttribute('onclick', 'result = b');
dispatchClick(div);
shouldBeEqualToString('result', 'document-b');
div.ownerDocument = {c: 'fake-c'};
div.setAttribute('onclick', 'result = c');
dispatchClick(div);
shouldBeEqualToString('result', 'document-c');
div.setAttribute('onclick', 'result = this');
dispatchClick(div);
shouldBe('result', 'div');
div.event = 'FAIL';
div.setAttribute('onclick', 'result = event');
dispatchClick(div);
shouldNotBe('result', '"FAIL"');
</script>