Bug 1260247. In chaos mode randomly decide to start a new image load even if the image is in the image cache when allowed by spec. r=seth
If the image load is from the same document that cached the image we are required to use the cached version. Otherwise we should be free to ignore the cached version.
--- a/image/imgLoader.cpp
+++ b/image/imgLoader.cpp
@@ -3,16 +3,17 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/Attributes.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/Move.h"
#include "mozilla/Preferences.h"
+ #include "mozilla/ChaosMode.h"
#include "ImageLogging.h"
#include "nsPrintfCString.h"
#include "imgLoader.h"
#include "imgRequestProxy.h"
#include "nsCOMPtr.h"
@@ -1767,16 +1768,22 @@ imgLoader::ValidateEntry(imgCacheEntry*
void *key = (void*) aCX;
if (request->LoadId() != key) {
// If we would need to revalidate this entry, but we're being told to
// bypass the cache, we don't allow this entry to be used.
if (aLoadFlags & nsIRequest::LOAD_BYPASS_CACHE) {
return false;
}
+ if (MOZ_UNLIKELY(ChaosMode::isActive(ChaosFeature::ImageCache))) {
+ if (ChaosMode::randomUint32LessThan(4) < 1) {
+ return false;
+ }
+ }
+
// Determine whether the cache aEntry must be revalidated...
validateRequest = ShouldRevalidateEntry(aEntry, aLoadFlags, hasExpired);
MOZ_LOG(gImgLog, LogLevel::Debug,
("imgLoader::ValidateEntry validating cache entry. "
"validateRequest = %d", validateRequest));
} else if (!key && MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
nsAutoCString spec;
--- a/mfbt/ChaosMode.h
+++ b/mfbt/ChaosMode.h
@@ -22,16 +22,18 @@ enum ChaosFeature {
// Altering network request scheduling.
NetworkScheduling = 0x2,
// Altering timer scheduling.
TimerScheduling = 0x4,
// Read and write less-than-requested amounts.
IOAmounts = 0x8,
// Iterate over hash tables in random order.
HashTableIteration = 0x10,
+ // Randomly refuse to use cached version of image (when allowed by spec).
+ ImageCache = 0x20,
Any = 0xffffffff,
};
namespace detail {
extern MFBT_DATA Atomic<uint32_t> gChaosModeCounter;
extern MFBT_DATA ChaosFeature gChaosFeatures;
} // namespace detail