multiple-frames.html 1.36 KB
Newer Older
1 2
<html>
<head>
3
<script src="../resources/js-test-pre.js"></script>
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
</head>
<body>
<script>
description('Tests using DeviceProximity from multiple frames.');

var DeviceProximityEvent;
function checkProximity(event) {
    DeviceProximityEvent = event;
    shouldBe('DeviceProximityEvent.value', 'firedEvent.value');
    shouldBe('DeviceProximityEvent.min', 'firedEvent.min');
    shouldBe('DeviceProximityEvent.max', 'firedEvent.max');
}

var hasMainFrameEventFired = false;
function mainFrameListener(event) {
    checkProximity(event);
    hasMainFrameEventFired = true;
    maybeFinishTest();
}

var hasChildFrameEventFired = false;
function childFrameListener(event) {
    checkProximity(event);
    hasChildFrameEventFired = true;
    maybeFinishTest();
}

function maybeFinishTest() {
    if (hasMainFrameEventFired && hasChildFrameEventFired)
        finishJSTest();
}

var childFrame = document.createElement('iframe');
document.body.appendChild(childFrame);
childFrame.contentWindow.addEventListener('webkitdeviceproximity', childFrameListener);

window.addEventListener('webkitdeviceproximity', mainFrameListener);
var firedEvent = {value: 2.2, min: 1.1, max: 3.3};
42
internals.setDeviceProximity('webkitdeviceproximity', firedEvent.value, firedEvent.min, firedEvent.max);
43 44 45

window.jsTestIsAsync = true;
</script>
46
<script src="../resources/js-test-post.js"></script>
47 48
</body>
</html>