summaryrefslogtreecommitdiffstats
path: root/browser/components/downloads/test/browser/browser_confirm_unblock_download.js
blob: d88fa9a0e578b2b0abb87e6d5a20838902e22826 (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
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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Tests the dialog which allows the user to unblock a downloaded file.

registerCleanupFunction(() => {});

async function assertDialogResult({ args, buttonToClick, expectedResult }) {
  let promise = BrowserTestUtils.promiseAlertDialog(buttonToClick);
  is(
    await DownloadsCommon.confirmUnblockDownload(args),
    expectedResult,
    `Expect ${expectedResult} from ${buttonToClick}`
  );
  await promise;
}

/**
 * Tests the "unblock" dialog, for each of the possible verdicts.
 */
add_task(async function test_unblock_dialog_unblock() {
  for (let verdict of [
    Downloads.Error.BLOCK_VERDICT_MALWARE,
    Downloads.Error.BLOCK_VERDICT_POTENTIALLY_UNWANTED,
    Downloads.Error.BLOCK_VERDICT_INSECURE,
    Downloads.Error.BLOCK_VERDICT_UNCOMMON,
  ]) {
    let args = { verdict, window, dialogType: "unblock" };

    // Test both buttons.
    await assertDialogResult({
      args,
      buttonToClick: "accept",
      expectedResult: "unblock",
    });
    await assertDialogResult({
      args,
      buttonToClick: "cancel",
      expectedResult: "cancel",
    });
  }
});

/**
 * Tests the "chooseUnblock" dialog for potentially unwanted downloads.
 */
add_task(async function test_chooseUnblock_dialog() {
  for (let verdict of [
    Downloads.Error.BLOCK_VERDICT_POTENTIALLY_UNWANTED,
    Downloads.Error.BLOCK_VERDICT_INSECURE,
  ]) {
    let args = {
      verdict,
      window,
      dialogType: "chooseUnblock",
    };

    // Test each of the three buttons.
    await assertDialogResult({
      args,
      buttonToClick: "accept",
      expectedResult: "unblock",
    });
    await assertDialogResult({
      args,
      buttonToClick: "cancel",
      expectedResult: "cancel",
    });
    await assertDialogResult({
      args,
      buttonToClick: "extra1",
      expectedResult: "confirmBlock",
    });
  }
});

/**
 * Tests the "chooseOpen" dialog for uncommon downloads.
 */
add_task(async function test_chooseOpen_dialog() {
  for (let verdict of [
    Downloads.Error.BLOCK_VERDICT_UNCOMMON,
    Downloads.Error.BLOCK_VERDICT_INSECURE,
  ]) {
    let args = {
      verdict,
      window,
      dialogType: "chooseOpen",
    };

    // Test each of the three buttons.
    await assertDialogResult({
      args,
      buttonToClick: "accept",
      expectedResult: "open",
    });
    await assertDialogResult({
      args,
      buttonToClick: "cancel",
      expectedResult: "cancel",
    });
    await assertDialogResult({
      args,
      buttonToClick: "extra1",
      expectedResult: "confirmBlock",
    });
  }
});