2010-08-28 21:30:49 -07:00
|
|
|
/* vim:set ts=2 sw=2 sts=2 et: */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Julian Viereck <jviereck@mozilla.com>
|
2010-10-11 09:57:56 -07:00
|
|
|
* Patrick Walton <pcwalton@mozilla.com>
|
2010-10-20 10:39:44 -07:00
|
|
|
* Mihai Șucan <mihai.sucan@gmail.com>
|
2010-08-28 21:30:49 -07:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2010-10-11 09:57:56 -07:00
|
|
|
// Tests that network log messages bring up the network panel.
|
2010-08-28 21:30:49 -07:00
|
|
|
|
2012-01-17 06:04:23 -08:00
|
|
|
const TEST_NETWORK_REQUEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-network-request.html";
|
2010-08-28 21:30:49 -07:00
|
|
|
|
2012-01-17 06:04:23 -08:00
|
|
|
const TEST_IMG = "http://example.com/browser/browser/devtools/webconsole/test/test-image.png";
|
2010-08-28 21:31:12 -07:00
|
|
|
|
2010-08-28 21:30:49 -07:00
|
|
|
const TEST_DATA_JSON_CONTENT =
|
|
|
|
'{ id: "test JSON data", myArray: [ "foo", "bar", "baz", "biff" ] }';
|
|
|
|
|
2010-10-20 10:39:44 -07:00
|
|
|
let lastRequest = null;
|
2011-01-19 06:23:07 -08:00
|
|
|
let requestCallback = null;
|
2012-05-29 05:48:05 -07:00
|
|
|
let lastActivity = null;
|
2010-10-20 10:39:44 -07:00
|
|
|
|
2010-10-11 09:57:56 -07:00
|
|
|
function test()
|
|
|
|
{
|
2012-03-24 04:34:42 -07:00
|
|
|
addTab("data:text/html;charset=utf-8,Web Console network logging tests");
|
2010-10-11 09:57:56 -07:00
|
|
|
|
2012-05-29 05:48:05 -07:00
|
|
|
browser.addEventListener("load", function onLoad() {
|
|
|
|
browser.removeEventListener("load", onLoad, true);
|
2010-10-20 10:39:44 -07:00
|
|
|
|
2012-05-29 05:48:05 -07:00
|
|
|
openConsole(null, function(aHud) {
|
|
|
|
hud = aHud;
|
2010-10-20 10:39:44 -07:00
|
|
|
|
2012-05-29 05:48:05 -07:00
|
|
|
HUDService.lastFinishedRequestCallback = function(aRequest) {
|
|
|
|
lastRequest = aRequest.log.entries[0];
|
|
|
|
lastActivity = aRequest;
|
|
|
|
if (requestCallback) {
|
|
|
|
requestCallback();
|
|
|
|
}
|
|
|
|
};
|
2010-10-20 10:39:44 -07:00
|
|
|
|
2012-05-29 05:48:05 -07:00
|
|
|
executeSoon(testPageLoad);
|
|
|
|
});
|
2010-10-11 09:57:56 -07:00
|
|
|
}, true);
|
|
|
|
}
|
2010-08-28 21:30:49 -07:00
|
|
|
|
2010-10-20 10:39:44 -07:00
|
|
|
function testPageLoad()
|
2010-08-28 21:30:49 -07:00
|
|
|
{
|
2012-05-29 05:48:05 -07:00
|
|
|
requestCallback = function() {
|
2010-10-20 10:39:44 -07:00
|
|
|
// Check if page load was logged correctly.
|
|
|
|
ok(lastRequest, "Page load was logged");
|
2012-05-29 05:48:05 -07:00
|
|
|
|
|
|
|
is(lastRequest.request.url, TEST_NETWORK_REQUEST_URI,
|
2010-10-20 10:39:44 -07:00
|
|
|
"Logged network entry is page load");
|
2012-05-29 05:48:05 -07:00
|
|
|
is(lastRequest.request.method, "GET", "Method is correct");
|
|
|
|
ok(!lastRequest.request.postData, "No request body was stored");
|
|
|
|
ok(!lastRequest.response.content.text, "No response body was stored");
|
2010-08-28 21:30:49 -07:00
|
|
|
|
2010-10-20 10:39:44 -07:00
|
|
|
lastRequest = null;
|
2012-05-29 05:48:05 -07:00
|
|
|
requestCallback = null;
|
2010-10-20 10:39:44 -07:00
|
|
|
executeSoon(testPageLoadBody);
|
2012-05-29 05:48:05 -07:00
|
|
|
};
|
2010-08-28 21:30:49 -07:00
|
|
|
|
2010-10-20 10:39:44 -07:00
|
|
|
content.location = TEST_NETWORK_REQUEST_URI;
|
2010-08-28 21:30:49 -07:00
|
|
|
}
|
|
|
|
|
2010-10-20 10:39:44 -07:00
|
|
|
function testPageLoadBody()
|
2010-08-28 21:30:49 -07:00
|
|
|
{
|
2012-06-04 09:45:10 -07:00
|
|
|
let loaded = false;
|
|
|
|
let requestCallbackInvoked = false;
|
|
|
|
|
2010-10-20 10:39:44 -07:00
|
|
|
// Turn on logging of request bodies and check again.
|
2012-07-26 08:06:04 -07:00
|
|
|
hud.ui.saveRequestAndResponseBodies = true;
|
2012-05-29 05:48:05 -07:00
|
|
|
requestCallback = function() {
|
2010-10-20 10:39:44 -07:00
|
|
|
ok(lastRequest, "Page load was logged again");
|
2012-05-29 05:48:05 -07:00
|
|
|
is(lastRequest.response.content.text.indexOf("<!DOCTYPE HTML>"), 0,
|
2010-10-20 10:39:44 -07:00
|
|
|
"Response body's beginning is okay");
|
2010-08-28 21:30:49 -07:00
|
|
|
|
2010-10-20 10:39:44 -07:00
|
|
|
lastRequest = null;
|
2012-05-29 05:48:05 -07:00
|
|
|
requestCallback = null;
|
2012-06-04 09:45:10 -07:00
|
|
|
requestCallbackInvoked = true;
|
|
|
|
|
|
|
|
if (loaded) {
|
|
|
|
executeSoon(testXhrGet);
|
|
|
|
}
|
2012-05-29 05:48:05 -07:00
|
|
|
};
|
2010-10-20 10:39:44 -07:00
|
|
|
|
2012-06-04 09:45:10 -07:00
|
|
|
browser.addEventListener("load", function onLoad() {
|
|
|
|
browser.removeEventListener("load", onLoad, true);
|
|
|
|
loaded = true;
|
|
|
|
|
|
|
|
if (requestCallbackInvoked) {
|
|
|
|
executeSoon(testXhrGet);
|
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
|
2010-10-20 10:39:44 -07:00
|
|
|
content.location.reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
function testXhrGet()
|
|
|
|
{
|
2011-01-19 06:23:07 -08:00
|
|
|
requestCallback = function() {
|
2010-10-20 10:39:44 -07:00
|
|
|
ok(lastRequest, "testXhrGet() was logged");
|
2012-05-29 05:48:05 -07:00
|
|
|
is(lastRequest.request.method, "GET", "Method is correct");
|
|
|
|
ok(!lastRequest.request.postData, "No request body was sent");
|
|
|
|
is(lastRequest.response.content.text, TEST_DATA_JSON_CONTENT,
|
2010-10-20 10:39:44 -07:00
|
|
|
"Response is correct");
|
|
|
|
|
|
|
|
lastRequest = null;
|
2011-01-19 06:23:07 -08:00
|
|
|
requestCallback = null;
|
2010-10-20 10:39:44 -07:00
|
|
|
executeSoon(testXhrPost);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Start the XMLHttpRequest() GET test.
|
2011-01-19 06:23:07 -08:00
|
|
|
content.wrappedJSObject.testXhrGet();
|
2010-10-20 10:39:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function testXhrPost()
|
|
|
|
{
|
2011-01-19 06:23:07 -08:00
|
|
|
requestCallback = function() {
|
2010-10-20 10:39:44 -07:00
|
|
|
ok(lastRequest, "testXhrPost() was logged");
|
2012-05-29 05:48:05 -07:00
|
|
|
is(lastRequest.request.method, "POST", "Method is correct");
|
|
|
|
is(lastRequest.request.postData.text, "Hello world!",
|
2010-10-20 10:39:44 -07:00
|
|
|
"Request body was logged");
|
2012-05-29 05:48:05 -07:00
|
|
|
is(lastRequest.response.content.text, TEST_DATA_JSON_CONTENT,
|
2010-10-20 10:39:44 -07:00
|
|
|
"Response is correct");
|
|
|
|
|
|
|
|
lastRequest = null;
|
2011-01-19 06:23:07 -08:00
|
|
|
requestCallback = null;
|
2010-10-20 10:39:44 -07:00
|
|
|
executeSoon(testFormSubmission);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Start the XMLHttpRequest() POST test.
|
2011-01-19 06:23:07 -08:00
|
|
|
content.wrappedJSObject.testXhrPost();
|
2010-10-20 10:39:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function testFormSubmission()
|
|
|
|
{
|
|
|
|
// Start the form submission test. As the form is submitted, the page is
|
|
|
|
// loaded again. Bind to the load event to catch when this is done.
|
2012-05-29 05:48:05 -07:00
|
|
|
requestCallback = function() {
|
2010-10-20 10:39:44 -07:00
|
|
|
ok(lastRequest, "testFormSubmission() was logged");
|
2012-05-29 05:48:05 -07:00
|
|
|
is(lastRequest.request.method, "POST", "Method is correct");
|
|
|
|
isnot(lastRequest.request.postData.text.
|
2010-10-20 10:39:44 -07:00
|
|
|
indexOf("Content-Type: application/x-www-form-urlencoded"), -1,
|
|
|
|
"Content-Type is correct");
|
2012-05-29 05:48:05 -07:00
|
|
|
isnot(lastRequest.request.postData.text.
|
2010-10-20 10:39:44 -07:00
|
|
|
indexOf("Content-Length: 20"), -1, "Content-length is correct");
|
2012-05-29 05:48:05 -07:00
|
|
|
isnot(lastRequest.request.postData.text.
|
2010-10-20 10:39:44 -07:00
|
|
|
indexOf("name=foo+bar&age=144"), -1, "Form data is correct");
|
2012-05-29 05:48:05 -07:00
|
|
|
is(lastRequest.response.content.text.indexOf("<!DOCTYPE HTML>"), 0,
|
2010-10-20 10:39:44 -07:00
|
|
|
"Response body's beginning is okay");
|
|
|
|
|
|
|
|
executeSoon(testNetworkPanel);
|
2012-05-29 05:48:05 -07:00
|
|
|
};
|
2010-10-20 10:39:44 -07:00
|
|
|
|
|
|
|
let form = content.document.querySelector("form");
|
|
|
|
ok(form, "we have the HTML form");
|
|
|
|
form.submit();
|
|
|
|
}
|
|
|
|
|
|
|
|
function testNetworkPanel()
|
|
|
|
{
|
|
|
|
// Open the NetworkPanel. The functionality of the NetworkPanel is tested
|
|
|
|
// within separate test files.
|
2012-07-26 08:06:04 -07:00
|
|
|
let networkPanel = hud.ui.openNetworkPanel(hud.ui.filterBox, lastActivity);
|
|
|
|
is(networkPanel, hud.ui.filterBox._netPanel,
|
2012-05-29 05:48:05 -07:00
|
|
|
"Network panel stored on anchor node");
|
2010-10-20 10:39:44 -07:00
|
|
|
|
2012-05-29 05:48:05 -07:00
|
|
|
networkPanel.panel.addEventListener("load", function onLoad(aEvent) {
|
|
|
|
networkPanel.panel.removeEventListener(aEvent.type, onLoad, true);
|
2010-10-20 10:39:44 -07:00
|
|
|
|
|
|
|
ok(true, "NetworkPanel was opened");
|
|
|
|
|
|
|
|
// All tests are done. Shutdown.
|
|
|
|
networkPanel.panel.hidePopup();
|
|
|
|
lastRequest = null;
|
2012-05-29 05:48:05 -07:00
|
|
|
lastActivity = null;
|
2010-10-20 10:39:44 -07:00
|
|
|
HUDService.lastFinishedRequestCallback = null;
|
|
|
|
executeSoon(finishTest);
|
|
|
|
}, true);
|
2010-08-28 21:30:49 -07:00
|
|
|
}
|
2010-10-20 10:39:44 -07:00
|
|
|
|