Remove browser tests - Part 1: The Tests (except for experiments)

This commit is contained in:
NTD 2018-02-03 06:00:38 -05:00 • committed by Roy Tam
commit 261374f310
1697 changed files with 0 additions and 144364 deletions

View file

@ -1,7 +0,0 @@
"use strict";
module.exports = { // eslint-disable-line no-undef
"extends": [
"../../../../../testing/mochitest/browser.eslintrc.js",
],
};

View file

@ -1,3 +0,0 @@
[DEFAULT]
[browser_check_installed.js]

View file

@ -1,14 +0,0 @@
"use strict";
add_task(function* test_enabled() {
let addon = yield new Promise(
resolve => AddonManager.getAddonByID("formautofill@mozilla.org", resolve)
);
isnot(addon, null, "Check addon exists");
is(addon.version, "1.0", "Check version");
is(addon.name, "Form Autofill", "Check name");
ok(addon.isCompatible, "Check application compatibility");
ok(!addon.appDisabled, "Check not app disabled");
ok(addon.isActive, "Check addon is active");
is(addon.type, "extension", "Check type is 'extension'");
});

View file

@ -1,5 +0,0 @@
{
"extends": [
"../../../../../testing/xpcshell/xpcshell.eslintrc.js"
],
}

View file

@ -1,81 +0,0 @@
/**
* Provides infrastructure for automated login components tests.
*/
/* exported importAutofillModule, getTempFile */
"use strict";
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://testing-common/MockDocument.jsm");
// Redirect the path of the resouce in addon to the exact file path.
let defineLazyModuleGetter = XPCOMUtils.defineLazyModuleGetter;
XPCOMUtils.defineLazyModuleGetter = function() {
let result = /^resource\:\/\/formautofill\/(.+)$/.exec(arguments[2]);
if (result) {
arguments[2] = Services.io.newFileURI(do_get_file(result[1])).spec;
}
return defineLazyModuleGetter.apply(this, arguments);
};
// Load the module by Service newFileURI API for running extension's XPCShell test
function importAutofillModule(module) {
return Cu.import(Services.io.newFileURI(do_get_file(module)).spec);
}
XPCOMUtils.defineLazyModuleGetter(this, "DownloadPaths",
"resource://gre/modules/DownloadPaths.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
"resource://gre/modules/FileUtils.jsm");
// While the previous test file should have deleted all the temporary files it
// used, on Windows these might still be pending deletion on the physical file
// system. Thus, start from a new base number every time, to make a collision
// with a file that is still pending deletion highly unlikely.
let gFileCounter = Math.floor(Math.random() * 1000000);
/**
* Returns a reference to a temporary file, that is guaranteed not to exist, and
* to have never been created before.
*
* @param {string} leafName
* Suggested leaf name for the file to be created.
*
* @returns {nsIFile} pointing to a non-existent file in a temporary directory.
*
* @note It is not enough to delete the file if it exists, or to delete the file
* after calling nsIFile.createUnique, because on Windows the delete
* operation in the file system may still be pending, preventing a new
* file with the same name to be created.
*/
function getTempFile(leafName) {
// Prepend a serial number to the extension in the suggested leaf name.
let [base, ext] = DownloadPaths.splitBaseNameAndExtension(leafName);
let finalLeafName = base + "-" + gFileCounter + ext;
gFileCounter++;
// Get a file reference under the temporary directory for this test file.
let file = FileUtils.getFile("TmpD", [finalLeafName]);
do_check_false(file.exists());
do_register_cleanup(function() {
if (file.exists()) {
file.remove(false);
}
});
return file;
}
add_task(function* test_common_initialize() {
Services.prefs.setBoolPref("dom.forms.autocomplete.experimental", true);
// Clean up after every test.
do_register_cleanup(() => {
Services.prefs.setBoolPref("dom.forms.autocomplete.experimental", false);
});
});

View file

