Fix glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, ...)

BUG=angleproject:1332

Change-Id: I591b9520bc1122eb6232803ac86b6d0322f8c349
Reviewed-on: https://chromium-review.googlesource.com/390323
Commit-Queue: John Bauman <jbauman@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/ContextState.cpp b/src/libANGLE/ContextState.cpp
index ef9b234..56f8d99 100644
--- a/src/libANGLE/ContextState.cpp
+++ b/src/libANGLE/ContextState.cpp
@@ -278,6 +278,14 @@
             *type      = GL_INT;
             *numParams = 1;
             return true;
+        case GL_TEXTURE_BINDING_EXTERNAL_OES:
+            if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
+            {
+                return false;
+            }
+            *type      = GL_INT;
+            *numParams = 1;
+            return true;
     }
 
     if (getExtensions().debug)
diff --git a/src/libANGLE/validationES.cpp b/src/libANGLE/validationES.cpp
index 4521be5..fff9088 100644
--- a/src/libANGLE/validationES.cpp
+++ b/src/libANGLE/validationES.cpp
@@ -1735,10 +1735,12 @@
       case GL_TEXTURE_BINDING_2D_ARRAY:
         break;
       case GL_TEXTURE_BINDING_EXTERNAL_OES:
-          if (!context->getExtensions().eglStreamConsumerExternal)
+          if (!context->getExtensions().eglStreamConsumerExternal &&
+              !context->getExtensions().eglImageExternal)
           {
-              context->handleError(
-                  Error(GL_INVALID_ENUM, "NV_EGL_stream_consumer_external extension not enabled"));
+              context->handleError(Error(GL_INVALID_ENUM,
+                                         "Neither NV_EGL_stream_consumer_external nor "
+                                         "GL_OES_EGL_image_external extensions enabled"));
               return false;
           }
           break;
diff --git a/src/tests/gl_tests/TextureTest.cpp b/src/tests/gl_tests/TextureTest.cpp
index 9d38ad7..50aed08 100644
--- a/src/tests/gl_tests/TextureTest.cpp
+++ b/src/tests/gl_tests/TextureTest.cpp
@@ -1196,6 +1196,30 @@
     EXPECT_GL_ERROR(GL_INVALID_VALUE);
 }
 
+// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
+TEST_P(Texture2DTest, QueryBinding)
+{
+    glBindTexture(GL_TEXTURE_2D, 0);
+    EXPECT_GL_ERROR(GL_NO_ERROR);
+
+    GLint textureBinding;
+    glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
+    EXPECT_GL_NO_ERROR();
+    EXPECT_EQ(0, textureBinding);
+
+    glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
+    if (extensionEnabled("GL_OES_EGL_image_external") ||
+        extensionEnabled("GL_NV_EGL_stream_consumer_external"))
+    {
+        EXPECT_GL_NO_ERROR();
+        EXPECT_EQ(0, textureBinding);
+    }
+    else
+    {
+        EXPECT_GL_ERROR(GL_INVALID_ENUM);
+    }
+}
+
 TEST_P(Texture2DTest, ZeroSizedUploads)
 {
     glBindTexture(GL_TEXTURE_2D, mTexture2D);