gamepad: Check that the DocumentLoader is not null

Gamepad timestamps are reported relative to the navigationStart
timestamp, accessed from the DocumentLoader's DocumentLoadTiming.
In some scenarios the document may have been detached before the
NavigatorGamepad is initialized, causing the DocumentLoader to be
nullptr.

This CL checks that the DocumentLoader is non-null, and uses the
current time in place of navigationStart if it is null.

Bug: 1483777
Change-Id: Ib3efcf3a612cd4c1c543218fa5fb8568c7129dcf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4899018
Reviewed-by: Alvin Ji <alvinji@chromium.org>
Commit-Queue: Matt Reynolds <mattreynolds@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1204813}
diff --git a/editing/crashtests/insertAdjacentElement-with-DOMSubtreeModified.html b/editing/crashtests/insertAdjacentElement-with-DOMSubtreeModified.html
new file mode 100644
index 0000000..4b95332
--- /dev/null
+++ b/editing/crashtests/insertAdjacentElement-with-DOMSubtreeModified.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<head>
+<script src="../resources/js-test.js"></script>
+<script>
+function onLoad() {
+    const x1 = document.getElementById('x1');
+    x1.addEventListener('DOMSubtreeModified', () => {
+        const x2 = document.getElementById('x2');
+        x2.contentDocument;
+    });
+    x1.setAttribute('inputmode', 'url');
+}
+function insertAdjacent() {
+    const x2 = document.getElementById('x2');
+    const x3 = document.getElementById('x3');
+    document.onreadystatechange = insertAdjacent;
+    x3.insertAdjacentElement('beforebegin', x2);
+}
+</script>
+</head>
+<body onload="onLoad()">
+<div id="x1"></div>
+<object id="x2" data="invalid-url" onerror="insertAdjacent()"></object>
+<div id="x3"></div>
+</body>
+</html>