michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Tests if blackboxing a program works properly. michael@0: */ michael@0: michael@0: function ifWebGLSupported() { michael@0: let [target, debuggee, panel] = yield initShaderEditor(MULTIPLE_CONTEXTS_URL); michael@0: let { gFront, EVENTS, ShadersListView, ShadersEditorsView } = panel.panelWin; michael@0: michael@0: once(panel.panelWin, EVENTS.SHADER_COMPILED).then(() => { michael@0: ok(false, "No shaders should be publicly compiled during this test."); michael@0: }); michael@0: michael@0: reload(target); michael@0: let [[firstProgramActor, secondProgramActor]] = yield promise.all([ michael@0: getPrograms(gFront, 2), michael@0: once(panel.panelWin, EVENTS.SOURCES_SHOWN) michael@0: ]); michael@0: michael@0: let vsEditor = yield ShadersEditorsView._getEditor("vs"); michael@0: let fsEditor = yield ShadersEditorsView._getEditor("fs"); michael@0: michael@0: vsEditor.once("change", () => { michael@0: ok(false, "The vertex shader source was unexpectedly changed."); michael@0: }); michael@0: fsEditor.once("change", () => { michael@0: ok(false, "The fragment shader source was unexpectedly changed."); michael@0: }); michael@0: once(panel.panelWin, EVENTS.SOURCES_SHOWN).then(() => { michael@0: ok(false, "No sources should be changed form this point onward."); michael@0: }); michael@0: michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); michael@0: michael@0: ok(!ShadersListView.selectedAttachment.isBlackBoxed, michael@0: "The first program should not be blackboxed yet."); michael@0: is(getBlackBoxCheckbox(panel, 0).checked, true, michael@0: "The first blackbox checkbox should be initially checked."); michael@0: ok(!ShadersListView.attachments[1].isBlackBoxed, michael@0: "The second program should not be blackboxed yet."); michael@0: is(getBlackBoxCheckbox(panel, 1).checked, true, michael@0: "The second blackbox checkbox should be initially checked."); michael@0: michael@0: getBlackBoxCheckbox(panel, 0).click(); michael@0: michael@0: ok(ShadersListView.selectedAttachment.isBlackBoxed, michael@0: "The first program should now be blackboxed."); michael@0: is(getBlackBoxCheckbox(panel, 0).checked, false, michael@0: "The first blackbox checkbox should now be unchecked."); michael@0: ok(!ShadersListView.attachments[1].isBlackBoxed, michael@0: "The second program should still not be blackboxed."); michael@0: is(getBlackBoxCheckbox(panel, 1).checked, true, michael@0: "The second blackbox checkbox should still be checked."); michael@0: michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); michael@0: ok(true, "The first program was correctly blackboxed."); michael@0: michael@0: getBlackBoxCheckbox(panel, 1).click(); michael@0: michael@0: ok(ShadersListView.selectedAttachment.isBlackBoxed, michael@0: "The first program should still be blackboxed."); michael@0: is(getBlackBoxCheckbox(panel, 0).checked, false, michael@0: "The first blackbox checkbox should still be unchecked."); michael@0: ok(ShadersListView.attachments[1].isBlackBoxed, michael@0: "The second program should now be blackboxed."); michael@0: is(getBlackBoxCheckbox(panel, 1).checked, false, michael@0: "The second blackbox checkbox should now be unchecked."); michael@0: michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas2"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas2"); michael@0: ok(true, "The second program was correctly blackboxed."); michael@0: michael@0: ShadersListView._onProgramMouseEnter({ target: getItemLabel(panel, 0) }); michael@0: michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas2"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas2"); michael@0: ok(true, "Highlighting shouldn't work while blackboxed (1)."); michael@0: michael@0: ShadersListView._onProgramMouseLeave({ target: getItemLabel(panel, 0) }); michael@0: ShadersListView._onProgramMouseEnter({ target: getItemLabel(panel, 1) }); michael@0: michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas2"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas2"); michael@0: ok(true, "Highlighting shouldn't work while blackboxed (2)."); michael@0: michael@0: ShadersListView._onProgramMouseLeave({ target: getItemLabel(panel, 1) }); michael@0: michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas2"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas2"); michael@0: ok(true, "Highlighting shouldn't work while blackboxed (3)."); michael@0: michael@0: getBlackBoxCheckbox(panel, 0).click(); michael@0: getBlackBoxCheckbox(panel, 1).click(); michael@0: michael@0: ok(!ShadersListView.selectedAttachment.isBlackBoxed, michael@0: "The first program should now be unblackboxed."); michael@0: is(getBlackBoxCheckbox(panel, 0).checked, true, michael@0: "The first blackbox checkbox should now be rechecked."); michael@0: ok(!ShadersListView.attachments[1].isBlackBoxed, michael@0: "The second program should now be unblackboxed."); michael@0: is(getBlackBoxCheckbox(panel, 1).checked, true, michael@0: "The second blackbox checkbox should now be rechecked."); michael@0: michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); michael@0: ok(true, "The two programs were correctly unblackboxed."); michael@0: michael@0: ShadersListView._onProgramMouseEnter({ target: getItemLabel(panel, 0) }); michael@0: michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 255, g: 0, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); michael@0: ok(true, "The first program was correctly highlighted."); michael@0: michael@0: ShadersListView._onProgramMouseLeave({ target: getItemLabel(panel, 0) }); michael@0: ShadersListView._onProgramMouseEnter({ target: getItemLabel(panel, 1) }); michael@0: michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 64, a: 255 }, true, "#canvas2"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 0, b: 64, a: 255 }, true, "#canvas2"); michael@0: ok(true, "The second program was correctly highlighted."); michael@0: michael@0: ShadersListView._onProgramMouseLeave({ target: getItemLabel(panel, 1) }); michael@0: michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1"); michael@0: yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); michael@0: ok(true, "The two programs were correctly unhighlighted."); michael@0: michael@0: yield teardown(panel); michael@0: finish(); michael@0: } michael@0: michael@0: function getItemLabel(aPanel, aIndex) { michael@0: return aPanel.panelWin.document.querySelectorAll( michael@0: ".side-menu-widget-item-contents")[aIndex]; michael@0: } michael@0: michael@0: function getBlackBoxCheckbox(aPanel, aIndex) { michael@0: return aPanel.panelWin.document.querySelectorAll( michael@0: ".side-menu-widget-item-checkbox")[aIndex]; michael@0: } michael@0: michael@0: function once(aTarget, aEvent) { michael@0: let deferred = promise.defer(); michael@0: aTarget.once(aEvent, deferred.resolve); michael@0: return deferred.promise; michael@0: }