Index: chrome/browser/extensions/content_verifier_browsertest.cc |
diff --git a/chrome/browser/extensions/content_verifier_browsertest.cc b/chrome/browser/extensions/content_verifier_browsertest.cc |
index 0f36164d7acacd6eda8e02866bf088ed7ff40124..385f4ec62fedae0338cb133bba722b94abaf75f2 100644 |
--- a/chrome/browser/extensions/content_verifier_browsertest.cc |
+++ b/chrome/browser/extensions/content_verifier_browsertest.cc |
@@ -493,6 +493,54 @@ class ContentVerifierTest : public ExtensionBrowserTest { |
unload_observer_.reset(); |
} |
+ void TestContentScriptExtension(const std::string& crx_relpath, |
+ const std::string& id, |
+ const std::string& script_relpath) { |
+ VerifierObserver verifier_observer; |
+ ContentVerifier::SetObserverForTests(&verifier_observer); |
+ // Install the extension with content scripts. The initial read of the |
+ // content scripts will fail verification because they are read before the |
+ // content verification system has completed a one-time processing of the |
+ // expected hashes. (The extension only contains the root level hashes of |
+ // the merkle tree, but the content verification system builds the entire |
+ // tree and caches it in the extension install directory - see |
+ // ContentHashFetcher for more details). |
+ const Extension* extension = InstallExtensionFromWebstore( |
+ test_data_dir_.AppendASCII(crx_relpath), 1); |
+ ASSERT_TRUE(extension); |
+ ASSERT_EQ(extension->id(), id); |
+ |
+ // Wait for the content verification code to finish processing the hashes. |
+ if (!base::ContainsKey(verifier_observer.completed_fetches(), id)) |
+ verifier_observer.WaitForFetchComplete(id); |
+ |
+ // Now disable the extension, since content scripts are read at enable time, |
+ // set up our job observer, and re-enable, expecting a success this time. |
+ DisableExtension(id); |
+ JobObserver job_observer; |
+ ContentVerifyJob::SetObserverForTests(&job_observer); |
+ base::FilePath script_relfilepath = |
+ base::FilePath().AppendASCII(script_relpath); |
+ job_observer.ExpectJobResult(id, script_relfilepath, |
+ JobObserver::Result::SUCCESS); |
+ EnableExtension(id); |
+ EXPECT_TRUE(job_observer.WaitForExpectedJobs()); |
+ |
+ // Now alter the contents of the content script, reload the extension, and |
+ // expect to see a job failure due to the content script content hash not |
+ // being what was signed by the webstore. |
+ base::FilePath scriptfile = extension->path().AppendASCII(script_relpath); |
+ std::string extra = "some_extra_function_call();"; |
+ ASSERT_TRUE(base::AppendToFile(scriptfile, extra.data(), extra.size())); |
+ DisableExtension(id); |
+ job_observer.ExpectJobResult(id, script_relfilepath, |
+ JobObserver::Result::FAILURE); |
+ EnableExtension(id); |
+ EXPECT_TRUE(job_observer.WaitForExpectedJobs()); |
+ |
+ ContentVerifyJob::SetObserverForTests(NULL); |
+ } |
+ |
protected: |
JobDelegate delegate_; |
std::unique_ptr<RegistryObserver> unload_observer_; |
@@ -565,51 +613,14 @@ IN_PROC_BROWSER_TEST_F(ContentVerifierTest, DotSlashPaths) { |
} |
IN_PROC_BROWSER_TEST_F(ContentVerifierTest, ContentScripts) { |
- VerifierObserver verifier_observer; |
- ContentVerifier::SetObserverForTests(&verifier_observer); |
- |
- // Install an extension with content scripts. The initial read of the content |
- // scripts will fail verification because they are read before the content |
- // verification system has completed a one-time processing of the expected |
- // hashes. (The extension only contains the root level hashes of the merkle |
- // tree, but the content verification system builds the entire tree and |
- // caches it in the extension install directory - see ContentHashFetcher for |
- // more details). |
- std::string id = "jmllhlobpjcnnomjlipadejplhmheiif"; |
- const Extension* extension = InstallExtensionFromWebstore( |
- test_data_dir_.AppendASCII("content_verifier/content_script.crx"), 1); |
- ASSERT_TRUE(extension); |
- ASSERT_EQ(extension->id(), id); |
- |
- // Wait for the content verification code to finish processing the hashes. |
- if (!base::ContainsKey(verifier_observer.completed_fetches(), id)) |
- verifier_observer.WaitForFetchComplete(id); |
- |
- // Now disable the extension, since content scripts are read at enable time, |
- // set up our job observer, and re-enable, expecting a success this time. |
- DisableExtension(id); |
- JobObserver job_observer; |
- ContentVerifyJob::SetObserverForTests(&job_observer); |
- job_observer.ExpectJobResult(id, |
- base::FilePath(FILE_PATH_LITERAL("script.js")), |
- JobObserver::Result::SUCCESS); |
- EnableExtension(id); |
- EXPECT_TRUE(job_observer.WaitForExpectedJobs()); |
- |
- // Now alter the contents of the content script, reload the extension, and |
- // expect to see a job failure due to the content script content hash not |
- // being what was signed by the webstore. |
- base::FilePath scriptfile = extension->path().AppendASCII("script.js"); |
- std::string extra = "some_extra_function_call();"; |
- ASSERT_TRUE(base::AppendToFile(scriptfile, extra.data(), extra.size())); |
- DisableExtension(id); |
- job_observer.ExpectJobResult(id, |
- base::FilePath(FILE_PATH_LITERAL("script.js")), |
- JobObserver::Result::FAILURE); |
- EnableExtension(id); |
- EXPECT_TRUE(job_observer.WaitForExpectedJobs()); |
+ TestContentScriptExtension("content_verifier/content_script.crx", |
+ "jmllhlobpjcnnomjlipadejplhmheiif", "script.js"); |
+} |
- ContentVerifyJob::SetObserverForTests(NULL); |
+IN_PROC_BROWSER_TEST_F(ContentVerifierTest, ContentScriptsInLocales) { |
+ TestContentScriptExtension("content_verifier/content_script_locales.crx", |
+ "jaghonccckpcikmliipifpoodmeofoon", |
+ "_locales/en/content_script.js"); |
} |
// Tests the case of a corrupt extension that is force-installed by policy and |