summaryrefslogtreecommitdiffstats
path: root/devtools/client/aboutdebugging/test/browser/mocks/helper-runtime-client-factory-mock.js
blob: b74c229fcf57875093e9bcbb64cc9d77a3b95968 (plain)
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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Setup the loader to return the provided mock object instead of the regular
 * runtime-client-factory module.
 *
 * @param {Object}
 *        mock should implement the following methods:
 *        - createClientForRuntime(runtime)
 */
function enableRuntimeClientFactoryMock(mock) {
  const {
    setMockedModule,
  } = require("resource://devtools/shared/loader/browser-loader-mocks.js");
  setMockedModule(
    mock,
    "devtools/client/aboutdebugging/src/modules/runtime-client-factory"
  );

  // When using a mocked client, we should not attempt to check default
  // preferences.
  mockRuntimeDefaultPreferences();
}
/* exported enableRuntimeClientFactoryMock */

const mockRuntimeDefaultPreferences = function () {
  const {
    removeMockedModule,
    setMockedModule,
  } = require("resource://devtools/shared/loader/browser-loader-mocks.js");

  const mock = {
    setDefaultPreferencesIfNeeded: () => {},
    DEFAULT_PREFERENCES: [],
  };
  setMockedModule(
    mock,
    "devtools/client/aboutdebugging/src/modules/runtime-default-preferences"
  );

  registerCleanupFunction(() => {
    removeMockedModule(
      "devtools/client/aboutdebugging/src/modules/runtime-default-preferences"
    );
  });
};

/**
 * Update the loader to clear the mock entry for the runtime-client-factory module.
 */
function disableRuntimeClientFactoryMock() {
  const {
    removeMockedModule,
  } = require("resource://devtools/shared/loader/browser-loader-mocks.js");
  removeMockedModule(
    "devtools/client/aboutdebugging/src/modules/runtime-client-factory"
  );
}
/* exported disableRuntimeClientFactoryMock */

/**
 * Creates a simple mock version for runtime-client-factory, implementing all the expected
 * methods with empty placeholders.
 */
function createRuntimeClientFactoryMock() {
  const RuntimeClientFactoryMock = {};
  RuntimeClientFactoryMock.createClientForRuntime = function (runtime) {
    console.log("MOCKED METHOD createClientForRuntime");
  };

  return RuntimeClientFactoryMock;
}
/* exported createRuntimeClientFactoryMock */