summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/lifecycle/worker-dispay-none.tentative.html
blob: 0bcfde6d179bb5573ce78fa46827211e7c38dc35 (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
64
65
66
<!DOCTYPE html>
<meta charset="utf-8">
<title>Child frame with worker marked as frozen</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
async_test((t) => {

  var child = document.createElement('iframe');

  var loaded = false;
  var frozen = false;
  var resumed = false;

  var subworker_freeze_count = 0;
  var subworker2_freeze_count = 0;
  var subworker_count = 0;
  var subworker2_count = 0;
  var bc = new BroadcastChannel('subworker_channel');
  bc.onmessage = t.step_func((e) => {
    if (e.data == 'subworker') {
      subworker_count++;
    } else if (e.data == 'subworker2') {
      subworker2_count++;
    } else {
      assert_unreached('bad message');
    }

    // Ensure that if we have resumed that we get at least
    // one message from each worker.
    if (loaded && frozen && resumed &&
        subworker2_count > subworker2_freeze_count &&
        subworker_count > subworker_freeze_count) {
      t.done();
    } else if (loaded && frozen && !resumed) {
      // Ensure that at most one message is sent after the frozen state.
      assert_true(subworker_count - subworker_freeze_count <= 1);
      assert_true(subworker2_count - subworker2_freeze_count <= 1);
    }
  });

  window.addEventListener('message', t.step_func((e) => {
    if (e.data == "load") {
      loaded = true;
    } else if (e.data == "freeze") {
      assert_true(loaded);
      frozen = true;
      subworker_freeze_count = subworker_count;
      subworker2_freeze_count = subworker2_count;
      child.style = "display: block";
    } else if (e.data == "resume") {
      assert_true(loaded);
      assert_true(frozen);
      resumed = true;
    }
  }));

  child.allow = "execution-while-not-rendered 'none'";
  child.src = "resources/subframe_worker.html";
  document.body.appendChild(child);
  child.style = "display: none";
}, "Child frame frozen");

</script>
</body>