summaryrefslogtreecommitdiffstats
path: root/browser/components/uitour/test/browser_UITour_sync.js
blob: 14ac0c1f684df1e5d95fb27bb55882595cc3bee3 (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
"use strict";

var gTestTab;
var gContentAPI;
var gContentWindow;

registerCleanupFunction(function() {
  Services.prefs.clearUserPref("services.sync.username");
});

add_task(setup_UITourTest);

add_UITour_task(function* test_checkSyncSetup_disabled() {
  let result = yield getConfigurationPromise("sync");
  is(result.setup, false, "Sync shouldn't be setup by default");
});

add_UITour_task(function* test_checkSyncSetup_enabled() {
  Services.prefs.setCharPref("services.sync.username", "uitour@tests.mozilla.org");
  let result = yield getConfigurationPromise("sync");
  is(result.setup, true, "Sync should be setup");
});

add_UITour_task(function* test_checkSyncCounts() {
  Services.prefs.setIntPref("services.sync.clients.devices.desktop", 4);
  Services.prefs.setIntPref("services.sync.clients.devices.mobile", 5);
  Services.prefs.setIntPref("services.sync.numClients", 9);
  let result = yield getConfigurationPromise("sync");
  is(result.mobileDevices, 5, "mobileDevices should be set");
  is(result.desktopDevices, 4, "desktopDevices should be set");
  is(result.totalDevices, 9, "totalDevices should be set");

  Services.prefs.clearUserPref("services.sync.clients.devices.desktop");
  result = yield getConfigurationPromise("sync");
  is(result.mobileDevices, 5, "mobileDevices should be set");
  is(result.desktopDevices, 0, "desktopDevices should be 0");
  is(result.totalDevices, 9, "totalDevices should be set");

  Services.prefs.clearUserPref("services.sync.clients.devices.mobile");
  result = yield getConfigurationPromise("sync");
  is(result.mobileDevices, 0, "mobileDevices should be 0");
  is(result.desktopDevices, 0, "desktopDevices should be 0");
  is(result.totalDevices, 9, "totalDevices should be set");

  Services.prefs.clearUserPref("services.sync.numClients");
  result = yield getConfigurationPromise("sync");
  is(result.mobileDevices, 0, "mobileDevices should be 0");
  is(result.desktopDevices, 0, "desktopDevices should be 0");
  is(result.totalDevices, 0, "totalDevices should be 0");
});

// The showFirefoxAccounts API is sync related, so we test that here too...
add_UITour_task(function* test_firefoxAccountsNoParams() {
  yield gContentAPI.showFirefoxAccounts();
  yield BrowserTestUtils.browserLoaded(gTestTab.linkedBrowser, false,
                                       "about:accounts?action=signup&entrypoint=uitour");
});

add_UITour_task(function* test_firefoxAccountsValidParams() {
  yield gContentAPI.showFirefoxAccounts({ utm_foo: "foo", utm_bar: "bar" });
  yield BrowserTestUtils.browserLoaded(gTestTab.linkedBrowser, false,
                                       "about:accounts?action=signup&entrypoint=uitour&utm_foo=foo&utm_bar=bar");
});

add_UITour_task(function* test_firefoxAccountsNonAlphaValue() {
  // All characters in the value are allowed, but they must be automatically escaped.
  // (we throw a unicode character in there too - it's not auto-utf8 encoded,
  // but that's ok, so long as it is escaped correctly.)
  let value = "foo& /=?:\\\xa9";
  // encodeURIComponent encodes spaces to %20 but we want "+"
  let expected = encodeURIComponent(value).replace(/%20/g, "+");
  yield gContentAPI.showFirefoxAccounts({ utm_foo: value });
  yield BrowserTestUtils.browserLoaded(gTestTab.linkedBrowser, false,
                                       "about:accounts?action=signup&entrypoint=uitour&utm_foo=" + expected);
});

// A helper to check the request was ignored due to invalid params.
function* checkAboutAccountsNotLoaded() {
  try {
    yield waitForConditionPromise(() => {
      return gBrowser.selectedBrowser.currentURI.spec.startsWith("about:accounts");
    }, "Check if about:accounts opened");
    ok(false, "No about:accounts tab should have opened");
  } catch (ex) {
    ok(true, "No about:accounts tab opened");
  }
}

add_UITour_task(function* test_firefoxAccountsNonObject() {
  // non-string should be rejected.
  yield gContentAPI.showFirefoxAccounts(99);
  yield checkAboutAccountsNotLoaded();
});

add_UITour_task(function* test_firefoxAccountsNonUtmPrefix() {
  // Any non "utm_" name should should be rejected.
  yield gContentAPI.showFirefoxAccounts({ utm_foo: "foo", bar: "bar" });
  yield checkAboutAccountsNotLoaded();
});

add_UITour_task(function* test_firefoxAccountsNonAlphaName() {
  // Any "utm_" name which includes non-alpha chars should be rejected.
  yield gContentAPI.showFirefoxAccounts({ utm_foo: "foo", "utm_bar=": "bar" });
  yield checkAboutAccountsNotLoaded();
});