Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 


Quelle  test_image.html   Sprache: HTML

 
 products/Sources/formale Sprachen/C/Firefox/toolkit/components/alerts/test/chrome/test_image.html


<!DOCTYPE HTML>
<html>
<head>
  <title>Test for Bug 1233086</title>
  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
</head>

<body>
<p id="display"></p>

<pre id="test">
<script class="testbody" type="text/javascript">

const Cc = SpecialPowers.Cc;
const Ci = SpecialPowers.Ci;
const Services = SpecialPowers.Services;

const imageServerURL = "http://mochi.test:8888/chrome/toolkit/components/alerts/test/chrome/image_server.sjs";

function makeAlert(...params) {
  var alert = Cc["@mozilla.org/alert-notification;1"]
                .createInstance(Ci.nsIAlertNotification);
  alert.init(...params);
  return alert;
}

function promiseImage(alert, timeout = 0, userData = null) {
  return new Promise(resolve => {
    var isDone = false;
    function done(value) {
      ok(!isDone, "Should call the image listener once");
      isDone = true;
      resolve(value);
    }
    alert.loadImage(timeout, SpecialPowers.wrapCallbackObject({
      onImageReady(aUserData, aRequest) {
        done([true, aRequest, aUserData]);
      },
      onImageMissing(aUserData) {
        done([false, aUserData]);
      },
    }), SpecialPowers.wrap(userData));
  });
}

add_task(async function testContext() {
  var inUserData = Cc["@mozilla.org/supports-PRInt64;1"]
                     .createInstance(Ci.nsISupportsPRInt64);
  inUserData.data = 123;

  var alert = makeAlert(null, imageServerURL + "?f=image.png");
  var [ready, , userData] = await promiseImage(alert, 0, inUserData);
  ok(ready, "Should load requested image");
  is(userData.QueryInterface(Ci.nsISupportsPRInt64).data, 123,
     "Should pass user data for loaded image");

  alert = makeAlert(null, imageServerURL + "?s=404");
  [ready, userData] = await promiseImage(alert, 0, inUserData);
  ok(!ready, "Should not load missing image");
  is(userData.QueryInterface(Ci.nsISupportsPRInt64).data, 123,
     "Should pass user data for missing image");
});

add_task(async function testTimeout() {
  var alert = makeAlert(null, imageServerURL + "?f=image.png&t=3");
  var [ready] = await promiseImage(alert, 1000);
  ok(!ready, "Should cancel request if timeout fires");

  [ready] = await promiseImage(alert, 45000);
  ok(ready, "Should load image if request finishes before timeout");
});

add_task(async function testAnimatedGIF() {
  var alert = makeAlert(null, imageServerURL + "?f=image.gif");
  var [ready, request] = await promiseImage(alert);
  ok(ready, "Should load first animated GIF frame");
  is(request.mimeType, "image/gif""Should report correct GIF MIME type");
  is(request.image.width, 256, "GIF width should be 256px");
  is(request.image.height, 256, "GIF height should be 256px");
});

add_task(async function testCancel() {
  var alert = makeAlert(null, imageServerURL + "?f=image.gif&t=180");
  await new Promise((resolve, reject) => {
    var request = alert.loadImage(0, SpecialPowers.wrapCallbackObject({
      onImageReady() {
        reject(new Error("Should not load cancelled request"));
      },
      onImageMissing() {
        resolve();
      },
    }), null);
    request.cancel(SpecialPowers.Cr.NS_BINDING_ABORTED);
  });
});

add_task(async function testMixedContent() {
  // Loading principal is HTTPS; image URL is HTTP.
  var origin = "https://mochi.test:8888";
  var principal = Services.scriptSecurityManager
                          .createContentPrincipalFromOrigin(origin);

  var alert = makeAlert(null, imageServerURL + "?f=image.png",
                        null, null, false, null, null, null,
                        null, principal);
  var [ready, request] = await promiseImage(alert);
  ok(ready, "Should load cross-protocol image");
  is(request.mimeType, "image/png""Should report correct MIME type");
  is(request.image.width, 32, "Width should be 32px");
  is(request.image.height, 32, "Height should be 32px");
});

</script>
</pre>
</body>
</html>

Messung V0.5
C=100 H=100 G=100

¤ Dauer der Verarbeitung: 0.3 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Produkte
     Quellcodebibliothek

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Monitoring

Montastic status badge