Bug 1257583 - Add test for bypassing the cache with tabs.reload. r=kmag
authorMatthew Wein <mwein@mozilla.com>
Thu, 07 Apr 2016 16:02:28 -0700
changeset 330763 f6241b9dc0e90b1a7b418142c3a12202ebfc0df4
parent 330762 12e42798a15089a17911ab222ad48aa715dc21a5
child 330764 c62d9a911c27721def2d877c66f622a7aa67668d
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1257583
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1257583 - Add test for bypassing the cache with tabs.reload. r=kmag MozReview-Commit-ID: KuJKLWSXvSk
browser/components/extensions/test/browser/browser.ini
browser/components/extensions/test/browser/browser_ext_tabs_reload_bypass_cache.js
browser/components/extensions/test/browser/file_bypass_cache.sjs
--- a/browser/components/extensions/test/browser/browser.ini
+++ b/browser/components/extensions/test/browser/browser.ini
@@ -4,68 +4,70 @@ support-files =
   context.html
   ctxmenu-image.png
   context_tabs_onUpdated_page.html
   context_tabs_onUpdated_iframe.html
   file_popup_api_injection_a.html
   file_popup_api_injection_b.html
   file_iframe_document.html
   file_iframe_document.sjs
+  file_bypass_cache.sjs
   file_language_fr_en.html
   file_language_ja.html
 
-[browser_ext_simple.js]
-[browser_ext_currentWindow.js]
-[browser_ext_browserAction_simple.js]
-[browser_ext_browserAction_pageAction_icon.js]
 [browser_ext_browserAction_context.js]
 [browser_ext_browserAction_disabled.js]
-[browser_ext_pageAction_simple.js]
-[browser_ext_pageAction_context.js]
-[browser_ext_pageAction_popup.js]
+[browser_ext_browserAction_pageAction_icon.js]
 [browser_ext_browserAction_popup.js]
-[browser_ext_popup_api_injection.js]
-[browser_ext_contextMenus.js]
+[browser_ext_browserAction_simple.js]
 [browser_ext_commands_execute_page_action.js]
 [browser_ext_commands_getAll.js]
 [browser_ext_commands_onCommand.js]
+[browser_ext_contentscript_connect.js]
+[browser_ext_contextMenus.js]
+[browser_ext_currentWindow.js]
 [browser_ext_getViews.js]
 [browser_ext_lastError.js]
+[browser_ext_optionsPage_privileges.js]
+[browser_ext_pageAction_context.js]
+[browser_ext_pageAction_popup.js]
+[browser_ext_pageAction_simple.js]
+[browser_ext_popup_api_injection.js]
 [browser_ext_runtime_openOptionsPage.js]
 [browser_ext_runtime_setUninstallURL.js]
+[browser_ext_simple.js]
+[browser_ext_tab_runtimeConnect.js]
 [browser_ext_tabs_audio.js]
 [browser_ext_tabs_captureVisibleTab.js]
+[browser_ext_tabs_create.js]
+[browser_ext_tabs_create_invalid_url.js]
 [browser_ext_tabs_detectLanguage.js]
+[browser_ext_tabs_duplicate.js]
 [browser_ext_tabs_events.js]
 [browser_ext_tabs_executeScript.js]
 [browser_ext_tabs_executeScript_good.js]
 [browser_ext_tabs_executeScript_bad.js]
 [browser_ext_tabs_executeScript_runAt.js]
+[browser_ext_tabs_getCurrent.js]
 [browser_ext_tabs_insertCSS.js]
-[browser_ext_tabs_query.js]
-[browser_ext_tabs_getCurrent.js]
-[browser_ext_tabs_create.js]
-[browser_ext_tabs_create_invalid_url.js]
-[browser_ext_tabs_duplicate.js]
-[browser_ext_tabs_update.js]
-[browser_ext_tabs_update_url.js]
-[browser_ext_tabs_onUpdated.js]
-[browser_ext_tabs_sendMessage.js]
 [browser_ext_tabs_move.js]
 [browser_ext_tabs_move_window.js]
 [browser_ext_tabs_move_window_multiple.js]
 [browser_ext_tabs_move_window_pinned.js]
 [browser_ext_tabs_onHighlighted.js]
