1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/devicestorage/test/test_overwrite.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,92 @@ 1.4 +<!-- 1.5 + Any copyright is dedicated to the Public Domain. 1.6 + http://creativecommons.org/publicdomain/zero/1.0/ 1.7 +--> 1.8 +<!DOCTYPE HTML> 1.9 +<html> 1.10 +<!-- 1.11 +https://bugzilla.mozilla.org/show_bug.cgi?id=717103 1.12 +--> 1.13 +<head> 1.14 + <title>Test for basic sanity of the device storage API </title> 1.15 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.16 + <script type="text/javascript" src="devicestorage_common.js"></script> 1.17 + 1.18 +<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.19 +</head> 1.20 +<body> 1.21 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=717103">Mozilla Bug 717103</a> 1.22 +<p id="display"></p> 1.23 +<div id="content" style="display: none"> 1.24 + 1.25 +</div> 1.26 +<pre id="test"> 1.27 +<script class="testbody" type="text/javascript"> 1.28 + 1.29 +var filename = "devicestorage/aaaa.png" 1.30 + 1.31 +devicestorage_setup(); 1.32 + 1.33 + 1.34 +function deleteSuccess(e) { 1.35 + devicestorage_cleanup(); 1.36 +} 1.37 + 1.38 +function deleteError(e) { 1.39 + ok(false, "deleteError was called : " + e.target.error.name); 1.40 + devicestorage_cleanup(); 1.41 +} 1.42 + 1.43 +function addOverwritingSuccess(e) { 1.44 + ok(false, "addOverwritingSuccess was called."); 1.45 + devicestorage_cleanup(); 1.46 +} 1.47 + 1.48 +function addOverwritingError(e) { 1.49 + ok(true, "Adding to the same location should fail"); 1.50 + ok(e.target.error.name == "NoModificationAllowedError", "Error must be NoModificationAllowedError"); 1.51 + 1.52 + var storage = navigator.getDeviceStorage("pictures"); 1.53 + request = storage.delete(filename) 1.54 + request.onsuccess = deleteSuccess; 1.55 + request.onerror = deleteError; 1.56 +} 1.57 + 1.58 +function addSuccess(e) { 1.59 + ok(true, "addSuccess was called"); 1.60 + 1.61 + var storage = navigator.getDeviceStorage("pictures"); 1.62 + ok(navigator.getDeviceStorage, "Should have getDeviceStorage"); 1.63 + 1.64 + request = storage.addNamed(createRandomBlob('image/png'), filename); 1.65 + ok(request, "Should have a non-null request"); 1.66 + 1.67 + request.onsuccess = addOverwritingSuccess; 1.68 + request.onerror = addOverwritingError; 1.69 +} 1.70 + 1.71 +function addError(e) { 1.72 + // test file is already exists. clean it up and try again.. 1.73 + var storage = navigator.getDeviceStorage("pictures"); 1.74 + request = storage.delete(filename) 1.75 + request.onsuccess = runtest; 1.76 +} 1.77 + 1.78 +function runtest() { 1.79 + var storage = navigator.getDeviceStorage("pictures"); 1.80 + ok(navigator.getDeviceStorage, "Should have getDeviceStorage"); 1.81 + 1.82 + request = storage.addNamed(createRandomBlob('image/png'), filename); 1.83 + ok(request, "Should have a non-null request"); 1.84 + 1.85 + request.onsuccess = addSuccess; 1.86 + request.onerror = addError; 1.87 +} 1.88 + 1.89 +runtest(); 1.90 + 1.91 +</script> 1.92 +</pre> 1.93 +</body> 1.94 +</html> 1.95 +