UI for Zipcoin Blue

test.drivers.js 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /* global beforeEach:true, describe:true, expect:true, it:true */
  2. describe('Driver API', function() {
  3. 'use strict';
  4. beforeEach(function(done) {
  5. if (localforage.supports(localforage.INDEXEDDB)) {
  6. localforage.setDriver(localforage.INDEXEDDB, function() {
  7. done();
  8. });
  9. } else if (localforage.supports(localforage.WEBSQL)) {
  10. localforage.setDriver(localforage.WEBSQL, function() {
  11. done();
  12. });
  13. } else {
  14. done();
  15. }
  16. });
  17. if ((localforage.supports(localforage.INDEXEDDB) &&
  18. localforage.driver() === localforage.INDEXEDDB) ||
  19. (localforage.supports(localforage.WEBSQL) &&
  20. localforage.driver() === localforage.WEBSQL)) {
  21. it('can change to localStorage from ' + localforage.driver() +
  22. ' [callback]', function(done) {
  23. var previousDriver = localforage.driver();
  24. localforage.setDriver(localforage.LOCALSTORAGE, function() {
  25. expect(localforage.driver()).to.be(localforage.LOCALSTORAGE);
  26. expect(localforage.driver()).to.not.be(previousDriver);
  27. done();
  28. });
  29. });
  30. it('can change to localStorage from ' + localforage.driver() +
  31. ' [promise]', function(done) {
  32. var previousDriver = localforage.driver();
  33. localforage.setDriver(localforage.LOCALSTORAGE).then(function() {
  34. expect(localforage.driver()).to.be(localforage.LOCALSTORAGE);
  35. expect(localforage.driver()).to.not.be(previousDriver);
  36. done();
  37. });
  38. });
  39. }
  40. if (!localforage.supports(localforage.INDEXEDDB)) {
  41. it("can't use unsupported IndexedDB [callback]", function(done) {
  42. var previousDriver = localforage.driver();
  43. expect(previousDriver).to.not.be(localforage.INDEXEDDB);
  44. // These should be rejected in component builds but aren't.
  45. // TODO: Look into why.
  46. localforage.setDriver(localforage.INDEXEDDB, null, function() {
  47. expect(localforage.driver()).to.be(previousDriver);
  48. done();
  49. });
  50. });
  51. it("can't use unsupported IndexedDB [promise]", function(done) {
  52. var previousDriver = localforage.driver();
  53. expect(previousDriver).to.not.be(localforage.INDEXEDDB);
  54. // These should be rejected in component builds but aren't.
  55. // TODO: Look into why.
  56. localforage.setDriver(localforage.INDEXEDDB).then(null,
  57. function() {
  58. expect(localforage.driver()).to.be(previousDriver);
  59. done();
  60. });
  61. });
  62. } else {
  63. it('can set already active IndexedDB [callback]', function(done) {
  64. var previousDriver = localforage.driver();
  65. expect(previousDriver).to.be(localforage.INDEXEDDB);
  66. localforage.setDriver(localforage.INDEXEDDB, function() {
  67. expect(localforage.driver()).to.be(previousDriver);
  68. done();
  69. });
  70. });
  71. it('can set already active IndexedDB [promise]', function(done) {
  72. var previousDriver = localforage.driver();
  73. expect(previousDriver).to.be(localforage.INDEXEDDB);
  74. localforage.setDriver(localforage.INDEXEDDB).then(function() {
  75. expect(localforage.driver()).to.be(previousDriver);
  76. done();
  77. });
  78. });
  79. }
  80. if (!localforage.supports(localforage.LOCALSTORAGE)) {
  81. it("can't use unsupported localStorage [callback]", function(done) {
  82. var previousDriver = localforage.driver();
  83. expect(previousDriver).to.not.be(localforage.LOCALSTORAGE);
  84. localforage.setDriver(localforage.LOCALSTORAGE, null, function() {
  85. expect(localforage.driver()).to.be(previousDriver);
  86. done();
  87. });
  88. });
  89. it("can't use unsupported localStorage [promise]", function(done) {
  90. var previousDriver = localforage.driver();
  91. expect(previousDriver).to.not.be(localforage.LOCALSTORAGE);
  92. localforage.setDriver(localforage.LOCALSTORAGE).then(null,
  93. function() {
  94. expect(localforage.driver()).to.be(previousDriver);
  95. done();
  96. });
  97. });
  98. } else if (!localforage.supports(localforage.INDEXEDDB) &&
  99. !localforage.supports(localforage.WEBSQL)) {
  100. it('can set already active localStorage [callback]', function(done) {
  101. var previousDriver = localforage.driver();
  102. expect(previousDriver).to.be(localforage.LOCALSTORAGE);
  103. localforage.setDriver(localforage.LOCALSTORAGE, function() {
  104. expect(localforage.driver()).to.be(previousDriver);
  105. done();
  106. });
  107. });
  108. it('can set already active localStorage [promise]', function(done) {
  109. var previousDriver = localforage.driver();
  110. expect(previousDriver).to.be(localforage.LOCALSTORAGE);
  111. localforage.setDriver(localforage.LOCALSTORAGE).then(function() {
  112. expect(localforage.driver()).to.be(previousDriver);
  113. done();
  114. });
  115. });
  116. }
  117. if (!localforage.supports(localforage.WEBSQL)) {
  118. it("can't use unsupported WebSQL [callback]", function(done) {
  119. var previousDriver = localforage.driver();
  120. expect(previousDriver).to.not.be(localforage.WEBSQL);
  121. localforage.setDriver(localforage.WEBSQL, null, function() {
  122. expect(localforage.driver()).to.be(previousDriver);
  123. done();
  124. });
  125. });
  126. it("can't use unsupported WebSQL [promise]", function(done) {
  127. var previousDriver = localforage.driver();
  128. expect(previousDriver).to.not.be(localforage.WEBSQL);
  129. localforage.setDriver(localforage.WEBSQL).then(null,
  130. function() {
  131. expect(localforage.driver()).to.be(previousDriver);
  132. done();
  133. });
  134. });
  135. } else {
  136. it('can set already active WebSQL [callback]', function(done) {
  137. localforage.setDriver(localforage.WEBSQL, function() {
  138. var previousDriver = localforage.driver();
  139. expect(previousDriver).to.be(localforage.WEBSQL);
  140. localforage.setDriver(localforage.WEBSQL, function() {
  141. expect(localforage.driver()).to.be(previousDriver);
  142. done();
  143. });
  144. });
  145. });
  146. it('can set already active WebSQL [promise]', function(done) {
  147. localforage.setDriver(localforage.WEBSQL).then(function() {
  148. var previousDriver = localforage.driver();
  149. expect(previousDriver).to.be(localforage.WEBSQL);
  150. localforage.setDriver(localforage.WEBSQL).then(function() {
  151. expect(localforage.driver()).to.be(previousDriver);
  152. done();
  153. });
  154. });
  155. });
  156. }
  157. });