Bug 1335180: Fix race in browser_ext_tabs_reload_bypass_cache. r=mixedpuppy

MozReview-Commit-ID: FXqRHwZUll6

--HG--
extra : rebase_source : ee1bee7f9ed4ca2b56159a769b65c25b523e3a05
This commit is contained in:
Kris Maglione 2017-03-14 09:20:17 -07:00
Родитель 4951f9acb7
Коммит 6e50c8fc6d
1 изменённых файлов: 21 добавлений и 11 удалений

Просмотреть файл

@ -12,29 +12,39 @@ add_task(function* () {
const BASE = "http://mochi.test:8888/browser/browser/components/extensions/test/browser/";
const URL = BASE + "file_bypass_cache.sjs";
function awaitLoad(tabId) {
return new Promise(resolve => {
browser.tabs.onUpdated.addListener(function listener(tabId_, changed, tab) {
if (tabId == tabId_ && changed.status == "complete" && tab.url == URL) {
browser.tabs.onUpdated.removeListener(listener);
resolve();
}
});
let tabId = null;
let loadPromise, resolveLoad;
function resetLoad() {
loadPromise = new Promise(resolve => {
resolveLoad = resolve;
});
}
function awaitLoad() {
return loadPromise.then(() => {
resetLoad();
});
}
resetLoad();
browser.tabs.onUpdated.addListener(function listener(tabId_, changed, tab) {
if (tabId == tabId_ && changed.status == "complete" && tab.url == URL) {
resolveLoad();
}
});
try {
let tab = await browser.tabs.create({url: URL});
await awaitLoad(tab.id);
tabId = tab.id;
await awaitLoad();
await browser.tabs.reload(tab.id, {bypassCache: false});
await awaitLoad(tab.id);
await awaitLoad();
let [textContent] = await browser.tabs.executeScript(tab.id, {code: "document.body.textContent"});
browser.test.assertEq("", textContent, "`textContent` should be empty when bypassCache=false");
await browser.tabs.reload(tab.id, {bypassCache: true});
await awaitLoad(tab.id);
await awaitLoad();
[textContent] = await browser.tabs.executeScript(tab.id, {code: "document.body.textContent"});