• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
5function test()
6{
7  if (document.location.hash === '#tab1') {
8    prepareDatabase(function () { doSetVersion(2); });
9  } else if (document.location.hash === '#tab2') {
10    doSetVersion(3);
11  } else {
12    result('fail - unexpected hash');
13  }
14}
15
16function prepareDatabase(callback)
17{
18  // Prepare the database, then exit normally
19  var delreq = window.indexedDB.deleteDatabase('version-change-blocked');
20  delreq.onerror = unexpectedErrorCallback;
21  delreq.onsuccess = function() {
22    reOpen(callback);
23  };
24}
25
26function reOpen(callback)
27{
28  request = indexedDB.open('version-change-blocked');
29  request.onerror = unexpectedErrorCallback;
30  request.onblocked = unexpectedBlockedCallback;
31  request.onupgradeneeded = function() {
32    db = event.target.result;
33    db.createObjectStore("someobjectstore");
34  };
35  request.onsuccess = function() {
36    db.close();
37    callback();
38  };
39}
40
41function doSetVersion(version)
42{
43  // Open the database and try a setVersion
44  var openreq = window.indexedDB.open('version-change-blocked', version);
45  openreq.onerror = unexpectedErrorCallback;
46  var upgradeneededComplete = false;
47  openreq.onblocked = function(e) {
48    result('setVersion(' + version + ') blocked');
49  };
50  openreq.onupgradeneeded = function(e) {
51    openreq.transaction.oncomplete = function(e2) {
52      result('setVersion(' + version + ') complete');
53    };
54  };
55}
56