Backed out changeset 289a3851e8c7 (bug 1595328) for causing test_ext_tabs_query.html to permafail CLOSED TREE

This commit is contained in:
Ciure Andrei 2019-11-15 03:27:50 +02:00
parent 70b54837ac
commit 5df04e0ac8
4 changed files with 0 additions and 154 deletions

View file

@ -5,11 +5,9 @@
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
XPCOMUtils.defineLazyModuleGetters(this, {
AppMenuNotifications: "resource://gre/modules/AppMenuNotifications.jsm",
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
ProfileAge: "resource://gre/modules/ProfileAge.jsm",
Services: "resource://gre/modules/Services.jsm",
});
@ -108,19 +106,6 @@ this.experiments_urlbar = class extends ExtensionAPI {
let errorCode = update ? update.errorCode : 0;
return updateStateIs("pending") && errorCode != 0;
},
async lastBrowserUpdateDate() {
// Get the newest update in the update history. This isn't perfect
// because these dates are when updates are applied, not when the
// user restarts with the update. See bug 1595328.
if (updateManager.updateCount) {
let update = updateManager.getUpdateAt(0);
return update.installDate;
}
// Fall back to the profile age.
let age = await ProfileAge();
return (await age.firstUse) || age.created;
},
},
},
};

View file

@ -11,4 +11,3 @@ support-files =
[browser_ext_urlbar_isBrowserShowingNotification.js]
[browser_ext_urlbar_isBrowserUpdateReadyToInstall.js]
[browser_ext_urlbar_lastBrowserUpdateDate.js]

View file

@ -1,131 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
/* global browser */
// This tests the browser.experiments.urlbar.lastBrowserUpdateDate WebExtension
// Experiment API. The parts related to the updates.xml file are adapted from
// browser_policy_override_postupdatepage.js and other similar tests.
"use strict";
XPCOMUtils.defineLazyModuleGetters(this, {
ProfileAge: "resource://gre/modules/ProfileAge.jsm",
});
XPCOMUtils.defineLazyServiceGetter(
this,
"updateManager",
"@mozilla.org/updates/update-manager;1",
"nsIUpdateManager"
);
const DATE_MS = 1368255600000;
add_task(async function setUp() {
let originalTimes = (await ProfileAge())._times;
registerCleanupFunction(async () => {
removeUpdatesFile();
let age = await ProfileAge();
age._times = originalTimes;
await age.writeTimes();
});
});
// no update history, same profile created and first-use date
add_task(async function noHistory_sameCreateAndFirstUse() {
removeUpdatesFile();
reloadUpdateManagerData();
Assert.equal(updateManager.updateCount, 0);
await updateProfileAge(DATE_MS, DATE_MS);
await checkExtension(DATE_MS);
});
// no update history, different profile created and first-use dates
add_task(async function noHistory_differentCreateAndFirstUse() {
removeUpdatesFile();
reloadUpdateManagerData();
Assert.equal(updateManager.updateCount, 0);
await updateProfileAge(DATE_MS - 30000, DATE_MS);
await checkExtension(DATE_MS);
});
// update history
add_task(async function history() {
removeUpdatesFile();
writeUpdatesFile(DATE_MS);
reloadUpdateManagerData();
Assert.equal(updateManager.updateCount, 1);
await updateProfileAge(DATE_MS - 60000, DATE_MS - 30000);
await checkExtension(DATE_MS);
});
async function checkExtension(expectedDate) {
let ext = await loadExtension(async () => {
let date = await browser.experiments.urlbar.lastBrowserUpdateDate();
browser.test.sendMessage("date", date);
});
let date = await ext.awaitMessage("date");
Assert.equal(date, expectedDate);
await ext.unload();
}
function getUpdatesFile() {
let updateRootDir = Services.dirsvc.get("UpdRootD", Ci.nsIFile);
let updatesFile = updateRootDir.clone();
updatesFile.append("updates.xml");
return updatesFile;
}
function removeUpdatesFile() {
try {
getUpdatesFile().remove(false);
} catch (e) {}
}
function reloadUpdateManagerData() {
updateManager
.QueryInterface(Ci.nsIObserver)
.observe(null, "um-reload-update-data", "");
}
function getUpdatesXML(installDate) {
return `<?xml version="1.0"?>
<updates xmlns="http://www.mozilla.org/2005/app-update">
<update appVersion="1.0" buildID="20080811053724" channel="nightly"
displayVersion="Version 1.0" installDate="${installDate}"
isCompleteUpdate="true" name="Update Test 1.0" type="minor"
detailsURL="http://example.com/" previousAppVersion="1.0"
serviceURL="https://example.com/"
statusText="The Update was successfully installed"
foregroundDownload="true">
<patch type="complete" URL="http://example.com/" size="775"
selected="true" state="succeeded"/>
</update>
</updates>`;
}
function writeUpdatesFile(installDate) {
const PERMS_FILE = 0o644;
const MODE_WRONLY = 0x02;
const MODE_CREATE = 0x08;
const MODE_TRUNCATE = 0x20;
let file = getUpdatesFile();
if (!file.exists()) {
file.create(Ci.nsIFile.NORMAL_FILE_TYPE, PERMS_FILE);
}
let fos = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(
Ci.nsIFileOutputStream
);
let flags = MODE_WRONLY | MODE_CREATE | MODE_TRUNCATE;
fos.init(file, flags, PERMS_FILE, 0);
let xml = getUpdatesXML(installDate);
fos.write(xml, xml.length);
fos.close();
}
async function updateProfileAge(created, firstUse) {
let age = await ProfileAge();
age._times = { created, firstUse };
await age.writeTimes();
}

View file

@ -16,13 +16,6 @@
"async": true,
"description": "Returns true if there is an update ready to install.",
"parameters": []
},
{
"name": "lastBrowserUpdateDate",
"type": "function",
"async": true,
"description": "Returns the date of the last browser update. If there's no update history, then the date the profile was first used is returned instead. The return value is milliseconds since 1 January 1970 UTC (i.e., suitable for passing to <code>new Date()</code>).",
"parameters": []
}
]
}