content/base/test/test_bug498897.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/test/test_bug498897.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,95 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=498897
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 498897</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.13 +</head>
    1.14 +<body>
    1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=498897">Mozilla Bug 498897</a>
    1.16 +<p id="display"><iframe id="testframe"></iframe></p>
    1.17 +<div id="content" style="display: none">
    1.18 +  
    1.19 +</div>
    1.20 +<pre id="test">
    1.21 +<script type="application/javascript">
    1.22 +
    1.23 +/** Test for Bug 498897 **/
    1.24 +
    1.25 +var checkedLoad = false;
    1.26 +
    1.27 +const Cc = SpecialPowers.Cc;
    1.28 +const Ci = SpecialPowers.Ci;
    1.29 +
    1.30 +// Content policy / factory implementation for the test
    1.31 +var policyID = SpecialPowers.wrap(SpecialPowers.Components).ID("{65944d64-2390-422e-bea3-80d0af7f69ef}");
    1.32 +var policyName = "@mozilla.org/498897_testpolicy;1";
    1.33 +var policy = {
    1.34 +  // nsISupports implementation
    1.35 +  QueryInterface: function(iid) {
    1.36 +    if (iid.equals(Ci.nsISupports) ||
    1.37 +        iid.equals(Ci.nsIFactory) ||
    1.38 +        iid.equals(Ci.nsIContentPolicy))
    1.39 +      return this;
    1.40 +
    1.41 +    throw SpecialPowers.Cr.NS_ERROR_NO_INTERFACE;
    1.42 +  },
    1.43 +
    1.44 +  // nsIFactory implementation
    1.45 +  createInstance: function(outer, iid) {
    1.46 +    return this.QueryInterface(iid);
    1.47 +  },
    1.48 +
    1.49 +  // nsIContentPolicy implementation
    1.50 +  shouldLoad: function(contentType, contentLocation, requestOrigin, context,
    1.51 +                       mimeTypeGuess, extra) {
    1.52 +    var url = window.location.href.substr(0, window.location.href.indexOf('test_bug498897'));
    1.53 +    if (contentLocation.spec == url + "file_bug498897.css" &&
    1.54 +        requestOrigin.spec == url + "file_bug498897.html") {
    1.55 +      checkedLoad = true;
    1.56 +    }
    1.57 +
    1.58 +    return Ci.nsIContentPolicy.ACCEPT;
    1.59 +  },
    1.60 +
    1.61 +  shouldProcess: function(contentType, contentLocation, requestOrigin, context,
    1.62 +                          mimeTypeGuess, extra) {
    1.63 +    return Ci.nsIContentPolicy.ACCEPT;
    1.64 +  }
    1.65 +}
    1.66 +policy = SpecialPowers.wrapCallbackObject(policy);
    1.67 +
    1.68 +var componentManager = SpecialPowers.wrap(SpecialPowers.Components).manager
    1.69 +                                 .QueryInterface(Ci.nsIComponentRegistrar);
    1.70 +componentManager.registerFactory(policyID, "Test content policy for bug 498897",
    1.71 +                                 policyName, policy);
    1.72 +
    1.73 +var categoryManager =
    1.74 +  Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
    1.75 +categoryManager.addCategoryEntry("content-policy", policyName, policyName,
    1.76 +                                 false, true);
    1.77 +
    1.78 +function testFinished()
    1.79 +{
    1.80 +  ok(checkedLoad, "Content policy didn't get called!");
    1.81 +
    1.82 +  categoryManager.deleteCategoryEntry("content-policy", policyName, false);
    1.83 +
    1.84 +  setTimeout(function() {
    1.85 +    componentManager.unregisterFactory(policyID, policy);
    1.86 +
    1.87 +    SimpleTest.finish();
    1.88 +  }, 0);
    1.89 +}
    1.90 +
    1.91 +SimpleTest.waitForExplicitFinish();
    1.92 +
    1.93 +document.getElementById("testframe").src = "file_bug498897.html";
    1.94 +
    1.95 +</script>
    1.96 +</pre>
    1.97 +</body>
    1.98 +</html>

mercurial