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 invalidated from the cache when a window is
6 * removed from the bfcache.
7 */
9 function ifWebGLSupported() {
10 let [target, debuggee, front] = yield initBackend(SIMPLE_CANVAS_URL);
11 front.setup({ reload: false });
13 // 0. Perform the initial reload.
15 reload(target);
16 let firstProgram = yield once(front, "program-linked");
17 let programs = yield front.getPrograms();
18 is(programs.length, 1,
19 "The first program should be returned by a call to getPrograms().");
20 is(programs[0], firstProgram,
21 "The first programs was correctly retrieved from the cache.");
23 // 1. Perform a simple navigation.
25 navigate(target, MULTIPLE_CONTEXTS_URL);
26 let [secondProgram, thirdProgram] = yield getPrograms(front, 2);
27 let programs = yield front.getPrograms();
28 is(programs.length, 2,
29 "The second and third programs should be returned by a call to getPrograms().");
30 is(programs[0], secondProgram,
31 "The second programs was correctly retrieved from the cache.");
32 is(programs[1], thirdProgram,
33 "The third programs was correctly retrieved from the cache.");
35 // 2. Perform a bfcache navigation.
37 yield navigateInHistory(target, "back");
38 let globalDestroyed = observe("inner-window-destroyed");
39 let globalCreated = observe("content-document-global-created");
40 reload(target);
42 yield globalDestroyed;
43 let programs = yield front.getPrograms();
44 is(programs.length, 0,
45 "There should be no cached program actors yet.");
47 yield globalCreated;
48 let programs = yield front.getPrograms();
49 is(programs.length, 1,
50 "There should be 1 cached program actor now.");
52 yield checkHighlightingInTheFirstPage(programs[0]);
53 ok(true, "The cached programs behave correctly after navigating back and reloading.");
55 // 3. Perform a bfcache navigation and a page reload.
57 yield navigateInHistory(target, "forward");
58 let globalDestroyed = observe("inner-window-destroyed");
59 let globalCreated = observe("content-document-global-created");
60 reload(target);
62 yield globalDestroyed;
63 let programs = yield front.getPrograms();
64 is(programs.length, 0,
65 "There should be no cached program actors yet.");
67 yield getPrograms(front, 2);
68 yield globalCreated;
69 let programs = yield front.getPrograms();
70 is(programs.length, 2,
71 "There should be 2 cached program actors now.");
73 yield checkHighlightingInTheSecondPage(programs[0], programs[1]);
74 ok(true, "The cached programs behave correctly after navigating forward and reloading.");
76 yield removeTab(target.tab);
77 finish();
79 function checkHighlightingInTheFirstPage(programActor) {
80 return Task.spawn(function() {
81 yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true);
82 yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true);
83 ok(true, "The corner pixel colors are correct before highlighting.");
85 yield programActor.highlight([0, 1, 0, 1]);
86 yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true);
87 yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true);
88 ok(true, "The corner pixel colors are correct after highlighting.");
90 yield programActor.unhighlight();
91 yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true);
92 yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true);
93 ok(true, "The corner pixel colors are correct after unhighlighting.");
94 });
95 }
97 function checkHighlightingInTheSecondPage(firstProgramActor, secondProgramActor) {
98 return Task.spawn(function() {
99 yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1");
100 yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2");
101 yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1");
102 yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2");
103 ok(true, "The two canvases are correctly drawn before highlighting.");
105 yield firstProgramActor.highlight([1, 0, 0, 1]);
106 yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true, "#canvas1");
107 yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2");
108 yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 255, g: 0, b: 0, a: 255 }, true, "#canvas1");
109 yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2");
110 ok(true, "The first canvas was correctly filled after highlighting.");
112 yield secondProgramActor.highlight([0, 1, 0, 1]);
113 yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true, "#canvas1");
114 yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 255, b: 0, a: 255 }, true, "#canvas2");
115 yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 255, g: 0, b: 0, a: 255 }, true, "#canvas1");
116 yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 255, b: 0, a: 255 }, true, "#canvas2");
117 ok(true, "The second canvas was correctly filled after highlighting.");
119 yield firstProgramActor.unhighlight();
120 yield secondProgramActor.unhighlight();
121 yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1");
122 yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2");
123 yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1");
124 yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2");
125 ok(true, "The two canvases were correctly filled after unhighlighting.");
126 });
127 }
128 }