AppHistory: |canGo*| attributes should returns false if not fully active

According to the spec[1], the document is not fully active, `canGoBack`
and `canGoForward` attributes should return `false`.

[1] https://wicg.github.io/app-history/#dom-apphistory-cangoback

Bug: 1183545
Change-Id: I38faffdc6742e955fe810a3b304c77aa73afe915
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3054671
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Reviewed-by: Nate Chapin <japhet@chromium.org>
Commit-Queue: Domenic Denicola <domenic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#906330}
diff --git a/app-history/navigate/canGoBack-if-not-fully-active.html b/app-history/navigate/canGoBack-if-not-fully-active.html
new file mode 100644
index 0000000..2565faf
--- /dev/null
+++ b/app-history/navigate/canGoBack-if-not-fully-active.html
@@ -0,0 +1,24 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<iframe id="iframe" src="/common/blank.html"></iframe>
+<script>
+
+function waitOnLoad(target) {
+  return new Promise((resolve, reject) => {
+    target.onload = resolve;
+  });
+}
+
+promise_test(async t => {
+  await waitOnLoad(window);
+  iframe.contentWindow.appHistory.navigate("?1");
+  await waitOnLoad(iframe);
+  assert_equals(iframe.contentWindow.appHistory.entries().length, 2);
+  assert_equals(iframe.contentWindow.appHistory.canGoBack, true);
+  const cached_app_history = iframe.contentWindow.appHistory;
+  iframe.remove();
+  assert_equals(cached_app_history.canGoBack, false);
+}, "canGoBack should return false if the document is not fully active");
+
+</script>
diff --git a/app-history/navigate/canGoForward-if-not-fully-active.html b/app-history/navigate/canGoForward-if-not-fully-active.html
new file mode 100644
index 0000000..2231be0
--- /dev/null
+++ b/app-history/navigate/canGoForward-if-not-fully-active.html
@@ -0,0 +1,26 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<iframe id="iframe" src="/common/blank.html"></iframe>
+<script>
+
+function waitOnLoad(target) {
+  return new Promise((resolve, reject) => {
+    target.onload = resolve;
+  });
+}
+
+promise_test(async t => {
+  await waitOnLoad(window);
+  iframe.contentWindow.appHistory.navigate("?1");
+  await waitOnLoad(iframe);
+  assert_equals(iframe.contentWindow.appHistory.entries().length, 2);
+  iframe.contentWindow.appHistory.back();
+  await waitOnLoad(iframe);
+  assert_equals(iframe.contentWindow.appHistory.canGoForward, true);
+  const cached_app_history = iframe.contentWindow.appHistory;
+  iframe.remove();
+  assert_equals(cached_app_history.canGoForward, false);
+}, "canGoForward should return false if the document is not fully active");
+
+</script>