|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Tests if program actors are cached when navigating in the bfcache. |
|
6 */ |
|
7 |
|
8 function ifWebGLSupported() { |
|
9 let [target, debuggee, front] = yield initBackend(SIMPLE_CANVAS_URL); |
|
10 front.setup({ reload: false }); |
|
11 |
|
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."); |
|
17 |
|
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."); |
|
23 |
|
24 once(front, "program-linked").then(() => { |
|
25 ok(false, "Shouldn't have received any more program-linked notifications."); |
|
26 }); |
|
27 |
|
28 yield navigateInHistory(target, "back"); |
|
29 yield checkFirstCachedPrograms(firstProgram); |
|
30 yield checkHighlightingInTheFirstPage(firstProgram); |
|
31 ok(true, "The cached programs behave correctly after navigating back."); |
|
32 |
|
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."); |
|
37 |
|
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."); |
|
42 |
|
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."); |
|
47 |
|
48 yield removeTab(target.tab); |
|
49 finish(); |
|
50 |
|
51 function checkFirstCachedPrograms(programActor) { |
|
52 return Task.spawn(function() { |
|
53 let programs = yield front.getPrograms(); |
|
54 |
|
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 } |
|
61 |
|
62 function checkSecondCachedPrograms(oldProgramActor, newProgramActors) { |
|
63 return Task.spawn(function() { |
|
64 let programs = yield front.getPrograms(); |
|
65 |
|
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."); |
|
72 |
|
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 } |
|
79 |
|
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."); |
|
85 |
|
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."); |
|
90 |
|
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 } |
|
97 |
|
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."); |
|
105 |
|
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."); |
|
112 |
|
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."); |
|
119 |
|
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 } |