#include "extensions/browser/content_verifier/content_verifier.h"
#include <list>
#include <memory>
#include <set>
#include <string>
#include "base/files/file_util.h"
#include "base/functional/callback_helpers.h"
#include "base/strings/string_split.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/test/test_file_util.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "chrome/browser/devtools/devtools_window.h"
#include "chrome/browser/extensions/browsertest_util.h"
#include "chrome/browser/extensions/chrome_content_verifier_delegate.h"
#include "chrome/browser/extensions/content_verifier_test_utils.h"
#include "chrome/browser/extensions/corrupted_extension_reinstaller.h"
#include "chrome/browser/extensions/crx_installer.h"
#include "chrome/browser/extensions/devtools_util.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_management_test_util.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/policy/policy_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/crx_file/id_util.h"
#include "components/policy/core/browser/browser_policy_connector.h"
#include "components/policy/core/common/mock_configuration_policy_provider.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/background_script_executor.h"
#include "extensions/browser/content_verifier/content_verify_job.h"
#include "extensions/browser/content_verifier/test_utils.h"
#include "extensions/browser/crx_file_info.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/external_install_info.h"
#include "extensions/browser/management_policy.h"
#include "extensions/browser/mock_external_provider.h"
#include "extensions/browser/test_extension_registry_observer.h"
#include "extensions/browser/updater/extension_update_data.h"
#include "extensions/browser/updater/manifest_fetch_data.h"
#include "extensions/common/extension_features.h"
#include "extensions/common/extension_urls.h"
#include "extensions/common/file_util.h"
#include "extensions/test/extension_test_message_listener.h"
#include "third_party/zlib/google/compression_utils.h"
#if BUILDFLAG(IS_MAC)
#include "extensions/common/extension_features.h"
#endif
ManifestLocation;
namespace extensions {
namespace {
constexpr char kTenMegResourceExtensionId[] = …;
constexpr char kStoragePermissionExtensionId[] = …;
constexpr char kStoragePermissionExtensionCrx[] = …;
class MockUpdateService : public UpdateService { … };
void ExtensionUpdateComplete(base::OnceClosure callback,
const std::optional<CrxInstallError>& error) { … }
ChromeContentVerifierDelegate::VerifyInfo GetVerifyInfoAndForceHashes(
const Extension& extension) { … }
}
class ContentVerifierTest : public ExtensionBrowserTest { … };
IN_PROC_BROWSER_TEST_F(ContentVerifierTest, DotSlashPaths) { … }
IN_PROC_BROWSER_TEST_F(ContentVerifierTest,
VerifierObserverNoCrashOnDestruction) { … }
IN_PROC_BROWSER_TEST_F(ContentVerifierTest, ContentScripts) { … }
IN_PROC_BROWSER_TEST_F(ContentVerifierTest, ContentScriptsInLocales) { … }
IN_PROC_BROWSER_TEST_F(ContentVerifierTest,
DeletedContentScriptFailsContentVerification) { … }
IN_PROC_BROWSER_TEST_F(ContentVerifierTest,
UnreadableContentScriptFailsContentVerification) { … }
class ContentVerifierTestWithForcedHashes : public ContentVerifierTest { … };
IN_PROC_BROWSER_TEST_F(ContentVerifierTestWithForcedHashes,
TestServiceWorkerCorruption_DisableAndEnable) { … }
IN_PROC_BROWSER_TEST_F(ContentVerifierTest,
PRE_TestServiceWorker_AcrossSession) { … }
IN_PROC_BROWSER_TEST_F(ContentVerifierTest, TestServiceWorker_AcrossSession) { … }
IN_PROC_BROWSER_TEST_F(ContentVerifierTest, PolicyCorrupted) { … }
IN_PROC_BROWSER_TEST_F(ContentVerifierTest,
ManualInstalledExtensionGotCorruptedThenForceInstalled) { … }
class UserInstalledContentVerifierTest : public ContentVerifierTest { … };
IN_PROC_BROWSER_TEST_F(UserInstalledContentVerifierTest,
PRE_UserInstalledCorruptedResourceOnStartup) { … }
IN_PROC_BROWSER_TEST_F(UserInstalledContentVerifierTest,
DISABLED_UserInstalledCorruptedResourceOnStartup) { … }
IN_PROC_BROWSER_TEST_F(ContentVerifierTest, VerificationFailureOnNavigate) { … }
IN_PROC_BROWSER_TEST_F(
ContentVerifierTest,
VerificationSuccessfulForCrxWithVerifiedContentsInjectedInHeader) { … }
IN_PROC_BROWSER_TEST_F(
ContentVerifierTest,
InstallationFailureForCrxWithMalformedVerifiedContentsInjectedInHeader) { … }
IN_PROC_BROWSER_TEST_F(ContentVerifierTest,
VerificationFailureForMissingVerifiedContents) { … }
IN_PROC_BROWSER_TEST_F(ContentVerifierTest, TamperLargeSizedResource) { … }
IN_PROC_BROWSER_TEST_F(ContentVerifierTest,
PRE_ResourceReadCancellationDoesNotFailVerification) { … }
IN_PROC_BROWSER_TEST_F(ContentVerifierTest,
ResourceReadCancellationDoesNotFailVerification) { … }
IN_PROC_BROWSER_TEST_F(ContentVerifierTest,
RemainsEnabledOnNavigateToPathEndingWithSlash) { … }
#if BUILDFLAG(IS_MAC)
class ContentVerifierTestWithSeparatorFlagDisabled
: public ContentVerifierTest {
protected:
ContentVerifierTestWithSeparatorFlagDisabled() {
feature_list_.InitAndDisableFeature(
extensions_features::kMacRejectFilePathsEndingWithSeparator);
}
private:
base::test::ScopedFeatureList feature_list_;
};
IN_PROC_BROWSER_TEST_F(ContentVerifierTestWithSeparatorFlagDisabled,
RemainsEnabledOnNavigateToPathEndingWithSlash) {
const Extension* extension = InstallExtensionFromWebstore(
test_data_dir_.AppendASCII("content_verifier/dot_slash_paths.crx"), 1);
ASSERT_TRUE(extension);
const ExtensionId kExtensionId = extension->id();
GURL page_url = extension->GetResourceURL("page.html/");
ui_test_utils::NavigateToURLWithDispositionBlockUntilNavigationsComplete(
browser(), page_url, 1, WindowOpenDisposition::CURRENT_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_LOAD_STOP);
ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
int reasons = prefs->GetDisableReasons(kExtensionId);
EXPECT_EQ(0, reasons);
}
#endif
IN_PROC_BROWSER_TEST_F(ContentVerifierTest,
RemainsEnabledOnNavigateToPathEndingWithDot) { … }
IN_PROC_BROWSER_TEST_F(ContentVerifierTest,
RemainsEnabledOnNavigateToPathWithIncorrectCase) { … }
class ContentVerifierPolicyTest : public ContentVerifierTest { … };
IN_PROC_BROWSER_TEST_F(ContentVerifierPolicyTest,
PRE_PolicyCorruptedOnStartup) { … }
#if BUILDFLAG(IS_MAC) && defined(ARCH_CPU_ARM64)
#define MAYBE_PolicyCorruptedOnStartup …
#else
#define MAYBE_PolicyCorruptedOnStartup …
#endif
IN_PROC_BROWSER_TEST_F(ContentVerifierPolicyTest,
MAYBE_PolicyCorruptedOnStartup) { … }
IN_PROC_BROWSER_TEST_F(ContentVerifierPolicyTest, Backoff) { … }
IN_PROC_BROWSER_TEST_F(ContentVerifierPolicyTest, FailedUpdateRetries) { … }
}