@ -1,200 +0,0 @@
/*
* Test for form auto fill content helper fill all inputs function.
*/
"use strict";
let {FormAutofillHandler} = importAutofillModule("FormAutofillContent.jsm");
const TESTCASES = [
{
description: "Form without autocomplete property",
document: `<form><input id="given-name"><input id="family-name">
<input id="street-addr"><input id="city"><input id="country">
<input id='email'><input id="tel"></form>`,
fieldDetails: [],
profileData: [],
expectedResult: {
"given-name": "",
"family-name": "",
"street-addr": "",
"city": "",
"country": "",
"email": "",
"tel": "",
},
},
{
description: "Form with autocomplete properties and 1 token",
document: `<form><input id="given-name" autocomplete="given-name">
<input id="family-name" autocomplete="family-name">
<input id="street-addr" autocomplete="street-address">
<input id="city" autocomplete="address-level2">
<input id="country" autocomplete="country">
<input id="email" autocomplete="email">
<input id="tel" autocomplete="tel"></form>`,
fieldDetails: [
{"section": "", "addressType": "", "contactType": "", "fieldName": "given-name", "element": {}},
{"section": "", "addressType": "", "contactType": "", "fieldName": "family-name", "element": {}},
{"section": "", "addressType": "", "contactType": "", "fieldName": "street-address", "element": {}},
{"section": "", "addressType": "", "contactType": "", "fieldName": "address-level2", "element": {}},
{"section": "", "addressType": "", "contactType": "", "fieldName": "country", "element": {}},
{"section": "", "addressType": "", "contactType": "", "fieldName": "email", "element": {}},
{"section": "", "addressType": "", "contactType": "", "fieldName": "tel", "element": {}},
],
profileData: [
{"section": "", "addressType": "", "fieldName": "given-name", "contactType": "", "index": 0, "value": "foo"},
{"section": "", "addressType": "", "fieldName": "family-name", "contactType": "", "index": 1, "value": "bar"},
{"section": "", "addressType": "", "fieldName": "street-address", "contactType": "", "index": 2, "value": "2 Harrison St"},
{"section": "", "addressType": "", "fieldName": "address-level2", "contactType": "", "index": 3, "value": "San Francisco"},
{"section": "", "addressType": "", "fieldName": "country", "contactType": "", "index": 4, "value": "US"},
{"section": "", "addressType": "", "fieldName": "email", "contactType": "", "index": 5, "value": "foo@mozilla.com"},
{"section": "", "addressType": "", "fieldName": "tel", "contactType": "", "index": 6, "value": "1234567"},
],
expectedResult: {
"given-name": "foo",
"family-name": "bar",
"street-addr": "2 Harrison St",
"city": "San Francisco",
"country": "US",
"email": "foo@mozilla.com",
"tel": "1234567",
},
},
{
description: "Form with autocomplete properties and 2 tokens",
document: `<form><input id="given-name" autocomplete="shipping given-name">
<input id="family-name" autocomplete="shipping family-name">
<input id="street-addr" autocomplete="shipping street-address">
<input id="city" autocomplete="shipping address-level2">
<input id="country" autocomplete="shipping country">
<input id='email' autocomplete="shipping email">
<input id="tel" autocomplete="shipping tel"></form>`,
fieldDetails: [
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "given-name", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "family-name", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "street-address", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "address-level2", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "country", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "email", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "tel", "element": {}},
],
profileData: [
{"section": "", "addressType": "shipping", "fieldName": "given-name", "contactType": "", "index": 0, "value": "foo"},
{"section": "", "addressType": "shipping", "fieldName": "family-name", "contactType": "", "index": 1, "value": "bar"},
{"section": "", "addressType": "shipping", "fieldName": "street-address", "contactType": "", "index": 2, "value": "2 Harrison St"},
{"section": "", "addressType": "shipping", "fieldName": "address-level2", "contactType": "", "index": 3, "value": "San Francisco"},
{"section": "", "addressType": "shipping", "fieldName": "country", "contactType": "", "index": 4, "value": "US"},
{"section": "", "addressType": "shipping", "fieldName": "email", "contactType": "", "index": 5, "value": "foo@mozilla.com"},
{"section": "", "addressType": "shipping", "fieldName": "tel", "contactType": "", "index": 6, "value": "1234567"},
],
expectedResult: {
"given-name": "foo",
"family-name": "bar",
"street-addr": "2 Harrison St",
"city": "San Francisco",
"country": "US",
"email": "foo@mozilla.com",
"tel": "1234567",
},
},
{
description: "Form with autocomplete properties and profile is partly matched",
document: `<form><input id="given-name" autocomplete="shipping given-name">
<input id="family-name" autocomplete="shipping family-name">
<input id="street-addr" autocomplete="shipping street-address">
<input id="city" autocomplete="shipping address-level2">
<input id="country" autocomplete="shipping country">
<input id='email' autocomplete="shipping email">
<input id="tel" autocomplete="shipping tel"></form>`,
fieldDetails: [
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "given-name", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "family-name", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "street-address", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "address-level2", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "country", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "email", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "tel", "element": {}},
],
profileData: [
{"section": "", "addressType": "shipping", "fieldName": "given-name", "contactType": "", "index": 0, "value": "foo"},
{"section": "", "addressType": "shipping", "fieldName": "family-name", "contactType": "", "index": 1, "value": "bar"},
{"section": "", "addressType": "shipping", "fieldName": "street-address", "contactType": "", "index": 2, "value": "2 Harrison St"},
{"section": "", "addressType": "shipping", "fieldName": "address-level2", "contactType": "", "index": 3, "value": "San Francisco"},
{"section": "", "addressType": "shipping", "fieldName": "country", "contactType": "", "index": 4, "value": "US"},
{"section": "", "addressType": "shipping", "fieldName": "email", "contactType": "", "index": 5},
{"section": "", "addressType": "shipping", "fieldName": "tel", "contactType": "", "index": 6},
],
expectedResult: {
"given-name": "foo",
"family-name": "bar",
"street-addr": "2 Harrison St",
"city": "San Francisco",
"country": "US",
"email": "",
"tel": "",
},
},
{
description: "Form with autocomplete properties but mismatched",
document: `<form><input id="given-name" autocomplete="shipping given-name">
<input id="family-name" autocomplete="shipping family-name">
<input id="street-addr" autocomplete="billing street-address">
<input id="city" autocomplete="billing address-level2">
<input id="country" autocomplete="billing country">
<input id='email' autocomplete="shipping email">
<input id="tel" autocomplete="shipping tel"></form>`,
fieldDetails: [
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "given-name", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "family-name", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "street-address", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "address-level2", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "country", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "email", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "tel", "element": {}},
],
profileData: [
{"section": "", "addressType": "shipping", "fieldName": "given-name", "contactType": "", "index": 0, "value": "foo"},
{"section": "", "addressType": "shipping", "fieldName": "family-name", "contactType": "", "index": 1, "value": "bar"},
{"section": "", "addressType": "shipping", "fieldName": "street-address", "contactType": "", "index": 2, "value": "2 Harrison St"},
{"section": "", "addressType": "shipping", "fieldName": "address-level2", "contactType": "", "index": 3, "value": "San Francisco"},
{"section": "", "addressType": "shipping", "fieldName": "country", "contactType": "", "index": 4, "value": "US"},
{"section": "", "addressType": "shipping", "fieldName": "email", "contactType": "", "index": 5, "value": "foo@mozilla.com"},
{"section": "", "addressType": "shipping", "fieldName": "tel", "contactType": "", "index": 6, "value": "1234567"},
],
expectedResult: {
"given-name": "foo",
"family-name": "bar",
"street-addr": "",
"city": "",
"country": "",
"email": "foo@mozilla.com",
"tel": "1234567",
},
},
];
for (let tc of TESTCASES) {
(function() {
let testcase = tc;
add_task(function* () {
do_print("Starting testcase: " + testcase.description);
let doc = MockDocument.createTestDocument("http://localhost:8080/test/",
testcase.document);
let form = doc.querySelector("form");
let handler = new FormAutofillHandler(form);
handler.fieldDetails = testcase.fieldDetails;
handler.fieldDetails.forEach((field, index) => {
field.element = doc.querySelectorAll("input")[index];
});
handler.autofillFormFields(testcase.profileData);
for (let id in testcase.expectedResult) {
Assert.equal(doc.getElementById(id).value, testcase.expectedResult[id],
"Check the " + id + " fields were filled with correct data");
}
});
})();
}

View file

