Home | History | Annotate | Download | only in indexeddb
      1 <html>
      2 <head>
      3 <link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
      4 <script src="../../fast/js/resources/js-test-pre.js"></script>
      5 <script src="../../fast/js/resources/js-test-post-function.js"></script>
      6 <script src="resources/shared.js"></script>
      7 </head>
      8 <body>
      9 <p id="description"></p>
     10 <div id="console"></div>
     11 <script>
     12 
     13 description("Test IndexedDB's openCursor.");
     14 if (window.layoutTestController)
     15     layoutTestController.waitUntilDone();
     16 
     17 function emptyCursorSuccess()
     18 {
     19     debug("Empty cursor opened successfully.")
     20     // FIXME: check that we can iterate the cursor.
     21     done();
     22 }
     23 
     24 function openEmptyCursor()
     25 {
     26     debug("Opening an empty cursor.");
     27     keyRange = webkitIDBKeyRange.lowerBound("InexistentKey");
     28     request = evalAndLog("objectStore.openCursor(keyRange)");
     29     request.onsuccess = emptyCursorSuccess;
     30     request.onerror = unexpectedErrorCallback;
     31 }
     32 
     33 function cursorSuccess()
     34 {
     35     debug("Cursor opened successfully.")
     36     // FIXME: check that we can iterate the cursor.
     37     shouldBe("event.target.result.direction", "0");
     38     shouldBe("event.target.result.key", "'myKey'");
     39     shouldBe("event.target.result.value", "'myValue'");
     40     debug("");
     41     try {
     42         debug("Passing an invalid key into .continue().");
     43         event.target.result.continue([]);
     44         testFailed("No exception thrown");
     45     } catch (e) {
     46         testPassed("Caught exception: " + e.toString());
     47     }
     48     debug("");
     49     openEmptyCursor();
     50 }
     51 
     52 function openCursor()
     53 {
     54     debug("Opening cursor");
     55     keyRange = webkitIDBKeyRange.lowerBound("myKey");
     56     request = evalAndLog("event.target.source.openCursor(keyRange)");
     57     request.onsuccess = cursorSuccess;
     58     request.onerror = unexpectedErrorCallback;
     59 }
     60 
     61 function setVersionSuccess()
     62 {
     63     debug("setVersionSuccess():");
     64     window.trans = evalAndLog("trans = event.target.result");
     65     shouldBeTrue("trans !== null");
     66     trans.onabort = unexpectedAbortCallback;
     67 
     68     deleteAllObjectStores(db);
     69 
     70     var objectStore = evalAndLog("objectStore = db.createObjectStore('test')");
     71     request = evalAndLog("objectStore.add('myValue', 'myKey')");
     72     request.onsuccess = openCursor;
     73     request.onerror = unexpectedErrorCallback;
     74 }
     75  
     76 function openSuccess()
     77 {
     78     var db = evalAndLog("db = event.target.result");
     79  
     80     request = evalAndLog("db.setVersion('new version')");
     81     request.onsuccess = setVersionSuccess;
     82     request.onerror = unexpectedErrorCallback;
     83 }
     84  
     85 function test()
     86 {
     87     request = evalAndLog("webkitIndexedDB.open('open-cursor')");
     88     request.onsuccess = openSuccess;
     89     request.onerror = unexpectedErrorCallback;
     90 }
     91 
     92 test();
     93 
     94 var successfullyParsed = true;
     95 
     96 </script>
     97 </body>
     98 </html>
     99