browser_se_shaders-edit-03.js 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 would permanently store
  5. * their new source on the backend and reshow it in the frontend when required.
  6. */
  7. function* ifWebGLSupported() {
  8. let { target, panel } = yield initShaderEditor(MULTIPLE_CONTEXTS_URL);
  9. let { gFront, EVENTS, ShadersListView, ShadersEditorsView } = panel.panelWin;
  10. reload(target);
  11. yield promise.all([
  12. once(gFront, "program-linked"),
  13. once(gFront, "program-linked")
  14. ]);
  15. yield once(panel.panelWin, EVENTS.SOURCES_SHOWN);
  16. let vsEditor = yield ShadersEditorsView._getEditor("vs");
  17. let fsEditor = yield ShadersEditorsView._getEditor("fs");
  18. is(ShadersListView.selectedIndex, 0,
  19. "The first program is currently selected.");
  20. is(vsEditor.getText().indexOf("1);"), 136,
  21. "The vertex shader editor contains the correct initial text (1).");
  22. is(fsEditor.getText().indexOf("1);"), 117,
  23. "The fragment shader editor contains the correct initial text (1).");
  24. is(vsEditor.getText().indexOf("2.);"), -1,
  25. "The vertex shader editor contains the correct initial text (2).");
  26. is(fsEditor.getText().indexOf(".0);"), -1,
  27. "The fragment shader editor contains the correct initial text (2).");
  28. vsEditor.replaceText("2.", { line: 5, ch: 44 }, { line: 5, ch: 45 });
  29. yield once(panel.panelWin, EVENTS.SHADER_COMPILED);
  30. fsEditor.replaceText(".0", { line: 5, ch: 35 }, { line: 5, ch: 37 });
  31. yield once(panel.panelWin, EVENTS.SHADER_COMPILED);
  32. ok(true, "Vertex and fragment shaders were changed.");
  33. yield ensurePixelIs(gFront, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas1");
  34. yield ensurePixelIs(gFront, { x: 32, y: 32 }, { r: 255, g: 255, b: 0, a: 0 }, true, "#canvas1");
  35. yield ensurePixelIs(gFront, { x: 64, y: 64 }, { r: 255, g: 255, b: 0, a: 0 }, true, "#canvas1");
  36. yield ensurePixelIs(gFront, { x: 127, y: 127 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas1");
  37. yield ensurePixelIs(gFront, { x: 0, y: 0 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2");
  38. yield ensurePixelIs(gFront, { x: 32, y: 32 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2");
  39. yield ensurePixelIs(gFront, { x: 64, y: 64 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2");
  40. yield ensurePixelIs(gFront, { x: 127, y: 127 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2");
  41. ok(true, "The vertex and fragment shaders were recompiled successfully.");
  42. EventUtils.sendMouseEvent({ type: "mousedown" }, ShadersListView.items[1].target);
  43. yield once(panel.panelWin, EVENTS.SOURCES_SHOWN);
  44. is(ShadersListView.selectedIndex, 1,
  45. "The second program is currently selected.");
  46. is(vsEditor.getText().indexOf("1);"), 136,
  47. "The vertex shader editor contains the correct text (1).");
  48. is(fsEditor.getText().indexOf("1);"), 117,
  49. "The fragment shader editor contains the correct text (1).");
  50. is(vsEditor.getText().indexOf("2.);"), -1,
  51. "The vertex shader editor contains the correct text (2).");
  52. is(fsEditor.getText().indexOf(".0);"), -1,
  53. "The fragment shader editor contains the correct text (2).");
  54. EventUtils.sendMouseEvent({ type: "mousedown" }, ShadersListView.items[0].target);
  55. yield once(panel.panelWin, EVENTS.SOURCES_SHOWN);
  56. is(ShadersListView.selectedIndex, 0,
  57. "The first program is currently selected again.");
  58. is(vsEditor.getText().indexOf("1);"), -1,
  59. "The vertex shader editor contains the correct text (3).");
  60. is(fsEditor.getText().indexOf("1);"), -1,
  61. "The fragment shader editor contains the correct text (3).");
  62. is(vsEditor.getText().indexOf("2.);"), 136,
  63. "The vertex shader editor contains the correct text (4).");
  64. is(fsEditor.getText().indexOf(".0);"), 116,
  65. "The fragment shader editor contains the correct text (4).");
  66. yield teardown(panel);
  67. finish();
  68. }