@ -1,122 +0,0 @@
/*
* Test for form auto fill content helper collectFormFields functions.
*/
"use strict";
let {FormAutofillHandler} = importAutofillModule("FormAutofillContent.jsm");
const TESTCASES = [
{
description: "Form without autocomplete property",
document: `<form><input id="given-name"><input id="family-name">
<input id="street-addr"><input id="city"><input id="country">
<input id='email'><input id="tel"></form>`,
returnedFormat: [],
fieldDetails: [],
},
{
description: "Form with autocomplete properties and 1 token",
document: `<form><input id="given-name" autocomplete="given-name">
<input id="family-name" autocomplete="family-name">
<input id="street-addr" autocomplete="street-address">
<input id="city" autocomplete="address-level2">
<input id="country" autocomplete="country">
<input id="email" autocomplete="email">
<input id="tel" autocomplete="tel"></form>`,
returnedFormat: [
{"section": "", "addressType": "", "contactType": "", "fieldName": "given-name", "index": 0},
{"section": "", "addressType": "", "contactType": "", "fieldName": "family-name", "index": 1},
{"section": "", "addressType": "", "contactType": "", "fieldName": "street-address", "index": 2},
{"section": "", "addressType": "", "contactType": "", "fieldName": "address-level2", "index": 3},
{"section": "", "addressType": "", "contactType": "", "fieldName": "country", "index": 4},
{"section": "", "addressType": "", "contactType": "", "fieldName": "email", "index": 5},
{"section": "", "addressType": "", "contactType": "", "fieldName": "tel", "index": 6},
],
fieldDetails: [
{"section": "", "addressType": "", "contactType": "", "fieldName": "given-name", "element": {}},
{"section": "", "addressType": "", "contactType": "", "fieldName": "family-name", "element": {}},
{"section": "", "addressType": "", "contactType": "", "fieldName": "street-address", "element": {}},
{"section": "", "addressType": "", "contactType": "", "fieldName": "address-level2", "element": {}},
{"section": "", "addressType": "", "contactType": "", "fieldName": "country", "element": {}},
{"section": "", "addressType": "", "contactType": "", "fieldName": "email", "element": {}},
{"section": "", "addressType": "", "contactType": "", "fieldName": "tel", "element": {}},
],
},
{
description: "Form with autocomplete properties and 2 tokens",
document: `<form><input id="given-name" autocomplete="shipping given-name">
<input id="family-name" autocomplete="shipping family-name">
<input id="street-addr" autocomplete="shipping street-address">
<input id="city" autocomplete="shipping address-level2">
<input id="country" autocomplete="shipping country">
<input id='email' autocomplete="shipping email">
<input id="tel" autocomplete="shipping tel"></form>`,
returnedFormat: [
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "given-name", "index": 0},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "family-name", "index": 1},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "street-address", "index": 2},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "address-level2", "index": 3},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "country", "index": 4},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "email", "index": 5},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "tel", "index": 6},
],
fieldDetails: [
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "given-name", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "family-name", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "street-address", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "address-level2", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "country", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "email", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "tel", "element": {}},
],
},
{
description: "Form with autocomplete properties and profile is partly matched",
document: `<form><input id="given-name" autocomplete="shipping given-name">
<input id="family-name" autocomplete="shipping family-name">
<input id="street-addr" autocomplete="shipping street-address">
<input id="city" autocomplete="shipping address-level2">
<input id="country" autocomplete="shipping country">
<input id='email' autocomplete="shipping email">
<input id="tel" autocomplete="shipping tel"></form>`,
returnedFormat: [
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "given-name", "index": 0},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "family-name", "index": 1},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "street-address", "index": 2},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "address-level2", "index": 3},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "country", "index": 4},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "email", "index": 5},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "tel", "index": 6},
],
fieldDetails: [
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "given-name", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "family-name", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "street-address", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "address-level2", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "country", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "email", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "tel", "element": {}},
],
},
];
for (let tc of TESTCASES) {
(function() {
let testcase = tc;
add_task(function* () {
do_print("Starting testcase: " + testcase.description);
let doc = MockDocument.createTestDocument("http://localhost:8080/test/",
testcase.document);
let form = doc.querySelector("form");
let handler = new FormAutofillHandler(form);
Assert.deepEqual(handler.collectFormFields(), testcase.returnedFormat,
"Check the format of form autofill were returned correctly");
Assert.deepEqual(handler.fieldDetails, testcase.fieldDetails,
"Check the fieldDetails were set correctly");
});
})();
}

View file

@ -1,106 +0,0 @@
/*
* Test for populating field values in Form Autofill Parent.
*/
/* global FormAutofillParent */
"use strict";
importAutofillModule("FormAutofillParent.jsm");
do_get_profile();
const TEST_FIELDS = [
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "organization"},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "street-address"},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "address-level2"},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "address-level1"},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "postal-code"},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "country"},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "tel"},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "email"},
];
const TEST_GUID = "test-guid";
const TEST_PROFILE = {
guid: TEST_GUID,
organization: "World Wide Web Consortium",
streetAddress: "32 Vassar Street\nMIT Room 32-G524",
addressLevel2: "Cambridge",
addressLevel1: "MA",
postalCode: "02139",
country: "US",
tel: "+1 617 253 5702",
email: "timbl@w3.org",
};
function camelCase(str) {
return str.toLowerCase().replace(/-([a-z])/g, s => s[1].toUpperCase());
}
add_task(function* test_populateFieldValues() {
FormAutofillParent.init();
let store = FormAutofillParent.getProfileStore();
do_check_neq(store, null);
store.get = function(guid) {
do_check_eq(guid, TEST_GUID);
return store._clone(TEST_PROFILE);
};
let notifyUsedCalledCount = 0;
store.notifyUsed = function(guid) {
do_check_eq(guid, TEST_GUID);
notifyUsedCalledCount++;
};
yield new Promise((resolve) => {
FormAutofillParent.receiveMessage({
name: "FormAutofill:PopulateFieldValues",
data: {
guid: TEST_GUID,
fields: TEST_FIELDS,
},
target: {
sendAsyncMessage: function(name, data) {
do_check_eq(name, "FormAutofill:fillForm");
let fields = data.fields;
do_check_eq(fields.length, TEST_FIELDS.length);
for (let i = 0; i < fields.length; i++) {
do_check_eq(fields[i].fieldName, TEST_FIELDS[i].fieldName);
do_check_eq(fields[i].value,
TEST_PROFILE[camelCase(fields[i].fieldName)]);
}
resolve();
},
},
});
});
do_check_eq(notifyUsedCalledCount, 1);
FormAutofillParent._uninit();
do_check_null(FormAutofillParent.getProfileStore());
});
add_task(function* test_populateFieldValues_with_invalid_guid() {
FormAutofillParent.init();
Assert.throws(() => {
FormAutofillParent.receiveMessage({
name: "FormAutofill:PopulateFieldValues",
data: {
guid: "invalid-guid",
fields: TEST_FIELDS,
},
target: {},
});
}, /No matching profile\./);
FormAutofillParent._uninit();
});

