Skip to content

Commit 6056691

Browse files
ergunshDevtools-frontend LUCI CQ
authored andcommitted
[GlobalAiButton] Show AI Assistance in sidebar initially
* If the user does not have any preference (i.e. they didn't moved the drawer to sidebar or vice-versa by clicking the button explicitly), we're going to show the AI assistance panel in the sidebar. Bug: none Change-Id: Iff2f8e445946d51f8b4d5031597f45842876f360 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6906117 Commit-Queue: Ergün Erdoğmuş <[email protected]> Commit-Queue: Piotr Paulski <[email protected]> Reviewed-by: Piotr Paulski <[email protected]> Auto-Submit: Ergün Erdoğmuş <[email protected]>
1 parent 6f55537 commit 6056691

File tree

5 files changed

+158
-26
lines changed

5 files changed

+158
-26
lines changed

front_end/entrypoints/main/GlobalAiButton.test.ts

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
import * as Common from '../../core/common/common.js';
6+
import * as Root from '../../core/root/root.js';
67
import {
78
renderElementIntoDOM,
89
} from '../../testing/DOMHelpers.js';
@@ -42,16 +43,73 @@ describeWithEnvironment('GlobalAiButton', () => {
4243
assert.strictEqual(view.input.state, Main.GlobalAiButton.GlobalAiButtonState.DEFAULT);
4344
});
4445

45-
it('shows freestyler in drawer and increases click count on click', async () => {
46-
const {view} = await createWidget();
47-
const showViewStub = sinon.stub(UI.ViewManager.ViewManager.instance(), 'showViewInLocation');
48-
const setting = Common.Settings.Settings.instance().settingForTest('global-ai-button-click-count');
49-
setting.set(0);
46+
describe('onClick', () => {
47+
let inspectorView: UI.InspectorView.InspectorView;
48+
let isUserExplicitlyUpdatedDrawerOrientationStub: sinon.SinonStub;
49+
let toggleDrawerOrientationSpy: sinon.SinonSpy;
50+
let showViewStub: sinon.SinonStub;
51+
let showDrawerStub: sinon.SinonStub;
52+
53+
beforeEach(() => {
54+
inspectorView = UI.InspectorView.InspectorView.instance();
55+
isUserExplicitlyUpdatedDrawerOrientationStub =
56+
sinon.stub(inspectorView, 'isUserExplicitlyUpdatedDrawerOrientation');
57+
toggleDrawerOrientationSpy = sinon.spy(inspectorView, 'toggleDrawerOrientation');
58+
showViewStub = sinon.stub(UI.ViewManager.ViewManager.instance(), 'showViewInLocation');
59+
showDrawerStub = sinon.stub(inspectorView, 'showDrawer');
60+
});
61+
62+
it('shows freestyler in drawer and increases click count', async () => {
63+
const {view} = await createWidget();
64+
const setting = Common.Settings.Settings.instance().settingForTest('global-ai-button-click-count');
65+
setting.set(0);
66+
67+
view.input.onClick();
68+
69+
sinon.assert.calledOnceWithExactly(showViewStub, 'freestyler', 'drawer-view');
70+
assert.strictEqual(setting.get(), 1);
71+
});
72+
73+
describe('with vertical drawer experiment', () => {
74+
beforeEach(() => {
75+
Root.Runtime.experiments.setEnabled(Root.Runtime.ExperimentName.VERTICAL_DRAWER, true);
76+
});
77+
78+
afterEach(() => {
79+
Root.Runtime.experiments.setEnabled(Root.Runtime.ExperimentName.VERTICAL_DRAWER, false);
80+
});
5081

51-
view.input.onClick();
82+
it('toggles drawer if experiment is on and user has no preference', async () => {
83+
const {view} = await createWidget();
84+
isUserExplicitlyUpdatedDrawerOrientationStub.returns(false);
5285

53-
sinon.assert.calledOnceWithExactly(showViewStub, 'freestyler', 'drawer-view');
54-
assert.strictEqual(setting.get(), 1);
86+
view.input.onClick();
87+
88+
sinon.assert.calledOnceWithExactly(showDrawerStub, {focus: true, hasTargetDrawer: false});
89+
sinon.assert.calledOnceWithExactly(toggleDrawerOrientationSpy, {force: 'vertical'});
90+
});
91+
92+
it('does not toggle drawer if user has preference', async () => {
93+
const {view} = await createWidget();
94+
isUserExplicitlyUpdatedDrawerOrientationStub.returns(true);
95+
96+
view.input.onClick();
97+
98+
sinon.assert.notCalled(showDrawerStub);
99+
sinon.assert.notCalled(toggleDrawerOrientationSpy);
100+
});
101+
});
102+
103+
it('does not toggle drawer if experiment is off', async () => {
104+
Root.Runtime.experiments.setEnabled(Root.Runtime.ExperimentName.VERTICAL_DRAWER, false);
105+
const {view} = await createWidget();
106+
isUserExplicitlyUpdatedDrawerOrientationStub.returns(false);
107+
108+
view.input.onClick();
109+
110+
sinon.assert.notCalled(showDrawerStub);
111+
sinon.assert.notCalled(toggleDrawerOrientationSpy);
112+
});
55113
});
56114

57115
describe('promotion lifecycle', () => {

front_end/entrypoints/main/GlobalAiButton.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,22 @@ export class GlobalAiButton extends UI.Widget.Widget {
155155
#onClick(): void {
156156
UI.ViewManager.ViewManager.instance().showViewInLocation('freestyler', 'drawer-view');
157157
incrementClickCountSetting();
158+
159+
const hasExplicitUserPreference =
160+
UI.InspectorView.InspectorView.instance().isUserExplicitlyUpdatedDrawerOrientation();
161+
const isVerticalDrawerExperimentEnabled =
162+
Root.Runtime.experiments.isEnabled(Root.Runtime.ExperimentName.VERTICAL_DRAWER);
163+
if (isVerticalDrawerExperimentEnabled && !hasExplicitUserPreference) {
164+
// This mimics what we're doing while showing the drawer via `ESC`.
165+
// There is a bug where opening the sidebar directly for the first time,
166+
// and triggering a drawer rotation without calling `showDrawer({focus: true})` makes the drawer disappear.
167+
UI.InspectorView.InspectorView.instance().showDrawer({
168+
focus: true,
169+
hasTargetDrawer: false,
170+
});
171+
UI.InspectorView.InspectorView.instance().toggleDrawerOrientation(
172+
{force: UI.InspectorView.DrawerOrientation.VERTICAL});
173+
}
158174
}
159175

160176
override performUpdate(): Promise<void>|void {

front_end/ui/legacy/InspectorView.test.ts

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import * as LegacyUI from './legacy.js';
1111

1212
const InspectorView = LegacyUI.InspectorView.InspectorView;
1313
const Settings = Common.Settings.Settings;
14-
const DRAWER_ORIENTATION_SETTING_NAME = 'inspector.use-vertical-drawer-orientation';
14+
const DrawerOrientation = LegacyUI.InspectorView.DrawerOrientation;
15+
const DRAWER_ORIENTATION_SETTING_NAME = 'inspector.drawer-orientation';
1516

1617
describeWithEnvironment('InspectorView', () => {
1718
beforeEach(() => {
@@ -72,28 +73,68 @@ describeWithEnvironment('InspectorView', () => {
7273
Common.Settings.Settings.instance({forceNew: true, syncedStorage, globalStorage, localStorage});
7374
});
7475

75-
it('drawer orientation and setting default to horizontal', () => {
76+
it('drawer orientation and setting default to unset', () => {
7677
const inspectorView = InspectorView.instance({forceNew: true});
7778
assert.isFalse(inspectorView.isDrawerOrientationVertical());
7879
const setting = Settings.instance().settingForTest(DRAWER_ORIENTATION_SETTING_NAME);
79-
assert.isFalse(setting.get());
80+
assert.strictEqual(setting.get(), DrawerOrientation.UNSET);
8081
});
8182

8283
it('drawer orientation setting updates after each toggle', () => {
8384
const inspectorView = InspectorView.instance({forceNew: true});
8485
const setting = Settings.instance().settingForTest(DRAWER_ORIENTATION_SETTING_NAME);
85-
assert.isFalse(setting.get());
86+
assert.strictEqual(setting.get(), DrawerOrientation.UNSET);
8687

8788
inspectorView.toggleDrawerOrientation();
88-
assert.isTrue(setting.get());
89+
assert.strictEqual(setting.get(), DrawerOrientation.VERTICAL);
8990

9091
inspectorView.toggleDrawerOrientation();
91-
assert.isFalse(setting.get());
92+
assert.strictEqual(setting.get(), DrawerOrientation.HORIZONTAL);
9293
});
9394

94-
it('drawer starts vertical if setting is true', () => {
95-
Settings.instance().createSetting(DRAWER_ORIENTATION_SETTING_NAME, true);
95+
it('drawer starts vertical if setting is vertical', () => {
96+
Settings.instance().createSetting(DRAWER_ORIENTATION_SETTING_NAME, DrawerOrientation.VERTICAL);
9697
const inspectorView = InspectorView.instance({forceNew: true});
9798
assert.isTrue(inspectorView.isDrawerOrientationVertical());
9899
});
100+
101+
it('isUserExplicitlyUpdatedDrawerOrientation returns false by default', () => {
102+
const inspectorView = InspectorView.instance({forceNew: true});
103+
assert.isFalse(inspectorView.isUserExplicitlyUpdatedDrawerOrientation());
104+
});
105+
106+
it('isUserExplicitlyUpdatedDrawerOrientation returns true when orientation is toggled', () => {
107+
const inspectorView = InspectorView.instance({forceNew: true});
108+
109+
inspectorView.toggleDrawerOrientation();
110+
111+
assert.isTrue(inspectorView.isUserExplicitlyUpdatedDrawerOrientation());
112+
});
113+
114+
it('toggleDrawerOrientation can force vertical orientation', () => {
115+
const inspectorView = InspectorView.instance({forceNew: true});
116+
const orientationSetting = Settings.instance().settingForTest(DRAWER_ORIENTATION_SETTING_NAME);
117+
const updatedSetting = Settings.instance().settingForTest(DRAWER_ORIENTATION_SETTING_NAME);
118+
119+
assert.isFalse(inspectorView.isDrawerOrientationVertical());
120+
121+
inspectorView.toggleDrawerOrientation({force: 'vertical'});
122+
123+
assert.isTrue(inspectorView.isDrawerOrientationVertical());
124+
assert.strictEqual(orientationSetting.get(), DrawerOrientation.VERTICAL);
125+
assert.strictEqual(updatedSetting.get(), DrawerOrientation.VERTICAL);
126+
});
127+
128+
it('toggleDrawerOrientation can force horizontal orientation', () => {
129+
Settings.instance().createSetting(DRAWER_ORIENTATION_SETTING_NAME, DrawerOrientation.VERTICAL);
130+
const inspectorView = InspectorView.instance({forceNew: true});
131+
const orientationSetting = Settings.instance().settingForTest(DRAWER_ORIENTATION_SETTING_NAME);
132+
133+
assert.isTrue(inspectorView.isDrawerOrientationVertical());
134+
135+
inspectorView.toggleDrawerOrientation({force: 'horizontal'});
136+
137+
assert.isFalse(inspectorView.isDrawerOrientationVertical());
138+
assert.strictEqual(orientationSetting.get(), DrawerOrientation.HORIZONTAL);
139+
});
99140
});

front_end/ui/legacy/InspectorView.ts

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,14 @@ const str_ = i18n.i18n.registerUIStrings('ui/legacy/InspectorView.ts', UIStrings
140140
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
141141
let inspectorViewInstance: InspectorView|null = null;
142142

143+
export enum DrawerOrientation {
144+
VERTICAL = 'vertical',
145+
HORIZONTAL = 'horizontal',
146+
UNSET = 'unset',
147+
}
148+
143149
export class InspectorView extends VBox implements ViewLocationResolver {
144-
private readonly drawerIsVerticalSetting: Common.Settings.Setting<boolean>;
150+
private readonly drawerOrientationSetting: Common.Settings.Setting<DrawerOrientation>;
145151
private readonly drawerSplitWidget: SplitWidget;
146152
private readonly tabDelegate: InspectorViewTabDelegate;
147153
private readonly drawerTabbedLocation: TabbedViewLocation;
@@ -164,10 +170,10 @@ export class InspectorView extends VBox implements ViewLocationResolver {
164170
this.setMinimumSize(250, 72);
165171

166172
// DevTools sidebar is a vertical split of main tab bar panels and a drawer.
167-
this.drawerIsVerticalSetting =
168-
Common.Settings.Settings.instance().createSetting('inspector.use-vertical-drawer-orientation', false);
169-
this.drawerSplitWidget =
170-
new SplitWidget(this.drawerIsVerticalSetting.get(), true, 'inspector.drawer-split-view-state', 200, 200);
173+
this.drawerOrientationSetting =
174+
Common.Settings.Settings.instance().createSetting('inspector.drawer-orientation', DrawerOrientation.UNSET);
175+
const isVertical = this.drawerOrientationSetting.get() === DrawerOrientation.VERTICAL;
176+
this.drawerSplitWidget = new SplitWidget(isVertical, true, 'inspector.drawer-split-view-state', 200, 200);
171177
this.drawerSplitWidget.hideSidebar();
172178
this.drawerSplitWidget.enableShowModeSaving();
173179
this.drawerSplitWidget.show(this.element);
@@ -195,7 +201,8 @@ export class InspectorView extends VBox implements ViewLocationResolver {
195201
this.drawerSplitWidget.isVertical() ? 'dock-bottom' : 'dock-right');
196202
this.#toggleOrientationButton.element.setAttribute('jslog', `${VisualLogging.toggle().track({click: true})}`);
197203
this.#toggleOrientationButton.element.setAttribute('jslogcontext', 'toggle-drawer-orientation');
198-
this.#toggleOrientationButton.addEventListener(ToolbarButton.Events.CLICK, this.toggleDrawerOrientation, this);
204+
this.#toggleOrientationButton.addEventListener(
205+
ToolbarButton.Events.CLICK, () => this.toggleDrawerOrientation(), this);
199206
this.drawerTabbedPane.addEventListener(
200207
TabbedPaneEvents.TabSelected,
201208
(event: Common.EventTarget.EventTargetEvent<EventData>) => this.tabSelected(event.data.tabId), this);
@@ -435,14 +442,24 @@ export class InspectorView extends VBox implements ViewLocationResolver {
435442
ARIAUtils.LiveAnnouncer.alert(i18nString(UIStrings.drawerHidden));
436443
}
437444

438-
toggleDrawerOrientation(): void {
439-
const drawerWillBeVertical = !this.drawerSplitWidget.isVertical();
445+
toggleDrawerOrientation({force}: {force?: Omit<DrawerOrientation, DrawerOrientation.UNSET>} = {}): void {
446+
let drawerWillBeVertical: boolean;
447+
if (force) {
448+
drawerWillBeVertical = force === DrawerOrientation.VERTICAL;
449+
} else {
450+
drawerWillBeVertical = !this.drawerSplitWidget.isVertical();
451+
}
452+
453+
this.drawerOrientationSetting.set(drawerWillBeVertical ? DrawerOrientation.VERTICAL : DrawerOrientation.HORIZONTAL);
440454
this.#toggleOrientationButton.setGlyph(drawerWillBeVertical ? 'dock-bottom' : 'dock-right');
441-
this.drawerIsVerticalSetting.set(drawerWillBeVertical);
442455
this.drawerSplitWidget.setVertical(drawerWillBeVertical);
443456
this.setDrawerMinimumSize();
444457
}
445458

459+
isUserExplicitlyUpdatedDrawerOrientation(): boolean {
460+
return this.drawerOrientationSetting.get() !== DrawerOrientation.UNSET;
461+
}
462+
446463
setDrawerMinimumSize(): void {
447464
const drawerIsVertical = this.drawerSplitWidget.isVertical();
448465
if (drawerIsVertical) {

front_end/ui/visual_logging/KnownContextValues.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1889,7 +1889,7 @@ export const knownContextValues = new Set([
18891889
'inspector-main.hard-reload',
18901890
'inspector-main.reload',
18911891
'inspector-stylesheet',
1892-
'inspector.use-vertical-drawer-orientation',
1892+
'inspector.drawer-orientation',
18931893
'installability',
18941894
'installing-entry-inspect',
18951895
'instance-id',

0 commit comments

Comments
 (0)