ContentVerification: Add back test that exercises failure during navigation.

Change Ib59e9f0c7a4aac9b6a883d7f42647cecc603fa79 removed two tests:
ContentVerifierTest.{FailOnRead,FailOnDone} that used to test navigating
a WebContents to a corrupted extension resource file and making sure
that the navigation correctly disables the extension. However, the tests
were simulating read failures in an obtrusive way. Bring back one of the
test to preserve test coverage around navigation.

Bug: 804630
Change-Id: I57f0e7ea50d7f7bb8a092f33481556593865f43c
Reviewed-on: https://chromium-review.googlesource.com/894373
Commit-Queue: Istiaque Ahmed <[email protected]>
Reviewed-by: Devlin <[email protected]>
Cr-Commit-Position: refs/heads/master@{#533355}
diff --git a/chrome/browser/extensions/content_verifier_browsertest.cc b/chrome/browser/extensions/content_verifier_browsertest.cc
index 1f18564..8a40559 100644
--- a/chrome/browser/extensions/content_verifier_browsertest.cc
+++ b/chrome/browser/extensions/content_verifier_browsertest.cc
@@ -22,6 +22,7 @@
 #include "chrome/browser/extensions/extension_service.h"
 #include "chrome/browser/extensions/policy_extension_reinstaller.h"
 #include "chrome/common/chrome_switches.h"
+#include "chrome/test/base/ui_test_utils.h"
 #include "components/policy/core/browser/browser_policy_connector.h"
 #include "components/policy/core/common/mock_configuration_policy_provider.h"
 #include "content/public/common/browser_side_navigation_policy.h"
@@ -461,9 +462,6 @@
     EnableExtension(id);
     EXPECT_TRUE(job_observer.WaitForExpectedJobs());
   }
-
- protected:
-  GURL page_url_;
 };
 
 IN_PROC_BROWSER_TEST_F(ContentVerifierTest, DotSlashPaths) {
@@ -584,6 +582,39 @@
   EXPECT_TRUE(found);
 }
 
+// Tests that verification failure during navigating to an extension resource
+// correctly disables the extension.
+IN_PROC_BROWSER_TEST_F(ContentVerifierTest, VerificationFailureOnNavigate) {
+  // |unload_observer| needs to destroy before the ExtensionRegistry gets
+  // deleted, which happens before TearDownOnMainThread is called.
+  // TODO(lazyboy): Use TestExtensionRegistryObserver.
+  RegistryObserver unload_observer(ExtensionRegistry::Get(profile()));
+  const Extension* extension = InstallExtensionFromWebstore(
+      test_data_dir_.AppendASCII("content_verifier/dot_slash_paths.crx"), 1);
+  ASSERT_TRUE(extension);
+  const ExtensionId kExtensionId = extension->id();
+  const base::FilePath::CharType kResource[] = FILE_PATH_LITERAL("page.html");
+  {
+    // Modify content so that content verification fails.
+    base::ScopedAllowBlockingForTesting allow_blocking;
+    base::FilePath real_path = extension->path().Append(kResource);
+    std::string extra = "some_extra_function_call();";
+    ASSERT_TRUE(base::AppendToFile(real_path, extra.data(), extra.size()));
+  }
+
+  GURL page_url = extension->GetResourceURL("page.html");
+  // Wait for 0 navigations to complete because with PlzNavigate it's racy
+  // when the didstop IPC arrives relative to the tab being closed. The
+  // wait call below is what the tests care about.
+  ui_test_utils::NavigateToURLWithDispositionBlockUntilNavigationsComplete(
+      browser(), page_url, 0, WindowOpenDisposition::NEW_FOREGROUND_TAB,
+      ui_test_utils::BROWSER_TEST_NONE);
+  EXPECT_TRUE(unload_observer.WaitForUnload(kExtensionId));
+  ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
+  int reasons = prefs->GetDisableReasons(kExtensionId);
+  EXPECT_TRUE(reasons & disable_reason::DISABLE_CORRUPTED);
+}
+
 class ContentVerifierPolicyTest : public ContentVerifierTest {
  public:
   // We need to do this work here because the force-install policy values are