Backed out changeset c058687eb204 (bug 1376973)

This commit is contained in:
Sebastian Hengst 2017-10-19 15:45:37 +02:00
Родитель 6b04a97785
Коммит 7f67463a70
2 изменённых файлов: 6 добавлений и 228 удалений

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

@ -6,10 +6,6 @@ const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
Cu.import("resource://gre/modules/PlacesUtils.jsm");
let EventUtils = {};
Services.scriptloader.loadSubScript(
"chrome://mochikit/content/tests/SimpleTest/EventUtils.js", EventUtils);
const FIRST_PARTY_ONE = "example.com";
const FIRST_PARTY_TWO = "example.org";
const THIRD_PARTY = "mochi.test:8888";
@ -56,10 +52,9 @@ function clearAllPlacesFavicons() {
});
}
function observeFavicon(aFirstPartyDomain, aExpectedCookie, aPageURI, aOnlyXUL) {
function observeFavicon(aFirstPartyDomain, aExpectedCookie, aPageURI) {
let faviconReqXUL = false;
// If aOnlyXUL is true, we only care about the favicon request from XUL.
let faviconReqPlaces = aOnlyXUL === true;
let faviconReqPlaces = false;
let expectedPrincipal = Services.scriptSecurityManager
.createCodebasePrincipal(aPageURI, { firstPartyDomain: aFirstPartyDomain });
@ -249,85 +244,6 @@ async function doTest(aTestPage, aExpectedCookies, aFaviconURL) {
await BrowserTestUtils.removeTab(tabInfo.tab);
}
async function doTestForAllTabsFavicon(aTestPage, aExpectedCookies, aIsThirdParty) {
let firstPageURI = makeURI(TEST_SITE_ONE + aTestPage);
let secondPageURI = makeURI(TEST_SITE_TWO + aTestPage);
let faviconURI = aIsThirdParty ? THIRD_PARTY_SITE + FAVICON_URI :
TEST_SITE_ONE + FAVICON_URI;
// Set the 'overflow' attribute to make allTabs button available.
let tabBrowser = document.getElementById("tabbrowser-tabs");
let allTabsBtn = document.getElementById("alltabs-button");
tabBrowser.setAttribute("overflow", true);
// Start to observe the event of that the favicon has been fully loaded.
let promiseFaviconLoaded = waitOnFaviconLoaded(faviconURI);
// Open the tab for the first site.
let tabInfo = await openTab(TEST_SITE_ONE + aTestPage);
// Waiting until the favicon loaded.
await promiseFaviconLoaded;
// We need to clear the image cache here for making sure the network request will
// be made for the favicon of allTabs menuitem.
clearAllImageCaches();
// Start to observe the allTabs favicon requests earlier in case we miss it.
let promiseObserveFavicon = observeFavicon(FIRST_PARTY_ONE, aExpectedCookies[0],
firstPageURI, true);
// Make the popup of allTabs showing up and trigger the loading of the favicon.
let allTabsPopupShownPromise = BrowserTestUtils.waitForEvent(allTabsBtn, "popupshown");
EventUtils.synthesizeMouseAtCenter(allTabsBtn, {});
await promiseObserveFavicon;
await allTabsPopupShownPromise;
// Close the popup of allTabs and wait until it's done.
let allTabsPopupHiddenPromise = BrowserTestUtils.waitForEvent(allTabsBtn, "popuphidden");
EventUtils.synthesizeMouseAtCenter(allTabsBtn, {});
await allTabsPopupHiddenPromise;
// Close the tab.
await BrowserTestUtils.removeTab(tabInfo.tab);
faviconURI = aIsThirdParty ? THIRD_PARTY_SITE + FAVICON_URI :
TEST_SITE_TWO + FAVICON_URI;
// Start to observe the event of that favicon has been fully loaded.
promiseFaviconLoaded = waitOnFaviconLoaded(faviconURI);
// Open the tab for the second site.
tabInfo = await openTab(TEST_SITE_TWO + aTestPage);
// Wait until the favicon is fully loaded.
await promiseFaviconLoaded;
// Clear the image cache for the favicon of the second site.
clearAllImageCaches();
// Start to observe the allTabs favicon requests earlier in case we miss it.
promiseObserveFavicon = observeFavicon(FIRST_PARTY_TWO, aExpectedCookies[1],
secondPageURI, true);
// Make the popup of allTabs showing up again.
allTabsPopupShownPromise = BrowserTestUtils.waitForEvent(allTabsBtn, "popupshown");
EventUtils.synthesizeMouseAtCenter(allTabsBtn, {});
await promiseObserveFavicon;
await allTabsPopupShownPromise;
// Close the popup of allTabs and wait until it's done.
allTabsPopupHiddenPromise = BrowserTestUtils.waitForEvent(allTabsBtn, "popuphidden");
EventUtils.synthesizeMouseAtCenter(allTabsBtn, {});
await allTabsPopupHiddenPromise;
// Close the tab.
await BrowserTestUtils.removeTab(tabInfo.tab);
// Reset the 'overflow' attribute to make the allTabs button hidden again.
tabBrowser.removeAttribute("overflow");
}
add_task(async function setup() {
// Make sure first party isolation is enabled.
await SpecialPowers.pushPrefEnv({"set": [
@ -366,28 +282,6 @@ add_task(async function test_favicon_firstParty() {
}
});
add_task(async function test_allTabs_favicon_firstParty() {
for (let testThirdParty of [false, true]) {
// Clear all image caches and network caches before running the test.
clearAllImageCaches();
let networkCache = Cc["@mozilla.org/netwerk/cache-storage-service;1"]
.getService(Ci.nsICacheStorageService);
networkCache.clear();
// Clear Places favicon caches.
await clearAllPlacesFavicons();
let cookies = await generateCookies(testThirdParty);
if (testThirdParty) {
await doTestForAllTabsFavicon(TEST_THIRD_PARTY_PAGE, cookies, testThirdParty);
} else {
await doTestForAllTabsFavicon(TEST_PAGE, cookies, testThirdParty);
}
}
});
add_task(async function test_favicon_cache_firstParty() {
// Clear all image caches and network caches before running the test.
clearAllImageCaches();

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

@ -7,10 +7,6 @@ const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
XPCOMUtils.defineLazyModuleGetter(this, "Promise",
"resource://gre/modules/Promise.jsm");
let EventUtils = {};
Services.scriptloader.loadSubScript(
"chrome://mochikit/content/tests/SimpleTest/EventUtils.js", EventUtils);
const TEST_SITE = "http://example.net";
const TEST_THIRD_PARTY_SITE = "http://mochi.test:8888";
@ -56,8 +52,8 @@ function clearAllPlacesFavicons() {
});
}
function FaviconObserver(aUserContextId, aExpectedCookie, aPageURI, aFaviconURL, aOnlyXUL) {
this.reset(aUserContextId, aExpectedCookie, aPageURI, aFaviconURL, aOnlyXUL);
function FaviconObserver(aUserContextId, aExpectedCookie, aPageURI, aFaviconURL) {
this.reset(aUserContextId, aExpectedCookie, aPageURI, aFaviconURL);
}
FaviconObserver.prototype = {
@ -112,14 +108,13 @@ FaviconObserver.prototype = {
}
},
reset(aUserContextId, aExpectedCookie, aPageURI, aFaviconURL, aOnlyXUL) {
reset(aUserContextId, aExpectedCookie, aPageURI, aFaviconURL) {
this._curUserContextId = aUserContextId;
this._expectedCookie = aExpectedCookie;
this._expectedPrincipal = Services.scriptSecurityManager
.createCodebasePrincipal(aPageURI, { userContextId: aUserContextId });
this._faviconReqXUL = false;
// If aOnlyXUL is true, we only care about the favicon request from XUL.
this._faviconReqPlaces = aOnlyXUL === true;
this._faviconReqPlaces = false;
this._faviconURL = aFaviconURL;
this._faviconLoaded = new Promise.defer();
},
@ -206,87 +201,6 @@ async function doTest(aTestPage, aFaviconHost, aFaviconURL) {
await BrowserTestUtils.removeTab(tabInfo.tab);
}
async function doTestForAllTabsFavicon(aTestPage, aFaviconHost, aFaviconURL) {
let cookies = await generateCookies(aFaviconHost);
let pageURI = makeURI(aTestPage);
// Set the 'overflow' attribute to make allTabs button available.
let tabBrowser = document.getElementById("tabbrowser-tabs");
let allTabsBtn = document.getElementById("alltabs-button");
tabBrowser.setAttribute("overflow", true);
// Create the observer object for observing request channels of the personal
// container.
let observer = new FaviconObserver(USER_CONTEXT_ID_PERSONAL, cookies[0], pageURI, aFaviconURL, true);
// Add the observer earlier in case we miss it.
let promiseWaitOnFaviconLoaded = waitOnFaviconLoaded(aFaviconURL);
// Open the tab with the personal container.
let tabInfo = await openTabInUserContext(aTestPage, USER_CONTEXT_ID_PERSONAL);
// Waiting for favicon loaded.
await promiseWaitOnFaviconLoaded;
// We need to clear the image cache here for making sure the network request will
// be made for the favicon of allTabs menuitem.
clearAllImageCaches();
// Add the observer for listening favicon requests.
Services.obs.addObserver(observer, "http-on-modify-request");
// Make the popup of allTabs showing up and trigger the loading of the favicon.
let allTabsPopupShownPromise = BrowserTestUtils.waitForEvent(allTabsBtn, "popupshown");
EventUtils.synthesizeMouseAtCenter(allTabsBtn, {});
await observer.promise;
await allTabsPopupShownPromise;
// Close the popup of allTabs and wait until it's done.
let allTabsPopupHiddenPromise = BrowserTestUtils.waitForEvent(allTabsBtn, "popuphidden");
EventUtils.synthesizeMouseAtCenter(allTabsBtn, {});
await allTabsPopupHiddenPromise;
// Remove the observer for not receiving the favicon requests for opening a tab
// since we want to focus on the favicon of allTabs menu here.
Services.obs.removeObserver(observer, "http-on-modify-request");
// Close the tab.
await BrowserTestUtils.removeTab(tabInfo.tab);
// Open the tab under the work container and wait until the favicon is loaded.
promiseWaitOnFaviconLoaded = waitOnFaviconLoaded(aFaviconURL);
tabInfo = await openTabInUserContext(aTestPage, USER_CONTEXT_ID_WORK);
await promiseWaitOnFaviconLoaded;
// Clear the image cache again.
clearAllImageCaches();
// Reset the observer for observing requests for the work container.
observer.reset(USER_CONTEXT_ID_WORK, cookies[1], pageURI, aFaviconURL, true);
// Add the observer back for listening the favicon requests for allTabs menuitem.
Services.obs.addObserver(observer, "http-on-modify-request");
// Make the popup of allTabs showing up again.
allTabsPopupShownPromise = BrowserTestUtils.waitForEvent(allTabsBtn, "popupshown");
EventUtils.synthesizeMouseAtCenter(allTabsBtn, {});
await observer.promise;
await allTabsPopupShownPromise;
// Close the popup of allTabs and wait until it's done.
allTabsPopupHiddenPromise = BrowserTestUtils.waitForEvent(allTabsBtn, "popuphidden");
EventUtils.synthesizeMouseAtCenter(allTabsBtn, {});
await allTabsPopupHiddenPromise;
Services.obs.removeObserver(observer, "http-on-modify-request");
// Close the tab.
await BrowserTestUtils.removeTab(tabInfo.tab);
// Reset the 'overflow' attribute to make the allTabs button hidden again.
tabBrowser.removeAttribute("overflow");
}
add_task(async function setup() {
// Make sure userContext is enabled.
await SpecialPowers.pushPrefEnv({"set": [
@ -333,33 +247,3 @@ add_task(async function test_thirdPartyFavicon_userContextId() {
await doTest(TEST_THIRD_PARTY_PAGE, TEST_THIRD_PARTY_SITE, THIRD_PARTY_FAVICON_URI);
});
add_task(async function test_allTabs_favicon_userContextId() {
// Clear all image caches before running the test.
clearAllImageCaches();
// Clear all network caches.
let networkCache = Cc["@mozilla.org/netwerk/cache-storage-service;1"]
.getService(Ci.nsICacheStorageService);
networkCache.clear();
// Clear Places favicon caches.
await clearAllPlacesFavicons();
await doTestForAllTabsFavicon(TEST_PAGE, TEST_SITE, FAVICON_URI);
});
add_task(async function test_allTabs_thirdPartyFavicon_userContextId() {
// Clear all image caches before running the test.
clearAllImageCaches();
// Clear all network caches.
let networkCache = Cc["@mozilla.org/netwerk/cache-storage-service;1"]
.getService(Ci.nsICacheStorageService);
networkCache.clear();
// Clear Places favicon caches.
await clearAllPlacesFavicons();
await doTestForAllTabsFavicon(TEST_THIRD_PARTY_PAGE, TEST_THIRD_PARTY_SITE, THIRD_PARTY_FAVICON_URI);
});