-
Notifications
You must be signed in to change notification settings - Fork 54
/
structured_clone_blob.html
35 lines (35 loc) · 1.24 KB
/
structured_clone_blob.html
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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Safe passing of structured data - Blob</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
async_test(function(t) {
var blob = new Blob(['<a id="a"><b id="b">hey!</b></a>'], {type:"text/plain"});
window.addEventListener("message", this.step_func(function(msg) {
assert_true(msg.data instanceof Blob);
assert_equals(msg.data.size, blob.size);
assert_equals(msg.data.type, blob.type);
var cloned_content, original_content;
var reader = new FileReader();
reader.addEventListener("loadend", this.step_func(function() {
original_content = reader.result;
var reader2 = new FileReader();
reader2.addEventListener("loadend", this.step_func_done(function() {
cloned_content = reader2.result;
assert_equals(typeof cloned_content, typeof original_content);
assert_equals(cloned_content, original_content);
}));
reader2.readAsText(msg.data);
}));
reader.readAsText(blob);
}), false);
window.postMessage(blob, '*');
}, "Cloning a Blob into the same realm");
</script>
</body>
</html>