file_app_isolation.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. SimpleTest.waitForExplicitFinish();
  2. var fileTestOnCurrentOrigin = (location.protocol + '//' + location.host + location.pathname)
  3. .replace('test_', 'file_')
  4. .replace('_inproc', '').replace('_oop', '');
  5. var previousPrefs = {
  6. mozBrowserFramesEnabled: undefined,
  7. oop_by_default: undefined,
  8. };
  9. try {
  10. previousPrefs.mozBrowserFramesEnabled = SpecialPowers.getBoolPref('dom.mozBrowserFramesEnabled');
  11. } catch(e)
  12. {
  13. }
  14. try {
  15. previousPrefs.oop_by_default = SpecialPowers.getBoolPref('dom.ipc.browser_frames.oop_by_default');
  16. } catch(e) {
  17. }
  18. SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', true);
  19. SpecialPowers.setBoolPref("dom.ipc.browser_frames.oop_by_default", location.pathname.indexOf('_inproc') == -1);
  20. SpecialPowers.addPermission("browser", true, window.document);
  21. var gData = [
  22. // APP 1
  23. {
  24. app: 'http://example.org/manifest.webapp',
  25. action: 'read-no',
  26. src: fileTestOnCurrentOrigin,
  27. },
  28. {
  29. app: 'http://example.org/manifest.webapp',
  30. action: 'write',
  31. src: fileTestOnCurrentOrigin,
  32. },
  33. {
  34. app: 'http://example.org/manifest.webapp',
  35. action: 'read-yes',
  36. src: fileTestOnCurrentOrigin,
  37. },
  38. // APP 2
  39. {
  40. app: 'https://example.com/manifest.webapp',
  41. action: 'read-no',
  42. src: fileTestOnCurrentOrigin,
  43. },
  44. {
  45. app: 'https://example.com/manifest.webapp',
  46. action: 'write',
  47. src: fileTestOnCurrentOrigin,
  48. },
  49. {
  50. app: 'https://example.com/manifest.webapp',
  51. action: 'read-yes',
  52. src: fileTestOnCurrentOrigin,
  53. },
  54. // Browser
  55. {
  56. browser: true,
  57. action: 'read-no',
  58. src: fileTestOnCurrentOrigin,
  59. },
  60. {
  61. browser: true,
  62. action: 'write',
  63. src: fileTestOnCurrentOrigin,
  64. },
  65. {
  66. browser: true,
  67. action: 'read-yes',
  68. src: fileTestOnCurrentOrigin,
  69. },
  70. ];
  71. function runTest() {
  72. for (var i in gData) {
  73. var iframe = document.createElement('iframe');
  74. var data = gData[i];
  75. if (data.app) {
  76. iframe.setAttribute('mozbrowser', '');
  77. iframe.setAttribute('mozapp', data.app);
  78. } else if (data.browser) {
  79. iframe.setAttribute('mozbrowser', '');
  80. }
  81. if (data.app || data.browser) {
  82. iframe.addEventListener('mozbrowsershowmodalprompt', function(e) {
  83. is(e.detail.message, 'success', 'test number ' + i);
  84. // document.getElementById('content').removeChild(iframe);
  85. i++;
  86. if (i >= gData.length) {
  87. if (previousPrefs.mozBrowserFramesEnabled !== undefined) {
  88. SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', previousPrefs.mozBrowserFramesEnabled);
  89. }
  90. if (previousPrefs.oop_by_default !== undefined) {
  91. SpecialPowers.setBoolPref("dom.ipc.browser_frames.oop_by_default", previousPrefs.oop_by_default);
  92. }
  93. SpecialPowers.removePermission("browser", window.document);
  94. indexedDB.deleteDatabase('AppIsolationTest').onsuccess = function() {
  95. SimpleTest.finish();
  96. };
  97. } else {
  98. gTestRunner.next();
  99. }
  100. });
  101. }
  102. iframe.src = data.src + '?' + data.action;
  103. document.getElementById('content').appendChild(iframe);
  104. yield undefined;
  105. }
  106. }
  107. var gTestRunner = runTest();
  108. function startTest() {
  109. var request = window.indexedDB.open('AppIsolationTest');
  110. var created = false;
  111. request.onupgradeneeded = function(event) {
  112. created = true;
  113. var db = event.target.result;
  114. var data = [
  115. { id: "0", name: "foo" },
  116. ];
  117. var objectStore = db.createObjectStore("test", { keyPath: "id" });
  118. for (var i in data) {
  119. objectStore.add(data[i]);
  120. }
  121. }
  122. request.onsuccess = function(event) {
  123. var db = event.target.result;
  124. is(created, true, "we should have created the db");
  125. db.transaction("test").objectStore("test").get("0").onsuccess = function(event) {
  126. is(event.target.result.name, 'foo', 'data have been written');
  127. db.close();
  128. gTestRunner.next();
  129. };
  130. }
  131. }
  132. // TODO: remove unsetting network.disable.ipc.security as part of bug 820712
  133. SpecialPowers.pushPrefEnv({
  134. "set": [
  135. ["network.disable.ipc.security", true],
  136. ]
  137. }, startTest);