Bug 1311237 - Fix the intermittent through making the observer been added earlier. r?baku
--- a/browser/components/originattributes/test/browser/browser_favicon_firstParty.js
+++ b/browser/components/originattributes/test/browser/browser_favicon_firstParty.js
@@ -291,24 +291,27 @@ add_task(function* test_favicon_firstPar
add_task(function* test_favicon_cache_firstParty() {
// 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();
+ // Start to observer the event of that favicon has been fully loaded and cached.
+ let promiseForFaviconLoaded = waitOnFaviconLoaded(THIRD_PARTY_SITE + TEST_FAVICON_CACHE_URI);
+
+ // Start to observer for the favicon response of the first tab.
+ let responsePromise = waitOnFaviconResponse(THIRD_PARTY_SITE + TEST_FAVICON_CACHE_URI);
+
// Open the tab for the first site.
let tabInfoA = yield openTab(TEST_SITE_ONE + TEST_CACHE_PAGE);
- // Start to observer the event of that favicon has been fully loaded and cached.
- let promiseForFaviconLoaded = waitOnFaviconLoaded(THIRD_PARTY_SITE + TEST_FAVICON_CACHE_URI);
-
- // Wait for the favicon response of the first tab.
- let response = yield waitOnFaviconResponse(THIRD_PARTY_SITE + TEST_FAVICON_CACHE_URI);
+ // Waiting for the favicon response.
+ let response = yield responsePromise;
// Make sure the favicon is loaded through the network and its first party domain is correct.
is(response.topic, "http-on-examine-response", "The favicon image should be loaded through network.");
is(response.firstPartyDomain, FIRST_PARTY_ONE, "We should only observe the network response for the first first party.");
// Waiting until the favicon has been loaded and cached.
yield promiseForFaviconLoaded;