mirror of
https://github.com/zen-browser/desktop.git
synced 2026-04-28 10:14:12 +00:00
test: Fixed workspace bookmarks tests and added new ones for workspace titles, b=closes #9900, c=workspaces, tests
This commit is contained in:
@@ -14,6 +14,7 @@ support-files = [
|
||||
["browser_overflow_scrollbox.js"]
|
||||
|
||||
["browser_issue_8699.js"]
|
||||
["browser_issue_9900.js"]
|
||||
|
||||
["browser_private_mode.js"]
|
||||
["browser_private_mode_startup.js"]
|
||||
|
||||
@@ -7,6 +7,7 @@ add_task(async function test_Restore_Closed_Tabs() {
|
||||
const currentTab = BrowserTestUtils.addTab(window.gBrowser, 'https://example.com/current', {
|
||||
skipAnimation: true,
|
||||
});
|
||||
const tabsToIgnore = gBrowser.tabs;
|
||||
BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||
const tabsToClose = [];
|
||||
for (let i = 0; i < 3; i++) {
|
||||
@@ -44,7 +45,7 @@ add_task(async function test_Restore_Closed_Tabs() {
|
||||
gBrowser.selectedTab = currentTab;
|
||||
resolve();
|
||||
});
|
||||
for (const tab of gBrowser.tabs.filter((t) => t !== currentTab)) {
|
||||
for (const tab of gBrowser.tabs.filter((t) => !tabsToIgnore.includes(t))) {
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
}
|
||||
});
|
||||
|
||||
37
src/zen/tests/workspaces/browser_issue_9900.js
Normal file
37
src/zen/tests/workspaces/browser_issue_9900.js
Normal file
@@ -0,0 +1,37 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
https://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
'use strict';
|
||||
|
||||
add_task(async function test_Invalid_Workspace_Name() {
|
||||
const fakeWorkspace = {
|
||||
name: '',
|
||||
};
|
||||
const icon = gZenWorkspaces.getWorkspaceIcon(fakeWorkspace);
|
||||
Assert.equal(icon, fakeWorkspace.icon, 'Test should not have crashed');
|
||||
});
|
||||
|
||||
add_task(async function test_Invalid_Workspace_Emoji() {
|
||||
const fakeWorkspace = {
|
||||
name: '👍 test test',
|
||||
};
|
||||
const icon = gZenWorkspaces.getWorkspaceIcon(fakeWorkspace);
|
||||
Assert.equal(icon, '👍', 'Emoji icon should match the first character of the workspace name');
|
||||
});
|
||||
|
||||
add_task(async function test_Invalid_Workspace_Name() {
|
||||
const fakeWorkspace = {
|
||||
name: 'my workspace',
|
||||
};
|
||||
const icon = gZenWorkspaces.getWorkspaceIcon(fakeWorkspace);
|
||||
Assert.equal(icon, 'M', 'Icon should match the first character of the workspace name');
|
||||
});
|
||||
|
||||
add_task(async function test_Invalid_Workspace_Name() {
|
||||
const fakeWorkspace = {
|
||||
name: 'my workspace',
|
||||
icon: '👍',
|
||||
};
|
||||
const icon = gZenWorkspaces.getWorkspaceIcon(fakeWorkspace);
|
||||
Assert.equal(icon, '👍', 'Icon should be from the workspace icon');
|
||||
});
|
||||
@@ -6,6 +6,7 @@
|
||||
add_task(async function test_Check_ScrollBox_Overflow() {
|
||||
const scrollbox = gZenWorkspaces.activeScrollbox;
|
||||
scrollbox.smoothScroll = false;
|
||||
const selectedTab = gBrowser.selectedTab;
|
||||
const tabsToRemove = [];
|
||||
while (!scrollbox.overflowing) {
|
||||
await BrowserTestUtils.openNewForegroundTab(window.gBrowser, 'https://example.com/', true);
|
||||
@@ -36,7 +37,7 @@ add_task(async function test_Check_ScrollBox_Overflow() {
|
||||
resolve();
|
||||
}, 200);
|
||||
});
|
||||
|
||||
gBrowser.selectedTab = selectedTab;
|
||||
for (const tab of tabsToRemove) {
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
function getToolbarNodeForItemGuid(aItemGuid) {
|
||||
function getToolbarNodeForItemGuid(aItemTitle) {
|
||||
var children = document.getElementById('PlacesToolbarItems').children;
|
||||
for (let child of children) {
|
||||
if (aItemGuid == child._placesNode.bookmarkGuid) {
|
||||
if (aItemTitle == child._placesNode.title) {
|
||||
return child;
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,8 @@ function promiseSetToolbarVisibility(aToolbar, aVisible) {
|
||||
}
|
||||
|
||||
async function changeWorkspaceForBookmark(aBookmark, aWorkspace) {
|
||||
const toolbarNode = getToolbarNodeForItemGuid(aBookmark.guid);
|
||||
const toolbarNode = getToolbarNodeForItemGuid(aBookmark.title);
|
||||
ok(toolbarNode, 'Toolbar node should be found');
|
||||
await withBookmarksDialog(
|
||||
false,
|
||||
async function openPropertiesDialog() {
|
||||
@@ -98,9 +99,6 @@ add_setup(async function () {
|
||||
});
|
||||
|
||||
add_task(async function test_workspace_bookmark() {
|
||||
todo(false, 'Properly implement this function');
|
||||
return;
|
||||
|
||||
await withBookmarksShowing(async () => {
|
||||
await gZenWorkspaces.createAndSaveWorkspace('Test Workspace 2');
|
||||
const workspaces = await gZenWorkspaces._workspaces();
|
||||
@@ -112,40 +110,47 @@ add_task(async function test_workspace_bookmark() {
|
||||
'The new workspace should be different from the current one.'
|
||||
);
|
||||
|
||||
await gZenWorkspaces.changeWorkspaceWithID(firstWorkspace.uuid);
|
||||
|
||||
const bookmark1 = await PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
title: 'workspace1',
|
||||
url: Services.io.newURI('https://example.com/'),
|
||||
workspaces: [firstWorkspace.uuid],
|
||||
});
|
||||
|
||||
await changeWorkspaceForBookmark(bookmark1, firstWorkspace);
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
const bookmark2 = await PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
title: 'workspace2',
|
||||
url: Services.io.newURI('https://example.com/'),
|
||||
workspaces: [secondWorkspace.uuid],
|
||||
});
|
||||
|
||||
await changeWorkspaceForBookmark(bookmark2, secondWorkspace);
|
||||
|
||||
await gZenWorkspaces.changeWorkspace(secondWorkspace);
|
||||
const toolbarNode1 = getToolbarNodeForItemGuid(bookmark1.guid);
|
||||
const toolbarNode2 = getToolbarNodeForItemGuid(bookmark2.guid);
|
||||
ok(toolbarNode1, 'Bookmark1 should be in the toolbar');
|
||||
ok(!toolbarNode2, 'Bookmark2 should be in the toolbar');
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
const toolbarNode1 = getToolbarNodeForItemGuid(bookmark1.title);
|
||||
const toolbarNode2 = getToolbarNodeForItemGuid(bookmark2.title);
|
||||
ok(!toolbarNode1, 'Bookmark1 should not be in the toolbar');
|
||||
ok(toolbarNode2, 'Bookmark2 should be in the toolbar');
|
||||
|
||||
await gZenWorkspaces.changeWorkspace(firstWorkspace);
|
||||
|
||||
const toolbarNode3 = getToolbarNodeForItemGuid(bookmark1.guid);
|
||||
const toolbarNode4 = getToolbarNodeForItemGuid(bookmark2.guid);
|
||||
ok(!toolbarNode3, 'Bookmark1 should be in the toolbar');
|
||||
ok(toolbarNode4, 'Bookmark2 should be in the toolbar');
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
const toolbarNode3 = getToolbarNodeForItemGuid(bookmark1.title);
|
||||
const toolbarNode4 = getToolbarNodeForItemGuid(bookmark2.title);
|
||||
ok(toolbarNode3, 'Bookmark1 should be in the toolbar');
|
||||
ok(!toolbarNode4, 'Bookmark2 should not be in the toolbar');
|
||||
|
||||
await PlacesUtils.bookmarks.remove(bookmark1);
|
||||
await PlacesUtils.bookmarks.remove(bookmark2);
|
||||
|
||||
await gZenWorkspaces.removeWorkspace(secondWorkspace.uuid);
|
||||
Assert.equal(
|
||||
(await gZenWorkspaces._workspaces()).workspaces.length,
|
||||
1,
|
||||
'Only one workspace should remain after removing the second one.'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -151,7 +151,7 @@ var gZenWorkspaces = new (class extends nsZenMultiWindowFeature {
|
||||
}
|
||||
|
||||
if (!this.privateWindowOrDisabled) {
|
||||
const observerFunction = async function observe() {
|
||||
const observerFunction = async () => {
|
||||
this._workspaceBookmarksCache = null;
|
||||
await this.workspaceBookmarks();
|
||||
this._invalidateBookmarkContainers();
|
||||
@@ -1315,7 +1315,11 @@ var gZenWorkspaces = new (class extends nsZenMultiWindowFeature {
|
||||
if (this.workspaceHasIcon(workspace)) {
|
||||
return workspace.icon;
|
||||
}
|
||||
return new Intl.Segmenter().segment(workspace.name).containing().segment.toUpperCase();
|
||||
try {
|
||||
return new Intl.Segmenter().segment(workspace.name).containing().segment.toUpperCase();
|
||||
} catch {
|
||||
return Array.from(workspace.name)[0]?.toUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
get shouldShowContainers() {
|
||||
|
||||
Reference in New Issue
Block a user