Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5855)

Unified Diff: chrome/browser/extensions/content_verifier_browsertest.cc

Issue 2845223003: [Merge m59] Only whitelist messages.json files in _locales for content verification (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/test/data/extensions/content_verifier/content_script_locales.crx » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 80e5a3fa1635c16252750bc6e36e6c372b1e7c08..321599130b6e2273332631d42ef315726b85528c 100644
--- a/chrome/browser/extensions/content_verifier_browsertest.cc
+++ b/chrome/browser/extensions/content_verifier_browsertest.cc
@@ -505,6 +505,51 @@ class ContentVerifierTest : public ExtensionBrowserTest {
EXPECT_TRUE(reasons & Extension::DISABLE_CORRUPTED);
}
+ void TestContentScriptExtension(const std::string& crx_relpath,
+ const std::string& id,
+ const std::string& script_relpath) {
+ VerifierObserver 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);
+ EXPECT_EQ(id, extension->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;
+ 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());
+ }
+
protected:
JobDelegate delegate_;
GURL page_url_;
@@ -586,47 +631,14 @@ IN_PROC_BROWSER_TEST_F(ContentVerifierTest, DotSlashPaths) {
}
IN_PROC_BROWSER_TEST_F(ContentVerifierTest, ContentScripts) {
- VerifierObserver 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;
- job_observer.ExpectJobResult(id,
- base::FilePath(FILE_PATH_LITERAL("script.js")),
- JobObserver::Result::SUCCESS);
- EnableExtension(id);
- EXPECT_TRUE(job_observer.WaitForExpectedJobs());
+ TestContentScriptExtension("content_verifier/content_script.crx",
+ "jmllhlobpjcnnomjlipadejplhmheiif", "script.js");
+}
- // 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());
+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
« no previous file with comments | « no previous file | chrome/test/data/extensions/content_verifier/content_script_locales.crx » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698