Commit 7250cc4a authored by jsbell@chromium.org's avatar jsbell@chromium.org

AppCache error details tests

Follows Blink (crrev.com/164873003) and Chromium (crrev.com/164933002)

BUG=342555

Review URL: https://codereview.chromium.org/217133002

git-svn-id: svn://svn.chromium.org/blink/trunk@170621 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 093e11ef
Test that subresources can be loaded if manifest is not available. Should say SUCCESS. Test that subresources can be loaded if manifest is not available.
SUCCESS On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS gotCheckingEvent is true
PASS window.applicationCache.status is applicationCache.UNCACHED
PASS event.reason is "manifest"
PASS event.url is "http://127.0.0.1:8000/appcache/does-not-exist.manifest"
PASS event.status is 404
PASS 'message' in event is true
PASS req.responseText is "Hello, World!"
PASS successfullyParsed is true
TEST COMPLETE
<html manifest="does-not-exist.manifest"> <html manifest="does-not-exist.manifest">
<script src="/js-test-resources/js-test.js"></script>
<script> <script>
if (window.testRunner) { var jsTestIsAsync = true;
testRunner.dumpAsText() description("Test that subresources can be loaded if manifest is not available.");
testRunner.waitUntilDone();
}
function log(message)
{
document.getElementById("result").innerHTML += message + "<br>";
}
function unexpectedEvent(name) function unexpectedEvent(name)
{ {
log("FAILURE: Unexpected " + name + " event."); testFailed("Unexpected " + name + " event.");
finishJSTest();
} }
applicationCache.addEventListener('noupdate', function() { unexpectedEvent("noupdate") }, false); applicationCache.addEventListener('noupdate', function() { unexpectedEvent("noupdate") }, false);
...@@ -22,38 +17,34 @@ applicationCache.addEventListener('updateready', function() { unexpectedEvent("u ...@@ -22,38 +17,34 @@ applicationCache.addEventListener('updateready', function() { unexpectedEvent("u
applicationCache.addEventListener('cached', function() { unexpectedEvent("cached") }, false); applicationCache.addEventListener('cached', function() { unexpectedEvent("cached") }, false);
applicationCache.addEventListener('obsolete', function() { unexpectedEvent("obsolete") }, false); applicationCache.addEventListener('obsolete', function() { unexpectedEvent("obsolete") }, false);
function test() function test(e)
{ {
if (!gotCheckingEvent) shouldBeTrue("gotCheckingEvent");
log("FAILURE: Did not get a checking event"); shouldBe("window.applicationCache.status", "applicationCache.UNCACHED");
if (window.applicationCache.status)
log("FAILURE: Cache status is not UNCACHED, " + window.applicationCache.status); event = e;
shouldBeEqualToString("event.reason", "manifest");
shouldBeEqualToString("event.url", "http://127.0.0.1:8000/appcache/does-not-exist.manifest");
shouldBe("event.status", "404");
shouldBeTrue("'message' in event");
// The manifest failed to load, so there should be no cache, and subresources should be loaded normally. // The manifest failed to load, so there should be no cache, and subresources should be loaded normally.
try { try {
var req = new XMLHttpRequest(); req = new XMLHttpRequest();
req.open("GET", "resources/simple.txt", false); req.open("GET", "resources/simple.txt", false);
req.send(); req.send();
if (req.responseText == 'Hello, World!') shouldBeEqualToString("req.responseText", 'Hello, World!');
log("SUCCESS");
else
log("FAILURE: Did not get expected response data.");
} catch (e) { } catch (e) {
log("FAILURE: Could not load data."); testFailed("Could not load data.");
} }
if (window.testRunner) finishJSTest();
testRunner.notifyDone();
} }
var gotCheckingEvent = false; var gotCheckingEvent = false;
applicationCache.addEventListener('checking', function() { gotCheckingEvent = true; }, false); applicationCache.addEventListener('checking', function() { gotCheckingEvent = true; }, false);
applicationCache.addEventListener('error', test, false);
applicationCache.addEventListener('error', function() { test() }, false);
</script> </script>
<p>Test that subresources can be loaded if manifest is not available. Should say SUCCESS.</p>
<div id=result></div>
</html> </html>
Test that a missing cross-origin resource failure doesn't leak details.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS applicationCache.status is applicationCache.UNCACHED
PASS event.reason is "resource"
PASS event.url is "http://127.0.0.1/does-not-exist.txt"
PASS event.status is 0
PASS event.message is ""
PASS successfullyParsed is true
TEST COMPLETE
<html manifest="resources/404-resource-cross-origin.manifest">
<script src="/js-test-resources/js-test.js"></script>
<script>
var jsTestIsAsync = true;
description("Test that a missing cross-origin resource failure doesn't leak details.");
function unexpectedCallback(eventName)
{
testFailed("An unexpected " + eventName + " event was dispatched on window.applicationCache.");
finishJSTest();
}
function test(e)
{
shouldBe("applicationCache.status", "applicationCache.UNCACHED");
event = e;
shouldBeEqualToString("event.reason", "resource");
shouldBeEqualToString("event.url", "http://127.0.0.1/does-not-exist.txt");
shouldBe("event.status", "0");
shouldBeEqualToString("event.message", "");
finishJSTest();
}
applicationCache.addEventListener('cached', function() { unexpectedCallback("cached"); }, false);
applicationCache.addEventListener('noupdate', function() { unexpectedCallback("noupdate"); }, false);
applicationCache.addEventListener('error', test, false);
</script>
</html>
Test that a missing explicit resource makes caching fail. Test that a missing explicit resource makes caching fail.
Should say SUCCESS: On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
SUCCESS
PASS applicationCache.status is applicationCache.UNCACHED
PASS event.reason is "resource"
PASS event.url is "http://127.0.0.1:8000/appcache/resources/does-not-exist.txt"
PASS event.status is 404
PASS 'message' in event is true
PASS successfullyParsed is true
TEST COMPLETE
<html manifest="resources/404-resource.manifest"> <html manifest="resources/404-resource.manifest">
<body> <script src="/js-test-resources/js-test.js"></script>
<p>Test that a missing explicit resource makes caching fail.</p>
<p>Should say SUCCESS:</p>
<div id=result></div>
<script> <script>
if (window.testRunner) { var jsTestIsAsync = true;
testRunner.dumpAsText() description("Test that a missing explicit resource makes caching fail.");
testRunner.waitUntilDone();
}
function log(message)
{
document.getElementById("result").innerHTML += message + "<br>";
}
function unexpectedCallback(eventName) function unexpectedCallback(eventName)
{ {
log("FAIL: An unexpected " + eventName + " event was dispatched on window.applicationCache."); testFailed("An unexpected " + eventName + " event was dispatched on window.applicationCache.");
finishJSTest();
} }
function test() function test(e)
{ {
if (applicationCache.status == applicationCache.UNCACHED) shouldBe("applicationCache.status", "applicationCache.UNCACHED");
log("SUCCESS");
else event = e;
log("FAILURE: cache status is not uncached: " + applicationCache.status); shouldBeEqualToString("event.reason", "resource");
shouldBeEqualToString("event.url", "http://127.0.0.1:8000/appcache/resources/does-not-exist.txt");
shouldBe("event.status", "404");
shouldBeTrue("'message' in event");
if (window.testRunner) finishJSTest();
testRunner.notifyDone();
} }
applicationCache.addEventListener('cached', function() { unexpectedCallback("cached"); cacheCallback() }, false); applicationCache.addEventListener('cached', function() { unexpectedCallback("cached"); }, false);
applicationCache.addEventListener('noupdate', function() { unexpectedCallback("noupdate"); cacheCallback() }, false); applicationCache.addEventListener('noupdate', function() { unexpectedCallback("noupdate"); }, false);
applicationCache.addEventListener('error', test, false); applicationCache.addEventListener('error', test, false);
</script> </script>
</body>
</html> </html>
Test that a manifest that changes during an update fails.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS gotCheckingEvent is true
PASS gotDownloadingEvent is true
PASS window.applicationCache.status is applicationCache.UNCACHED
PASS event.reason is "changed"
PASS event.url is ""
PASS event.status is 0
PASS 'message' in event is true
PASS successfullyParsed is true
TEST COMPLETE
<html manifest="resources/modified-manifest.php">
<script src="/js-test-resources/js-test.js"></script>
<script>
var jsTestIsAsync = true;
description("Test that a manifest that changes during an update fails.");
var gotCheckingEvent = false;
function onChecking() { gotCheckingEvent = true; }
var gotDownloadingEvent = false;
function onDownloading() { gotDownloadingEvent = true; }
function onError(e)
{
shouldBeTrue("gotCheckingEvent");
shouldBeTrue("gotDownloadingEvent");
shouldBe("window.applicationCache.status", "applicationCache.UNCACHED");
event = e;
shouldBeEqualToString("event.reason", "changed");
shouldBeEqualToString("event.url", "");
shouldBe("event.status", "0");
shouldBeTrue("'message' in event");
finishJSTest();
}
applicationCache.addEventListener('checking', onChecking, false);
applicationCache.addEventListener('downloading', onDownloading, false);
applicationCache.addEventListener('error', onError, false);
</script>
</html>
Test that master list entries receive errors when manifest becomes obsolete.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS eventDetailsFromWindow.type is "obsolete"
PASS eventDetailsFromFrame.type is "error"
PASS eventDetailsFromFrame.reason is "manifest"
PASS eventDetailsFromFrame.url is ""
PASS eventDetailsFromFrame.status is 404
PASS successfullyParsed is true
TEST COMPLETE
<html manifest="resources/fail-on-update.php">
<script src="/js-test-resources/js-test.js"></script>
<script>
var jsTestIsAsync = true;
description("Test that master list entries receive errors when manifest becomes obsolete.");
function setManifestState(state)
{
var req = new XMLHttpRequest;
req.open("GET", "resources/fail-on-update.php?command=" + (state), false);
req.send(null);
}
var eventDetailsFromFrame = null;
function onMessage(e) {
eventDetailsFromFrame = e.data;
checkEvents();
};
var eventDetailsFromWindow = null;
function onObsolete(e) {
eventDetailsFromWindow = e;
checkEvents();
}
// Event order is indeterminate, so wait for both to arrive.
function checkEvents() {
if (!eventDetailsFromFrame || !eventDetailsFromWindow)
return;
shouldBeEqualToString("eventDetailsFromWindow.type", "obsolete");
shouldBeEqualToString("eventDetailsFromFrame.type", "error");
shouldBeEqualToString("eventDetailsFromFrame.reason", "manifest");
shouldBeEqualToString("eventDetailsFromFrame.url", "");
shouldBe("eventDetailsFromFrame.status", "404");
finishJSTest();
}
function test()
{
applicationCache.onnoupdate = function() { testFailed("Unexpected noupdate event") }
applicationCache.oncached = function() { testFailed("Unexpected cached event") }
setManifestState('delete');
// The frame will be associated to a cache, but update will obsolete it.
var ifr = document.createElement("iframe");
ifr.setAttribute("src", "resources/obsolete-error-events-frame.html");
document.body.appendChild(ifr);
applicationCache.onobsolete = onObsolete;
window.onmessage = onMessage;
}
function resetManifest()
{
if (applicationCache.status !== applicationCache.UNCACHED && applicationCache.status !== applicationCache.OBSOLETE) {
timeoutId = setTimeout(resetManifest, 100);
return;
}
setManifestState('reset');
location.reload();
}
applicationCache.oncached = function() {
clearTimeout(timeoutId);
test();
};
// If the manifest script happened to be in a wrong state, reset it.
var timeoutId = setTimeout(resetManifest, 100);
</script>
</body>
</html>
Test that a redirect makes resource caching fail. Test that a redirect makes resource caching fail.
Should say SUCCESS: On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
SUCCESS
PASS window.applicationCache.status is window.applicationCache.UNCACHED
PASS event.reason is "resource"
PASS event.url is "http://127.0.0.1:8000/appcache/resources/resource-redirect.php"
PASS event.status is 307
PASS 'message' in event is true
PASS successfullyParsed is true
TEST COMPLETE
<html manifest="resources/resource-redirect.manifest"> <html manifest="resources/resource-redirect.manifest">
<body> <script src="/js-test-resources/js-test.js"></script>
<p>Test that a redirect makes resource caching fail.</p>
<p>Should say SUCCESS:</p>
<div id=result></div>
<script> <script>
if (window.testRunner) { var jsTestIsAsync = true;
testRunner.dumpAsText() description("Test that a redirect makes resource caching fail.");
testRunner.waitUntilDone();
}
function log(message) function unexpectedCallback(eventName)
{ {
document.getElementById("result").innerHTML += message + "<br>"; testFailed("An unexpected " + eventName + " event was dispatched on window.applicationCache.");
finishJSTest();
} }
function cacheCallback() function test(e)
{ {
log("FAIL: An unexpected event was dispatched on window.applicationCache."); shouldBe("window.applicationCache.status", "window.applicationCache.UNCACHED");
}
function test() event = e;
{ shouldBeEqualToString("event.reason", "resource");
// Wait for cache update to finish. shouldBeEqualToString("event.url", "http://127.0.0.1:8000/appcache/resources/resource-redirect.php");
if (window.applicationCache.status != window.applicationCache.UNCACHED) shouldBe("event.status", "307");
log("FAILURE: Unexpected cache status: " + window.applicationCache.status); shouldBeTrue("'message' in event");
else
log("SUCCESS");
if (window.testRunner) finishJSTest();
testRunner.notifyDone();
} }
applicationCache.addEventListener('cached', function() { log("cached"); cacheCallback() }, false); applicationCache.addEventListener('cached', function() { unexpectedCallback("cached"); }, false);
applicationCache.addEventListener('noupdate', function() { log("noupdate"); cacheCallback() }, false); applicationCache.addEventListener('noupdate', function() { unexpectedCallback("noupdate"); }, false);
applicationCache.addEventListener('error', test, false); applicationCache.addEventListener('error', test, false);
</script> </script>
......
CACHE MANIFEST
CACHE:
simple.txt
http://127.0.0.1/does-not-exist.txt
<?php
require_once '../../resources/portabilityLayer.php';
# This manifest references itself with a command to bump a counter, so
# that a subsequent fetch of the same manifest URL returns a file that
# is not byte-for-byte identical, which will cause caching to fail.
$tmpFile = sys_get_temp_dir() . "/" . "appcache_modified_manifest_counter";
function getCount($file)
{
if (!file_exists($file)) {
file_put_contents($file, "0");
return "0";
}
return file_get_contents($file);
}
function stepCounter($file)
{
if (file_exists($file)) {
$value = getCount($file);
file_put_contents($file, ++$value);
}
}
if ("step" == $_GET['command'])
stepCounter($tmpFile);
header("Expires: Thu, 01 Dec 2003 16:00:00 GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Content-Type: text/cache-manifest");
print("CACHE MANIFEST\n");
print("# version " . getCount($tmpFile) . "\n");
print("CACHE:\n");
print("modified-manifest.php?command=step\n");
?>
<html manifest="fail-on-update.php">
<script>
applicationCache.addEventListener('obsolete', function(e) {
window.parent.postMessage({
type: e.type
}, '*');
});
applicationCache.addEventListener('error', function(e) {
window.parent.postMessage({
type: e.type,
reason: e.reason,
url: e.url,
status: e.status
}, '*');
});
</script>
</html>
Test that a manifest served with a wrong signature isn't treated as such. Test that a manifest served with a wrong signature isn't treated as such.
Should say SUCCESS: On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
SUCCESS
PASS window.applicationCache.status is applicationCache.UNCACHED
PASS event.reason is "signature"
PASS event.url is ""
PASS event.status is 0
PASS 'message' in event is true
PASS successfullyParsed is true
TEST COMPLETE
<html manifest="resources/wrong-signature-2.manifest"> <html manifest="resources/wrong-signature-2.manifest">
<body> <script src="/js-test-resources/js-test.js"></script>
<p>Test that a manifest served with a wrong signature isn't treated as such.</p>
<p>Should say SUCCESS:</p>
<div id=result></div>
<script> <script>
if (window.testRunner) { var jsTestIsAsync = true;
testRunner.dumpAsText() description("Test that a manifest served with a wrong signature isn't treated as such.");
testRunner.waitUntilDone();
}
function log(message) function unexpectedEvent(name)
{ {
document.getElementById("result").innerHTML += message + "<br>"; testFailed("Unexpected " + name + " event.");
finishJSTest();
} }
function cacheCallback() function test(e)
{ {
log("FAIL: An event was dispatched on window.applicationCache, even though it was not associated wuth any cache yet."); shouldBe("window.applicationCache.status", "applicationCache.UNCACHED");
}
function test() event = e;
{ shouldBeEqualToString("event.reason", "signature");
// Wait for cache update to finish. shouldBeEqualToString("event.url", "");
if (window.applicationCache.status != window.applicationCache.UNCACHED) shouldBe("event.status", "0");
log("FAILURE: Unexpected cache status: " + window.applicationCache.status); shouldBeTrue("'message' in event");
else
log("SUCCESS");
if (window.testRunner) finishJSTest();
testRunner.notifyDone();
} }
applicationCache.addEventListener('cached', function() { log("cached"); cacheCallback() }, false); applicationCache.addEventListener('cached', function() { unexpectedEvent("cached"); }, false);
applicationCache.addEventListener('noupdate', function() { log("noupdate"); cacheCallback() }, false); applicationCache.addEventListener('noupdate', function() { unexpectedEvent("noupdate"); }, false);
applicationCache.addEventListener('error', test, false); applicationCache.addEventListener('error', test, false);
</script> </script>
......
Test that a manifest served with a wrong signature isn't treated as such. Test that a manifest served with a wrong signature isn't treated as such.
Should say SUCCESS: On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
SUCCESS
PASS window.applicationCache.status is applicationCache.UNCACHED
PASS event.reason is "signature"
PASS event.url is ""
PASS event.status is 0
PASS 'message' in event is true
PASS successfullyParsed is true
TEST COMPLETE
<html manifest="resources/wrong-signature.manifest"> <html manifest="resources/wrong-signature.manifest">
<body> <script src="/js-test-resources/js-test.js"></script>
<p>Test that a manifest served with a wrong signature isn't treated as such.</p>
<p>Should say SUCCESS:</p>
<div id=result></div>
<script> <script>
if (window.testRunner) { var jsTestIsAsync = true;
testRunner.dumpAsText() description("Test that a manifest served with a wrong signature isn't treated as such.");
testRunner.waitUntilDone();
}
function log(message) function unexpectedEvent(name)
{ {
document.getElementById("result").innerHTML += message + "<br>"; testFailed("Unexpected " + name + " event.");
finishJSTest();
} }
function cacheCallback() function test(e)
{ {
log("FAIL: An event was dispatched on window.applicationCache, even though it was not associated wuth any cache yet."); shouldBe("window.applicationCache.status", "applicationCache.UNCACHED");
}
function test() event = e;
{ shouldBeEqualToString("event.reason", "signature");
// Wait for cache update to finish. shouldBeEqualToString("event.url", "");
if (window.applicationCache.status != window.applicationCache.UNCACHED) shouldBe("event.status", "0");
log("FAILURE: Unexpected cache status: " + window.applicationCache.status); shouldBeTrue("'message' in event");
else
log("SUCCESS");
if (window.testRunner) finishJSTest();
testRunner.notifyDone();
} }
applicationCache.addEventListener('cached', function() { log("cached"); cacheCallback() }, false); applicationCache.addEventListener('cached', function() { unexpectedEvent("cached"); }, false);
applicationCache.addEventListener('noupdate', function() { log("noupdate"); cacheCallback() }, false); applicationCache.addEventListener('noupdate', function() { unexpectedEvent("noupdate"); }, false);
applicationCache.addEventListener('error', test, false); applicationCache.addEventListener('error', test, false);
</script> </script>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment