зеркало из https://github.com/mozilla/pjs.git
tests for bugs 336359/336682 - WHATWG online/offline events
r+sr=jst
This commit is contained in:
Родитель
2441a1ff2e
Коммит
72f3f19660
|
@ -44,7 +44,11 @@ relativesrcdir = content/events/test
|
|||
include $(DEPTH)/config/autoconf.mk
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
_TEST_FILES = test_bug367781.html \
|
||||
_TEST_FILES = \
|
||||
test_bug336682_1.html \
|
||||
test_bug336682_2.xul \
|
||||
test_bug336682.js \
|
||||
test_bug367781.html \
|
||||
test_bug379120.html \
|
||||
$(NULL)
|
||||
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* Helper functions for online/offline events tests.
|
||||
*
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/licenses/publicdomain/
|
||||
*/
|
||||
var gState = 0;
|
||||
/**
|
||||
* After all the on/offline handlers run,
|
||||
* gState is expected to be equal to MAX_STATE.
|
||||
*/
|
||||
var MAX_STATE;
|
||||
|
||||
function trace(text) {
|
||||
var t = text.replace(/&/g, "&" + "amp;").replace(/</g, "&" + "lt;") + "<br>";
|
||||
//document.getElementById("display").innerHTML += t;
|
||||
}
|
||||
|
||||
// window.ononline and window.onclick shouldn't work
|
||||
// Right now, <body ononline=...> sets window.ononline (bug 380618)
|
||||
// When these start passing, be sure to uncomment the code inside if(0) below.
|
||||
todo(typeof window.ononline == "undefined",
|
||||
"window.ononline should be undefined at this point");
|
||||
todo(typeof window.onoffline == "undefined",
|
||||
"window.onoffline should be undefined at this point");
|
||||
|
||||
if (0) {
|
||||
window.ononline = function() {
|
||||
ok(false, "window.ononline shouldn't be called");
|
||||
}
|
||||
window.onoffline = function() {
|
||||
ok(false, "window.onclick shouldn't be called");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a handler function for an online/offline event. The returned handler
|
||||
* ensures the passed event object has expected properties and that the handler
|
||||
* is called at the right moment (according to the gState variable).
|
||||
* @param nameTemplate The string identifying the hanlder. '%1' in that
|
||||
* string will be replaced with the event name.
|
||||
* @param eventName 'online' or 'offline'
|
||||
* @param expectedStates an array listing the possible values of gState at the
|
||||
* moment the handler is called. The handler increases
|
||||
* gState by one before checking if it's listed in
|
||||
* expectedStates.
|
||||
*/
|
||||
function makeHandler(nameTemplate, eventName, expectedStates) {
|
||||
return function(e) {
|
||||
var name = nameTemplate.replace(/%1/, eventName);
|
||||
++gState;
|
||||
trace(name + ": gState=" + gState);
|
||||
ok(expectedStates.indexOf(gState) != -1,
|
||||
"handlers called in the right order: " + name + " is called, " +
|
||||
"gState=" + gState + ", expectedStates=" + expectedStates);
|
||||
ok(e.constructor == Event, "event should be an Event");
|
||||
ok(e.type == eventName, "event type should be " + eventName);
|
||||
ok(e.bubbles, "event should bubble");
|
||||
ok(!e.cancelable, "event should not be cancelable");
|
||||
ok(e.target == (document instanceof HTMLDocument
|
||||
? document.body : document.documentElement),
|
||||
"the event target should be the body element");
|
||||
}
|
||||
}
|
||||
|
||||
function doTest() {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
var iosvc = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService2);
|
||||
iosvc.manageOfflineStatus = false;
|
||||
iosvc.offline = false;
|
||||
ok(navigator.onLine, "navigator.onLine should be true, since we've just " +
|
||||
"set nsIIOService.offline to false");
|
||||
|
||||
gState = 0;
|
||||
|
||||
trace("setting iosvc.offline = true");
|
||||
iosvc.offline = true;
|
||||
trace("done setting iosvc.offline = true");
|
||||
ok(!navigator.onLine,
|
||||
"navigator.onLine should be false when iosvc.offline == true");
|
||||
ok(gState == window.MAX_STATE,
|
||||
"offline event: all registered handlers should have been invoked, " +
|
||||
"actual: " + gState);
|
||||
|
||||
gState = 0;
|
||||
trace("setting iosvc.offline = false");
|
||||
iosvc.offline = false;
|
||||
trace("done setting iosvc.offline = false");
|
||||
ok(navigator.onLine,
|
||||
"navigator.onLine should be true when iosvc.offline == false");
|
||||
ok(gState == window.MAX_STATE,
|
||||
"online event: all registered handlers should have been invoked, " +
|
||||
"actual: " + gState);
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
Bug 336682: online/offline events tests.
|
||||
|
||||
Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/licenses/publicdomain/
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 336682 (online/offline events)</title>
|
||||
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body ononline="trace('<body ononline=...>');
|
||||
bodyOnonline(this, event)"
|
||||
onoffline="trace('<body onoffline=...>'); bodyOnoffline(this, event)"
|
||||
>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=336682">Mozilla Bug 336682</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
<script type="text/javascript" src="test_bug336682.js"></script>
|
||||
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
function makeBodyHandler(eventName) {
|
||||
return function (aThis, aEvent) {
|
||||
var handler = makeHandler("<body on%1='...'>", eventName, [3,4]);
|
||||
handler(aEvent);
|
||||
}
|
||||
}
|
||||
addLoadEvent(function() {
|
||||
/** @see test_bug336682.js */
|
||||
MAX_STATE = 4;
|
||||
|
||||
for each(var event in ["online", "offline"]) {
|
||||
document.body.addEventListener(
|
||||
event,
|
||||
makeHandler("document.body.addEventListener('%1', ..., false)",
|
||||
event, [1]),
|
||||
false);
|
||||
|
||||
document.addEventListener(
|
||||
event,
|
||||
makeHandler("document.addEventListener('%1', ..., false)",
|
||||
event, [2]),
|
||||
false);
|
||||
|
||||
window["bodyOn" + event] = makeBodyHandler(event);
|
||||
|
||||
window.addEventListener(
|
||||
event,
|
||||
makeHandler("window.addEventListener('%1', ..., false)",
|
||||
event, [3,4]),
|
||||
false);
|
||||
}
|
||||
|
||||
doTest();
|
||||
SimpleTest.finish();
|
||||
});
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,72 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
||||
<?xml-stylesheet href="/tests/SimpleTest/test.css" type="text/css"?>
|
||||
<!--
|
||||
Bug 336682: online/offline events tests.
|
||||
|
||||
Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/licenses/publicdomain/
|
||||
-->
|
||||
<window title="Mozilla Bug 336682"
|
||||
onoffline="trace('lt;body onoffline=...'); windowOnoffline(this, event)"
|
||||
ononline="trace('lt;body ononline=...'); windowOnonline(this, event)"
|
||||
|
||||
xmlns:html="http://www.w3.org/1999/xhtml"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<script type="application/javascript" src="/MochiKit/packed.js"></script>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
|
||||
<body xmlns="http://www.w3.org/1999/xhtml">
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=336682">
|
||||
Mozilla Bug 336682 (online/offline events)</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
</div>
|
||||
</body>
|
||||
|
||||
<script type="text/javascript" src="test_bug336682.js"/>
|
||||
<script class="testbody" type="text/javascript">
|
||||
<![CDATA[
|
||||
addLoadEvent(function() {
|
||||
/** @see test_bug336682.js */
|
||||
MAX_STATE = 4;
|
||||
|
||||
function makeWindowHandler(eventName) {
|
||||
return function (aThis, aEvent) {
|
||||
var handler = makeHandler("<body on%1='...'>", eventName, [3,4]);
|
||||
handler(aEvent);
|
||||
}
|
||||
}
|
||||
|
||||
for each(var event in ["online", "offline"]) {
|
||||
document.documentElement.addEventListener(
|
||||
event,
|
||||
makeHandler("document.body.addEventListener('%1', ..., false)",
|
||||
event, [1]),
|
||||
false);
|
||||
|
||||
document.addEventListener(
|
||||
event,
|
||||
makeHandler("document.addEventListener('%1', ..., false)",
|
||||
event, [2]),
|
||||
false);
|
||||
|
||||
window["windowOn" + event] = makeWindowHandler(event);
|
||||
|
||||
window.addEventListener(
|
||||
event,
|
||||
makeHandler("window.addEventListener('%1', ..., false)",
|
||||
event, [3,4]),
|
||||
false);
|
||||
}
|
||||
|
||||
doTest();
|
||||
SimpleTest.finish();
|
||||
});
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
]]>
|
||||
</script>
|
||||
|
||||
</window>
|
Загрузка…
Ссылка в новой задаче