Validate GL_COLOR_ATTACHMENT0 separately from the draw buffers attachments.

EXT_draw_buffers may not be enabled but the maxColorAttachments cap is
always initialized so make sure to validate for the extension instead of
just checking that the attachment is in the valid range.

BUG=angleproject:2058

Change-Id: I5b48cb496bf96cbc0911295aa5bf87784ce9241b
Reviewed-on: https://chromium-review.googlesource.com/735749
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Geoff Lang <geofflang@chromium.org>
diff --git a/src/tests/gl_tests/WebGLCompatibilityTest.cpp b/src/tests/gl_tests/WebGLCompatibilityTest.cpp
index 345b760..d7eb664 100644
--- a/src/tests/gl_tests/WebGLCompatibilityTest.cpp
+++ b/src/tests/gl_tests/WebGLCompatibilityTest.cpp
@@ -3443,6 +3443,29 @@
     EXPECT_GL_NO_ERROR();
 }
 
+// Test that it's not possible to query the non-zero color attachments without the drawbuffers
+// extension in WebGL1
+TEST_P(WebGLCompatibilityTest, FramebufferAttachmentQuery)
+{
+    ANGLE_SKIP_TEST_IF(getClientMajorVersion() > 2);
+    ANGLE_SKIP_TEST_IF(extensionEnabled("GL_EXT_draw_buffers"));
+
+    GLFramebuffer fbo;
+    glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+    EXPECT_GL_NO_ERROR();
+
+    GLint result;
+    glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1,
+                                          GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &result);
+    EXPECT_GL_ERROR(GL_INVALID_ENUM);
+
+    GLRenderbuffer renderbuffer;
+    glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
+    glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 1, 1);
+    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, renderbuffer);
+    EXPECT_GL_ERROR(GL_INVALID_ENUM);
+}
+
 // Tests the WebGL removal of undefined behavior when attachments aren't written to.
 TEST_P(WebGLCompatibilityTest, DrawBuffers)
 {