Add valid checks in places we query isTestingOnlyBackendTexture

Bug: skia:7477
Change-Id: I410427f12c7bb85d11a5e4ed1f09bbd80bbbb54c
Reviewed-on: https://skia-review.googlesource.com/93000
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/tests/EGLImageTest.cpp b/tests/EGLImageTest.cpp
index 9ea6379..efa7de2 100644
--- a/tests/EGLImageTest.cpp
+++ b/tests/EGLImageTest.cpp
@@ -88,7 +88,8 @@
     backendTexture1 =
         gpu1->createTestingOnlyBackendTexture(nullptr, kSize, kSize, kRGBA_8888_GrPixelConfig,
                                               false, GrMipMapped::kNo);
-    if (!gpu1->isTestingOnlyBackendTexture(backendTexture1)) {
+
+    if (!backendTexture1.isValid() || !gpu1->isTestingOnlyBackendTexture(backendTexture1)) {
         ERRORF(reporter, "Error creating texture for EGL Image");
         cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image);
         return;
diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp
index 7b2d835..27d1971 100644
--- a/tests/ResourceCacheTest.cpp
+++ b/tests/ResourceCacheTest.cpp
@@ -211,6 +211,11 @@
     backendTextures[1] = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH,
                                                               kRGBA_8888_GrPixelConfig,
                                                               false, GrMipMapped::kNo);
+    REPORTER_ASSERT(reporter, backendTextures[0].isValid());
+    REPORTER_ASSERT(reporter, backendTextures[1].isValid());
+    if (!backendTextures[0].isValid() || !backendTextures[1].isValid()) {
+        return;
+    }
 
     context->resetContext();
 
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp
index 0864e32..a07b336 100644
--- a/tests/SurfaceTest.cpp
+++ b/tests/SurfaceTest.cpp
@@ -592,7 +592,7 @@
     *outTexture = context->getGpu()->createTestingOnlyBackendTexture(
         pixels.get(), kWidth, kHeight, kRGBA_8888_GrPixelConfig, true, GrMipMapped::kNo);
 
-    if (!context->getGpu()->isTestingOnlyBackendTexture(*outTexture)) {
+    if (!outTexture->isValid() || !context->getGpu()->isTestingOnlyBackendTexture(*outTexture)) {
         return nullptr;
     }
 
@@ -617,7 +617,7 @@
     *outTexture = context->getGpu()->createTestingOnlyBackendTexture(
         pixels.get(), kWidth, kHeight, kRGBA_8888_GrPixelConfig, true, GrMipMapped::kNo);
 
-    if (!context->getGpu()->isTestingOnlyBackendTexture(*outTexture)) {
+    if (!outTexture->isValid() || !context->getGpu()->isTestingOnlyBackendTexture(*outTexture)) {
         return nullptr;
     }
 
@@ -889,7 +889,8 @@
         GrBackendTexture backendTex = context->getGpu()->createTestingOnlyBackendTexture(
                 nullptr, kSize, kSize, config, true, GrMipMapped::kNo);
 
-        if (!context->getGpu()->isTestingOnlyBackendTexture(backendTex)) {
+        if (!backendTex.isValid() ||
+            !context->getGpu()->isTestingOnlyBackendTexture(backendTex)) {
             return sk_sp<SkSurface>(nullptr);
         }
         backendTextures.push_back(backendTex);