summaryrefslogtreecommitdiffstats
path: root/browser/components/customizableui/test/browser_987185_syncButton.js
blob: 988d738be4b8e48eb4fabc99ad483aab94ea3dc9 (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
/* 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";

var syncService = {};
Components.utils.import("resource://services-sync/service.js", syncService);

var needsSetup;
var originalSync;
var service = syncService.Service;
var syncWasCalled = false;

add_task(function* testSyncButtonFunctionality() {
  info("Check Sync button functionality");
  storeInitialValues();
  mockFunctions();

  // add the Sync button to the panel
  CustomizableUI.addWidgetToArea("sync-button", CustomizableUI.AREA_PANEL);

  // check the button's functionality
  yield PanelUI.show();
  info("The panel menu was opened");

  let syncButton = document.getElementById("sync-button");
  ok(syncButton, "The Sync button was added to the Panel Menu");
  // click the button - the panel should open.
  syncButton.click();
  let syncPanel = document.getElementById("PanelUI-remotetabs");
  ok(syncPanel.getAttribute("current"), "Sync Panel is in view");

  // Find and click the "setup" button.
  let syncNowButton = document.getElementById("PanelUI-remotetabs-syncnow");
  syncNowButton.click();

  info("The sync button was clicked");

  yield waitForCondition(() => syncWasCalled);
});

add_task(function* asyncCleanup() {
  // reset the panel UI to the default state
  yield resetCustomization();
  ok(CustomizableUI.inDefaultState, "The panel UI is in default state again.");

  if (isPanelUIOpen()) {
    let panelHidePromise = promisePanelHidden(window);
    PanelUI.hide();
    yield panelHidePromise;
  }

  restoreValues();
});

function mockFunctions() {
  // mock needsSetup
  gSyncUI._needsSetup = () => Promise.resolve(false);

  // mock service.errorHandler.syncAndReportErrors()
  service.errorHandler.syncAndReportErrors = mocked_syncAndReportErrors;
}

function mocked_syncAndReportErrors() {
  syncWasCalled = true;
}

function restoreValues() {
  gSyncUI._needsSetup = needsSetup;
  service.sync = originalSync;
}

function storeInitialValues() {
  needsSetup = gSyncUI._needsSetup;
  originalSync = service.sync;
}