Validate destination texture states for CopyTextureForBrowser

Current implmentation of ValidateCopyTextureForBrowser has a bug
to verify destination texture states.
This CL fix the simple bug and add noop copy in unittest to catch this
issue.

Bug: dawn:1306
Change-Id: I193105ced89db5092873d604c7dbf43d7ea4fba0
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/82101
Commit-Queue: Shaobo Yan <shaobo.yan@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
diff --git a/src/dawn/native/CopyTextureForBrowserHelper.cpp b/src/dawn/native/CopyTextureForBrowserHelper.cpp
index 84b78c3..bfaa268 100644
--- a/src/dawn/native/CopyTextureForBrowserHelper.cpp
+++ b/src/dawn/native/CopyTextureForBrowserHelper.cpp
@@ -329,8 +329,9 @@
         DAWN_INVALID_IF(source->texture->GetTextureState() == TextureBase::TextureState::Destroyed,
                         "Source texture %s is destroyed.", source->texture);
 
-        DAWN_INVALID_IF(source->texture->GetTextureState() == TextureBase::TextureState::Destroyed,
-                        "Destination texture %s is destroyed.", destination->texture);
+        DAWN_INVALID_IF(
+            destination->texture->GetTextureState() == TextureBase::TextureState::Destroyed,
+            "Destination texture %s is destroyed.", destination->texture);
 
         DAWN_TRY_CONTEXT(ValidateImageCopyTexture(device, *source, *copySize),
                          "validating the ImageCopyTexture for the source");
diff --git a/src/dawn/tests/unittests/validation/CopyTextureForBrowserTests.cpp b/src/dawn/tests/unittests/validation/CopyTextureForBrowserTests.cpp
index 881c602..489a802 100644
--- a/src/dawn/tests/unittests/validation/CopyTextureForBrowserTests.cpp
+++ b/src/dawn/tests/unittests/validation/CopyTextureForBrowserTests.cpp
@@ -159,33 +159,57 @@
 
 // Test source or destination texture is destroyed.
 TEST_F(CopyTextureForBrowserTest, DestroyedTexture) {
-    wgpu::Texture source =
-        Create2DTexture(16, 16, 5, 4, wgpu::TextureFormat::RGBA8Unorm,
-                        wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::TextureBinding);
-    wgpu::Texture destination =
-        Create2DTexture(16, 16, 5, 4, wgpu::TextureFormat::RGBA8Unorm,
-                        wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::RenderAttachment);
-
     wgpu::CopyTextureForBrowserOptions options = {};
 
     // Valid src and dst textures.
     {
+        wgpu::Texture source =
+            Create2DTexture(16, 16, 5, 4, wgpu::TextureFormat::RGBA8Unorm,
+                            wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::TextureBinding);
+        wgpu::Texture destination =
+            Create2DTexture(16, 16, 5, 4, wgpu::TextureFormat::RGBA8Unorm,
+                            wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::RenderAttachment);
         TestCopyTextureForBrowser(utils::Expectation::Success, source, 0, {0, 0, 0}, destination, 0,
                                   {0, 0, 0}, {4, 4, 1}, wgpu::TextureAspect::All, options);
+
+        // Check noop copy
+        TestCopyTextureForBrowser(utils::Expectation::Success, source, 0, {0, 0, 0}, destination, 0,
+                                  {0, 0, 0}, {0, 0, 0}, wgpu::TextureAspect::All, options);
     }
 
     // Destroyed src texture.
     {
+        wgpu::Texture source =
+            Create2DTexture(16, 16, 5, 4, wgpu::TextureFormat::RGBA8Unorm,
+                            wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::TextureBinding);
+        wgpu::Texture destination =
+            Create2DTexture(16, 16, 5, 4, wgpu::TextureFormat::RGBA8Unorm,
+                            wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::RenderAttachment);
         source.Destroy();
         TestCopyTextureForBrowser(utils::Expectation::Failure, source, 0, {0, 0, 0}, destination, 0,
                                   {0, 0, 0}, {4, 4, 1}, wgpu::TextureAspect::All, options);
+
+        // Check noop copy
+        TestCopyTextureForBrowser(utils::Expectation::Failure, source, 0, {0, 0, 0}, destination, 0,
+                                  {0, 0, 0}, {0, 0, 0}, wgpu::TextureAspect::All, options);
     }
 
     // Destroyed dst texture.
     {
+        wgpu::Texture source =
+            Create2DTexture(16, 16, 5, 4, wgpu::TextureFormat::RGBA8Unorm,
+                            wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::TextureBinding);
+        wgpu::Texture destination =
+            Create2DTexture(16, 16, 5, 4, wgpu::TextureFormat::RGBA8Unorm,
+                            wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::RenderAttachment);
+
         destination.Destroy();
         TestCopyTextureForBrowser(utils::Expectation::Failure, source, 0, {0, 0, 0}, destination, 0,
                                   {0, 0, 0}, {4, 4, 1}, wgpu::TextureAspect::All, options);
+
+        // Check noop copy
+        TestCopyTextureForBrowser(utils::Expectation::Failure, source, 0, {0, 0, 0}, destination, 0,
+                                  {0, 0, 0}, {0, 0, 0}, wgpu::TextureAspect::All, options);
     }
 }