Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/services/sync/tests/unit/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 3 kB image not shown  

Quelle  test_prefs_tracker.js   Sprache: JAVA

 
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */


const { Service } = ChromeUtils.importESModule(
  "resource://services-sync/service.sys.mjs"
);

add_task(async function run_test() {
  let engine = Service.engineManager.get("prefs");
  let tracker = engine._tracker;

  try {
    _("tracker.modified corresponds to preference.");
    // Assert preference is not defined.
    Assert.equal(
      Svc.PrefBranch.getPrefType("engine.prefs.modified"),
      Ci.nsIPrefBranch.PREF_INVALID
    );
    Assert.ok(!tracker.modified);

    tracker.modified = true;
    Assert.equal(Svc.PrefBranch.getBoolPref("engine.prefs.modified"), true);
    Assert.ok(tracker.modified);

    _("Engine's getChangedID() just returns the one GUID we have.");
    let changedIDs = await engine.getChangedIDs();
    let ids = Object.keys(changedIDs);
    Assert.equal(ids.length, 1);
    Assert.equal(ids[0], CommonUtils.encodeBase64URL(Services.appinfo.ID));

    Svc.PrefBranch.setBoolPref("engine.prefs.modified"false);
    Assert.ok(!tracker.modified);

    _("No modified state, so no changed IDs.");
    do_check_empty(await engine.getChangedIDs());

    _("Initial score is 0");
    Assert.equal(tracker.score, 0);

    _("Test fixtures.");
    Svc.PrefBranch.setBoolPref("prefs.sync.testing.int"true);

    _(
      "Test fixtures haven't upped the tracker score yet because it hasn't started tracking yet."
    );
    Assert.equal(tracker.score, 0);

    _("Tell the tracker to start tracking changes.");
    tracker.start();
    Services.prefs.setIntPref("testing.int", 23);
    await tracker.asyncObserver.promiseObserversComplete();
    Assert.equal(tracker.score, SCORE_INCREMENT_XLARGE);
    Assert.equal(tracker.modified, true);

    _("Clearing changed IDs reset modified status.");
    await tracker.clearChangedIDs();
    Assert.equal(tracker.modified, false);

    _("Resetting a pref ups the score, too.");
    Services.prefs.clearUserPref("testing.int");
    await tracker.asyncObserver.promiseObserversComplete();
    Assert.equal(tracker.score, SCORE_INCREMENT_XLARGE * 2);
    Assert.equal(tracker.modified, true);
    await tracker.clearChangedIDs();

    _("So does changing a pref sync pref.");
    Svc.PrefBranch.setBoolPref("prefs.sync.testing.int"false);
    await tracker.asyncObserver.promiseObserversComplete();
    Assert.equal(tracker.score, SCORE_INCREMENT_XLARGE * 3);
    Assert.equal(tracker.modified, true);
    await tracker.clearChangedIDs();

    _(
      "Now that the pref sync pref has been flipped, changes to it won't be picked up."
    );
    Services.prefs.setIntPref("testing.int", 42);
    await tracker.asyncObserver.promiseObserversComplete();
    Assert.equal(tracker.score, SCORE_INCREMENT_XLARGE * 3);
    Assert.equal(tracker.modified, false);
    await tracker.clearChangedIDs();

    _("Changing some other random pref won't do anything.");
    Services.prefs.setStringPref("testing.other""blergh");
    await tracker.asyncObserver.promiseObserversComplete();
    Assert.equal(tracker.score, SCORE_INCREMENT_XLARGE * 3);
    Assert.equal(tracker.modified, false);
  } finally {
    await tracker.stop();
    for (const pref of Services.prefs.getChildList("")) {
      Services.prefs.clearUserPref(pref);
    }
  }
});

Messung V0.5
C=94 H=99 G=96

¤ Dauer der Verarbeitung: 0.1 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.