dom/datastore/tests/file_duplicate.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <meta charset="utf-8">
michael@0 5 <title>Test for DataStore - duplicate keys</title>
michael@0 6 </head>
michael@0 7 <body>
michael@0 8 <div id="container"></div>
michael@0 9 <script type="application/javascript;version=1.7">
michael@0 10
michael@0 11 var gStore;
michael@0 12 var gEvent;
michael@0 13 var gChangeId;
michael@0 14
michael@0 15 function ok(a, msg) {
michael@0 16 alert((a ? 'OK' : 'KO')+ ' ' + msg)
michael@0 17 }
michael@0 18
michael@0 19 function is(a, b, msg) {
michael@0 20 ok(a === b, msg);
michael@0 21 }
michael@0 22
michael@0 23 function cbError() {
michael@0 24 alert('KO error');
michael@0 25 }
michael@0 26
michael@0 27 function finish() {
michael@0 28 alert('DONE');
michael@0 29 }
michael@0 30
michael@0 31 function testGetDataStores() {
michael@0 32 navigator.getDataStores('foo').then(function(stores) {
michael@0 33 gStore = stores[0];
michael@0 34 runTest();
michael@0 35 }, cbError);
michael@0 36 }
michael@0 37
michael@0 38 function testAdd(success) {
michael@0 39 gStore.add({ a: 42 }, 'test').then(function() {
michael@0 40 is(success, true, "Record added");
michael@0 41 runTest();
michael@0 42 }, function(e) {
michael@0 43 is(success, false, "Record failed");
michael@0 44 ok(e instanceof DOMError, "DOMError received");
michael@0 45 is(e.name, 'ConstraintError', 'e.name: ConstraintError');
michael@0 46 is(e.message, '', 'e.message');
michael@0 47 runTest();
michael@0 48 });
michael@0 49 }
michael@0 50
michael@0 51 var tests = [
michael@0 52 // Test for GetDataStore
michael@0 53 testGetDataStores,
michael@0 54
michael@0 55 // add
michael@0 56 function() { testAdd(true); },
michael@0 57
michael@0 58 // add duplicate
michael@0 59 function() { testAdd(false); }
michael@0 60 ];
michael@0 61
michael@0 62 function runTest() {
michael@0 63 if (!tests.length) {
michael@0 64 finish();
michael@0 65 return;
michael@0 66 }
michael@0 67
michael@0 68 var test = tests.shift();
michael@0 69 test();
michael@0 70 }
michael@0 71
michael@0 72 runTest();
michael@0 73 </script>
michael@0 74 </body>
michael@0 75 </html>

mercurial