test_cache_add.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. var singleUrl = './test_cache_add.js';
  2. var urlList = [
  3. './empty.html',
  4. './frame.html',
  5. './test_cache.js'
  6. ];
  7. var cache;
  8. var name = "adder" + context;
  9. caches.open(name).then(function(openCache) {
  10. cache = openCache;
  11. return cache.add('ftp://example.com/invalid' + context);
  12. }).catch(function (err) {
  13. is(err.name, 'TypeError', 'add() should throw TypeError for invalid scheme');
  14. return cache.addAll(['http://example.com/valid' + context, 'ftp://example.com/invalid' + context]);
  15. }).catch(function (err) {
  16. is(err.name, 'TypeError', 'addAll() should throw TypeError for invalid scheme');
  17. var promiseList = urlList.map(function(url) {
  18. return cache.match(url);
  19. });
  20. promiseList.push(cache.match(singleUrl));
  21. return Promise.all(promiseList);
  22. }).then(function(resultList) {
  23. is(urlList.length + 1, resultList.length, 'Expected number of results');
  24. resultList.every(function(result) {
  25. is(undefined, result, 'URLs should not already be in the cache');
  26. });
  27. return cache.add(singleUrl);
  28. }).then(function(result) {
  29. is(undefined, result, 'Successful add() should resolve undefined');
  30. return cache.addAll(urlList);
  31. }).then(function(result) {
  32. is(undefined, result, 'Successful addAll() should resolve undefined');
  33. var promiseList = urlList.map(function(url) {
  34. return cache.match(url);
  35. });
  36. promiseList.push(cache.match(singleUrl));
  37. return Promise.all(promiseList);
  38. }).then(function(resultList) {
  39. is(urlList.length + 1, resultList.length, 'Expected number of results');
  40. resultList.every(function(result) {
  41. ok(!!result, 'Responses should now be in cache for each URL.');
  42. });
  43. return cache.matchAll();
  44. }).then(function(resultList) {
  45. is(urlList.length + 1, resultList.length, 'Expected number of results');
  46. resultList.every(function(result) {
  47. ok(!!result, 'Responses should now be in cache for each URL.');
  48. });
  49. return caches.delete(name);
  50. }).then(function() {
  51. testDone();
  52. }).catch(function(err) {
  53. ok(false, 'Caught error: ' + err);
  54. testDone();
  55. });