browser/devtools/shadereditor/test/browser_webgl-actor-test-15.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/shadereditor/test/browser_webgl-actor-test-15.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,129 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Tests if program actors are cached when navigating in the bfcache.
     1.9 + */
    1.10 +
    1.11 +function ifWebGLSupported() {
    1.12 +  let [target, debuggee, front] = yield initBackend(SIMPLE_CANVAS_URL);
    1.13 +  front.setup({ reload: false });
    1.14 +
    1.15 +  reload(target);
    1.16 +  let firstProgram = yield once(front, "program-linked");
    1.17 +  yield checkFirstCachedPrograms(firstProgram);
    1.18 +  yield checkHighlightingInTheFirstPage(firstProgram);
    1.19 +  ok(true, "The cached programs behave correctly before the navigation.");
    1.20 +
    1.21 +  navigate(target, MULTIPLE_CONTEXTS_URL);
    1.22 +  let [secondProgram, thirdProgram] = yield getPrograms(front, 2);
    1.23 +  yield checkSecondCachedPrograms(firstProgram, [secondProgram, thirdProgram]);
    1.24 +  yield checkHighlightingInTheSecondPage(secondProgram, thirdProgram);
    1.25 +  ok(true, "The cached programs behave correctly after the navigation.");
    1.26 +
    1.27 +  once(front, "program-linked").then(() => {
    1.28 +    ok(false, "Shouldn't have received any more program-linked notifications.");
    1.29 +  });
    1.30 +
    1.31 +  yield navigateInHistory(target, "back");
    1.32 +  yield checkFirstCachedPrograms(firstProgram);
    1.33 +  yield checkHighlightingInTheFirstPage(firstProgram);
    1.34 +  ok(true, "The cached programs behave correctly after navigating back.");
    1.35 +
    1.36 +  yield navigateInHistory(target, "forward");
    1.37 +  yield checkSecondCachedPrograms(firstProgram, [secondProgram, thirdProgram]);
    1.38 +  yield checkHighlightingInTheSecondPage(secondProgram, thirdProgram);
    1.39 +  ok(true, "The cached programs behave correctly after navigating forward.");
    1.40 +
    1.41 +  yield navigateInHistory(target, "back");
    1.42 +  yield checkFirstCachedPrograms(firstProgram);
    1.43 +  yield checkHighlightingInTheFirstPage(firstProgram);
    1.44 +  ok(true, "The cached programs behave correctly after navigating back again.");
    1.45 +
    1.46 +  yield navigateInHistory(target, "forward");
    1.47 +  yield checkSecondCachedPrograms(firstProgram, [secondProgram, thirdProgram]);
    1.48 +  yield checkHighlightingInTheSecondPage(secondProgram, thirdProgram);
    1.49 +  ok(true, "The cached programs behave correctly after navigating forward again.");
    1.50 +
    1.51 +  yield removeTab(target.tab);
    1.52 +  finish();
    1.53 +
    1.54 +  function checkFirstCachedPrograms(programActor) {
    1.55 +    return Task.spawn(function() {
    1.56 +      let programs = yield front.getPrograms();
    1.57 +
    1.58 +      is(programs.length, 1,
    1.59 +        "There should be 1 cached program actor.");
    1.60 +      is(programs[0], programActor,
    1.61 +        "The cached program actor was the expected one.");
    1.62 +    })
    1.63 +  }
    1.64 +
    1.65 +  function checkSecondCachedPrograms(oldProgramActor, newProgramActors) {
    1.66 +    return Task.spawn(function() {
    1.67 +      let programs = yield front.getPrograms();
    1.68 +
    1.69 +      is(programs.length, 2,
    1.70 +        "There should be 2 cached program actors after the navigation.");
    1.71 +      is(programs[0], newProgramActors[0],
    1.72 +        "The first cached program actor was the expected one after the navigation.");
    1.73 +      is(programs[1], newProgramActors[1],
    1.74 +        "The second cached program actor was the expected one after the navigation.");
    1.75 +
    1.76 +      isnot(newProgramActors[0], oldProgramActor,
    1.77 +        "The old program actor is not equal to the new first program actor.");
    1.78 +      isnot(newProgramActors[1], oldProgramActor,
    1.79 +        "The old program actor is not equal to the new second program actor.");
    1.80 +    });
    1.81 +  }
    1.82 +
    1.83 +  function checkHighlightingInTheFirstPage(programActor) {
    1.84 +    return Task.spawn(function() {
    1.85 +      yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true);
    1.86 +      yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true);
    1.87 +      ok(true, "The corner pixel colors are correct before highlighting.");
    1.88 +
    1.89 +      yield programActor.highlight([0, 1, 0, 1]);
    1.90 +      yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true);
    1.91 +      yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true);
    1.92 +      ok(true, "The corner pixel colors are correct after highlighting.");
    1.93 +
    1.94 +      yield programActor.unhighlight();
    1.95 +      yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true);
    1.96 +      yield ensurePixelIs(debuggee, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true);
    1.97 +      ok(true, "The corner pixel colors are correct after unhighlighting.");
    1.98 +    });
    1.99 +  }
   1.100 +
   1.101 +  function checkHighlightingInTheSecondPage(firstProgramActor, secondProgramActor) {
   1.102 +    return Task.spawn(function() {
   1.103 +      yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1");
   1.104 +      yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2");
   1.105 +      yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1");
   1.106 +      yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2");
   1.107 +      ok(true, "The two canvases are correctly drawn before highlighting.");
   1.108 +
   1.109 +      yield firstProgramActor.highlight([1, 0, 0, 1]);
   1.110 +      yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true, "#canvas1");
   1.111 +      yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2");
   1.112 +      yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 255, g: 0, b: 0, a: 255 }, true, "#canvas1");
   1.113 +      yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2");
   1.114 +      ok(true, "The first canvas was correctly filled after highlighting.");
   1.115 +
   1.116 +      yield secondProgramActor.highlight([0, 1, 0, 1]);
   1.117 +      yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true, "#canvas1");
   1.118 +      yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 255, b: 0, a: 255 }, true, "#canvas2");
   1.119 +      yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 255, g: 0, b: 0, a: 255 }, true, "#canvas1");
   1.120 +      yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 255, b: 0, a: 255 }, true, "#canvas2");
   1.121 +      ok(true, "The second canvas was correctly filled after highlighting.");
   1.122 +
   1.123 +      yield firstProgramActor.unhighlight();
   1.124 +      yield secondProgramActor.unhighlight();
   1.125 +      yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1");
   1.126 +      yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2");
   1.127 +      yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1");
   1.128 +      yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2");
   1.129 +      ok(true, "The two canvases were correctly filled after unhighlighting.");
   1.130 +    });
   1.131 +  }
   1.132 +}

mercurial