3 <script src="../../../http/tests/inspector/inspector-test.js"></script>
4 <script src="../canvas-profiler-test.js"></script>
7 window.internals.settings.setWebGLErrorsToConsoleEnabled(false);
28 /** @type {!Object.<number, Object>} */
29 this._items = Object.create(null);
40 return key in this._items;
49 return this._items[key];
54 * @param {Object} item
56 put: function(key, item)
60 this._items[key] = item;
68 function assertNoErrors(gl)
70 console.assert(gl.getError() === gl.NO_ERROR, "No GL error was expected at this time");
73 function assertEqualArrays(a, b)
75 console.assert(a.length === b.length, "assertEqualArrays: a.length=" + a.length + ", b.length=" + b.length);
80 a.forEach(function(element, index) {
81 console.assert(a[index] === b[index], "assertEqualArrays: different values at index " + index);
85 function generateWebGLError(gl, error)
89 gl.pixelStorei(123, 234);
91 case gl.INVALID_VALUE:
92 gl.pixelStorei(gl.PACK_ALIGNMENT, 234);
94 case gl.INVALID_OPERATION:
96 gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
101 function getAllErrors(gl)
105 var error = gl.getError();
106 if (error === gl.NO_ERROR)
108 console.assert(typeof error === "number", "getError() should return a number instead of a " + (typeof error));
114 function createAndRunWebGLProgram()
116 gl = createWebGLContext();
117 console.assert(gl, "Failed to create WebGL context");
119 glResource = gl["__resourceObject"];
120 console.assert(glResource, "WebGL context is not wrapped");
122 rawGL = glResource.wrappedObject();
123 console.assert(rawGL, "No raw WebGL context found");
124 console.assert(gl !== rawGL, "Proxy and RAW contexts should not be the same");
127 assertNoErrors(rawGL);
129 // 1) Generate errors directly on the RAW context
130 // 2) Pick them via proxy.
131 var errors = [rawGL.INVALID_ENUM, rawGL.INVALID_VALUE, rawGL.INVALID_OPERATION];
132 errors.forEach(generateWebGLError.bind(this, rawGL));
133 assertEqualArrays(errors, getAllErrors(gl));
135 assertNoErrors(rawGL);
137 // 1) Generate errors on RAW context
138 // 2) Convert Resource to a Replayable => this should clean up the RAW context and save the errors in proxy
139 // 3) Check that RAW context no longer have errors
140 // 4) Check that proxy still has the original errors saved
141 var errors = [rawGL.INVALID_ENUM, rawGL.INVALID_VALUE, rawGL.INVALID_OPERATION];
142 errors.forEach(generateWebGLError.bind(this, rawGL));
143 glResource.toReplayable(new Cache());
144 assertNoErrors(rawGL);
145 assertEqualArrays(errors, getAllErrors(gl));
148 // 1) Repeat 1-3 steps from the above
149 // 2) Check proxy and RAW errors interleaved
150 var errors = [rawGL.INVALID_ENUM, rawGL.INVALID_VALUE, rawGL.INVALID_OPERATION];
151 errors.forEach(generateWebGLError.bind(this, rawGL));
152 glResource.toReplayable(new Cache());
153 assertNoErrors(rawGL);
155 var value = gl.getError();
156 console.assert(typeof value === "number", "getError() should return a number instead of a " + (typeof value));
157 console.assert(value !== gl.NO_ERROR, "An error was expected");
158 errors.forEach(generateWebGLError.bind(this, rawGL)); // Generate again in the RAW context.
159 // Now we "have" 2 errors left in the proxy and 3 new errors in the RAW context => should return 3 errors from the proxy.
160 assertEqualArrays(errors, getAllErrors(gl));
162 assertNoErrors(rawGL);
169 InspectorTest.enableCanvasAgent(step1);
172 InspectorTest.evaluateInPage("createAndRunWebGLProgram()", step2);
174 function step2(error)
176 InspectorTest.assertEquals("SUCCESS", error.description);
177 InspectorTest.completeTest();
183 <body onload="runTest()">
185 Tests WebGL getError() status.
187 <a href="https://bugs.webkit.org/show_bug.cgi?id=95443">Bug 95443</a>