Bug 702353 - Proof-of-concept on some pretty involved tests. r=ted

This commit is contained in:
Bobby Holley 2012-01-18 19:10:14 -08:00
parent 5e68024fa3
commit 52ddceaaa3
3 changed files with 22 additions and 29 deletions

View File

@ -21,21 +21,20 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=166235
<script type="application/javascript">
/** Test for Bug 166235 **/
var Cc = SpecialPowers.wrap(Components).classes;
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var webnav = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
var webnav = SpecialPowers.wrap(window).QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
var docShell = webnav.QueryInterface(Components.interfaces.nsIDocShell);
var documentViewer = docShell.contentViewer
.QueryInterface(Components.interfaces.nsIContentViewerEdit);
var clipboard = Components.classes["@mozilla.org/widget/clipboard;1"]
.getService(Components.interfaces.nsIClipboard);
var clipboard = Cc["@mozilla.org/widget/clipboard;1"]
.getService(Components.interfaces.nsIClipboard);
var textarea = document.getElementById('input');
var textarea = SpecialPowers.wrap(document).getElementById('input');
function copyChildrenToClipboard(id) {
textarea.blur();
@ -47,11 +46,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=166235
is(clipboard.hasDataMatchingFlavors(["text/html"], 1,1), true);
}
function getClipboardData(mime) {
var transferable = Components.classes['@mozilla.org/widget/transferable;1']
.createInstance(Components.interfaces.nsITransferable);
var transferable = Cc['@mozilla.org/widget/transferable;1']
.createInstance(Components.interfaces.nsITransferable);
transferable.addDataFlavor(mime);
clipboard.getData(transferable, 1);
var data = {};
var data = SpecialPowers.wrap({});
transferable.getTransferData(mime, data, {}) ;
return data;
}

View File

@ -19,27 +19,25 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=375314
/** Test for Bug 375314 **/
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var lastContentType = -1;
const testURL = window.location.href + "/this/is/the/test/url";
const Cc = Components.classes;
const Cc = SpecialPowers.wrap(Components).classes;
const Ci = Components.interfaces;
// Content policy / factory implementation for the test
var policyID = Components.ID("{b80e19d0-878f-d41b-2654-194714a4115c}");
var policyID = SpecialPowers.wrap(Components).ID("{b80e19d0-878f-d41b-2654-194714a4115c}");
var policyName = "@mozilla.org/testpolicy;1";
var policy = {
// nsISupports implementation
QueryInterface: function(iid) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
iid = SpecialPowers.wrap(iid);
if (iid.equals(Ci.nsISupports) ||
iid.equals(Ci.nsIFactory) ||
iid.equals(Ci.nsIContentPolicy))
return this;
throw Components.results.NS_ERROR_NO_INTERFACE;
throw SpecialPowers.wrap(Components).results.NS_ERROR_NO_INTERFACE;
},
// nsIFactory implementation
@ -49,10 +47,9 @@ var policy = {
// nsIContentPolicy implementation
shouldLoad: function(contentType, contentLocation, requestOrigin, context, mimeTypeGuess, extra) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
// Remember last content type seen for the test url
if (contentLocation.spec == testURL) {
if (SpecialPowers.wrap(contentLocation).spec == testURL) {
lastContentType = contentType;
return Ci.nsIContentPolicy.REJECT_REQUEST;
}
@ -61,15 +58,15 @@ var policy = {
},
shouldProcess: function(contentType, contentLocation, requestOrigin, context, mimeTypeGuess, extra) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
return Ci.nsIContentPolicy.ACCEPT;
}
}
// Register content policy
var componentManager = Components.manager
.QueryInterface(Ci.nsIComponentRegistrar);
var componentManager = SpecialPowers.wrap(Components).manager
.QueryInterface(Ci.nsIComponentRegistrar);
componentManager.registerFactory(policyID, "Test content policy", policyName, policy);
var categoryManager = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
@ -85,7 +82,6 @@ SimpleTest.waitForExplicitFinish();
setTimeout(runNextTest, 0);
function runNextTest() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
if (curTest >= 0) {
var type = "TYPE_" + tests[curTest];
@ -113,7 +109,6 @@ function runNextTest() {
setTimeout(function() {
// Component must be unregistered delayed, otherwise other content
// policy will not be removed from the category correctly
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
componentManager.unregisterFactory(policyID, policy);
}, 0);

View File

@ -23,17 +23,17 @@ function loadFileContent(aFile, aCharset) {
if(aCharset == undefined)
aCharset = 'UTF-8';
var baseUri = Components.classes['@mozilla.org/network/standard-url;1']
var baseUri = SpecialPowers.wrap(Components).classes['@mozilla.org/network/standard-url;1']
.createInstance(Components.interfaces.nsIURI);
baseUri.spec = window.location.href;
var ios = Components.classes['@mozilla.org/network/io-service;1']
var ios = SpecialPowers.wrap(Components).classes['@mozilla.org/network/io-service;1']
.getService(Components.interfaces.nsIIOService);
var chann = ios.newChannel(aFile, aCharset, baseUri);
var cis = Components.interfaces.nsIConverterInputStream;
var inputStream = Components.classes["@mozilla.org/intl/converter-input-stream;1"]
var inputStream = SpecialPowers.wrap(Components).classes["@mozilla.org/intl/converter-input-stream;1"]
.createInstance(cis);
inputStream.init(chann.open(), aCharset, 1024, cis.DEFAULT_REPLACEMENT_CHARACTER);
var str = {}, content = '';
@ -45,12 +45,11 @@ function loadFileContent(aFile, aCharset) {
function testHtmlSerializer_1 () {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const de = Components.interfaces.nsIDocumentEncoder
var encoder = Components.classes["@mozilla.org/layout/documentEncoder;1?type=application/xhtml+xml"]
var encoder = SpecialPowers.wrap(Components).classes["@mozilla.org/layout/documentEncoder;1?type=application/xhtml+xml"]
.createInstance(Components.interfaces.nsIDocumentEncoder);
var doc = $("testframe").contentDocument;
var doc = SpecialPowers.wrap($("testframe")).contentDocument;
var out, expected;
// in the following tests, we must use the OutputLFLineBreak flag, to avoid