Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use manifest.minimum_chrome_version as XML's prodversionmin #102

Merged
merged 4 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/crx.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,19 +258,33 @@ class ChromeExtension {
/**
* Generates an updateXML file from the extension content.
*
* If manifest does not include `minimum_chrome_version`, defaults to:
* - '29.0.0' for CRX2, which is earliest extensions API available
* - '64.0.3242' for CRX3, which is when Chrome etension packager switched to CRX3
*
* BC BREAK `this.updateXML` is not stored anymore (since 1.0.0)
*
* @see
* [Chrome Extensions APIs]{@link https://developer.chrome.com/extensions/api_index}
* @see
* [Chrome verions]{@link https://en.wikipedia.org/wiki/Google_Chrome_version_history}
* @see
* [Chromium switches to CRX3]{@link https://chromium.googlesource.com/chromium/src.git/+/b8bc9f99ef4ad6223dfdcafd924051561c05ac75}
* @returns {Buffer}
*/
generateUpdateXML () {
if (!this.codebase) {
throw new Error("No URL provided for update.xml.");
}

var browserVersion = this.manifest.minimum_chrome_version
|| (this.version < 3 && "29.0.0") // Earliest version with extensions API
|| "64.0.3242"; // Chrome started generating CRX3 packages

return Buffer.from(`<?xml version='1.0' encoding='UTF-8'?>
<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
<app appid='${this.appId || this.generateAppId()}'>
<updatecheck codebase='${this.codebase}' version='${this.manifest.version}' />
<updatecheck codebase='${this.codebase}' version='${this.manifest.version}' prodversionmin='${browserVersion}' />
</app>
</gupdate>`);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
<app appid='eoilidhiokfphdhpmhoaengdkehanjif'>
<updatecheck codebase='http://localhost:8000/myFirstExtension.crx' version='1.0' />
<updatecheck codebase='http://localhost:8000/myFirstExtension.crx' version='1.0' prodversionmin='29.0.0' />
</app>
</gupdate>
6 changes: 6 additions & 0 deletions test/expectations/updateCRX3.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
<app appid='eoilidhiokfphdhpmhoaengdkehanjif'>
<updatecheck codebase='http://localhost:8000/myFirstExtension.crx' version='1.0' prodversionmin='64.0.3242' />
</app>
</gupdate>
6 changes: 6 additions & 0 deletions test/expectations/updateProdVersionMin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
<app appid='eoilidhiokfphdhpmhoaengdkehanjif'>
<updatecheck codebase='http://localhost:8000/myFirstExtension.crx' version='1.0' prodversionmin='99.99.99-crxtest' />
</app>
</gupdate>
20 changes: 17 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ var Zip = require("adm-zip");
var ChromeExtension = require("../");
var join = require("path").join;
var privateKey = fs.readFileSync(join(__dirname, "key.pem"));
var updateXml = fs.readFileSync(join(__dirname, "expectations", "update.xml"));
var updateXml2 = fs.readFileSync(join(__dirname, "expectations", "updateCRX2.xml"));
var updateXml3 = fs.readFileSync(join(__dirname, "expectations", "updateCRX3.xml"));
var updateXmlCustom = fs.readFileSync(join(__dirname, "expectations", "updateProdVersionMin.xml"));

function newCrx(opts){
return new ChromeExtension(Object.assign({
Expand Down Expand Up @@ -109,18 +111,30 @@ TESTS.loadContents = function(t, opts){


TESTS.generateUpdateXML = function(t, opts){
t.plan(2);
t.plan(3);

t.throws(() => new ChromeExtension({}).generateUpdateXML(), 'No URL provided for update.xml');

var crx = newCrx(opts);
var expected = crx.version === 2 ? updateXml2 : updateXml3;

crx.pack().then(function(){
var xmlBuffer = crx.generateUpdateXML();

t.equals(xmlBuffer.toString(), updateXml.toString());
t.equals(xmlBuffer.toString(), expected.toString());
})
.catch(t.error.bind(t));

var crxCustom = newCrx(opts);
crxCustom.load().then(() => {
crxCustom.manifest.minimum_chrome_version = '99.99.99-crxtest';
crxCustom.pack().then(function(){
var xmlBuffer = crxCustom.generateUpdateXML();

t.equals(xmlBuffer.toString(), updateXmlCustom.toString());
})
.catch(t.error.bind(t));
});
};

TESTS.generatePublicKey = function(t, opts) {
Expand Down