Home | History | Annotate | Download | only in indexeddb
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 function test()
      6 {
      7   if (document.location.hash === '#part1') {
      8     testPart1();
      9   } else if (document.location.hash === '#part2') {
     10     testPart2();
     11   } else {
     12     result('fail - unexpected hash');
     13   }
     14 }
     15 
     16 function testPart1()
     17 {
     18   var delreq = window.indexedDB.deleteDatabase('bug90635');
     19   delreq.onerror = unexpectedErrorCallback;
     20   delreq.onsuccess = function() {
     21     var openreq = window.indexedDB.open('bug90635', 1);
     22     openreq.onerror = unexpectedErrorCallback;
     23     openreq.onblocked = unexpectedBlockedCallback;
     24     openreq.onupgradeneeded = function(e) {
     25       db = openreq.result;
     26       var transaction = openreq.transaction;
     27       transaction.onabort = unexpectedAbortCallback;
     28 
     29       db.createObjectStore('store1');
     30       db.createObjectStore('store2', {keyPath: ''});
     31       db.createObjectStore('store3', {keyPath: 'some_path'});
     32     };
     33     openreq.onsuccess = function() {
     34       test_store(db, 'first run');
     35     };
     36   };
     37 }
     38 
     39 function testPart2()
     40 {
     41   var openreq = window.indexedDB.open('bug90635');
     42   openreq.onerror = unexpectedErrorCallback;
     43   openreq.onsuccess = function(e) {
     44     var db = openreq.result;
     45     test_store(db, 'second run');
     46   };
     47 }
     48 
     49 function test_store(db, msg) {
     50   var transaction = db.transaction(['store1', 'store2', 'store3'], 'readonly');
     51   var store1 = transaction.objectStore('store1');
     52   var store2 = transaction.objectStore('store2');
     53   var store3 = transaction.objectStore('store3');
     54 
     55   if (store1.keyPath !== null ||
     56       store2.keyPath !== '' ||
     57       store3.keyPath !== 'some_path') {
     58     result('fail - ' + msg);
     59   } else {
     60     result('pass - ' + msg);
     61   }
     62 }
     63