Bug 702353 - Proof-of-concept on some pretty involved tests. r=ted
authorBobby Holley <bobbyholley@gmail.com>
Wed, 18 Jan 2012 19:10:14 -0800
changeset 86082 a904454ebfbbec94690d601e0bf99239172c822c
parent 86081 679b3a8d94c198d99e0fe5ffd3909386d49887f4
child 86083 8af1f1a4d79f7806f162c7d7abbcc1bf98f1796a
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs702353
milestone12.0a1
Bug 702353 - Proof-of-concept on some pretty involved tests. r=ted
content/base/test/test_bug166235.html
content/base/test/test_bug375314.html
content/base/test/test_bug422403-1.html
--- a/content/base/test/test_bug166235.html
+++ b/content/base/test/test_bug166235.html
@@ -16,47 +16,46 @@ https://bugzilla.mozilla.org/show_bug.cg
 <div id="content" style="display: none">
   
 </div>
 <textarea id="input"></textarea>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 166235 **/
-
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+  var Cc = SpecialPowers.wrap(Components).classes;
 
-  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();
     clipboard.emptyClipboard(1);
     window.getSelection().selectAllChildren(document.getElementById(id));
     documentViewer.copySelection();
 
     is(clipboard.hasDataMatchingFlavors(["text/unicode"], 1,1), true);
     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;
   }
   function testClipboardValue(mime, expected, test) {
     var data = getClipboardData(mime);
     is (data.value == null ? data.value :
         data.value.QueryInterface(Components.interfaces.nsISupportsString).data,
       expected,
--- a/content/base/test/test_bug375314.html
+++ b/content/base/test/test_bug375314.html
@@ -14,83 +14,79 @@ https://bugzilla.mozilla.org/show_bug.cg
 <div id="content" style="display: none">
   
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 /** 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
   createInstance: function(outer, iid) {
     return this.QueryInterface(iid);
   },
 
   // 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;
     }
 
     return Ci.nsIContentPolicy.ACCEPT;
   },
 
   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);
 categoryManager.addCategoryEntry("content-policy", policyName, policyName, false, true);
 
 // Try creating different request types
 var tests = ["SCRIPT", "IMAGE", "STYLESHEET", "OBJECT", "DOCUMENT", "SUBDOCUMENT", "XBL", "XMLHTTPREQUEST"];
 var curTest = -1;
 
 var div;
 
 SimpleTest.waitForExplicitFinish();
 setTimeout(runNextTest, 0);
 
 function runNextTest() {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
 
   if (curTest >= 0) {
     var type = "TYPE_" + tests[curTest];
     is(lastContentType, Ci.nsIContentPolicy[type], "Content policies triggered for " + type);
 
     if (tests[curTest] == "XBL")
     {
       //XXX Removing binding to work-around a memory leak (bugs 478528, 499735).
@@ -108,17 +104,16 @@ function runNextTest() {
   }
   else {
     // Unregister content policy
     categoryManager.deleteCategoryEntry("content-policy", policyName, false);
 
     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);
 
     SimpleTest.finish();
   }
 }
 
 // Request creating functions
--- a/content/base/test/test_bug422403-1.html
+++ b/content/base/test/test_bug422403-1.html
@@ -18,44 +18,43 @@
 <script class="testbody" type="text/javascript">
 
 
 function loadFileContent(aFile, aCharset) {
     //if(aAsIso == undefined) aAsIso = false;
     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 = '';
     while (inputStream.readString(4096, str) != 0) {
         content += str.value;
     }
     return content;
 }
 
 
 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
   // to have the default line break of the platform in the result, so the test
   // can pass on all platform
 
   //------------ no flags
   encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak);