browser_webgl-actor-test-06.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. /**
  4. * Tests that the highlight/unhighlight and blackbox/unblackbox operations on
  5. * program actors work as expected.
  6. */
  7. function* ifWebGLSupported() {
  8. let { target, front } = yield initBackend(SIMPLE_CANVAS_URL);
  9. front.setup({ reload: true });
  10. let programActor = yield once(front, "program-linked");
  11. let vertexShader = yield programActor.getVertexShader();
  12. let fragmentShader = yield programActor.getFragmentShader();
  13. yield ensurePixelIs(front, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true);
  14. yield ensurePixelIs(front, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true);
  15. yield checkShaderSource("The shader sources are correct before highlighting.");
  16. ok(true, "The corner pixel colors are correct before highlighting.");
  17. yield programActor.highlight([0, 1, 0, 1]);
  18. yield ensurePixelIs(front, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true);
  19. yield ensurePixelIs(front, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true);
  20. yield checkShaderSource("The shader sources are preserved after highlighting.");
  21. ok(true, "The corner pixel colors are correct after highlighting.");
  22. yield programActor.unhighlight();
  23. yield ensurePixelIs(front, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true);
  24. yield ensurePixelIs(front, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true);
  25. yield checkShaderSource("The shader sources are correct after unhighlighting.");
  26. ok(true, "The corner pixel colors are correct after unhighlighting.");
  27. yield programActor.blackbox();
  28. yield ensurePixelIs(front, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true);
  29. yield ensurePixelIs(front, { x: 511, y: 511 }, { r: 0, g: 0, b: 0, a: 255 }, true);
  30. yield checkShaderSource("The shader sources are preserved after blackboxing.");
  31. ok(true, "The corner pixel colors are correct after blackboxing.");
  32. yield programActor.unblackbox();
  33. yield ensurePixelIs(front, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true);
  34. yield ensurePixelIs(front, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true);
  35. yield checkShaderSource("The shader sources are correct after unblackboxing.");
  36. ok(true, "The corner pixel colors are correct after unblackboxing.");
  37. function checkShaderSource(aMessage) {
  38. return Task.spawn(function* () {
  39. let newVertexShader = yield programActor.getVertexShader();
  40. let newFragmentShader = yield programActor.getFragmentShader();
  41. is(vertexShader, newVertexShader,
  42. "The same vertex shader actor was retrieved.");
  43. is(fragmentShader, newFragmentShader,
  44. "The same fragment shader actor was retrieved.");
  45. let vertSource = yield newVertexShader.getText();
  46. let fragSource = yield newFragmentShader.getText();
  47. ok(vertSource.includes("I'm special!") &&
  48. fragSource.includes("I'm also special!"), aMessage);
  49. });
  50. }
  51. yield removeTab(target.tab);
  52. finish();
  53. }