Skip window and surface tests if glfwInit fails

This skips tests that would fail on SwiftShader on systems with
no display.

Bug: dawn:283
Change-Id: Ie3aa46349df3116305712a5aa143d874cef0d4b4
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/21781
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
diff --git a/src/tests/end2end/SwapChainValidationTests.cpp b/src/tests/end2end/SwapChainValidationTests.cpp
index b4a76d4..e92bf84 100644
--- a/src/tests/end2end/SwapChainValidationTests.cpp
+++ b/src/tests/end2end/SwapChainValidationTests.cpp
@@ -32,7 +32,7 @@
         glfwSetErrorCallback([](int code, const char* message) {
             dawn::ErrorLog() << "GLFW error " << code << " " << message;
         });
-        glfwInit();
+        DAWN_SKIP_TEST_IF(!glfwInit());
 
         // The SwapChainValidationTests don't create devices so we don't need to call
         // SetupGLFWWindowHintsForBackend. Set GLFW_NO_API anyway to avoid GLFW bringing up a GL
diff --git a/src/tests/end2end/WindowSurfaceTests.cpp b/src/tests/end2end/WindowSurfaceTests.cpp
index 29e4fcb..7bfc107 100644
--- a/src/tests/end2end/WindowSurfaceTests.cpp
+++ b/src/tests/end2end/WindowSurfaceTests.cpp
@@ -16,6 +16,7 @@
 #include "common/Platform.h"
 #include "dawn/dawn_proc.h"
 #include "dawn_native/DawnNative.h"
+#include "tests/DawnTest.h"
 #include "utils/GLFWUtils.h"
 
 #include <gtest/gtest.h>
@@ -47,7 +48,7 @@
         glfwSetErrorCallback([](int code, const char* message) {
             dawn::ErrorLog() << "GLFW error " << code << " " << message;
         });
-        glfwInit();
+        DAWN_SKIP_TEST_IF(!glfwInit());
 
         DawnProcTable procs = dawn_native::GetProcs();
         dawnProcSetProcs(&procs);