View file

@ -1,222 +0,0 @@
/**
* Tests ProfileStorage object.
*/
/* global ProfileStorage */
"use strict";
Cu.import("resource://gre/modules/Task.jsm");
Cu.import(Services.io.newFileURI(do_get_file("ProfileStorage.jsm")).spec);
const TEST_STORE_FILE_NAME = "test-profile.json";
const TEST_PROFILE_1 = {
organization: "World Wide Web Consortium",
streetAddress: "32 Vassar Street\nMIT Room 32-G524",
addressLevel2: "Cambridge",
addressLevel1: "MA",
postalCode: "02139",
country: "US",
tel: "+1 617 253 5702",
email: "timbl@w3.org",
};
const TEST_PROFILE_2 = {
streetAddress: "Some Address",
country: "US",
};
const TEST_PROFILE_3 = {
streetAddress: "Other Address",
postalCode: "12345",
};
const TEST_PROFILE_WITH_INVALID_FIELD = {
streetAddress: "Another Address",
invalidField: "INVALID",
};
let prepareTestProfiles = Task.async(function* (path) {
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
profileStorage.add(TEST_PROFILE_1);
profileStorage.add(TEST_PROFILE_2);
yield profileStorage._saveImmediately();
});
let do_check_profile_matches = (profileWithMeta, profile) => {
for (let key in profile) {
do_check_eq(profileWithMeta[key], profile[key]);
}
};
add_task(function* test_initialize() {
let path = getTempFile(TEST_STORE_FILE_NAME).path;
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
do_check_eq(profileStorage._store.data.version, 1);
do_check_eq(profileStorage._store.data.profiles.length, 0);
let data = profileStorage._store.data;
yield profileStorage._saveImmediately();
profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
Assert.deepEqual(profileStorage._store.data, data);
});
add_task(function* test_getAll() {
let path = getTempFile(TEST_STORE_FILE_NAME).path;
yield prepareTestProfiles(path);
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
let profiles = profileStorage.getAll();
do_check_eq(profiles.length, 2);
do_check_profile_matches(profiles[0], TEST_PROFILE_1);
do_check_profile_matches(profiles[1], TEST_PROFILE_2);
// Modifying output shouldn't affect the storage.
profiles[0].organization = "test";
do_check_profile_matches(profileStorage.getAll()[0], TEST_PROFILE_1);
});
add_task(function* test_get() {
let path = getTempFile(TEST_STORE_FILE_NAME).path;
yield prepareTestProfiles(path);
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
let profiles = profileStorage.getAll();
let guid = profiles[0].guid;
let profile = profileStorage.get(guid);
do_check_profile_matches(profile, TEST_PROFILE_1);
// Modifying output shouldn't affect the storage.
profile.organization = "test";
do_check_profile_matches(profileStorage.get(guid), TEST_PROFILE_1);
Assert.throws(() => profileStorage.get("INVALID_GUID"),
/No matching profile\./);
});
add_task(function* test_add() {
let path = getTempFile(TEST_STORE_FILE_NAME).path;
yield prepareTestProfiles(path);
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
let profiles = profileStorage.getAll();
do_check_eq(profiles.length, 2);
do_check_profile_matches(profiles[0], TEST_PROFILE_1);
do_check_profile_matches(profiles[1], TEST_PROFILE_2);
do_check_neq(profiles[0].guid, undefined);
do_check_neq(profiles[0].timeCreated, undefined);
do_check_eq(profiles[0].timeLastModified, profiles[0].timeCreated);
do_check_eq(profiles[0].timeLastUsed, 0);
do_check_eq(profiles[0].timesUsed, 0);
Assert.throws(() => profileStorage.add(TEST_PROFILE_WITH_INVALID_FIELD),
/"invalidField" is not a valid field\./);
});
add_task(function* test_update() {
let path = getTempFile(TEST_STORE_FILE_NAME).path;
yield prepareTestProfiles(path);
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
let profiles = profileStorage.getAll();
let guid = profiles[1].guid;
let timeLastModified = profiles[1].timeLastModified;
do_check_neq(profiles[1].country, undefined);
profileStorage.update(guid, TEST_PROFILE_3);
yield profileStorage._saveImmediately();
profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
let profile = profileStorage.get(guid);
do_check_eq(profile.country, undefined);
do_check_neq(profile.timeLastModified, timeLastModified);
do_check_profile_matches(profile, TEST_PROFILE_3);
Assert.throws(
() => profileStorage.update("INVALID_GUID", TEST_PROFILE_3),
/No matching profile\./
);
Assert.throws(
() => profileStorage.update(guid, TEST_PROFILE_WITH_INVALID_FIELD),
/"invalidField" is not a valid field\./
);
});
add_task(function* test_notifyUsed() {
let path = getTempFile(TEST_STORE_FILE_NAME).path;
yield prepareTestProfiles(path);
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
let profiles = profileStorage.getAll();
let guid = profiles[1].guid;
let timeLastUsed = profiles[1].timeLastUsed;
let timesUsed = profiles[1].timesUsed;
profileStorage.notifyUsed(guid);
yield profileStorage._saveImmediately();
profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
let profile = profileStorage.get(guid);
do_check_eq(profile.timesUsed, timesUsed + 1);
do_check_neq(profile.timeLastUsed, timeLastUsed);
Assert.throws(() => profileStorage.notifyUsed("INVALID_GUID"),
/No matching profile\./);
});
add_task(function* test_remove() {
let path = getTempFile(TEST_STORE_FILE_NAME).path;
yield prepareTestProfiles(path);
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
let profiles = profileStorage.getAll();
let guid = profiles[1].guid;
do_check_eq(profiles.length, 2);
profileStorage.remove(guid);
yield profileStorage._saveImmediately();
profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
profiles = profileStorage.getAll();
do_check_eq(profiles.length, 1);
Assert.throws(() => profileStorage.get(guid), /No matching profile\./);
});

View file

