<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<div id="parent">
<canvas id="mycanvas" width="200" height="200"></canvas>
<script>
test(function(t) {
var parent = document.getElementById("parent");
var canvas = document.getElementById('mycanvas');
var ctx = canvas.getContext('2d');
ctx.fillStyle = 'red';
ctx.fillRect(0, 0, 200, 200);
var imageData;
imageData = ctx.getImageData(100, 100, 1, 1);
var data = imageData.data;
assert_equals(data[0], 255);
assert_equals(data[1], 0);
assert_equals(data[2], 0);
parent.removeChild(canvas);
// GC makes sure canvas element is removed.
if (window.GCController)
GCController.collect();
imageData = ctx.getImageData(100, 100, 1, 1);
data = imageData.data;
assert_equals(data[0], 255);
assert_equals(data[1], 0);
assert_equals(data[2], 0);
}, 'Test that the context is valid although the canvas is detached from document.');
</script>