[soft-navigations] Avoid firing LCP entries when the feature is disabled

As it turns out, when we enabled Soft Navigation LCP UKM collection, we
accidentally started firing web exposed LCP entries for such LCPs.
This CL fixes that, by verifying that such entries are exposed only when
soft navigations deliberately restarted LCP reporting.

Bug: 1488273
Change-Id: I2745bf52e5aaa777248d011c6f4f7d28b0c8fd3b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4905895
Commit-Queue: Yoav Weiss <yoavweiss@chromium.org>
Reviewed-by: Anders Hartvoll Ruud <andruud@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1203913}
diff --git a/soft-navigation-heuristics/disabled.html b/soft-navigation-heuristics/disabled.html
new file mode 100644
index 0000000..b53c2f7
--- /dev/null
+++ b/soft-navigation-heuristics/disabled.html
@@ -0,0 +1,31 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<meta charset="utf-8">
+<title>Detect simple soft navigation.</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script src="resources/soft-navigation-helper.js"></script>
+</head>
+<body>
+  <main id=main>
+  <a id=link>Click me!</a>
+  </main>
+    <script>
+    const link = document.getElementById("link");
+    testSoftNavigationNotDetected({
+      eventHandler: url => {
+        addTextToDivOnMain();
+        history.pushState({}, '', 'foobar.html');
+      },
+      link: link,
+      eventName: "click",
+      eventTarget: link,
+      testName: "Test that a soft navigation is not detected when the feature "
+                + "is disabled"});
+  </script>
+</body>
+</html>
+
diff --git a/soft-navigation-heuristics/resources/soft-navigation-helper.js b/soft-navigation-heuristics/resources/soft-navigation-helper.js
index 37097b2..7f83df7 100644
--- a/soft-navigation-heuristics/resources/soft-navigation-helper.js
+++ b/soft-navigation-heuristics/resources/soft-navigation-helper.js
@@ -91,8 +91,13 @@
         });
         t.step_timeout(resolve, 1000);
       });
-      assert_equals(
+      if (document.softNavigations) {
+        assert_equals(
           document.softNavigations, 0, 'Soft Navigation not detected');
+      }
+      const postClickLcp = await getLcpEntries();
+      assert_equals(
+          preClickLcp.length, postClickLcp.length, 'No LCP entries accumulated');
     }, options.testName);
   };