@ -1,12 +0,0 @@
[DEFAULT]
head = head.js
tail =
support-files =
../../content/FormAutofillContent.jsm
../../content/FormAutofillParent.jsm
../../content/ProfileStorage.jsm
[test_autofillFormFields.js]
[test_collectFormFields.js]
[test_populateFieldValues.js]
[test_profileStorage.js]

View file

@ -1,7 +0,0 @@
"use strict";
module.exports = {
"extends": [
"../../../../testing/mochitest/browser.eslintrc.js"
]
};

View file

@ -1,10 +0,0 @@
[DEFAULT]
support-files =
file_pdfjs_test.pdf
head.js
[browser_pdfjs_main.js]
[browser_pdfjs_navigation.js]
[browser_pdfjs_savedialog.js]
[browser_pdfjs_views.js]
[browser_pdfjs_zoom.js]

View file

@ -1,67 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
const RELATIVE_DIR = "browser/extensions/pdfjs/test/";
const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR;
add_task(function* test() {
let handlerService = Cc["@mozilla.org/uriloader/handler-service;1"].getService(Ci.nsIHandlerService);
let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
let handlerInfo = mimeService.getFromTypeAndExtension('application/pdf', 'pdf');
// Make sure pdf.js is the default handler.
is(handlerInfo.alwaysAskBeforeHandling, false, 'pdf handler defaults to always-ask is false');
is(handlerInfo.preferredAction, Ci.nsIHandlerInfo.handleInternally, 'pdf handler defaults to internal');
info('Pref action: ' + handlerInfo.preferredAction);
yield BrowserTestUtils.withNewTab({ gBrowser: gBrowser, url: "about:blank" },
function* (newTabBrowser) {
yield waitForPdfJS(newTabBrowser, TESTROOT + "file_pdfjs_test.pdf");
ok(gBrowser.isFindBarInitialized(), "Browser FindBar initialized!");
yield ContentTask.spawn(newTabBrowser, null, function* () {
//
// Overall sanity tests
//
Assert.ok(content.document.querySelector('div#viewer'), "document content has viewer UI");
Assert.ok('PDFJS' in content.wrappedJSObject, "window content has PDFJS object");
//
// Sidebar: open
//
var sidebar = content.document.querySelector('button#sidebarToggle'),
outerContainer = content.document.querySelector('div#outerContainer');
sidebar.click();
Assert.ok(outerContainer.classList.contains('sidebarOpen'), "sidebar opens on click");
//
// Sidebar: close
//
sidebar.click();
Assert.ok(!outerContainer.classList.contains('sidebarOpen'), "sidebar closes on click");
//
// Page change from prev/next buttons
//
var prevPage = content.document.querySelector('button#previous'),
nextPage = content.document.querySelector('button#next');
var pgNumber = content.document.querySelector('input#pageNumber').value;
Assert.equal(parseInt(pgNumber, 10), 1, "initial page is 1");
//
// Bookmark button
//
var viewBookmark = content.document.querySelector('a#viewBookmark');
viewBookmark.click();
Assert.ok(viewBookmark.href.length > 0, "viewBookmark button has href");
var viewer = content.wrappedJSObject.PDFViewerApplication;
yield viewer.close();
});
});
});

View file

@ -1,283 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
requestLongerTimeout(2);
Components.utils.import("resource://gre/modules/Promise.jsm", this);
const RELATIVE_DIR = "browser/extensions/pdfjs/test/";
const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR;
const PDF_OUTLINE_ITEMS = 17;
const TESTS = [
{
action: {
selector: "button#next",
event: "click"
},
expectedPage: 2,
message: "navigated to next page using NEXT button"
},
{
action: {
selector: "button#previous",
event: "click"
},
expectedPage: 1,
message: "navigated to previous page using PREV button"
},
{
action: {
selector: "button#next",
event: "click"
},
expectedPage: 2,
message: "navigated to next page using NEXT button"
},
{
action: {
selector: "input#pageNumber",
value: 1,
event: "change"
},
expectedPage: 1,
message: "navigated to first page using pagenumber"
},
{
action: {
selector: "#thumbnailView a:nth-child(4)",
event: "click"
},
expectedPage: 4,
message: "navigated to 4th page using thumbnail view"
},
{
action: {
selector: "#thumbnailView a:nth-child(2)",
event: "click"
},
expectedPage: 2,
message: "navigated to 2nd page using thumbnail view"
},
{
action: {
selector: "#viewer",
event: "keydown",
keyCode: 36
},
expectedPage: 1,
message: "navigated to 1st page using 'home' key"
},
{
action: {
selector: "#viewer",
event: "keydown",
keyCode: 34
},
expectedPage: 2,
message: "navigated to 2nd page using 'Page Down' key"
},
{
action: {
selector: "#viewer",
event: "keydown",
keyCode: 33
},
expectedPage: 1,
message: "navigated to 1st page using 'Page Up' key"
},
{
action: {
selector: "#viewer",
event: "keydown",
keyCode: 39
},
expectedPage: 2,
message: "navigated to 2nd page using 'right' key"
},
{
action: {
selector: "#viewer",
event: "keydown",
keyCode: 37
},
expectedPage: 1,
message: "navigated to 1st page using 'left' key"
},
{
action: {
selector: "#viewer",
event: "keydown",
keyCode: 35
},
expectedPage: 5,
message: "navigated to last page using 'home' key"
},
{
action: {
selector: ".outlineItem:nth-child(1) a",
event: "click"
},
expectedPage: 1,
message: "navigated to 1st page using outline view"
},
{
action: {
selector: ".outlineItem:nth-child(" + PDF_OUTLINE_ITEMS + ") a",
event: "click"
},
expectedPage: 4,
message: "navigated to 4th page using outline view"
},
{
action: {
selector: "input#pageNumber",
value: 5,
event: "change"
},
expectedPage: 5,
message: "navigated to 5th page using pagenumber"
}
];
add_task(function* test() {
let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
let handlerInfo = mimeService.getFromTypeAndExtension('application/pdf', 'pdf');
// Make sure pdf.js is the default handler.
is(handlerInfo.alwaysAskBeforeHandling, false, 'pdf handler defaults to always-ask is false');
is(handlerInfo.preferredAction, Ci.nsIHandlerInfo.handleInternally, 'pdf handler defaults to internal');
info('Pref action: ' + handlerInfo.preferredAction);
yield BrowserTestUtils.withNewTab({ gBrowser, url: "about:blank" },
function* (newTabBrowser) {
yield waitForPdfJS(newTabBrowser, TESTROOT + "file_pdfjs_test.pdf");
yield ContentTask.spawn(newTabBrowser, null, function* () {
// Check if PDF is opened with internal viewer
Assert.ok(content.document.querySelector("div#viewer"), "document content has viewer UI");
Assert.ok("PDFJS" in content.wrappedJSObject, "window content has PDFJS object");
});
yield ContentTask.spawn(newTabBrowser, null, contentSetUp);
yield Task.spawn(runTests(newTabBrowser));
yield ContentTask.spawn(newTabBrowser, null, function*() {
let pageNumber = content.document.querySelector('input#pageNumber');
Assert.equal(pageNumber.value, pageNumber.max, "Document is left on the last page");
});
});
});
function* contentSetUp() {
/**
* Outline Items gets appended to the document later on we have to
* wait for them before we start to navigate though document
*
* @param document
* @returns {deferred.promise|*}
*/
function waitForOutlineItems(document) {
return new Promise((resolve, reject) => {
document.addEventListener("outlineloaded", function outlineLoaded(evt) {
document.removeEventListener("outlineloaded", outlineLoaded);
var outlineCount = evt.detail.outlineCount;
if (document.querySelectorAll(".outlineItem").length === outlineCount) {
resolve();
} else {
reject();
}
});
});
}
/**
* The key navigation has to happen in page-fit, otherwise it won't scroll
* through a complete page
*
* @param document
* @returns {deferred.promise|*}
*/
function setZoomToPageFit(document) {
return new Promise((resolve) => {
document.addEventListener("pagerendered", function onZoom(e) {
document.removeEventListener("pagerendered", onZoom);
document.querySelector("#viewer").click();
resolve();
});
var select = document.querySelector("select#scaleSelect");
select.selectedIndex = 2;
select.dispatchEvent(new Event("change"));
});
}
yield waitForOutlineItems(content.document);
yield setZoomToPageFit(content.document);
}
/**
* As the page changes asynchronously, we have to wait for the event after
* we trigger the action so we will be at the expected page number after each action
*
* @param document
* @param window
* @param test
* @param callback
*/
function* runTests(browser) {
yield ContentTask.spawn(browser, TESTS, function* (TESTS) {
let window = content;
let document = window.document;
for (let test of TESTS) {
let deferred = {};
deferred.promise = new Promise((resolve, reject) => {
deferred.resolve = resolve;
deferred.reject = reject;
});
let pageNumber = document.querySelector('input#pageNumber');
// Add an event-listener to wait for page to change, afterwards resolve the promise
let timeout = window.setTimeout(() => deferred.reject(), 5000);
window.addEventListener('pagechange', function pageChange() {
if (pageNumber.value == test.expectedPage) {
window.removeEventListener('pagechange', pageChange);
window.clearTimeout(timeout);
deferred.resolve(+pageNumber.value);
}
});
// Get the element and trigger the action for changing the page
var el = document.querySelector(test.action.selector);
Assert.ok(el, "Element '" + test.action.selector + "' has been found");
// The value option is for input case
if (test.action.value)
el.value = test.action.value;
// Dispatch the event for changing the page
if (test.action.event == "keydown") {
var ev = document.createEvent("KeyboardEvent");
ev.initKeyEvent("keydown", true, true, null, false, false, false, false,
test.action.keyCode, 0);
el.dispatchEvent(ev);
}
else {
var ev = new Event(test.action.event);
}
el.dispatchEvent(ev);
let pgNumber = yield deferred.promise;
Assert.equal(pgNumber, test.expectedPage, test.message);
}
var viewer = content.wrappedJSObject.PDFViewerApplication;
yield viewer.close();
});
}

View file

@ -1,65 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
const RELATIVE_DIR = "browser/extensions/pdfjs/test/";
const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR;
function test() {
var oldAction = changeMimeHandler(Ci.nsIHandlerInfo.useSystemDefault, true);
var tab = gBrowser.addTab(TESTROOT + "file_pdfjs_test.pdf");
//
// Test: "Open with" dialog comes up when pdf.js is not selected as the default
// handler.
//
addWindowListener('chrome://mozapps/content/downloads/unknownContentType.xul', finish);
waitForExplicitFinish();
registerCleanupFunction(function() {
changeMimeHandler(oldAction[0], oldAction[1]);
gBrowser.removeTab(tab);
});
}
function changeMimeHandler(preferredAction, alwaysAskBeforeHandling) {
let handlerService = Cc["@mozilla.org/uriloader/handler-service;1"].getService(Ci.nsIHandlerService);
let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
let handlerInfo = mimeService.getFromTypeAndExtension('application/pdf', 'pdf');
var oldAction = [handlerInfo.preferredAction, handlerInfo.alwaysAskBeforeHandling];
// Change and save mime handler settings
handlerInfo.alwaysAskBeforeHandling = alwaysAskBeforeHandling;
handlerInfo.preferredAction = preferredAction;
handlerService.store(handlerInfo);
Services.obs.notifyObservers(null, 'pdfjs:handlerChanged', null);
// Refresh data
handlerInfo = mimeService.getFromTypeAndExtension('application/pdf', 'pdf');
//
// Test: Mime handler was updated
//
is(handlerInfo.alwaysAskBeforeHandling, alwaysAskBeforeHandling, 'always-ask prompt change successful');
is(handlerInfo.preferredAction, preferredAction, 'mime handler change successful');
return oldAction;
}
function addWindowListener(aURL, aCallback) {
Services.wm.addListener({
onOpenWindow: function(aXULWindow) {
info("window opened, waiting for focus");
Services.wm.removeListener(this);
var domwindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow);
waitForFocus(function() {
is(domwindow.document.location.href, aURL, "should have seen the right window open");
domwindow.close();
aCallback();
}, domwindow);
},
onCloseWindow: function(aXULWindow) { },
onWindowTitleChange: function(aXULWindow, aNewTitle) { }
});
}

View file

@ -1,67 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
const RELATIVE_DIR = "browser/extensions/pdfjs/test/";
const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR;
add_task(function* test() {
let handlerService = Cc["@mozilla.org/uriloader/handler-service;1"].getService(Ci.nsIHandlerService);
let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
let handlerInfo = mimeService.getFromTypeAndExtension('application/pdf', 'pdf');
// Make sure pdf.js is the default handler.
is(handlerInfo.alwaysAskBeforeHandling, false, 'pdf handler defaults to always-ask is false');
is(handlerInfo.preferredAction, Ci.nsIHandlerInfo.handleInternally, 'pdf handler defaults to internal');
info('Pref action: ' + handlerInfo.preferredAction);
yield BrowserTestUtils.withNewTab({ gBrowser, url: "about:blank" },
function* (browser) {
// check that PDF is opened with internal viewer
yield waitForPdfJS(browser, TESTROOT + "file_pdfjs_test.pdf");
yield ContentTask.spawn(browser, null, function* () {
Assert.ok(content.document.querySelector("div#viewer"), "document content has viewer UI");
Assert.ok("PDFJS" in content.wrappedJSObject, "window content has PDFJS object");
//open sidebar
var sidebar = content.document.querySelector('button#sidebarToggle');
var outerContainer = content.document.querySelector('div#outerContainer');
sidebar.click();
Assert.ok(outerContainer.classList.contains("sidebarOpen"), "sidebar opens on click");
// check that thumbnail view is open
var thumbnailView = content.document.querySelector('div#thumbnailView');
var outlineView = content.document.querySelector('div#outlineView');
Assert.equal(thumbnailView.getAttribute("class"), null,
"Initial view is thumbnail view");
Assert.equal(outlineView.getAttribute("class"), "hidden",
"Outline view is hidden initially");
//switch to outline view
var viewOutlineButton = content.document.querySelector('button#viewOutline');
viewOutlineButton.click();
Assert.equal(thumbnailView.getAttribute("class"), "hidden",
"Thumbnail view is hidden when outline is selected");
Assert.equal(outlineView.getAttribute("class"), "",
"Outline view is visible when selected");
//switch back to thumbnail view
var viewThumbnailButton = content.document.querySelector('button#viewThumbnail');
viewThumbnailButton.click();
Assert.equal(thumbnailView.getAttribute("class"), "",
"Thumbnail view is visible when selected");
Assert.equal(outlineView.getAttribute("class"), "hidden",
"Outline view is hidden when thumbnail is selected");
sidebar.click();
var viewer = content.wrappedJSObject.PDFViewerApplication;
yield viewer.close();
});
});
});

View file

@ -1,154 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
requestLongerTimeout(2);
Components.utils.import("resource://gre/modules/Promise.jsm", this);
const RELATIVE_DIR = "browser/extensions/pdfjs/test/";
const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR;
const TESTS = [
{
action: {
selector: "button#zoomIn",
event: "click"
},
expectedZoom: 1, // 1 - zoom in
message: "Zoomed in using the '+' (zoom in) button"
},
{
action: {
selector: "button#zoomOut",
event: "click"
},
expectedZoom: -1, // -1 - zoom out
message: "Zoomed out using the '-' (zoom out) button"
},
{
action: {
keyboard: true,
keyCode: 61,
event: "+"
},
expectedZoom: 1, // 1 - zoom in
message: "Zoomed in using the CTRL++ keys"
},
{
action: {
keyboard: true,
keyCode: 109,
event: "-"
},
expectedZoom: -1, // -1 - zoom out
message: "Zoomed out using the CTRL+- keys"
},
{
action: {
selector: "select#scaleSelect",
index: 5,
event: "change"
},
expectedZoom: -1, // -1 - zoom out
message: "Zoomed using the zoom picker"
}
];
add_task(function* test() {
let handlerService = Cc["@mozilla.org/uriloader/handler-service;1"]
.getService(Ci.nsIHandlerService);
let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
let handlerInfo = mimeService.getFromTypeAndExtension('application/pdf', 'pdf');
// Make sure pdf.js is the default handler.
is(handlerInfo.alwaysAskBeforeHandling, false,
'pdf handler defaults to always-ask is false');
is(handlerInfo.preferredAction, Ci.nsIHandlerInfo.handleInternally,
'pdf handler defaults to internal');
info('Pref action: ' + handlerInfo.preferredAction);
yield BrowserTestUtils.withNewTab({ gBrowser, url: "about:blank" },
function* (newTabBrowser) {
yield waitForPdfJS(newTabBrowser, TESTROOT + "file_pdfjs_test.pdf" + "#zoom=100");
yield ContentTask.spawn(newTabBrowser, TESTS, function* (TESTS) {
let document = content.document;
function waitForRender() {
return new Promise((resolve) => {
document.addEventListener("pagerendered", function onPageRendered(e) {
if(e.detail.pageNumber !== 1) {
return;
}
document.removeEventListener("pagerendered", onPageRendered, true);
resolve();
}, true);
});
}
// check that PDF is opened with internal viewer
Assert.ok(content.document.querySelector("div#viewer"), "document content has viewer UI");
Assert.ok("PDFJS" in content.wrappedJSObject, "window content has PDFJS object");
let initialWidth, previousWidth;
initialWidth = previousWidth =
parseInt(content.document.querySelector("div#pageContainer1").style.width);
for (let test of TESTS) {
// We zoom using an UI element
var ev;
if (test.action.selector) {
// Get the element and trigger the action for changing the zoom
var el = document.querySelector(test.action.selector);
Assert.ok(el, "Element '" + test.action.selector + "' has been found");
if (test.action.index){
el.selectedIndex = test.action.index;
}
// Dispatch the event for changing the zoom
ev = new Event(test.action.event);
}
// We zoom using keyboard
else {
// Simulate key press
ev = new content.KeyboardEvent("keydown",
{ key: test.action.event,
keyCode: test.action.keyCode,
ctrlKey: true });
el = content;
}
el.dispatchEvent(ev);
yield waitForRender();
var pageZoomScale = content.document.querySelector('select#scaleSelect');
// The zoom value displayed in the zoom select
var zoomValue = pageZoomScale.options[pageZoomScale.selectedIndex].innerHTML;
let pageContainer = content.document.querySelector('div#pageContainer1');
let actualWidth = parseInt(pageContainer.style.width);
// the actual zoom of the PDF document
let computedZoomValue = parseInt(((actualWidth/initialWidth).toFixed(2))*100) + "%";
Assert.equal(computedZoomValue, zoomValue, "Content has correct zoom");
// Check that document zooms in the expected way (in/out)
let zoom = (actualWidth - previousWidth) * test.expectedZoom;
Assert.ok(zoom > 0, test.message);
previousWidth = actualWidth;
}
var viewer = content.wrappedJSObject.PDFViewerApplication;
yield viewer.close();
});
});
});

