forked from mirrors/gecko-dev
		
	 dd1fce1d1a
			
		
	
	
		dd1fce1d1a
		
	
	
	
	
		
			
			The UIState.ON_UPDATE notification should be enough to reset the state of the panel every time the test is about to be executed. Wrong. In response to this notification, gSync.onActivityStop() is called, which disables the syncing animation immediately ONLY if it has been running for at least 1.5sec (which is almost never happening in tests), otherwise we get a setTimeout with the remaining time. When the sync animation is running, we also do not react to clicks (disabled), hence the test failing. We fix this by stopping the animation ourselves manually at the end of the test, so any subsequent test will start with a correct UI state. MozReview-Commit-ID: CrEb82Tw5SO --HG-- extra : rebase_source : da4822c9fb6f41e6fbfeec5a63086c43aeca7944
		
			
				
	
	
		
			91 lines
		
	
	
	
		
			2.7 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			91 lines
		
	
	
	
		
			2.7 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| /* 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";
 | |
| 
 | |
| let syncService = {};
 | |
| ChromeUtils.import("resource://services-sync/service.js", syncService);
 | |
| const service = syncService.Service;
 | |
| const {UIState} = ChromeUtils.import("resource://services-sync/UIState.jsm", {});
 | |
| 
 | |
| let getState;
 | |
| let originalSync;
 | |
| let syncWasCalled = false;
 | |
| 
 | |
| // TODO: This test should probably be re-written, we don't really test much here.
 | |
| add_task(async function testSyncRemoteTabsButtonFunctionality() {
 | |
|   info("Test the Sync Remote Tabs button in the panel");
 | |
|   storeInitialValues();
 | |
|   mockFunctions();
 | |
| 
 | |
|   // Force UI update.
 | |
|   Services.obs.notifyObservers(null, UIState.ON_UPDATE);
 | |
| 
 | |
|   // add the sync remote tabs button to the panel
 | |
|   CustomizableUI.addWidgetToArea("sync-button", CustomizableUI.AREA_FIXED_OVERFLOW_PANEL);
 | |
| 
 | |
|   await waitForOverflowButtonShown();
 | |
| 
 | |
|   // check the button's functionality
 | |
|   await document.getElementById("nav-bar").overflowable.show();
 | |
|   info("The panel menu was opened");
 | |
| 
 | |
|   let syncRemoteTabsBtn = document.getElementById("sync-button");
 | |
|   let remoteTabsPanel = document.getElementById("PanelUI-remotetabs");
 | |
|   let viewShown = BrowserTestUtils.waitForEvent(remoteTabsPanel, "ViewShown");
 | |
|   ok(syncRemoteTabsBtn, "The sync remote tabs button was added to the Panel Menu");
 | |
|   // click the button - the panel should open.
 | |
|   syncRemoteTabsBtn.click();
 | |
|   await viewShown;
 | |
|   ok(remoteTabsPanel.getAttribute("visible"), "Sync Panel is in view");
 | |
| 
 | |
|   // Find and click the "setup" button.
 | |
|   let syncNowButton = document.getElementById("PanelUI-remotetabs-syncnow");
 | |
|   syncNowButton.click();
 | |
|   info("The sync now button was clicked");
 | |
| 
 | |
|   await waitForCondition(() => syncWasCalled);
 | |
| 
 | |
|   // We need to stop the Syncing animation manually otherwise the button
 | |
|   // will be disabled at the beginning of a next test.
 | |
|   gSync._onActivityStop();
 | |
| });
 | |
| 
 | |
| add_task(async function asyncCleanup() {
 | |
|   // reset the panel UI to the default state
 | |
|   await resetCustomization();
 | |
|   ok(CustomizableUI.inDefaultState, "The panel UI is in default state again.");
 | |
| 
 | |
|   if (isOverflowOpen()) {
 | |
|     let panelHidePromise = promiseOverflowHidden(window);
 | |
|     PanelUI.overflowPanel.hidePopup();
 | |
|     await panelHidePromise;
 | |
|   }
 | |
| 
 | |
|   restoreValues();
 | |
| });
 | |
| 
 | |
| function mockFunctions() {
 | |
|   // mock UIState.get()
 | |
|   UIState.get = () => ({
 | |
|     status: UIState.STATUS_SIGNED_IN,
 | |
|     email: "user@mozilla.com"
 | |
|   });
 | |
| 
 | |
|   service.sync = mocked_sync;
 | |
| }
 | |
| 
 | |
| function mocked_sync() {
 | |
|   syncWasCalled = true;
 | |
| }
 | |
| 
 | |
| function restoreValues() {
 | |
|   UIState.get = getState;
 | |
|   service.sync = originalSync;
 | |
| }
 | |
| 
 | |
| function storeInitialValues() {
 | |
|   getState = UIState.get;
 | |
|   originalSync = service.sync;
 | |
| }
 |