summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/workers/constructors/SharedWorker/same-origin.html
blob: 78d53164e6423f12cdb6650c61f392bc3252cbaf (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
67
<!--
/*
-->
<!doctype html>
<title>same-origin checks</title>
<link rel=help href="http://www.whatwg.org/html/#dom-sharedworker">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
// Needed to prevent a race condition if a worker throws an exception that may or may
// not propogate to the window before the tests finish
setup({allow_uncaught_exception: true});

function testSharedWorkerHelper(t, script) {
  try {
    var worker = new SharedWorker(script, '');
    worker.onerror = t.step_func_done(function(e) {
      assert_true(e instanceof Event);
    });
  } catch (e) {
    t.step_func_done(function(e) { assert_true(true); });
  }
}

test(function() {
  assert_throws("SecurityError", function() { new SharedWorker('unsupported:', ''); });
}, "unsupported_scheme");

async_test(function() {
  var worker = new SharedWorker('data:,onconnect = function(e) { e.ports[0].postMessage(1); }', '');
  worker.port.onmessage = this.step_func_done(function(e) {
    assert_equals(e.data, 1);
  });
}, "data_url");

async_test(function(t) {
  testSharedWorkerHelper(this, 'javascript:""');
}, "javascript_url");

async_test(function(t) {
  testSharedWorkerHelper(this, 'about:blank');
}, "about_blank");

async_test(function(t) {
  testSharedWorkerHelper(this, 'http://www.opera.com/');
}, "opera_com");

async_test(function(t) {
  testSharedWorkerHelper(this, location.protocol+'//'+location.hostname+':81/');
}, "port_81");

async_test(function(t) {
  testSharedWorkerHelper(this, 'https://'+location.hostname+':80/');
}, "https_port_80");

async_test(function(t) {
  testSharedWorkerHelper(this, 'https://'+location.hostname+':8000/');
}, "https_port_8000");

async_test(function(t) {
  testSharedWorkerHelper(this, 'http://'+location.hostname+':8012/');
}, "http_port_8012");
</script>
<!--
*/
//-->