1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/shadereditor/test/browser_se_programs-blackbox-01.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,169 @@ 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 blackboxing a program works properly. 1.9 + */ 1.10 + 1.11 +function ifWebGLSupported() { 1.12 + let [target, debuggee, panel] = yield initShaderEditor(MULTIPLE_CONTEXTS_URL); 1.13 + let { gFront, EVENTS, ShadersListView, ShadersEditorsView } = panel.panelWin; 1.14 + 1.15 + once(panel.panelWin, EVENTS.SHADER_COMPILED).then(() => { 1.16 + ok(false, "No shaders should be publicly compiled during this test."); 1.17 + }); 1.18 + 1.19 + reload(target); 1.20 + let [[firstProgramActor, secondProgramActor]] = yield promise.all([ 1.21 + getPrograms(gFront, 2), 1.22 + once(panel.panelWin, EVENTS.SOURCES_SHOWN) 1.23 + ]); 1.24 + 1.25 + let vsEditor = yield ShadersEditorsView._getEditor("vs"); 1.26 + let fsEditor = yield ShadersEditorsView._getEditor("fs"); 1.27 + 1.28 + vsEditor.once("change", () => { 1.29 + ok(false, "The vertex shader source was unexpectedly changed."); 1.30 + }); 1.31 + fsEditor.once("change", () => { 1.32 + ok(false, "The fragment shader source was unexpectedly changed."); 1.33 + }); 1.34 + once(panel.panelWin, EVENTS.SOURCES_SHOWN).then(() => { 1.35 + ok(false, "No sources should be changed form this point onward."); 1.36 + }); 1.37 + 1.38 + yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1"); 1.39 + yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); 1.40 + yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1"); 1.41 + yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); 1.42 + 1.43 + ok(!ShadersListView.selectedAttachment.isBlackBoxed, 1.44 + "The first program should not be blackboxed yet."); 1.45 + is(getBlackBoxCheckbox(panel, 0).checked, true, 1.46 + "The first blackbox checkbox should be initially checked."); 1.47 + ok(!ShadersListView.attachments[1].isBlackBoxed, 1.48 + "The second program should not be blackboxed yet."); 1.49 + is(getBlackBoxCheckbox(panel, 1).checked, true, 1.50 + "The second blackbox checkbox should be initially checked."); 1.51 + 1.52 + getBlackBoxCheckbox(panel, 0).click(); 1.53 + 1.54 + ok(ShadersListView.selectedAttachment.isBlackBoxed, 1.55 + "The first program should now be blackboxed."); 1.56 + is(getBlackBoxCheckbox(panel, 0).checked, false, 1.57 + "The first blackbox checkbox should now be unchecked."); 1.58 + ok(!ShadersListView.attachments[1].isBlackBoxed, 1.59 + "The second program should still not be blackboxed."); 1.60 + is(getBlackBoxCheckbox(panel, 1).checked, true, 1.61 + "The second blackbox checkbox should still be checked."); 1.62 + 1.63 + yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas1"); 1.64 + yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); 1.65 + yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas1"); 1.66 + yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); 1.67 + ok(true, "The first program was correctly blackboxed."); 1.68 + 1.69 + getBlackBoxCheckbox(panel, 1).click(); 1.70 + 1.71 + ok(ShadersListView.selectedAttachment.isBlackBoxed, 1.72 + "The first program should still be blackboxed."); 1.73 + is(getBlackBoxCheckbox(panel, 0).checked, false, 1.74 + "The first blackbox checkbox should still be unchecked."); 1.75 + ok(ShadersListView.attachments[1].isBlackBoxed, 1.76 + "The second program should now be blackboxed."); 1.77 + is(getBlackBoxCheckbox(panel, 1).checked, false, 1.78 + "The second blackbox checkbox should now be unchecked."); 1.79 + 1.80 + yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas1"); 1.81 + yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas2"); 1.82 + yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas1"); 1.83 + yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas2"); 1.84 + ok(true, "The second program was correctly blackboxed."); 1.85 + 1.86 + ShadersListView._onProgramMouseEnter({ target: getItemLabel(panel, 0) }); 1.87 + 1.88 + yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas1"); 1.89 + yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas2"); 1.90 + yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas1"); 1.91 + yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas2"); 1.92 + ok(true, "Highlighting shouldn't work while blackboxed (1)."); 1.93 + 1.94 + ShadersListView._onProgramMouseLeave({ target: getItemLabel(panel, 0) }); 1.95 + ShadersListView._onProgramMouseEnter({ target: getItemLabel(panel, 1) }); 1.96 + 1.97 + yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas1"); 1.98 + yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas2"); 1.99 + yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas1"); 1.100 + yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas2"); 1.101 + ok(true, "Highlighting shouldn't work while blackboxed (2)."); 1.102 + 1.103 + ShadersListView._onProgramMouseLeave({ target: getItemLabel(panel, 1) }); 1.104 + 1.105 + yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas1"); 1.106 + yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas2"); 1.107 + yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas1"); 1.108 + yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 0, b: 0, a: 255 }, true, "#canvas2"); 1.109 + ok(true, "Highlighting shouldn't work while blackboxed (3)."); 1.110 + 1.111 + getBlackBoxCheckbox(panel, 0).click(); 1.112 + getBlackBoxCheckbox(panel, 1).click(); 1.113 + 1.114 + ok(!ShadersListView.selectedAttachment.isBlackBoxed, 1.115 + "The first program should now be unblackboxed."); 1.116 + is(getBlackBoxCheckbox(panel, 0).checked, true, 1.117 + "The first blackbox checkbox should now be rechecked."); 1.118 + ok(!ShadersListView.attachments[1].isBlackBoxed, 1.119 + "The second program should now be unblackboxed."); 1.120 + is(getBlackBoxCheckbox(panel, 1).checked, true, 1.121 + "The second blackbox checkbox should now be rechecked."); 1.122 + 1.123 + yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1"); 1.124 + yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); 1.125 + yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1"); 1.126 + yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); 1.127 + ok(true, "The two programs were correctly unblackboxed."); 1.128 + 1.129 + ShadersListView._onProgramMouseEnter({ target: getItemLabel(panel, 0) }); 1.130 + 1.131 + yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 0, b: 0, a: 255 }, true, "#canvas1"); 1.132 + yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); 1.133 + yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 255, g: 0, b: 0, a: 255 }, true, "#canvas1"); 1.134 + yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); 1.135 + ok(true, "The first program was correctly highlighted."); 1.136 + 1.137 + ShadersListView._onProgramMouseLeave({ target: getItemLabel(panel, 0) }); 1.138 + ShadersListView._onProgramMouseEnter({ target: getItemLabel(panel, 1) }); 1.139 + 1.140 + yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1"); 1.141 + yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 0, b: 64, a: 255 }, true, "#canvas2"); 1.142 + yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1"); 1.143 + yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 0, b: 64, a: 255 }, true, "#canvas2"); 1.144 + ok(true, "The second program was correctly highlighted."); 1.145 + 1.146 + ShadersListView._onProgramMouseLeave({ target: getItemLabel(panel, 1) }); 1.147 + 1.148 + yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1"); 1.149 + yield ensurePixelIs(debuggee, { x: 0, y: 0 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); 1.150 + yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 255, g: 255, b: 0, a: 255 }, true, "#canvas1"); 1.151 + yield ensurePixelIs(debuggee, { x: 127, y: 127 }, { r: 0, g: 255, b: 255, a: 255 }, true, "#canvas2"); 1.152 + ok(true, "The two programs were correctly unhighlighted."); 1.153 + 1.154 + yield teardown(panel); 1.155 + finish(); 1.156 +} 1.157 + 1.158 +function getItemLabel(aPanel, aIndex) { 1.159 + return aPanel.panelWin.document.querySelectorAll( 1.160 + ".side-menu-widget-item-contents")[aIndex]; 1.161 +} 1.162 + 1.163 +function getBlackBoxCheckbox(aPanel, aIndex) { 1.164 + return aPanel.panelWin.document.querySelectorAll( 1.165 + ".side-menu-widget-item-checkbox")[aIndex]; 1.166 +} 1.167 + 1.168 +function once(aTarget, aEvent) { 1.169 + let deferred = promise.defer(); 1.170 + aTarget.once(aEvent, deferred.resolve); 1.171 + return deferred.promise; 1.172 +}