browser_cache_pb_window.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. var name = 'pb-window-cache';
  2. function testMatch(win) {
  3. return new Promise(function(resolve, reject) {
  4. win.caches.match('http://foo.com').then(function(response) {
  5. ok(false, 'caches.match() should not return success');
  6. reject();
  7. }).catch(function(err) {
  8. is('SecurityError', err.name, 'caches.match() should throw SecurityError');
  9. resolve();
  10. });
  11. });
  12. }
  13. function testHas(win) {
  14. return new Promise(function(resolve, reject) {
  15. win.caches.has(name).then(function(result) {
  16. ok(false, 'caches.has() should not return success');
  17. reject();
  18. }).catch(function(err) {
  19. is('SecurityError', err.name, 'caches.has() should throw SecurityError');
  20. resolve();
  21. });
  22. });
  23. }
  24. function testOpen(win) {
  25. return new Promise(function(resolve, reject) {
  26. win.caches.open(name).then(function(c) {
  27. ok(false, 'caches.open() should not return success');
  28. reject();
  29. }).catch(function(err) {
  30. is('SecurityError', err.name, 'caches.open() should throw SecurityError');
  31. resolve();
  32. });
  33. });
  34. }
  35. function testDelete(win) {
  36. return new Promise(function(resolve, reject) {
  37. win.caches.delete(name).then(function(result) {
  38. ok(false, 'caches.delete() should not return success');
  39. reject();
  40. }).catch(function(err) {
  41. is('SecurityError', err.name, 'caches.delete() should throw SecurityError');
  42. resolve();
  43. });
  44. });
  45. }
  46. function testKeys(win) {
  47. return new Promise(function(resolve, reject) {
  48. win.caches.keys().then(function(names) {
  49. ok(false, 'caches.keys() should not return success');
  50. reject();
  51. }).catch(function(err) {
  52. is('SecurityError', err.name, 'caches.keys() should throw SecurityError');
  53. resolve();
  54. });
  55. });
  56. }
  57. function test() {
  58. waitForExplicitFinish();
  59. SpecialPowers.pushPrefEnv({'set': [['dom.caches.enabled', true],
  60. ['dom.caches.testing.enabled', true]]},
  61. function() {
  62. var privateWin = OpenBrowserWindow({private: true});
  63. privateWin.addEventListener('load', function() {
  64. Promise.all([
  65. testMatch(privateWin),
  66. testHas(privateWin),
  67. testOpen(privateWin),
  68. testDelete(privateWin),
  69. testKeys(privateWin)
  70. ]).then(function() {
  71. BrowserTestUtils.closeWindow(privateWin).then(finish);
  72. });
  73. });
  74. });
  75. }