зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1315514 - Bookmark keywords are still broken for POST forms. r=adw
MozReview-Commit-ID: 3lrRbZVtgii --HG-- rename : browser/base/content/test/general/print_postdata.sjs => browser/base/content/test/urlbar/print_postdata.sjs extra : rebase_source : 9bae5a403c648e58134afb70de05834566b22ef2
This commit is contained in:
Родитель
339324700f
Коммит
37f96e3c4c
|
@ -1,67 +1,69 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
var testData = [
|
||||
/* baseURI, field name, expected */
|
||||
[ 'http://example.com/', 'q', 'http://example.com/?q=%s' ],
|
||||
[ 'http://example.com/new-path-here/', 'q', 'http://example.com/new-path-here/?q=%s' ],
|
||||
[ '', 'q', 'http://example.org/browser/browser/base/content/test/general/dummy_page.html?q=%s' ],
|
||||
// Tests for proper behaviour when called on a form whose action contains a question mark.
|
||||
[ 'http://example.com/search?oe=utf-8', 'q', 'http://example.com/search?oe=utf-8&q=%s' ],
|
||||
{ desc: "No path",
|
||||
action: "http://example.com/",
|
||||
param: "q",
|
||||
},
|
||||
{ desc: "With path",
|
||||
action: "http://example.com/new-path-here/",
|
||||
param: "q",
|
||||
},
|
||||
{ desc: "No action",
|
||||
action: "",
|
||||
param: "q",
|
||||
},
|
||||
{ desc: "With Query String",
|
||||
action: "http://example.com/search?oe=utf-8",
|
||||
param: "q",
|
||||
},
|
||||
];
|
||||
|
||||
add_task(function*() {
|
||||
yield BrowserTestUtils.withNewTab({
|
||||
gBrowser,
|
||||
url: "http://example.org/browser/browser/base/content/test/general/dummy_page.html",
|
||||
}, function* (browser) {
|
||||
yield ContentTask.spawn(browser, null, function* () {
|
||||
let doc = content.document;
|
||||
let base = doc.createElement("base");
|
||||
doc.head.appendChild(base);
|
||||
});
|
||||
const TEST_URL = "http://example.org/browser/browser/base/content/test/general/dummy_page.html";
|
||||
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URL);
|
||||
|
||||
var mm = browser.messageManager;
|
||||
let count = 0;
|
||||
for (let method of ["GET", "POST"]) {
|
||||
for (let {desc, action, param } of testData) {
|
||||
info(`Running ${method} keyword test '${desc}'`);
|
||||
let id = `keyword-form-${count++}`;
|
||||
let contextMenu = document.getElementById("contentAreaContextMenu");
|
||||
let contextMenuPromise =
|
||||
BrowserTestUtils.waitForEvent(contextMenu, "popupshown")
|
||||
.then(() => gContextMenuContentData.popupNode);
|
||||
|
||||
for (let [baseURI, fieldName, expected] of testData) {
|
||||
let popupShownPromise = BrowserTestUtils.waitForEvent(document.getElementById("contentAreaContextMenu"),
|
||||
"popupshown");
|
||||
|
||||
yield ContentTask.spawn(browser, { baseURI, fieldName }, function* (args) {
|
||||
yield ContentTask.spawn(tab.linkedBrowser,
|
||||
{ action, param, method, id }, function* (args) {
|
||||
let doc = content.document;
|
||||
|
||||
let base = doc.querySelector('head > base');
|
||||
base.href = args.baseURI;
|
||||
|
||||
let form = doc.createElement("form");
|
||||
form.id = "keyword-form";
|
||||
form.id = args.id;
|
||||
form.method = args.method;
|
||||
form.action = args.action;
|
||||
let element = doc.createElement("input");
|
||||
element.setAttribute("type", "text");
|
||||
element.setAttribute("name", args.fieldName);
|
||||
element.setAttribute("name", args.param);
|
||||
form.appendChild(element);
|
||||
doc.body.appendChild(form);
|
||||
|
||||
/* Open context menu so chrome can access the element */
|
||||
const domWindowUtils =
|
||||
content.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
||||
.getInterface(Components.interfaces.nsIDOMWindowUtils);
|
||||
let rect = element.getBoundingClientRect();
|
||||
let left = rect.left + rect.width / 2;
|
||||
let top = rect.top + rect.height / 2;
|
||||
domWindowUtils.sendMouseEvent("contextmenu", left, top, 2,
|
||||
1, 0, false, 0, 0, true);
|
||||
});
|
||||
|
||||
yield popupShownPromise;
|
||||
yield BrowserTestUtils.synthesizeMouseAtCenter(`#${id} > input`,
|
||||
{ type : "contextmenu", button : 2 },
|
||||
tab.linkedBrowser);
|
||||
let target = yield contextMenuPromise;
|
||||
|
||||
let target = gContextMenuContentData.popupNode;
|
||||
|
||||
let urlCheck = new Promise((resolve, reject) => {
|
||||
yield new Promise(resolve => {
|
||||
let url = action || tab.linkedBrowser.currentURI.spec;
|
||||
let mm = tab.linkedBrowser.messageManager;
|
||||
let onMessage = (message) => {
|
||||
mm.removeMessageListener("ContextMenu:SearchFieldBookmarkData:Result", onMessage);
|
||||
|
||||
is(message.data.spec, expected,
|
||||
`Bookmark spec for search field named ${fieldName} and baseURI ${baseURI} incorrect`);
|
||||
if (method == "GET") {
|
||||
ok(message.data.spec.endsWith(`${param}=%s`),
|
||||
`Check expected url for field named ${param} and action ${action}`);
|
||||
} else {
|
||||
is(message.data.spec, url,
|
||||
`Check expected url for field named ${param} and action ${action}`);
|
||||
is(message.data.postData, `${param}%3D%25s`,
|
||||
`Check expected POST data for field named ${param} and action ${action}`);
|
||||
}
|
||||
resolve();
|
||||
};
|
||||
mm.addMessageListener("ContextMenu:SearchFieldBookmarkData:Result", onMessage);
|
||||
|
@ -69,14 +71,11 @@ add_task(function*() {
|
|||
mm.sendAsyncMessage("ContextMenu:SearchFieldBookmarkData", null, { target });
|
||||
});
|
||||
|
||||
yield urlCheck;
|
||||
|
||||
document.getElementById("contentAreaContextMenu").hidePopup();
|
||||
|
||||
yield ContentTask.spawn(browser, null, function* () {
|
||||
let doc = content.document;
|
||||
doc.body.removeChild(doc.getElementById("keyword-form"));
|
||||
});
|
||||
let popupHiddenPromise = BrowserTestUtils.waitForEvent(contextMenu, "popuphidden");
|
||||
contextMenu.hidePopup();
|
||||
yield popupHiddenPromise;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
yield BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
|
|
|
@ -7,6 +7,8 @@ support-files =
|
|||
skip-if = (os == "linux" || os == "mac") && debug # bug 970052, bug 970053
|
||||
[browser_action_keyword.js]
|
||||
skip-if = os == "linux" # Bug 1188154
|
||||
support-files =
|
||||
print_postdata.sjs
|
||||
[browser_action_keyword_override.js]
|
||||
[browser_action_searchengine.js]
|
||||
[browser_action_searchengine_alias.js]
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
var gOnSearchComplete = null;
|
||||
|
||||
function* promise_first_result(inputText) {
|
||||
yield promiseAutocompleteResultPopup(inputText);
|
||||
|
||||
|
@ -10,41 +5,47 @@ function* promise_first_result(inputText) {
|
|||
return firstResult;
|
||||
}
|
||||
|
||||
const TEST_URL = "http://mochi.test:8888/browser/browser/base/content/test/urlbar/print_postdata.sjs";
|
||||
|
||||
add_task(function*() {
|
||||
let tab = gBrowser.selectedTab = gBrowser.addTab("about:mozilla");
|
||||
let tabs = [tab];
|
||||
add_task(function* setup() {
|
||||
yield PlacesUtils.keywords.insert({ keyword: "get",
|
||||
url: TEST_URL + "?q=%s" });
|
||||
yield PlacesUtils.keywords.insert({ keyword: "post",
|
||||
url: TEST_URL,
|
||||
postData: "q=%s" });
|
||||
registerCleanupFunction(function* () {
|
||||
for (let tab of tabs)
|
||||
gBrowser.removeTab(tab);
|
||||
yield PlacesUtils.bookmarks.remove(bm);
|
||||
yield PlacesUtils.keywords.remove("get");
|
||||
yield PlacesUtils.keywords.remove("post");
|
||||
while (gBrowser.tabs.length > 1) {
|
||||
yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
yield BrowserTestUtils.browserLoaded(tab.linkedBrowser);
|
||||
add_task(function* get_keyword() {
|
||||
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
|
||||
|
||||
let bm = yield PlacesUtils.bookmarks.insert({ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
|
||||
url: "http://example.com/?q=%s",
|
||||
title: "test" });
|
||||
yield PlacesUtils.keywords.insert({ keyword: "keyword",
|
||||
url: "http://example.com/?q=%s" });
|
||||
|
||||
let result = yield promise_first_result("keyword something");
|
||||
let result = yield promise_first_result("get something");
|
||||
isnot(result, null, "Expect a keyword result");
|
||||
|
||||
let types = new Set(result.getAttribute("type").split(/\s+/));
|
||||
Assert.ok(types.has("keyword"));
|
||||
is(result.getAttribute("actiontype"), "keyword", "Expect correct `actiontype` attribute");
|
||||
is(result.getAttribute("title"), "example.com", "Expect correct title");
|
||||
is(result.getAttribute("title"), "mochi.test:8888", "Expect correct title");
|
||||
|
||||
// We need to make a real URI out of this to ensure it's normalised for
|
||||
// comparison.
|
||||
let uri = NetUtil.newURI(result.getAttribute("url"));
|
||||
is(uri.spec, PlacesUtils.mozActionURI("keyword", {url: "http://example.com/?q=something", input: "keyword something"}), "Expect correct url");
|
||||
is(uri.spec, PlacesUtils.mozActionURI("keyword",
|
||||
{ url: TEST_URL + "?q=something",
|
||||
input: "get something"}),
|
||||
"Expect correct url");
|
||||
|
||||
let titleHbox = result._titleText.parentNode.parentNode;
|
||||
ok(titleHbox.classList.contains("ac-title"), "Title hbox element sanity check");
|
||||
is_element_visible(titleHbox, "Title element should be visible");
|
||||
is(result._titleText.textContent, "example.com: something", "Node should contain the name of the bookmark and query");
|
||||
is(result._titleText.textContent, "mochi.test:8888: something",
|
||||
"Node should contain the name of the bookmark and query");
|
||||
|
||||
let urlHbox = result._urlText.parentNode.parentNode;
|
||||
ok(urlHbox.classList.contains("ac-url"), "URL hbox element sanity check");
|
||||
|
@ -60,22 +61,59 @@ add_task(function*() {
|
|||
let tabPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
|
||||
EventUtils.synthesizeMouseAtCenter(result, {});
|
||||
yield tabPromise;
|
||||
is(tab.linkedBrowser.currentURI.spec, "http://example.com/?q=something", "Tab should have loaded from clicking on result");
|
||||
is(tab.linkedBrowser.currentURI.spec, TEST_URL + "?q=something",
|
||||
"Tab should have loaded from clicking on result");
|
||||
|
||||
// Middle-click on the result
|
||||
info("Middle-click on result");
|
||||
result = yield promise_first_result("keyword somethingmore");
|
||||
result = yield promise_first_result("get somethingmore");
|
||||
isnot(result, null, "Expect a keyword result");
|
||||
// We need to make a real URI out of this to ensure it's normalised for
|
||||
// comparison.
|
||||
uri = NetUtil.newURI(result.getAttribute("url"));
|
||||
is(uri.spec, PlacesUtils.mozActionURI("keyword", {url: "http://example.com/?q=somethingmore", input: "keyword somethingmore"}), "Expect correct url");
|
||||
is(uri.spec, PlacesUtils.mozActionURI("keyword",
|
||||
{ url: TEST_URL + "?q=somethingmore",
|
||||
input: "get somethingmore" }),
|
||||
"Expect correct url");
|
||||
|
||||
tabPromise = BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "TabOpen");
|
||||
EventUtils.synthesizeMouseAtCenter(result, {button: 1});
|
||||
let tabOpenEvent = yield tabPromise;
|
||||
let newTab = tabOpenEvent.target;
|
||||
tabs.push(newTab);
|
||||
yield BrowserTestUtils.browserLoaded(newTab.linkedBrowser);
|
||||
is(newTab.linkedBrowser.currentURI.spec, "http://example.com/?q=somethingmore", "Tab should have loaded from middle-clicking on result");
|
||||
is(newTab.linkedBrowser.currentURI.spec,
|
||||
TEST_URL + "?q=somethingmore",
|
||||
"Tab should have loaded from middle-clicking on result");
|
||||
});
|
||||
|
||||
|
||||
add_task(function* post_keyword() {
|
||||
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
|
||||
|
||||
let result = yield promise_first_result("post something");
|
||||
isnot(result, null, "Expect a keyword result");
|
||||
|
||||
let types = new Set(result.getAttribute("type").split(/\s+/));
|
||||
Assert.ok(types.has("keyword"));
|
||||
is(result.getAttribute("actiontype"), "keyword", "Expect correct `actiontype` attribute");
|
||||
is(result.getAttribute("title"), "mochi.test:8888", "Expect correct title");
|
||||
|
||||
is(result.getAttribute("url"),
|
||||
PlacesUtils.mozActionURI("keyword", { url: TEST_URL,
|
||||
input: "post something",
|
||||
"postData": "q=something" }),
|
||||
"Expect correct url");
|
||||
|
||||
// Click on the result
|
||||
info("Normal click on result");
|
||||
let tabPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
|
||||
EventUtils.synthesizeMouseAtCenter(result, {});
|
||||
yield tabPromise;
|
||||
is(tab.linkedBrowser.currentURI.spec, TEST_URL,
|
||||
"Tab should have loaded from clicking on result");
|
||||
|
||||
let postData = yield ContentTask.spawn(tab.linkedBrowser, null, function* () {
|
||||
return content.document.body.textContent;
|
||||
});
|
||||
is(postData, "q=something", "post data was submitted correctly");
|
||||
});
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
const CC = Components.Constructor;
|
||||
const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1",
|
||||
"nsIBinaryInputStream",
|
||||
"setInputStream");
|
||||
|
||||
function handleRequest(request, response) {
|
||||
response.setHeader("Content-Type", "text/plain", false);
|
||||
if (request.method == "GET") {
|
||||
response.write(request.queryString);
|
||||
} else {
|
||||
var body = new BinaryInputStream(request.bodyInputStream);
|
||||
|
||||
var avail;
|
||||
var bytes = [];
|
||||
|
||||
while ((avail = body.available()) > 0)
|
||||
Array.prototype.push.apply(bytes, body.readByteArray(avail));
|
||||
|
||||
var data = String.fromCharCode.apply(null, bytes);
|
||||
response.bodyOutputStream.write(data, data.length);
|
||||
}
|
||||
}
|
|
@ -444,7 +444,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|||
break;
|
||||
case "keyword":
|
||||
if (action.params.postData) {
|
||||
postData = getPostDataStream(postData);
|
||||
postData = getPostDataStream(action.params.postData);
|
||||
}
|
||||
mayInheritPrincipal = true;
|
||||
url = action.params.url;
|
||||
|
|
Загрузка…
Ссылка в новой задаче