<script>
if (window.testRunner) {
	testRunner.dumpAsText();
	testRunner.waitUntilDone();
}

var iterationCount = 0;
var maxIterations = 20;
var firstFrameText = null;
var foundDifferentTextAtLeastOnce = false;

function runIteration()
{
	setTimeout(function() {
		if (window.eventSender) { 
			var el = document.getElementById("testLink");
			eventSender.mouseMoveTo(el.offsetLeft + 5, el.offsetTop + 5); 
			eventSender.mouseDown(); 
			eventSender.mouseUp();
		}
	}, 0);
}

function frameLoaded()
{	
	if (frames[0].document.URL == "about:blank")
		return;

	if (firstFrameText == null)
		firstFrameText = frames[0].document.body.innerText;

	if (firstFrameText != frames[0].document.body.innerText)
		foundDifferentTextAtLeastOnce = true;

	++iterationCount;

	if (iterationCount == maxIterations) {
		if (foundDifferentTextAtLeastOnce)
			alert("Success: A different page was loaded at least once.");
		else
			alert("Failure: From the perspective of this script, the same page was loaded " + maxIterations + " times. This is highly unlikely.");

		if (window.testRunner)
			testRunner.notifyDone();
	} else {
		runIteration();
	}
}

</script>
<body onload="runIteration();">
This test clicks a link that loads a URL into an iframe.<br>
The URL redirects to a different, random URL every time the link is clicked.<br>
When main resources are in the memory cache they are keyed off the original URL, not the post-redirect URL.<br>
In the case where the redirect takes us to a different URL than the CachedResource we're revalidating, we need to abort the revalidate and issue an unconditional request.<br>
<br>
This test makes sure that trying the random redirect multiple times results in at least one different load result.<br>
Since the nature of this test is "random redirects", it runs enough multiple iterations to make it very likely we'll get at least one different redirect.<br>
<a id="testLink" href="http://127.0.0.1:8000/navigation/resources/randomredirects/randomredirect.py" target="linkTarget">Click for random redirect</a><br>
<iframe name="linkTarget" onload="frameLoaded();"><br>
</body>

