[dawn][emscripten] Add bare-bone unit testing for Emscripten bindings.

Change-Id: Id950fa83fc3c36e0433e516f96a6c3acbecc1862
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/211235
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Loko Kung <lokokung@google.com>
diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt
index 05c7bb4..1bc7f06 100644
--- a/third_party/CMakeLists.txt
+++ b/third_party/CMakeLists.txt
@@ -33,7 +33,7 @@
 # a parent project that does not want to use depot_tools.
 if (DAWN_FETCH_DEPENDENCIES)
     set(EXTRA_FETCH_ARGS)
-    if (NOT TARGET gmock AND ${TINT_BUILD_TESTS})
+    if (NOT TARGET gmock AND (DAWN_BUILD_TESTS OR TINT_BUILD_TESTS))
         list(APPEND EXTRA_FETCH_ARGS --use-test-deps)
     endif()
 
@@ -70,6 +70,15 @@
     add_subdirectory(${DAWN_ABSEIL_DIR} "${CMAKE_CURRENT_BINARY_DIR}/abseil")
 endif()
 
+if ((DAWN_BUILD_TESTS OR TINT_BUILD_TESTS) AND NOT TARGET gmock)
+    set(gtest_force_shared_crt ON CACHE BOOL "Controls whether a shared run-time library should be used even when Google Test is built as static library" FORCE)
+    if (${DAWN_ENABLE_EMSCRIPTEN})
+        # For Emscripten builds, we need to disable pthreads.
+        set(gtest_disable_pthreads ON)
+    endif()
+    add_subdirectory(${DAWN_GOOGLETEST_DIR} "${CMAKE_CURRENT_BINARY_DIR}/googletest" EXCLUDE_FROM_ALL)
+endif()
+
 ################################################################################
 # End of Emscripten enabled third party directories
 ################################################################################
@@ -161,11 +170,6 @@
     add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/google_benchmark/src EXCLUDE_FROM_ALL)
 endif()
 
-if (TINT_BUILD_TESTS AND NOT TARGET gmock)
-    set(gtest_force_shared_crt ON CACHE BOOL "Controls whether a shared run-time library should be used even when Google Test is built as static library" FORCE)
-    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/googletest EXCLUDE_FROM_ALL)
-endif()
-
 # Populates 'targets' with list of all targets under 'dir'
 # Use 'get_all_targets_recursive' instead of this macro
 macro(do_get_all_targets_recursive targets dir)