Return a program binary size of 0 when the program is not linked.

From the GLES3 spec:
"... When a program object's LINK_STATUS is FALSE, its program binary
length is zero ..."

Querying the size was generating errors in the GL backend.

BUG=angleproject:2569

Change-Id: I1be511040331abaec2bba98502d8aa88fb4bd19c
Reviewed-on: https://chromium-review.googlesource.com/1076317
Commit-Queue: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/Program.cpp b/src/libANGLE/Program.cpp
index e0a697e..7a736e0 100644
--- a/src/libANGLE/Program.cpp
+++ b/src/libANGLE/Program.cpp
@@ -1401,6 +1401,11 @@
 
 GLint Program::getBinaryLength(const Context *context) const
 {
+    if (!mLinked)
+    {
+        return 0;
+    }
+
     GLint length;
     Error error = saveBinary(context, nullptr, nullptr, std::numeric_limits<GLint>::max(), &length);
     if (error.isError())
diff --git a/src/tests/gl_tests/ProgramBinaryTest.cpp b/src/tests/gl_tests/ProgramBinaryTest.cpp
index 95897c5..b6de1e9 100644
--- a/src/tests/gl_tests/ProgramBinaryTest.cpp
+++ b/src/tests/gl_tests/ProgramBinaryTest.cpp
@@ -235,6 +235,17 @@
     ASSERT_GL_NO_ERROR();
 }
 
+// Test that unlinked programs have a binary size of 0
+TEST_P(ProgramBinaryTest, ZeroSizedUnlinkedBinary)
+{
+    ANGLE_SKIP_TEST_IF(!supported());
+
+    ANGLE_GL_EMPTY_PROGRAM(program);
+    GLsizei length = 0;
+    glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH, &length);
+    ASSERT_EQ(0, length);
+}
+
 // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
 ANGLE_INSTANTIATE_TEST(ProgramBinaryTest,
                        ES2_D3D9(),
diff --git a/src/tests/test_utils/gl_raii.h b/src/tests/test_utils/gl_raii.h
index 48aca15..aaed0e6 100644
--- a/src/tests/test_utils/gl_raii.h
+++ b/src/tests/test_utils/gl_raii.h
@@ -101,6 +101,8 @@
 
     ~GLProgram() { glDeleteProgram(mHandle); }
 
+    void makeEmpty() { mHandle = glCreateProgram(); }
+
     void makeCompute(const std::string &computeShader)
     {
         mHandle = CompileComputeProgram(computeShader);
@@ -152,6 +154,11 @@
 };
 }  // namespace priv
 
+#define ANGLE_GL_EMPTY_PROGRAM(name) \
+    priv::GLProgram name;            \
+    name.makeEmpty();                \
+    ASSERT_TRUE(name.valid());
+
 #define ANGLE_GL_PROGRAM(name, vertex, fragment) \
     priv::GLProgram name;                        \
     name.makeRaster(vertex, fragment);           \