worthless
'], {type: 'text/html'}); 8 | 9 | var storage = new lls({name: 'lls-urlcache-test', size: 10 * 1024 * 1024}); 10 | LargeLocalStorage.contrib.URLCache.addTo(storage); 11 | var cacheObj = storage.pipe.getHandler('URLCache').cache; 12 | 13 | // for debug 14 | // window.cacheObj = cacheObj; 15 | // window.storage = storage; 16 | 17 | // TODO: spy on LargeLocalStorage to ensure that 18 | // revokeAttachmentURL is being called. 19 | // And also spy to make sure piped methods are receiving their calls. 20 | 21 | function loadTests() { 22 | describe('URLCache', function() { 23 | it('Caches getAttachmentURL operations', 24 | function(done) { 25 | storage.setAttachment('doc', 'attach', blob) 26 | .then(function() { 27 | console.log('Getting attach url'); 28 | return storage.getAttachmentURL('doc', 'attach'); 29 | }) 30 | .then(function(url) { 31 | console.log('Comparison'); 32 | expect(url).to.equal(cacheObj.main.doc.attach); 33 | expect(cacheObj.reverse[url]).to.eql({ 34 | docKey: 'doc', 35 | attachKey: 'attach' 36 | }); 37 | }).done(done); 38 | }); 39 | 40 | it('Removes the URL from the cache when updating the attachment', 41 | function(done) { 42 | storage.setAttachment('doc', 'attach', blob) 43 | .then(function() { 44 | expect(cacheObj.main.doc.attach).to.equal(undefined); 45 | expect(cacheObj.reverse).to.eql({}); 46 | }).done(done); 47 | }); 48 | 49 | it('Removes the URL from the cache when removing the attachment', 50 | function(done) { 51 | var theUrl; 52 | storage.getAttachmentURL('doc', 'attach').then(function(url) { 53 | expect(url).to.equal(cacheObj.main.doc.attach); 54 | theUrl = url; 55 | return storage.rmAttachment('doc', 'attach'); 56 | }).then(function() { 57 | expect(cacheObj.main.doc.attach).to.equal(undefined); 58 | expect(cacheObj.reverse[theUrl]).to.equal(undefined); 59 | }).done(done); 60 | }); 61 | 62 | it('Removes the URL from the cache when removing the attachment via removing the host document', 63 | function(done) { 64 | storage.setAttachment('doc2', 'attach', blob) 65 | .then(function() { 66 | return storage.rm('doc2'); 67 | }).then(function() { 68 | expect(cacheObj.main.doc2).to.equal(undefined); 69 | expect(cacheObj.reverse).to.eql({}); 70 | }).done(done); 71 | }); 72 | 73 | it('Removes the URL from the cache when revoking the URL', 74 | function(done) { 75 | storage.setAttachment('doc3', 'attach', blob) 76 | .then(function() { 77 | return storage.getAttachmentURL('doc3', 'attach'); 78 | }).then(function(url) { 79 | expect(url).to.equal(cacheObj.main.doc3.attach); 80 | expect(cacheObj.reverse[url]).to.eql({ 81 | docKey: 'doc3', 82 | attachKey: 'attach' 83 | }); 84 | storage.revokeAttachmentURL(url); 85 | expect(cacheObj.main.doc3.attach).to.equal(undefined); 86 | expect(cacheObj.reverse).to.eql({}); 87 | }).done(done); 88 | }); 89 | 90 | it('Removes all URLs when emptying the database', 91 | function(done) { 92 | Q.all([storage.setAttachment('doc4', 'attach', blob), 93 | storage.setAttachment('doc5', 'attach', blob)]) 94 | .then(function() { 95 | return storage.clear(); 96 | }).then(function() { 97 | expect(cacheObj.reverse).to.eql({}); 98 | expect(cacheObj.main).to.eql({}); 99 | }).done(done); 100 | }); 101 | }); 102 | } 103 | 104 | loadTests(); 105 | storage.initialized.then(function() { 106 | window.runMocha(); 107 | }); 108 | })(LargeLocalStorage); --------------------------------------------------------------------------------