browser_se_shaders-edit-01.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. /**
  4. * Tests if editing a vertex and a fragment shader works properly.
  5. */
  6. function* ifWebGLSupported() {
  7. let { target, panel } = yield initShaderEditor(SIMPLE_CANVAS_URL);
  8. let { gFront, $, EVENTS, ShadersEditorsView } = panel.panelWin;
  9. reload(target);
  10. yield promise.all([
  11. once(gFront, "program-linked"),
  12. once(panel.panelWin, EVENTS.SOURCES_SHOWN)
  13. ]);
  14. let vsEditor = yield ShadersEditorsView._getEditor("vs");
  15. let fsEditor = yield ShadersEditorsView._getEditor("fs");
  16. is(vsEditor.getText().indexOf("gl_Position"), 170,
  17. "The vertex shader editor contains the correct text.");
  18. is(fsEditor.getText().indexOf("gl_FragColor"), 97,
  19. "The fragment shader editor contains the correct text.");
  20. is($("#vs-editor-label").hasAttribute("selected"), false,
  21. "The vertex shader editor shouldn't be initially selected.");
  22. is($("#fs-editor-label").hasAttribute("selected"), false,
  23. "The vertex shader editor shouldn't be initially selected.");
  24. yield ensurePixelIs(gFront, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true);
  25. yield ensurePixelIs(gFront, { x: 128, y: 128 }, { r: 191, g: 64, b: 0, a: 255 }, true);
  26. yield ensurePixelIs(gFront, { x: 511, y: 511 }, { r: 0, g: 255, b: 0, a: 255 }, true);
  27. vsEditor.focus();
  28. is($("#vs-editor-label").hasAttribute("selected"), true,
  29. "The vertex shader editor should now be selected.");
  30. is($("#fs-editor-label").hasAttribute("selected"), false,
  31. "The vertex shader editor shouldn't still not be selected.");
  32. vsEditor.replaceText("2.0", { line: 7, ch: 44 }, { line: 7, ch: 47 });
  33. yield once(panel.panelWin, EVENTS.SHADER_COMPILED);
  34. ok(true, "Vertex shader was changed.");
  35. yield ensurePixelIs(gFront, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true);
  36. yield ensurePixelIs(gFront, { x: 128, y: 128 }, { r: 255, g: 0, b: 0, a: 255 }, true);
  37. yield ensurePixelIs(gFront, { x: 511, y: 511 }, { r: 0, g: 0, b: 0, a: 255 }, true);
  38. ok(true, "The vertex shader was recompiled successfully.");
  39. fsEditor.focus();
  40. is($("#vs-editor-label").hasAttribute("selected"), false,
  41. "The vertex shader editor should now be deselected.");
  42. is($("#fs-editor-label").hasAttribute("selected"), true,
  43. "The vertex shader editor should now be selected.");
  44. fsEditor.replaceText("0.5", { line: 5, ch: 44 }, { line: 5, ch: 47 });
  45. yield once(panel.panelWin, EVENTS.SHADER_COMPILED);
  46. ok(true, "Fragment shader was changed.");
  47. yield ensurePixelIs(gFront, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true);
  48. yield ensurePixelIs(gFront, { x: 128, y: 128 }, { r: 255, g: 0, b: 0, a: 127 }, true);
  49. yield ensurePixelIs(gFront, { x: 511, y: 511 }, { r: 0, g: 0, b: 0, a: 255 }, true);
  50. ok(true, "The fragment shader was recompiled successfully.");
  51. yield teardown(panel);
  52. finish();
  53. }