DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (c68fe15a81fc)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
/* This Source Code Form is subject to the terms of the Mozilla Public
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/*
 * This file provides common and shared functionality to facilitate
 * This file provides common and shared functionality to facilitate
 * testing of the Crashes component (CrashManager.jsm).
 */

"use strict";


var EXPORTED_SYMBOLS = [
  "configureLogging",
  "getManager",
  "sleep",
  "TestingCrashManager",
  "TestingCrashManager",
];

ChromeUtils.import("resource://gre/modules/CrashManager.jsm", this);
ChromeUtils.import("resource://gre/modules/CrashManager.jsm", this);
ChromeUtils.import("resource://gre/modules/Log.jsm", this);
ChromeUtils.import("resource://gre/modules/Log.jsm", this);
ChromeUtils.import("resource://gre/modules/osfile.jsm", this);
ChromeUtils.import("resource://gre/modules/Timer.jsm", this);


var loggingConfigured = false;

var configureLogging = function() {
  if (loggingConfigured) {
  if (loggingConfigured) {
    return;
  }

  let log = Log.repository.getLogger("Crashes.CrashManager");
  log.level = Log.Level.All;
  log.level = Log.Level.All;
  let appender = new Log.DumpAppender();
  appender.level = Log.Level.All;
  log.addAppender(appender);
  loggingConfigured = true;
};
};

var sleep = function(wait) {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve();
      resolve();
    }, wait);
  });
};

var TestingCrashManager = function(options) {
  CrashManager.call(this, options);
};


TestingCrashManager.prototype = {
  __proto__: CrashManager.prototype,

  createDummyDump(submitted = false, date = new Date(), hr = false) {
  createDummyDump(submitted = false, date = new Date(), hr = false) {
    let uuid = Cc["@mozilla.org/uuid-generator;1"]
      .getService(Ci.nsIUUIDGenerator)
      .generateUUID()
      .toString();
    uuid = uuid.substring(1, uuid.length - 1);
    uuid = uuid.substring(1, uuid.length - 1);

    let path;
    let mode;
    if (submitted) {
      if (hr) {
      if (hr) {
        path = OS.Path.join(this._submittedDumpsDir, "bp-hr-" + uuid + ".txt");
      } else {
        path = OS.Path.join(this._submittedDumpsDir, "bp-" + uuid + ".txt");
      }
      mode =
      mode =
        OS.Constants.libc.S_IRUSR |
        OS.Constants.libc.S_IWUSR |
        OS.Constants.libc.S_IRGRP |
        OS.Constants.libc.S_IRGRP |
        OS.Constants.libc.S_IROTH;
    } else {
      path = OS.Path.join(this._pendingDumpsDir, uuid + ".dmp");
      mode = OS.Constants.libc.S_IRUSR | OS.Constants.libc.S_IWUSR;
    }
    }

    return (async function() {
      let f = await OS.File.open(path, { create: true }, { unixMode: mode });
      await f.setDates(date, date);
      await f.close();
      await f.close();
      dump("Created fake crash: " + path + "\n");

      return uuid;
    })();
  },
  },

  createIgnoredDumpFile(filename, submitted = false) {
    let path;
    if (submitted) {
      path = OS.Path.join(this._submittedDumpsDir, filename);
      path = OS.Path.join(this._submittedDumpsDir, filename);
    } else {
      path = OS.Path.join(this._pendingDumpsDir, filename);
    }

    return (async function() {
    return (async function() {
      let mode = OS.Constants.libc.S_IRUSR | OS.Constants.libc.S_IWUSR;
      await OS.File.open(path, { create: true }, { unixMode: mode });
      dump("Create ignored dump file: " + path + "\n");
    })();
  },
  },

  createEventsFile(filename, type, date, id, content, index = 0) {
    let path = OS.Path.join(this._eventsDirs[index], filename);
    let dateInSecs = Math.floor(date.getTime() / 1000);
    let data = type + "\n" + dateInSecs + "\n" + id + "\n" + content;
    let data = type + "\n" + dateInSecs + "\n" + id + "\n" + content;
    let encoder = new TextEncoder();
    let array = encoder.encode(data);

    return (async function() {
      await OS.File.writeAtomic(path, array);
      await OS.File.setDates(path, date, date);
    })();
    })();
  },

  /**
   * Overwrite event file handling to process our test file type.
   *
   *
   * We can probably delete this once we have actual events defined.
   */
  _handleEventFilePayload(store, entry, type, date, payload) {
    if (type == "test.1") {
      if (payload == "malformed") {
      if (payload == "malformed") {
        return this.EVENT_FILE_ERROR_MALFORMED;
      } else if (payload == "success") {
        return this.EVENT_FILE_SUCCESS;
      }
      return this.EVENT_FILE_ERROR_UNKNOWN_EVENT;
      return this.EVENT_FILE_ERROR_UNKNOWN_EVENT;
    }

    return CrashManager.prototype._handleEventFilePayload.call(
      this,
      store,
      store,
      entry,
      type,
      date,
      payload
    );
    );
  },
};


var DUMMY_DIR_COUNT = 0;
var DUMMY_DIR_COUNT = 0;

var getManager = function() {
  return (async function() {
  return (async function() {
    const dirMode = OS.Constants.libc.S_IRWXU;
    let baseFile = OS.Constants.Path.profileDir;

    function makeDir(create = true) {
      return (async function() {
        let path = OS.Path.join(baseFile, "dummy-dir-" + DUMMY_DIR_COUNT++);


        if (!create) {
          return path;
        }

        dump("Creating directory: " + path + "\n");
        dump("Creating directory: " + path + "\n");
        await OS.File.makeDir(path, { unixMode: dirMode });

        return path;
      })();
    }
    }

    let pendingD = await makeDir();
    let submittedD = await makeDir();
    let eventsD1 = await makeDir();
    let eventsD2 = await makeDir();
    let eventsD2 = await makeDir();

    // Store directory is created at run-time if needed. Ensure those code
    // paths are triggered.
    let storeD = await makeDir(false);

    let m = new TestingCrashManager({
      pendingDumpsDir: pendingD,
      pendingDumpsDir: pendingD,
      submittedDumpsDir: submittedD,
      eventsDirs: [eventsD1, eventsD2],
      storeDir: storeD,
      telemetryStoreSizeKey: "CRASH_STORE_COMPRESSED_BYTES",
    });
    });

    return m;
  })();
};