dom/devicestorage/test/test_watchOther.html

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:650790a3112c
1 <!--
2 Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/
4 -->
5 <!DOCTYPE HTML>
6 <html> <!--
7 https://bugzilla.mozilla.org/show_bug.cgi?id=717103
8 -->
9 <head>
10 <title>Test for the device storage API </title>
11 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
12 <script type="text/javascript" src="devicestorage_common.js"></script>
13
14 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
15 </head>
16 <body>
17 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=717103">Mozilla Bug 717103</a>
18 <p id="display"></p>
19 <div id="content" style="display: none">
20
21 </div>
22 <pre id="test">
23 <script class="testbody" type="text/javascript">
24
25 devicestorage_setup();
26
27 var gFileName = randomFilename(20) + ".png"
28
29 function addSuccess(e) {
30 }
31
32 function addError(e) {
33 ok(false, "addError was called : " + e.target.error.name);
34 devicestorage_cleanup();
35 }
36
37 function onChange(e) {
38
39 dump("we saw: " + e.path + " " + e.reason + "\n");
40
41 var filename = e.path;
42 if (filename[0] == "/") {
43 // We got /storageName/prefix/filename
44 // Remove the storageName (this shows up on FirefoxOS)
45 filename = filename.substring(1); // Remove leading slash
46 var slashIndex = filename.indexOf("/");
47 if (slashIndex >= 0) {
48 filename = filename.substring(slashIndex + 1); // Remove storageName
49 }
50 }
51 if (filename == gFileName) {
52 ok(true, "we saw the file get created");
53 storage.removeEventListener("change", onChange);
54 devicestorage_cleanup();
55 }
56 else {
57 // we may see other file changes during the test, and
58 // that is completely ok
59 }
60 }
61
62 function onChangeFail(e) {
63 dump("onChangeFail: " + e.path + " " + e.reason + "\n");
64 ok(false, "We should never see any changes");
65 }
66
67 var storage = navigator.getDeviceStorage("pictures");
68 ok(storage, "Should have storage");
69 storage.addEventListener("change", onChange);
70
71 var storageOther = navigator.getDeviceStorage("music");
72 ok(storageOther, "Should have storage");
73 storageOther.addEventListener("change", onChangeFail);
74
75 request = storage.addNamed(createRandomBlob('image/png'), gFileName);
76 ok(request, "Should have a non-null request");
77
78 request.onsuccess = addSuccess;
79 request.onerror = addError;
80
81 </script>
82 </pre>
83 </body>
84 </html>

mercurial