diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /browser/modules/test/browser_BrowserUITelemetry_syncedtabs.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'browser/modules/test/browser_BrowserUITelemetry_syncedtabs.js')
-rw-r--r-- | browser/modules/test/browser_BrowserUITelemetry_syncedtabs.js | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/browser/modules/test/browser_BrowserUITelemetry_syncedtabs.js b/browser/modules/test/browser_BrowserUITelemetry_syncedtabs.js new file mode 100644 index 000000000..d3e1eac57 --- /dev/null +++ b/browser/modules/test/browser_BrowserUITelemetry_syncedtabs.js @@ -0,0 +1,114 @@ +// Test the SyncedTabs counters in BrowserUITelemetry. +"use strict"; + +const { BrowserUITelemetry: BUIT } = Cu.import("resource:///modules/BrowserUITelemetry.jsm", {}); +const {SyncedTabs} = Cu.import("resource://services-sync/SyncedTabs.jsm", {}); + +function mockSyncedTabs() { + // Mock SyncedTabs.jsm + let mockedInternal = { + get isConfiguredToSyncTabs() { return true; }, + getTabClients() { + return Promise.resolve([ + { + id: "guid_desktop", + type: "client", + name: "My Desktop", + tabs: [ + { + title: "http://example.com/10", + lastUsed: 10, // the most recent + }, + ], + } + ]); + }, + syncTabs() { + return Promise.resolve(); + }, + hasSyncedThisSession: true, + }; + + let oldInternal = SyncedTabs._internal; + SyncedTabs._internal = mockedInternal; + + // configure our broadcasters so we are in the right state. + document.getElementById("sync-reauth-state").hidden = true; + document.getElementById("sync-setup-state").hidden = true; + document.getElementById("sync-syncnow-state").hidden = false; + + registerCleanupFunction(() => { + SyncedTabs._internal = oldInternal; + + document.getElementById("sync-reauth-state").hidden = true; + document.getElementById("sync-setup-state").hidden = false; + document.getElementById("sync-syncnow-state").hidden = true; + }); +} + +mockSyncedTabs(); + +function promiseTabsUpdated() { + return new Promise(resolve => { + Services.obs.addObserver(function onNotification(aSubject, aTopic, aData) { + Services.obs.removeObserver(onNotification, aTopic); + resolve(); + }, "synced-tabs-menu:test:tabs-updated", false); + }); +} + +add_task(function* test_menu() { + // Reset BrowserUITelemetry's world. + BUIT._countableEvents = {}; + + let tabsUpdated = promiseTabsUpdated(); + + // check the button's functionality + yield PanelUI.show(); + + let syncButton = document.getElementById("sync-button"); + syncButton.click(); + + yield tabsUpdated; + // Get our 1 tab and click on it. + let tabList = document.getElementById("PanelUI-remotetabs-tabslist"); + let tabEntry = tabList.firstChild.nextSibling; + tabEntry.click(); + + let counts = BUIT._countableEvents[BUIT.currentBucket]; + Assert.deepEqual(counts, { + "click-builtin-item": { "sync-button": { left: 1 } }, + "synced-tabs": { open: { "toolbarbutton-subview": 1 } }, + }); +}); + +add_task(function* test_sidebar() { + // Reset BrowserUITelemetry's world. + BUIT._countableEvents = {}; + + yield SidebarUI.show('viewTabsSidebar'); + + let syncedTabsDeckComponent = SidebarUI.browser.contentWindow.syncedTabsDeckComponent; + + syncedTabsDeckComponent._accountStatus = () => Promise.resolve(true); + + // Once the tabs container has been selected (which here means "'selected' + // added to the class list") we are ready to test. + let container = SidebarUI.browser.contentDocument.querySelector(".tabs-container"); + let promiseUpdated = BrowserTestUtils.waitForAttribute("class", container); + + yield syncedTabsDeckComponent.updatePanel(); + yield promiseUpdated; + + let selectedPanel = syncedTabsDeckComponent.container.querySelector(".sync-state.selected"); + let tab = selectedPanel.querySelector(".tab"); + tab.click(); + let counts = BUIT._countableEvents[BUIT.currentBucket]; + Assert.deepEqual(counts, { + sidebar: { + viewTabsSidebar: { show: 1 }, + }, + "synced-tabs": { open: { sidebar: 1 } } + }); + yield SidebarUI.hide(); +}); |