App history: use base URL to resolve navigate() URLs

Bug: 1183545
Change-Id: Id069fcaed421d13e2602aac5040b1d44e559ade6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3342249
Auto-Submit: Domenic Denicola <domenic@chromium.org>
Reviewed-by: Nate Chapin <japhet@chromium.org>
Commit-Queue: Nate Chapin <japhet@chromium.org>
Cr-Commit-Position: refs/heads/main@{#952145}
diff --git a/app-history/navigate/navigate-base-url.html b/app-history/navigate/navigate-base-url.html
new file mode 100644
index 0000000..b11a71a
--- /dev/null
+++ b/app-history/navigate/navigate-base-url.html
@@ -0,0 +1,15 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<iframe id="i" src="resources/page-with-base-url-common.html"></iframe>
+<script>
+async_test(t => {
+  window.onload = t.step_func(() => {
+    i.contentWindow.appHistory.navigate("blank.html");
+    i.onload = t.step_func_done(() => {
+      const iframeURL = new URL(i.contentWindow.appHistory.current.url);
+      assert_equals(iframeURL.pathname, "/common/blank.html");
+    });
+  });
+}, "navigate() must resolve URLs relative to appHistory object's base URL");
+</script>
diff --git a/app-history/navigate/reload-base-url.html b/app-history/navigate/reload-base-url.html
new file mode 100644
index 0000000..35b29b9
--- /dev/null
+++ b/app-history/navigate/reload-base-url.html
@@ -0,0 +1,16 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<iframe id="i" src="resources/page-with-base-url-common.html"></iframe>
+<script>
+async_test(t => {
+  window.onload = t.step_func(() => {
+    const startingURL = new URL(i.src);
+    i.contentWindow.appHistory.reload();
+    i.onload = t.step_func_done(() => {
+      const iframeURL = new URL(i.contentWindow.appHistory.current.url);
+      assert_equals(iframeURL.pathname, startingURL.pathname);
+    });
+  });
+}, "reload() must ignore the AppHistory object's base URL");
+</script>
diff --git a/app-history/navigate/resources/page-with-base-url-common.html b/app-history/navigate/resources/page-with-base-url-common.html
new file mode 100644
index 0000000..8d9fedc
--- /dev/null
+++ b/app-history/navigate/resources/page-with-base-url-common.html
@@ -0,0 +1,2 @@
+<!DOCTYPE html>
+<base href="/common/">