+[browser_ext_tabs_onUpdated.js]
+[browser_ext_tabs_query.js]
 [browser_ext_tabs_reload.js]
+[browser_ext_tabs_reload_bypass_cache.js]
+[browser_ext_tabs_sendMessage.js]
+[browser_ext_tabs_update.js]
+[browser_ext_tabs_update_url.js]
+[browser_ext_topwindowid.js]
+[browser_ext_webNavigation_getFrames.js]
+[browser_ext_windows.js]
 [browser_ext_windows_create.js]
 tags = fullscreen
 [browser_ext_windows_create_tabId.js]
 [browser_ext_windows_events.js]
-[browser_ext_windows.js]
 [browser_ext_windows_size.js]
 skip-if = os == 'mac' # Fails when windows are randomly opened in fullscreen mode
 [browser_ext_windows_update.js]
 tags = fullscreen
-[browser_ext_contentscript_connect.js]
-[browser_ext_tab_runtimeConnect.js]
-[browser_ext_topwindowid.js]
-[browser_ext_webNavigation_getFrames.js]
-[browser_ext_optionsPage_privileges.js]
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_reload_bypass_cache.js
@@ -0,0 +1,59 @@
+/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set sts=2 sw=2 et tw=80: */
+"use strict";
+
+add_task(function* () {
+  let extension = ExtensionTestUtils.loadExtension({
+    manifest: {
+      "permissions": ["tabs", "<all_urls>"],
+    },
+
+    background: function() {
+      const BASE = "http://mochi.test:8888/browser/browser/components/extensions/test/browser/";
+      const URL = BASE + "file_bypass_cache.sjs";
+
+      function awaitLoad(tabId) {
+        return new Promise(resolve => {
+          browser.tabs.onUpdated.addListener(function listener(tabId_, changed, tab) {
+            if (tabId == tabId_ && changed.status == "complete" && tab.url == URL) {
+              browser.tabs.onUpdated.removeListener(listener);
+              resolve();
+            }
+          });
+        });
+      }
+
+      let tabId;
+      browser.tabs.create({url: URL}).then((tab) => {
+        tabId = tab.id;
+        return awaitLoad(tabId);
+      }).then(() => {
+        return browser.tabs.reload(tabId, {bypassCache: false});
+      }).then(() => {
+        return awaitLoad(tabId);
+      }).then(() => {
+        return browser.tabs.executeScript(tabId, {code: "document.body.textContent"});
+      }).then(textContent => {
+        browser.test.assertEq("", textContent, "`textContent` should be empty when bypassCache=false");
+        return browser.tabs.reload(tabId, {bypassCache: true});
+      }).then(() => {
+        return awaitLoad(tabId);
+      }).then(() => {
+        return browser.tabs.executeScript(tabId, {code: "document.body.textContent"});
+      }).then(textContent => {
+        let [pragma, cacheControl] = textContent.split(":");
+        browser.test.assertEq("no-cache", pragma, "`pragma` should be set to `no-cache` when bypassCache is true");
+        browser.test.assertEq("no-cache", cacheControl, "`cacheControl` should be set to `no-cache` when bypassCache is true");
+        browser.tabs.remove(tabId);
+        browser.test.notifyPass("tabs.reload_bypass_cache");
+      }).catch(error => {
+        browser.test.fail(`${error} :: ${error.stack}`);
+        browser.test.notifyFail("tabs.reload_bypass_cache");
+      });
+    },
+  });
+
+  yield extension.startup();
+  yield extension.awaitFinish("tabs.reload_bypass_cache");
+  yield extension.unload();
+});
new file mode 100644
--- /dev/null
+++ b/browser/components/extensions/test/browser/file_bypass_cache.sjs
@@ -0,0 +1,11 @@
+/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set sts=2 sw=2 et tw=80 ft=javascript: */
+"use strict";
+
+function handleRequest(request, response) {
+  response.setHeader("Content-Type", "text/plain; charset=UTF-8", false);
+
+  if (request.hasHeader("pragma") && request.hasHeader("cache-control")) {
+    response.write(`${request.getHeader("pragma")}:${request.getHeader("cache-control")}`);
+  }
+}
\ No newline at end of file