summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/update/tests/unit_aus_update/onlyDownloadUpdatesThisSession.js
blob: ab08ac854f9002e9b081fc7726b63bd12549a3d3 (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
/* 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/.
 */

"use strict";

function setup() {
  setupTestCommon();
  start_httpserver();
  setUpdateURL(gURLData + gHTTPHandlerPath);
  setUpdateChannel("test_channel");
}
setup();

/**
 * Checks for updates and makes sure that the update process does not proceed
 * beyond the downloading stage.
 */
async function downloadUpdate() {
  let patches = getRemotePatchString({});
  let updateString = getRemoteUpdateString({}, patches);
  gResponseBody = getRemoteUpdatesXMLString(updateString);

  let { updates } = await waitForUpdateCheck(true);

  initMockIncrementalDownload();
  gIncrementalDownloadErrorType = 3;

  let downloadRestrictionHitPromise = new Promise(resolve => {
    let downloadRestrictionHitListener = (subject, topic) => {
      Services.obs.removeObserver(downloadRestrictionHitListener, topic);
      resolve();
    };
    Services.obs.addObserver(
      downloadRestrictionHitListener,
      "update-download-restriction-hit"
    );
  });

  let bestUpdate = gAUS.selectUpdate(updates);
  let success = await gAUS.downloadUpdate(bestUpdate, false);
  Assert.ok(success, "Update download should have started");
  return downloadRestrictionHitPromise;
}

add_task(async function onlyDownloadUpdatesThisSession() {
  gAUS.onlyDownloadUpdatesThisSession = true;

  await downloadUpdate();

  Assert.ok(
    !gUpdateManager.readyUpdate,
    "There should not be a ready update. The update should still be downloading"
  );
  Assert.ok(
    !!gUpdateManager.downloadingUpdate,
    "A downloading update should exist"
  );
  Assert.equal(
    gUpdateManager.downloadingUpdate.state,
    STATE_DOWNLOADING,
    "The downloading update should still be in the downloading state"
  );
});

add_task(async function finish() {
  stop_httpserver(doTestFinish);
});