Skip to content

Commit 7054030

Browse files
committed
ntp: send background-tab on windows middle-click
1 parent c86cc1d commit 7054030

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

special-pages/pages/new-tab/app/favorites/integration-tests/favorites.page.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ export class FavoritesPage {
3232
expect(calls[1].payload.params).toStrictEqual({ id: 'id-many-1', url: 'https://example.com/?id=id-many-1', target: 'new-window' });
3333
}
3434

35+
async opensInBackgroundTab() {
36+
await this.nthFavorite(0).click({ button: 'middle' });
37+
const calls = await this.ntp.mocks.waitForCallCount({ method: 'favorites_open', count: 1 });
38+
expect(calls[0].payload.params).toStrictEqual({
39+
id: 'id-many-1',
40+
url: 'https://example.com/?id=id-many-1',
41+
target: 'background-tab',
42+
});
43+
}
44+
3545
async opensInSameTab() {
3646
await this.nthFavorite(0).click();
3747
const calls = await this.ntp.mocks.waitForCallCount({ method: 'favorites_open', count: 1 });

special-pages/pages/new-tab/app/favorites/integration-tests/favorites.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ test.describe('newtab favorites', () => {
5151
await ntp.openPage({ platformName: 'macos' });
5252
await favorites.opensInNewWindow();
5353
});
54+
test('Opens a favorite in background tab', async ({ page }, workerInfo) => {
55+
const ntp = NewtabPage.create(page, workerInfo);
56+
const favorites = new FavoritesPage(ntp);
57+
await ntp.reducedMotion();
58+
await ntp.openPage({ platformName: 'windows' });
59+
await favorites.opensInBackgroundTab();
60+
});
5461
test('Adds an item', async ({ page }, workerInfo) => {
5562
const ntp = NewtabPage.create(page, workerInfo);
5663
const favorites = new FavoritesPage(ntp);

special-pages/pages/new-tab/app/utils.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ export function eventToTarget(event, platformName) {
7070
const isControlClick = platformName === 'macos' ? event.metaKey : event.ctrlKey;
7171
if (isControlClick) {
7272
return 'new-tab';
73-
} else if (event.shiftKey || event.button === 1 /* middle click */) {
73+
} else if (event.shiftKey) {
74+
return 'new-window';
75+
} else if (event.button === 1 /* middle click */) {
76+
if (platformName === 'windows') {
77+
return 'background-tab';
78+
}
7479
return 'new-window';
7580
}
7681
return 'same-tab';

special-pages/pages/new-tab/messages/types/open-target.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"$schema": "http://json-schema.org/draft-07/schema#",
33
"title": "Open Target",
44
"type": "string",
5-
"enum": ["same-tab", "new-tab", "new-window"]
5+
"enum": ["same-tab", "new-tab", "new-window", "background-tab"]
66
}

special-pages/pages/new-tab/types/new-tab.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @module NewTab Messages
77
*/
88

9-
export type OpenTarget = "same-tab" | "new-tab" | "new-window";
9+
export type OpenTarget = "same-tab" | "new-tab" | "new-window" | "background-tab";
1010
/**
1111
* Represents the expansion state of a widget
1212
*/

0 commit comments

Comments
 (0)