dom/devicestorage/test/test_watchOther.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/devicestorage/test/test_watchOther.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,84 @@
     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 +https://bugzilla.mozilla.org/show_bug.cgi?id=717103
    1.11 +-->
    1.12 +<head>
    1.13 +  <title>Test for the device storage API </title>
    1.14 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.15 +  <script type="text/javascript" src="devicestorage_common.js"></script>
    1.16 +
    1.17 +<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.18 +</head>
    1.19 +<body>
    1.20 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=717103">Mozilla Bug 717103</a>
    1.21 +<p id="display"></p>
    1.22 +<div id="content" style="display: none">
    1.23 +
    1.24 +</div>
    1.25 +<pre id="test">
    1.26 +<script class="testbody" type="text/javascript">
    1.27 +
    1.28 +devicestorage_setup();
    1.29 +
    1.30 +var gFileName = randomFilename(20) + ".png"
    1.31 +
    1.32 +function addSuccess(e) {
    1.33 +}
    1.34 +
    1.35 +function addError(e) {
    1.36 +  ok(false, "addError was called : " + e.target.error.name);
    1.37 +  devicestorage_cleanup();
    1.38 +}
    1.39 +
    1.40 +function onChange(e) {
    1.41 +
    1.42 +  dump("we saw: " + e.path + " " + e.reason + "\n");
    1.43 +
    1.44 +  var filename = e.path;
    1.45 +  if (filename[0] == "/") {
    1.46 +    // We got /storageName/prefix/filename
    1.47 +    // Remove the storageName (this shows up on FirefoxOS)
    1.48 +    filename = filename.substring(1); // Remove leading slash
    1.49 +    var slashIndex = filename.indexOf("/");
    1.50 +    if (slashIndex >= 0) {
    1.51 +      filename = filename.substring(slashIndex + 1); // Remove storageName
    1.52 +    }
    1.53 +  }
    1.54 +  if (filename == gFileName) {
    1.55 +    ok(true, "we saw the file get created");
    1.56 +    storage.removeEventListener("change", onChange);
    1.57 +    devicestorage_cleanup();
    1.58 +  }
    1.59 +  else {
    1.60 +    // we may see other file changes during the test, and
    1.61 +    // that is completely ok
    1.62 +  }
    1.63 +}
    1.64 +
    1.65 +function onChangeFail(e) {
    1.66 +  dump("onChangeFail: " + e.path + " " + e.reason + "\n");
    1.67 +  ok(false, "We should never see any changes");
    1.68 +}
    1.69 +
    1.70 +var storage = navigator.getDeviceStorage("pictures");
    1.71 +ok(storage, "Should have storage");
    1.72 +storage.addEventListener("change", onChange);
    1.73 +
    1.74 +var storageOther = navigator.getDeviceStorage("music");
    1.75 +ok(storageOther, "Should have storage");
    1.76 +storageOther.addEventListener("change", onChangeFail);
    1.77 +
    1.78 +request = storage.addNamed(createRandomBlob('image/png'), gFileName);
    1.79 +ok(request, "Should have a non-null request");
    1.80 +
    1.81 +request.onsuccess = addSuccess;
    1.82 +request.onerror = addError;
    1.83 +
    1.84 +</script>
    1.85 +</pre>
    1.86 +</body>
    1.87 +</html>

mercurial