mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 01:48:05 +00:00
Bug 846458 - intermittent TEST-UNEXPECTED-PASS | /tests/content/base/test/test_bug548193.html | Assertion count 0 is less than expected range 1-1 assertions. (r=sstamm)
This commit is contained in:
parent
ffd5109d25
commit
e1ca908429
@ -1909,7 +1909,14 @@ CSPViolationReportListener.prototype = {
|
||||
function(request, context) { },
|
||||
|
||||
onDataAvailable:
|
||||
function(request, context, inputStream, offset, count) { },
|
||||
function(request, context, inputStream, offset, count) {
|
||||
// We MUST read equal to count from the inputStream to avoid an assertion.
|
||||
var input = Components.classes['@mozilla.org/scriptableinputstream;1']
|
||||
.createInstance(Ci.nsIScriptableInputStream);
|
||||
|
||||
input.init(inputStream);
|
||||
input.read(count);
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
|
@ -12,48 +12,45 @@
|
||||
|
||||
<iframe style="width:200px;height:200px;" id='cspframe'></iframe>
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
SimpleTest.expectAssertions(1);
|
||||
|
||||
// This is used to watch requests go out so we can see if the report is
|
||||
// sent correctly
|
||||
function examiner() {
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
var obsvc = Components.classes['@mozilla.org/observer-service;1']
|
||||
.getService(Components.interfaces.nsIObserverService);
|
||||
obsvc.addObserver(this, "http-on-modify-request", false);
|
||||
SpecialPowers.addObserver(this, "http-on-opening-request", false);
|
||||
}
|
||||
examiner.prototype = {
|
||||
observe: function(subject, topic, data) {
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
// subject should be an nsURI
|
||||
if(!subject.QueryInterface)
|
||||
if (!SpecialPowers.can_QI(subject))
|
||||
return;
|
||||
|
||||
const reportURI = "http://mochi.test:8888/csp-report.cgi";
|
||||
|
||||
if (topic === "http-on-modify-request") {
|
||||
var uri = subject.QueryInterface(Components.interfaces.nsIHttpChannel).URI;
|
||||
if (uri.asciiSpec !== reportURI) return;
|
||||
if (topic === "http-on-opening-request") {
|
||||
var asciiSpec = SpecialPowers.getPrivilegedProps(SpecialPowers.do_QueryInterface(subject, "nsIHttpChannel"), "URI.asciiSpec");
|
||||
if (asciiSpec !== reportURI) return;
|
||||
|
||||
// Verify that the report was properly formatted.
|
||||
// We'll parse the report text as JSON and verify that the properties
|
||||
// have expected values.
|
||||
var reportText = "{}";
|
||||
try {
|
||||
var uploadStream = subject.QueryInterface(Components.interfaces.nsIUploadChannel).uploadStream;
|
||||
var uploadStream = SpecialPowers.wrap(SpecialPowers.do_QueryInterface(subject, "nsIUploadChannel")).uploadStream;
|
||||
|
||||
if (uploadStream) {
|
||||
// get the bytes from the request body
|
||||
var binstream = Components.classes["@mozilla.org/binaryinputstream;1"]
|
||||
.createInstance(Components.interfaces.nsIBinaryInputStream);
|
||||
var binstream = SpecialPowers.Cc["@mozilla.org/binaryinputstream;1"]
|
||||
.createInstance(SpecialPowers.Ci.nsIBinaryInputStream);
|
||||
binstream.setInputStream(uploadStream);
|
||||
|
||||
var segments = [];
|
||||
for (var count = uploadStream.available(); count; count = uploadStream.available())
|
||||
segments.push(binstream.readBytes(count));
|
||||
for (var count = uploadStream.available(); count; count = uploadStream.available()) {
|
||||
var data = binstream.readBytes(count);
|
||||
segments.push(data);
|
||||
}
|
||||
|
||||
var reportText = segments.join("");
|
||||
// rewind stream as we are supposed to - there will be an assertion later if we don't.
|
||||
SpecialPowers.do_QueryInterface(uploadStream, "nsISeekableStream").seek(SpecialPowers.Ci.nsISeekableStream.NS_SEEK_SET, 0);
|
||||
}
|
||||
}
|
||||
catch(e) {}
|
||||
@ -71,10 +68,7 @@ examiner.prototype = {
|
||||
|
||||
// remove the listener
|
||||
remove: function() {
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
var obsvc = Components.classes['@mozilla.org/observer-service;1']
|
||||
.getService(Components.interfaces.nsIObserverService);
|
||||
obsvc.removeObserver(this, "http-on-modify-request");
|
||||
SpecialPowers.removeObserver(this, "http-on-opening-request");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user