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

"use strict";

const TOPIC_BROWSERGLUE_TEST = "browser-glue-test";
const TOPICDATA_BROWSERGLUE_TEST = "force-ui-migration";

const gBrowserGlue = Cc["@mozilla.org/browser/browserglue;1"].getService(
  Ci.nsIObserver
);
const UI_VERSION = 124;

function ensureOldPrefsAreCleared() {
  Assert.ok(
    !Services.prefs.prefHasUserValue("extensions.formautofill.available"),
    "main module available pref should have been cleared"
  );
  Assert.ok(
    !Services.prefs.prefHasUserValue(
      "extensions.formautofill.creditCards.available"
    ),
    "old credit card available pref should have been cleared"
  );
}

add_task(async function setup() {
  registerCleanupFunction(() => {
    Services.prefs.clearUserPref("browser.migration.version");
    Services.prefs.clearUserPref("extensions.formautofill.available");
    Services.prefs.clearUserPref(
      "extensions.formautofill.creditCards.available"
    );
    Services.prefs.clearUserPref(
      "extensions.formautofill.creditCards.supported"
    );
  });
});

add_task(async function test_check_form_autofill_module_detect() {
  Services.prefs.setIntPref("browser.migration.version", UI_VERSION - 1);
  Services.prefs.setCharPref("extensions.formautofill.available", "detect");
  // Simulate a migration.
  gBrowserGlue.observe(
    null,
    TOPIC_BROWSERGLUE_TEST,
    TOPICDATA_BROWSERGLUE_TEST
  );
  // old credit card available should migrate to "detect" due to
  // "extensions.formautofill.available" being "detect".
  Assert.equal(
    Services.prefs.getCharPref("extensions.formautofill.creditCards.supported"),
    "detect"
  );
  // old address available pref follows the main module pref
  Assert.equal(
    Services.prefs.getCharPref("extensions.formautofill.addresses.supported"),
    "detect"
  );
  ensureOldPrefsAreCleared();
});

add_task(async function test_check_old_form_autofill_module_off() {
  Services.prefs.setIntPref("browser.migration.version", UI_VERSION - 1);
  Services.prefs.setCharPref("extensions.formautofill.available", "off");

  // Simulate a migration.
  gBrowserGlue.observe(
    null,
    TOPIC_BROWSERGLUE_TEST,
    TOPICDATA_BROWSERGLUE_TEST
  );

  // old credit card available should migrate to off due to
  // "extensions.formautofill.available" being off.
  Assert.equal(
    Services.prefs.getCharPref("extensions.formautofill.creditCards.supported"),
    "off"
  );
  // old address available pref follows the main module pref
  Assert.equal(
    Services.prefs.getCharPref("extensions.formautofill.addresses.supported"),
    "off"
  );
  ensureOldPrefsAreCleared();
});

add_task(async function test_check_old_form_autofill_module_on_cc_on() {
  Services.prefs.setIntPref("browser.migration.version", UI_VERSION - 1);
  Services.prefs.setCharPref("extensions.formautofill.available", "on");
  Services.prefs.setBoolPref(
    "extensions.formautofill.creditCards.available",
    true
  );

  // Simulate a migration.
  gBrowserGlue.observe(
    null,
    TOPIC_BROWSERGLUE_TEST,
    TOPICDATA_BROWSERGLUE_TEST
  );

  // old credit card available should migrate to "on" due to
  // "extensions.formautofill.available" being on and
  // "extensions.formautofill.creditCards.available" having a default value of true.
  Assert.equal(
    Services.prefs.getCharPref("extensions.formautofill.creditCards.supported"),
    "on"
  );
  // old address available pref follows the main module pref
  Assert.equal(
    Services.prefs.getCharPref("extensions.formautofill.addresses.supported"),
    "on"
  );
  ensureOldPrefsAreCleared();
});

add_task(async function test_check_old_form_autofill_module_on_cc_off() {
  Services.prefs.setIntPref("browser.migration.version", UI_VERSION - 1);
  Services.prefs.setCharPref("extensions.formautofill.available", "on");
  Services.prefs.setBoolPref(
    "extensions.formautofill.creditCards.available",
    false
  );

  // Simulate a migration.
  gBrowserGlue.observe(
    null,
    TOPIC_BROWSERGLUE_TEST,
    TOPICDATA_BROWSERGLUE_TEST
  );

  // old credit card available should migrate to "off" due to
  // "extensions.formautofill.available" being on and
  // "extensions.formautofill.creditCards.available" having a user set value of false.
  Assert.equal(
    Services.prefs.getCharPref("extensions.formautofill.creditCards.supported"),
    "off"
  );

  ensureOldPrefsAreCleared();
});