summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/dom/events/Event-timestamp-cross-realm-getter.html
blob: 45823de26b27f963d3a5b594e8c2e5f3946d6693 (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
<!doctype html>
<meta charset="utf-8">
<title>event.timeStamp is initialized using event's relevant global object</title>
<link rel="help" href="https://dom.spec.whatwg.org/#ref-for-dom-event-timestamp%E2%91%A1">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<body>
<script>
const t = async_test();
t.step_timeout(() => {
  const iframeDelayed = document.createElement("iframe");
  iframeDelayed.onload = t.step_func_done(() => {
    // Use eval() to eliminate false-positive test result for WebKit builds before r280256,
    // which invoked WebIDL accessors in context of lexical (caller) global object.
    const timeStampExpected = iframeDelayed.contentWindow.eval(`new Event("foo").timeStamp`);
    const eventDelayed = new iframeDelayed.contentWindow.Event("foo");

    const {get} = Object.getOwnPropertyDescriptor(Event.prototype, "timeStamp");
    assert_approx_equals(get.call(eventDelayed), timeStampExpected, 5, "via Object.getOwnPropertyDescriptor");

    Object.setPrototypeOf(eventDelayed, Event.prototype);
    assert_approx_equals(eventDelayed.timeStamp, timeStampExpected, 5, "via Object.setPrototypeOf");
  });
  document.body.append(iframeDelayed);
}, 1000);
</script>