fix: crash when loadExtension fails (#27561)

This commit is contained in:
Samuel Maddock 2021-02-02 05:20:05 -05:00 committed by GitHub
parent 20a71be849
commit b6df7cd327
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 15 deletions

View file

@ -112,7 +112,6 @@ void ElectronExtensionLoader::FinishExtensionLoad(
scoped_refptr<const Extension> extension = result.first;
if (extension) {
extension_registrar_.AddExtension(extension);
}
// Write extension install time to ExtensionPrefs. This is required by
// WebRequestAPI which calls extensions::ExtensionPrefs::GetInstallTime.
@ -126,8 +125,9 @@ void ElectronExtensionLoader::FinishExtensionLoad(
extensions::pref_names::kPrefPreferences);
auto preference = update.Create();
const base::Time install_time = base::Time().Now();
preference->SetString("install_time",
base::NumberToString(install_time.ToInternalValue()));
preference->SetString(
"install_time", base::NumberToString(install_time.ToInternalValue()));
}
}
std::move(cb).Run(extension.get(), result.second);

View file

@ -107,6 +107,12 @@ describe('chrome extensions', () => {
expect(bg).to.equal('red');
});
it('does not crash when failing to load an extension', async () => {
const customSession = session.fromPartition(`persist:${uuid.v4()}`);
const promise = customSession.loadExtension(path.join(fixtures, 'extensions', 'load-error'));
await expect(promise).to.eventually.be.rejected();
});
it('serializes a loaded extension', async () => {
const extensionPath = path.join(fixtures, 'extensions', 'red-bg');
const manifest = JSON.parse(fs.readFileSync(path.join(extensionPath, 'manifest.json'), 'utf-8'));

View file

@ -0,0 +1,8 @@
{
"name": "load-error",
"version": "1.0",
"icons": {
"16": "/images/error.png"
},
"manifest_version": 2
}