View file

@ -1,15 +0,0 @@
function waitForPdfJS(browser, url) {
// Runs tests after all 'load' event handlers have fired off
return ContentTask.spawn(browser, url, function* (url) {
yield new Promise((resolve) => {
// NB: Add the listener to the global object so that we receive the
// event fired from the new window.
addEventListener("documentload", function listener() {
removeEventListener("documentload", listener, false);
resolve();
}, false, true);
content.location = url;
});
});
}

View file

@ -1,7 +0,0 @@
"use strict";
module.exports = {
"extends": [
"../../../../testing/mochitest/browser.eslintrc.js"
]
};

View file

@ -1,6 +0,0 @@
[DEFAULT]
support-files =
head.js
test.html
[browser_pocket_ui_check.js]

View file

@ -1,61 +0,0 @@
"use strict";
function checkWindowProperties(expectPresent, l) {
for (let name of l) {
is(!!window.hasOwnProperty(name), expectPresent, "property " + name + (expectPresent ? " is" : " is not") + " present");
}
}
function checkElements(expectPresent, l) {
for (let id of l) {
is(!!document.getElementById(id), expectPresent, "element " + id + (expectPresent ? " is" : " is not") + " present");
}
}
add_task(function* test_setup() {
let clearValue = Services.prefs.prefHasUserValue("extensions.pocket.enabled");
let enabledOnStartup = Services.prefs.getBoolPref("extensions.pocket.enabled");
registerCleanupFunction(() => {
if (clearValue) {
Services.prefs.clearUserPref("extensions.pocket.enabled");
} else {
Services.prefs.setBoolPref("extensions.pocket.enabled", enabledOnStartup);
}
});
});
add_task(function*() {
yield promisePocketEnabled();
checkWindowProperties(true, ["Pocket", "pktUI", "pktUIMessaging"]);
checkElements(true, ["pocket-button", "panelMenu_pocket", "menu_pocket", "BMB_pocket",
"panelMenu_pocketSeparator", "menu_pocketSeparator",
"BMB_pocketSeparator"]);
// check context menu exists
info("checking content context menu");
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "https://example.com/browser/browser/extensions/pocket/test/test.html");
let contextMenu = document.getElementById("contentAreaContextMenu");
let popupShown = BrowserTestUtils.waitForEvent(contextMenu, "popupshown");
let popupHidden = BrowserTestUtils.waitForEvent(contextMenu, "popuphidden");
yield BrowserTestUtils.synthesizeMouseAtCenter("body", {
type: "contextmenu",
button: 2
}, tab.linkedBrowser);
yield popupShown;
checkElements(true, ["context-pocket", "context-savelinktopocket"]);
contextMenu.hidePopup();
yield popupHidden;
yield BrowserTestUtils.removeTab(tab);
yield promisePocketDisabled();
checkWindowProperties(false, ["Pocket", "pktUI", "pktUIMessaging"]);
checkElements(false, ["pocket-button", "panelMenu_pocket", "menu_pocket", "BMB_pocket",
"panelMenu_pocketSeparator", "menu_pocketSeparator",
"BMB_pocketSeparator", "context-pocket", "context-savelinktopocket"]);
yield promisePocketReset();
});

View file

@ -1,67 +0,0 @@
// Currently Pocket is disabled in tests. We want these tests to work under
// either case that Pocket is disabled or enabled on startup of the browser,
// and that at the end we're reset to the correct state.
let enabledOnStartup = false;
// PocketEnabled/Disabled promises return true if it was already
// Enabled/Disabled, and false if it need to Enable/Disable.
function promisePocketEnabled() {
if (Services.prefs.getPrefType("extensions.pocket.enabled") != Services.prefs.PREF_INVALID &&
Services.prefs.getBoolPref("extensions.pocket.enabled")) {
info( "pocket was already enabled, assuming enabled by default for tests");
enabledOnStartup = true;
return Promise.resolve(true);
}
info( "pocket is not enabled");
return new Promise((resolve, reject) => {
let listener = {
onWidgetAfterCreation(widgetid) {
if (widgetid == "pocket-button") {
info("pocket-button created");
CustomizableUI.removeListener(listener);
resolve(false);
}
}
}
CustomizableUI.addListener(listener);
Services.prefs.setBoolPref("extensions.pocket.enabled", true);
});
}
function promisePocketDisabled() {
if (Services.prefs.getPrefType("extensions.pocket.enabled") == Services.prefs.PREF_INVALID ||
!Services.prefs.getBoolPref("extensions.pocket.enabled")) {
info("pocket-button already disabled");
return Promise.resolve(true);
}
return new Promise((resolve, reject) => {
let listener = {
onWidgetDestroyed: function(widgetid) {
if (widgetid == "pocket-button") {
CustomizableUI.removeListener(listener);
info( "pocket-button destroyed");
// wait for a full unload of pocket
BrowserTestUtils.waitForCondition(() => {
return !window.hasOwnProperty("pktUI");
}, "pocket properties removed from window").then(() => {
resolve(false);
})
}
}
}
CustomizableUI.addListener(listener);
info("reset pocket enabled pref");
// testing/profiles/prefs_general.js uses user_pref to disable pocket, set
// back to false.
Services.prefs.setBoolPref("extensions.pocket.enabled", false);
});
}
function promisePocketReset() {
if (enabledOnStartup) {
info("reset is enabling pocket addon");
return promisePocketEnabled();
}
info("reset is disabling pocket addon");
return promisePocketDisabled();
}

View file

@ -1,11 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<meta charset="utf-8" />
</head>
<body>
</body>
</html>

View file

@ -1,7 +0,0 @@
"use strict";
module.exports = {
"extends": [
"../../../../../testing/mochitest/browser.eslintrc.js"
]
};

View file

@ -1,3 +0,0 @@
[DEFAULT]
[browser_check_installed.js]

View file

@ -1,13 +0,0 @@
"use strict";
add_task(function* test_enabled() {
let addon = yield new Promise(
resolve => AddonManager.getAddonByID("webcompat@mozilla.org", resolve)
);
isnot(addon, null, "Check addon exists");
is(addon.version, "1.0", "Check version");
is(addon.name, "Web Compat", "Check name");
ok(addon.isCompatible, "Check application compatibility");
ok(!addon.appDisabled, "Check not app disabled");
ok(addon.isActive, "Check addon is active");
});