Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | /** |
michael@0 | 5 | * Tests if program actors are cached when navigating in the bfcache. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | function ifWebGLSupported() { |
michael@0 | 9 | let [target, debuggee, front] = yield initBackend(SIMPLE_CANVAS_URL); |
michael@0 | 10 | front.setup({ reload: false }); |
michael@0 | 11 | |
michael@0 | 12 | reload(target); |
michael@0 | 13 | let firstProgram = yield once(front, "program-linked"); |
michael@0 | 14 | yield checkFirstCachedPrograms(firstProgram); |
michael@0 | 15 | yield checkHighlightingInTheFirstPage(firstProgram); |
michael@0 | 16 | ok(true, "The cached programs behave correctly before the navigation."); |
michael@0 | 17 | |
michael@0 | 18 | navigate(target, MULTIPLE_CONTEXTS_URL); |
michael@0 | 19 | let [secondProgram, thirdProgram] = yield getPrograms(front, 2); |
michael@0 | 20 | yield checkSecondCachedPrograms(firstProgram, [secondProgram, thirdProgram]); |
michael@0 | 21 | yield checkHighlightingInTheSecondPage(secondProgram, thirdProgram); |
michael@0 | 22 | ok(true, "The cached programs behave correctly after the navigation."); |
michael@0 | 23 | |
michael@0 | 24 | once(front, "program-linked").then(() => { |
michael@0 | 25 | ok(false, "Shouldn't have received any more program-linked notifications."); |
michael@0 | 26 | }); |
michael@0 | 27 | |
michael@0 | 28 | yield navigateInHistory(target, "back"); |
michael@0 | 29 | yield checkFirstCachedPrograms(firstProgram); |
michael@0 | 30 | yield checkHighlightingInTheFirstPage(firstProgram); |
michael@0 | 31 | ok(true, "The cached programs behave correctly after navigating back."); |
michael@0 | 32 | |
michael@0 | 33 | yield navigateInHistory(target, "forward"); |
michael@0 | 34 | yield checkSecondCachedPrograms(firstProgram, [secondProgram, thirdProgram]); |
michael@0 | 35 | yield checkHighlightingInTheSecondPage(secondProgram, thirdProgram); |
michael@0 | 36 | ok(true, "The cached programs behave correctly after navigating forward."); |
michael@0 | 37 | |
michael@0 | 38 | yield navigateInHistory(target, "back"); |
michael@0 | 39 | yield checkFirstCachedPrograms(firstProgram); |
michael@0 | 40 | yield checkHighlightingInTheFirstPage(firstProgram); |
michael@0 | 41 | ok(true, "The cached programs behave correctly after navigating back again."); |
michael@0 | 42 | |
michael@0 | 43 | yield navigateInHistory(target, "forward"); |
michael@0 | 44 | yield checkSecondCachedPrograms(firstProgram, [secondProgram, thirdProgram]); |
michael@0 | 45 | yield checkHighlightingInTheSecondPage(secondProgram, thirdProgram); |
michael@0 | 46 | ok(true, "The cached programs behave correctly after navigating forward again."); |
michael@0 | 47 | |
michael@0 | 48 | yield removeTab(target.tab); |
michael@0 | 49 | finish(); |
michael@0 | 50 | |
michael@0 | 51 | function checkFirstCachedPrograms(programActor) { |
michael@0 | 52 | return Task.spawn(function() { |
michael@0 | 53 | let programs = yield front.getPrograms(); |
michael@0 | 54 | |
michael@0 | 55 | is(programs.length, 1, |
michael@0 | 56 | "There should be 1 cached program actor."); |
michael@0 | 57 | is(programs[0], programActor, |
michael@0 | 58 | "The cached program actor was the expected one."); |
michael@0 | 59 | }) |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | function checkSecondCachedPrograms(oldProgramActor, newProgramActors) { |
michael@0 | 63 | return Task.spawn(function() { |
michael@0 | 64 | let programs = yield front.getPrograms(); |
michael@0 | 65 | |
michael@0 | 66 | is(programs.length, 2, |
michael@0 | 67 | "There should be 2 cached program actors after the navigation."); |
michael@0 | 68 | is(programs[0], newProgramActors[0], |
michael@0 | 69 | "The first cached program actor was the expected one after the navigation."); |
michael@0 | 70 | is(programs[1], newProgramActors[1], |
michael@0 | 71 | "The second cached program actor was the expected one after the navigation."); |
michael@0 | 72 | |
michael@0 | 73 | isnot(newProgramActors[0], oldProgramActor, |
michael@0 | 74 | "The old program actor is not equal to the new first program actor."); |
michael@0 | 75 | isnot(newProgramActors[1], oldProgramActor, |
michael@0 | 76 | "The old program actor is not equal to the new second program actor."); |
michael@0 | 77 | }); |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | function checkHighlightingInTheFirstPage(programActor) { |
michael@0 | 81 | return Task.spawn(function() { |
michael@0 | 82 | yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true); |
michael@0 | 83 | yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true); |
michael@0 | 84 | ok(true, "The corner pixel colors are correct before highlighting."); |
michael@0 | 85 | |
michael@0 | 86 | yield programActor.highlight([0, 1, 0, 1]); |
michael@0 | 87 | yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true); |
michael@0 | 88 | yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true); |
michael@0 | 89 | ok(true, "The corner pixel colors are correct after highlighting."); |
michael@0 | 90 | |
michael@0 | 91 | yield programActor.unhighlight(); |
michael@0 | 92 | yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true); |
michael@0 | 93 | yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true); |
michael@0 | 94 | ok(true, "The corner pixel colors are correct after unhighlighting."); |
michael@0 | 95 | }); |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | function checkHighlightingInTheSecondPage(firstProgramActor, secondProgramActor) { |
michael@0 | 99 | return Task.spawn(function() { |
michael@0 | 100 | yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1"); |
michael@0 | 101 | yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); |
michael@0 | 102 | yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1"); |
michael@0 | 103 | yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); |
michael@0 | 104 | ok(true, "The two canvases are correctly drawn before highlighting."); |
michael@0 | 105 | |
michael@0 | 106 | yield firstProgramActor.highlight([1, 0, 0, 1]); |
michael@0 | 107 | yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true, "#canvas1"); |
michael@0 | 108 | yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); |
michael@0 | 109 | yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 255, g: 0, b: 0, a: 255 }, true, "#canvas1"); |
michael@0 | 110 | yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); |
michael@0 | 111 | ok(true, "The first canvas was correctly filled after highlighting."); |
michael@0 | 112 | |
michael@0 | 113 | yield secondProgramActor.highlight([0, 1, 0, 1]); |
michael@0 | 114 | yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true, "#canvas1"); |
michael@0 | 115 | yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 255, b: 0, a: 255 }, true, "#canvas2"); |
michael@0 | 116 | yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 255, g: 0, b: 0, a: 255 }, true, "#canvas1"); |
michael@0 | 117 | yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 255, b: 0, a: 255 }, true, "#canvas2"); |
michael@0 | 118 | ok(true, "The second canvas was correctly filled after highlighting."); |
michael@0 | 119 | |
michael@0 | 120 | yield firstProgramActor.unhighlight(); |
michael@0 | 121 | yield secondProgramActor.unhighlight(); |
michael@0 | 122 | yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1"); |
michael@0 | 123 | yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); |
michael@0 | 124 | yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1"); |
michael@0 | 125 | yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); |
michael@0 | 126 | ok(true, "The two canvases were correctly filled after unhighlighting."); |
michael@0 | 127 | }); |
michael@0 | 128 | } |
michael@0 | 129 | } |