Bug 1257583 - Add test for bypassing the cache with tabs.reload. r=kmag

MozReview-Commit-ID: KuJKLWSXvSk

--HG--
extra : amend_source : 0cb4f489d1a494a714ff2841ba6d1433da4f451c
extra : transplant_source : %7E%80%D2%A2%7E%C6%3D%A0%DD%E7%F4%FC%9A%8B%5EG%91%93%BC%EB
This commit is contained in:
Matthew Wein 2016-04-07 16:02:28 -07:00
Родитель a24156ff6c
Коммит dbe4de5824
3 изменённых файлов: 96 добавлений и 24 удалений

Просмотреть файл

@ -9,63 +9,65 @@ support-files =
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_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_insertCSS.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]

Просмотреть файл

@ -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();
});

Просмотреть файл

@ -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")}`);
}
}