summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/http/tests/serviceworker/fetch-frame-resource.html
blob: 9a202235fb5c0ae41f15a20ef5de232d30b9a292 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!DOCTYPE html>
<title>Service Worker: Fetch for the frame loading.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../resources/get-host-info.js"></script>
<script src="resources/test-helpers.js"></script>
<body>
<script>
var worker = 'resources/fetch-rewrite-worker.js';
var path = base_path() + 'resources/fetch-access-control.php';
var host_info = get_host_info();

if (window.testRunner) {
  testRunner.setCanOpenWindows();
}

async_test(function(t) {
    var scope = 'resources/fetch-frame-resource/frame-basic';
    service_worker_unregister_and_register(t, worker, scope)
      .then(function(reg) {
          return wait_for_state(t, reg.installing, 'activated');
        })
      .then(function() {
          return with_iframe(
            scope + '?url=' +
            encodeURIComponent(host_info['HTTP_ORIGIN'] + path));
        })
      .then(function(frame) {
          assert_not_equals(
            frame.contentDocument.body.textContent,
            '',
            'Basic type response could be loaded in the iframe.');
          frame.remove();
          return service_worker_unregister_and_done(t, scope);
        })
      .catch(unreached_rejection(t));
  }, 'Basic type response could be loaded in the iframe.');

async_test(function(t) {
    var scope = 'resources/fetch-frame-resource/frame-cors';
    service_worker_unregister_and_register(t, worker, scope)
      .then(function(reg) {
          return wait_for_state(t, reg.installing, 'activated');
        })
      .then(function() {
          var frame = document.createElement('iframe');
          frame.src =
            scope + '?mode=cors&url=' +
            encodeURIComponent(host_info['HTTP_REMOTE_ORIGIN'] + path +
                               '?ACAOrigin=' + host_info['HTTP_ORIGIN']);
          document.body.appendChild(frame);
          // We can't catch the network error on iframe. So we use the timer.
          return new Promise(function(resolve) {
              setTimeout(function() { resolve(frame); }, 1000);
            });
        })
      .then(function(frame) {
          assert_equals(
            frame.contentDocument.body.textContent,
            '',
            'CORS type response could not be loaded in the iframe.');
          frame.remove();
          return service_worker_unregister_and_done(t, scope);
        })
      .catch(unreached_rejection(t));
  }, 'CORS type response could not be loaded in the iframe.');

async_test(function(t) {
    var scope = 'resources/fetch-frame-resource/frame-opaque';
    service_worker_unregister_and_register(t, worker, scope)
      .then(function(reg) {
          return wait_for_state(t, reg.installing, 'activated');
        })
      .then(function() {
          var frame = document.createElement('iframe');
          frame.src =
            scope + '?mode=no-cors&url=' +
            encodeURIComponent(host_info['HTTP_REMOTE_ORIGIN'] + path);
          document.body.appendChild(frame);
          // We can't catch the network error on iframe. So we use the timer.
          return new Promise(function(resolve) {
              setTimeout(function() { resolve(frame); }, 1000);
            });
        })
      .then(function(frame) {
          assert_equals(
            frame.contentDocument.body.textContent,
            '',
            'Opaque type response could not be loaded in the iframe.');
          frame.remove();
          return service_worker_unregister_and_done(t, scope);
        })
      .catch(unreached_rejection(t));
  }, 'Opaque type response could not be loaded in the iframe.');

async_test(function(t) {
    var scope = 'resources/fetch-frame-resource/window-basic';
    service_worker_unregister_and_register(t, worker, scope)
      .then(function(reg) {
          return wait_for_state(t, reg.installing, 'activated');
        })
      .then(function() {
          return new Promise(function(resolve) {
              var win = window.open(
                scope + '?url=' +
                encodeURIComponent(host_info['HTTP_ORIGIN'] + path));
              win.onload = function() { resolve(win); };
            });
        })
      .then(function(win) {
          assert_not_equals(
            win.document.body.textContent,
            '',
            'Basic type response could be loaded in the new window.');
          win.close();
          return service_worker_unregister_and_done(t, scope);
        })
      .catch(unreached_rejection(t));
  }, 'Basic type response could be loaded in the new window.');

async_test(function(t) {
    var scope = 'resources/fetch-frame-resource/window-cors';
    service_worker_unregister_and_register(t, worker, scope)
      .then(function(reg) {
          return wait_for_state(t, reg.installing, 'activated');
        })
      .then(function() {
          var win = window.open(
            scope + '?mode=cors&url=' +
            encodeURIComponent(host_info['HTTP_REMOTE_ORIGIN'] + path +
                               '?ACAOrigin=' + host_info['HTTP_ORIGIN']));
          // We can't catch the network error on window. So we use the timer.
          return new Promise(function(resolve) {
              setTimeout(function() { resolve(win); }, 1000);
            });
        })
      .then(function(win) {
          assert_equals(
            win.document.body.textContent,
            '',
            'CORS type response could not be loaded in the new window.');
          win.close();
          return service_worker_unregister_and_done(t, scope);
        })
      .catch(unreached_rejection(t));
  }, 'CORS type response could not be loaded in the new window.');

async_test(function(t) {
    var scope = 'resources/fetch-frame-resource/window-opaque';
    service_worker_unregister_and_register(t, worker, scope)
      .then(function(reg) {
          return wait_for_state(t, reg.installing, 'activated');
        })
      .then(function() {
          var win = window.open(
            scope + '?mode=no-cors&url=' +
            encodeURIComponent(host_info['HTTP_REMOTE_ORIGIN'] + path));
          // We can't catch the network error on window. So we use the timer.
          return new Promise(function(resolve) {
              setTimeout(function() { resolve(win); }, 1000);
            });
        })
      .then(function(win) {
          assert_equals(
            win.document.body.textContent,
            '',
            'Opaque type response could not be loaded in the new window.');
          win.close();
          return service_worker_unregister_and_done(t, scope);
        })
      .catch(unreached_rejection(t));
  }, 'Opaque type response could not be loaded in the new window.');
</script>
</body>