michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Tests if program actors are invalidated from the cache when a window is michael@0: * removed from the bfcache. michael@0: */ michael@0: michael@0: function ifWebGLSupported() { michael@0: let [target, debuggee, front] = yield initBackend(SIMPLE_CANVAS_URL); michael@0: front.setup({ reload: false }); michael@0: michael@0: // 0. Perform the initial reload. michael@0: michael@0: reload(target); michael@0: let firstProgram = yield once(front, "program-linked"); michael@0: let programs = yield front.getPrograms(); michael@0: is(programs.length, 1, michael@0: "The first program should be returned by a call to getPrograms()."); michael@0: is(programs[0], firstProgram, michael@0: "The first programs was correctly retrieved from the cache."); michael@0: michael@0: // 1. Perform a simple navigation. michael@0: michael@0: navigate(target, MULTIPLE_CONTEXTS_URL); michael@0: let [secondProgram, thirdProgram] = yield getPrograms(front, 2); michael@0: let programs = yield front.getPrograms(); michael@0: is(programs.length, 2, michael@0: "The second and third programs should be returned by a call to getPrograms()."); michael@0: is(programs[0], secondProgram, michael@0: "The second programs was correctly retrieved from the cache."); michael@0: is(programs[1], thirdProgram, michael@0: "The third programs was correctly retrieved from the cache."); michael@0: michael@0: // 2. Perform a bfcache navigation. michael@0: michael@0: yield navigateInHistory(target, "back"); michael@0: let globalDestroyed = observe("inner-window-destroyed"); michael@0: let globalCreated = observe("content-document-global-created"); michael@0: reload(target); michael@0: michael@0: yield globalDestroyed; michael@0: let programs = yield front.getPrograms(); michael@0: is(programs.length, 0, michael@0: "There should be no cached program actors yet."); michael@0: michael@0: yield globalCreated; michael@0: let programs = yield front.getPrograms(); michael@0: is(programs.length, 1, michael@0: "There should be 1 cached program actor now."); michael@0: michael@0: yield checkHighlightingInTheFirstPage(programs[0]); michael@0: ok(true, "The cached programs behave correctly after navigating back and reloading."); michael@0: michael@0: // 3. Perform a bfcache navigation and a page reload. michael@0: michael@0: yield navigateInHistory(target, "forward"); michael@0: let globalDestroyed = observe("inner-window-destroyed"); michael@0: let globalCreated = observe("content-document-global-created"); michael@0: reload(target); michael@0: michael@0: yield globalDestroyed; michael@0: let programs = yield front.getPrograms(); michael@0: is(programs.length, 0, michael@0: "There should be no cached program actors yet."); michael@0: michael@0: yield getPrograms(front, 2); michael@0: yield globalCreated; michael@0: let programs = yield front.getPrograms(); michael@0: is(programs.length, 2, michael@0: "There should be 2 cached program actors now."); michael@0: michael@0: yield checkHighlightingInTheSecondPage(programs[0], programs[1]); michael@0: ok(true, "The cached programs behave correctly after navigating forward and reloading."); michael@0: michael@0: yield removeTab(target.tab); michael@0: finish(); michael@0: michael@0: function checkHighlightingInTheFirstPage(programActor) { michael@0: return Task.spawn(function() { michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true); michael@0: yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true); michael@0: ok(true, "The corner pixel colors are correct before highlighting."); michael@0: michael@0: yield programActor.highlight([0, 1, 0, 1]); michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true); michael@0: yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true); michael@0: ok(true, "The corner pixel colors are correct after highlighting."); michael@0: michael@0: yield programActor.unhighlight(); michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true); michael@0: yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true); michael@0: ok(true, "The corner pixel colors are correct after unhighlighting."); michael@0: }); michael@0: } michael@0: michael@0: function checkHighlightingInTheSecondPage(firstProgramActor, secondProgramActor) { michael@0: return Task.spawn(function() { michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); michael@0: ok(true, "The two canvases are correctly drawn before highlighting."); michael@0: michael@0: yield firstProgramActor.highlight([1, 0, 0, 1]); michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 255, g: 0, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); michael@0: ok(true, "The first canvas was correctly filled after highlighting."); michael@0: michael@0: yield secondProgramActor.highlight([0, 1, 0, 1]); michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 255, b: 0, a: 255 }, true, "#canvas2"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 255, g: 0, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 255, b: 0, a: 255 }, true, "#canvas2"); michael@0: ok(true, "The second canvas was correctly filled after highlighting."); michael@0: michael@0: yield firstProgramActor.unhighlight(); michael@0: yield secondProgramActor.unhighlight(); michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); michael@0: ok(true, "The two canvases were correctly filled after unhighlighting."); michael@0: }); michael@0: } michael@0: }