Skip to content

Commit

Permalink
Bug 1052803 adding simple-pref optionsURL placeholder, and running jp…
Browse files Browse the repository at this point in the history
…m test on all add-ons in the test/addons/ dir
  • Loading branch information
erikvold committed Sep 17, 2014
1 parent ed278ae commit 74d6c6c
Show file tree
Hide file tree
Showing 22 changed files with 253 additions and 316 deletions.
6 changes: 5 additions & 1 deletion lib/firefox.js
Expand Up @@ -5,7 +5,7 @@ var createProfile = require("./profile");
var console = require("./utils").console;
var normalizeBinary = require("./utils").normalizeBinary;
var getID = require("jetpack-id");
var TEST_RESULTS_REGEX = /\d+ of \d+ tests passed/i
var TEST_RESULTS_REGEX = /(\d+) of (\d+) tests passed/i
var isTest = process.env.NODE_ENV === "test";

/**
Expand Down Expand Up @@ -109,6 +109,10 @@ function runFirefox (manifest, options) {
} else if (write) {
writeLog(data);
}

if (TEST_RESULTS_REGEX.test(data) && RegExp.$1 === RegExp.$2) {
writeLog("All tests passed!");
}
});

function killFirefox () {
Expand Down
5 changes: 5 additions & 0 deletions lib/rdf.js
Expand Up @@ -44,6 +44,11 @@ function createRDF (manifest) {
"em:icon64URL": manifest.icon64 || "icon64.png",
};

if (manifest.preferences) {
jetpackMeta["em:optionsURL"] = xmlEscape("data:text/xml,<placeholder/>")
jetpackMeta["em:optionsType"] = 2;
}

header[0].children.push(description);
description.children.push(jetpackMeta);

Expand Down
14 changes: 0 additions & 14 deletions test/addons/reddit-panel/README.md

This file was deleted.

167 changes: 0 additions & 167 deletions test/addons/reddit-panel/data/jquery-1.4.4.min.js

This file was deleted.

35 changes: 0 additions & 35 deletions test/addons/reddit-panel/data/panel.js

This file was deleted.

49 changes: 0 additions & 49 deletions test/addons/reddit-panel/lib/main.js

This file was deleted.

10 changes: 0 additions & 10 deletions test/addons/reddit-panel/package.json

This file was deleted.

22 changes: 0 additions & 22 deletions test/addons/reddit-panel/tests/test-main.js

This file was deleted.

5 changes: 1 addition & 4 deletions test/addons/simple-addon/package.json
Expand Up @@ -5,8 +5,5 @@
"description": "",
"main": "index.js",
"author": "",
"license": "MIT",
"engines": {
"Firefox": ">=41.0"
}
"license": "MIT"
}
1 change: 1 addition & 0 deletions test/addons/simple-prefs/index.js
@@ -0,0 +1 @@
"use strict";
28 changes: 28 additions & 0 deletions test/addons/simple-prefs/package.json
@@ -0,0 +1,28 @@
{
"id": "test-simple-prefs@jetpack",
"preferences": [{
"name": "somePreference",
"title": "some-title",
"description": "Some short description for the preference",
"type": "string",
"value": "TEST"
},
{
"description": "How many of them we have.",
"name": "myInteger",
"type": "integer",
"value": 8,
"title": "my-int"
}, {
"name": "myHiddenInt",
"type": "integer",
"hidden": true,
"value": 5,
"title": "hidden-int"
}, {
"name": "sayHello",
"type": "control",
"label": "Click me!",
"title": "hello"
}]
}
113 changes: 113 additions & 0 deletions test/addons/simple-prefs/test/test-inline-prefs.js
@@ -0,0 +1,113 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
'use strict';

const { Cu } = require('chrome');
const sp = require('sdk/simple-prefs');
const app = require('sdk/system/xul-app');
const self = require('sdk/self');
const { preferencesBranch } = self;
const { open } = require('sdk/preferences/utils');
const { getTabForId } = require('sdk/tabs/utils');
const { Tab } = require('sdk/tabs/tab');
require('sdk/tabs');

const { AddonManager } = Cu.import('resource://gre/modules/AddonManager.jsm', {});

exports.testDefaultValues = function (assert) {
assert.equal(sp.prefs.myHiddenInt, 5, 'myHiddenInt default is 5');
assert.equal(sp.prefs.myInteger, 8, 'myInteger default is 8');
assert.equal(sp.prefs.somePreference, 'TEST', 'somePreference default is correct');
}

exports.testOptionsType = function(assert, done) {
AddonManager.getAddonByID(self.id, function(aAddon) {
assert.equal(aAddon.optionsType, AddonManager.OPTIONS_TYPE_INLINE, 'options type is inline');
done();
});
}

exports.testButton = function(assert, done) {
open(self).then(({ tabId, document }) => {
let tab = Tab({ tab: getTabForId(tabId) });
sp.once('sayHello', _ => {
assert.pass('The button was pressed!');
tab.close(done);
});

tab.attach({
contentScript: 'unsafeWindow.document.querySelector("button[label=\'Click me!\']").click();'
});
});
}

if (app.is('Firefox')) {
exports.testAOM = function(assert, done) {
open(self).then(({ tabId }) => {
let tab = Tab({ tab: getTabForId(tabId) });
assert.pass('the add-on prefs page was opened.');

tab.attach({
contentScriptWhen: "end",
contentScript: 'self.postMessage({\n' +
'someCount: unsafeWindow.document.querySelectorAll("setting[title=\'some-title\']").length,\n' +
'somePreference: getAttributes(unsafeWindow.document.querySelector("setting[title=\'some-title\']")),\n' +
'myInteger: getAttributes(unsafeWindow.document.querySelector("setting[title=\'my-int\']")),\n' +
'myHiddenInt: getAttributes(unsafeWindow.document.querySelector("setting[title=\'hidden-int\']")),\n' +
'sayHello: getAttributes(unsafeWindow.document.querySelector("button[label=\'Click me!\']"))\n' +
'});\n' +
'function getAttributes(ele) {\n' +
'if (!ele) return {};\n' +
'return {\n' +
'pref: ele.getAttribute("pref"),\n' +
'type: ele.getAttribute("type"),\n' +
'title: ele.getAttribute("title"),\n' +
'desc: ele.getAttribute("desc"),\n' +
'"data-jetpack-id": ele.getAttribute(\'data-jetpack-id\')\n' +
'}\n' +
'}\n',
onMessage: msg => {
// test against doc caching
assert.equal(msg.someCount, 1, 'there is exactly one <setting> node for somePreference');

// test somePreference
assert.equal(msg.somePreference.type, 'string', 'some pref is a string');
assert.equal(msg.somePreference.pref, 'extensions.'+self.id+'.somePreference', 'somePreference path is correct');
assert.equal(msg.somePreference.title, 'some-title', 'somePreference title is correct');
assert.equal(msg.somePreference.desc, 'Some short description for the preference', 'somePreference description is correct');
assert.equal(msg.somePreference['data-jetpack-id'], self.id, 'data-jetpack-id attribute value is correct');

// test myInteger
assert.equal(msg.myInteger.type, 'integer', 'myInteger is a int');
assert.equal(msg.myInteger.pref, 'extensions.'+self.id+'.myInteger', 'extensions.test-simple-prefs.myInteger');
assert.equal(msg.myInteger.title, 'my-int', 'myInteger title is correct');
assert.equal(msg.myInteger.desc, 'How many of them we have.', 'myInteger desc is correct');
assert.equal(msg.myInteger['data-jetpack-id'], self.id, 'data-jetpack-id attribute value is correct');

// test myHiddenInt
assert.equal(msg.myHiddenInt.type, undefined, 'myHiddenInt was not displayed');
assert.equal(msg.myHiddenInt.pref, undefined, 'myHiddenInt was not displayed');
assert.equal(msg.myHiddenInt.title, undefined, 'myHiddenInt was not displayed');
assert.equal(msg.myHiddenInt.desc, undefined, 'myHiddenInt was not displayed');

// test sayHello
assert.equal(msg.sayHello['data-jetpack-id'], self.id, 'data-jetpack-id attribute value is correct');

tab.close(done);
}
});
})
}

// run it again, to test against inline options document caching
// and duplication of <setting> nodes upon re-entry to about:addons
exports.testAgainstDocCaching = exports.testAOM;

}

exports.testDefaultPreferencesBranch = function(assert) {
assert.equal(preferencesBranch, self.id, 'preferencesBranch default the same as self.id');
}

require('sdk/test').run(exports);
Empty file.
8 changes: 8 additions & 0 deletions test/fixtures/test-failure/package.json
@@ -0,0 +1,8 @@
{
"name": "test-failure",
"title": "test-failure",
"id": "test-failure@jetpack",
"main": "index.js",
"license": "MPL 2.0",
"version": "0.0.1"
}
11 changes: 11 additions & 0 deletions test/fixtures/test-failure/test/test-failure.js
@@ -0,0 +1,11 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";

exports.testFailure = function(assert) {
assert.pass("Passes!");
assert.fail("Fails!");
};

require('sdk/test').run(exports);
Empty file.
8 changes: 8 additions & 0 deletions test/fixtures/test-success/package.json
@@ -0,0 +1,8 @@
{
"name": "test-success",
"title": "test-success",
"id": "test-success@jetpack",
"main": "index.js",
"license": "MPL 2.0",
"version": "0.0.1"
}
11 changes: 11 additions & 0 deletions test/fixtures/test-success/test/test-success.js
@@ -0,0 +1,11 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";

exports.testSuccess = function(assert) {
assert.pass("Passes!");
assert.pass("Passes again!");
};

require('sdk/test').run(exports);
34 changes: 34 additions & 0 deletions test/functional/test.addons.js
@@ -0,0 +1,34 @@
var utils = require("../utils");
var path = require("path");
var fs = require("fs");
var chai = require("chai");
var expect = chai.expect;
var assert = chai.assert;
var exec = utils.exec;

var addonsPath = path.join(__dirname, "..", "addons");

var binary = process.env.JPM_FIREFOX_BINARY || "nightly";

describe("jpm test addons", function () {
beforeEach(utils.setup);
afterEach(utils.tearDown);

fs.readdirSync(addonsPath).filter(function (file) {
if (/^invalid-/.test(file)) return false;
var stat = fs.statSync(path.join(addonsPath, file))
return (stat && stat.isDirectory());
}).forEach(function (file) {
it(file, function (done) {
var addonPath = path.join(addonsPath, file);
process.chdir(addonPath);

var options = { cwd: addonPath, env: { JPM_FIREFOX_BINARY: binary }};
var proc = exec("test", options, function (err, stdout, stderr) {
expect(err).to.not.be.ok;
expect(stdout).to.contain("All tests passed!");
done();
});
});
});
});

0 comments on commit 74d6c6c

Please sign in to comment.