Thu, 22 Jan 2015 13:21:57 +0100
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 - bug 976311 app1</title> |
michael@0 | 6 | </head> |
michael@0 | 7 | <body> |
michael@0 | 8 | <p id="display"></p> |
michael@0 | 9 | <div id="content" style="display: none"> |
michael@0 | 10 | |
michael@0 | 11 | </div> |
michael@0 | 12 | <pre id="test"> |
michael@0 | 13 | <script type="application/javascript;version=1.7"> |
michael@0 | 14 | |
michael@0 | 15 | var gStores = []; |
michael@0 | 16 | var expectedWhere; |
michael@0 | 17 | |
michael@0 | 18 | function is(a, b, msg) { |
michael@0 | 19 | ok(a === b, msg); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | function ok(a, msg) { |
michael@0 | 23 | alert((a ? 'OK' : 'KO')+ ' ' + msg) |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | function cbError() { |
michael@0 | 27 | alert('KO error'); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | function finish() { |
michael@0 | 31 | alert('DONE'); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | function checkEvent(id) { |
michael@0 | 35 | is(expectedWhere, id, "Message on the correct DS: " + id + " " + expectedWhere); |
michael@0 | 36 | runTest(); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | function testGetDataStores() { |
michael@0 | 40 | navigator.getDataStores('foo').then(function(stores) { |
michael@0 | 41 | is(stores.length, 2, "getDataStores('foo') returns 1 element"); |
michael@0 | 42 | |
michael@0 | 43 | is(stores[0].name, 'foo', 'The dataStore.name is foo'); |
michael@0 | 44 | is(stores[0].readOnly, false, 'The dataStore foo is not in readonly'); |
michael@0 | 45 | stores[0].onchange = function(evt) { checkEvent(0); } |
michael@0 | 46 | gStores.push(stores[0]); |
michael@0 | 47 | |
michael@0 | 48 | is(stores[1].name, 'foo', 'The dataStore.name is foo'); |
michael@0 | 49 | is(stores[1].readOnly, false, 'The dataStore foo is not in readonly'); |
michael@0 | 50 | stores[1].onchange = function(evt) { checkEvent(1); } |
michael@0 | 51 | gStores.push(stores[1]); |
michael@0 | 52 | |
michael@0 | 53 | runTest(); |
michael@0 | 54 | }, cbError); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | function testStoreAdd(where, value) { |
michael@0 | 58 | expectedWhere = where; |
michael@0 | 59 | dump("ADD TO: " + gStores[where].owner + "\n"); |
michael@0 | 60 | gStores[where].add({ a: value }); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | var tests = [ |
michael@0 | 64 | // Test for GetDataStore |
michael@0 | 65 | testGetDataStores, |
michael@0 | 66 | |
michael@0 | 67 | function() { testStoreAdd(0, 1); }, |
michael@0 | 68 | function() { testStoreAdd(1, 2); }, |
michael@0 | 69 | function() { testStoreAdd(0, 3); }, |
michael@0 | 70 | function() { testStoreAdd(1, 4); } |
michael@0 | 71 | ]; |
michael@0 | 72 | |
michael@0 | 73 | function runTest() { |
michael@0 | 74 | if (!tests.length) { |
michael@0 | 75 | finish(); |
michael@0 | 76 | return; |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | var test = tests.shift(); |
michael@0 | 80 | test(); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | runTest(); |
michael@0 | 84 | </script> |
michael@0 | 85 | </pre> |
michael@0 | 86 | </body> |
michael@0 | 87 | </html> |
michael@0 | 88 |