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