Skip to content

Commit

Permalink
fix: running tests with release build (#31140)
Browse files Browse the repository at this point in the history
* fix: running tests with release build

* Update electron_api_v8_util.cc

Co-authored-by: Milan Burda <milan.burda@gmail.com>
  • Loading branch information
trop[bot] and miniak committed Sep 29, 2021
1 parent 4cdb2c4 commit b62cef5
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 28 deletions.
6 changes: 1 addition & 5 deletions shell/browser/api/electron_api_menu.cc
Expand Up @@ -236,13 +236,11 @@ std::u16string Menu::GetToolTipAt(int index) const {
return model_->GetToolTipAt(index);
}

#if DCHECK_IS_ON()
std::u16string Menu::GetAcceleratorTextAtForTesting(int index) const {
ui::Accelerator accelerator;
model_->GetAcceleratorAtWithParams(index, true, &accelerator);
return accelerator.GetShortcutText();
}
#endif

bool Menu::IsItemCheckedAt(int index) const {
return model_->IsItemCheckedAt(index);
Expand Down Expand Up @@ -297,9 +295,7 @@ v8::Local<v8::ObjectTemplate> Menu::FillObjectTemplate(
.SetMethod("isVisibleAt", &Menu::IsVisibleAt)
.SetMethod("popupAt", &Menu::PopupAt)
.SetMethod("closePopupAt", &Menu::ClosePopupAt)
#if DCHECK_IS_ON()
.SetMethod("getAcceleratorTextAt", &Menu::GetAcceleratorTextAtForTesting)
#endif
.SetMethod("_getAcceleratorTextAt", &Menu::GetAcceleratorTextAtForTesting)
#if defined(OS_MAC)
.SetMethod("_getUserAcceleratorAt", &Menu::GetUserAcceleratorAt)
#endif
Expand Down
2 changes: 0 additions & 2 deletions shell/browser/api/electron_api_menu.h
Expand Up @@ -79,9 +79,7 @@ class Menu : public gin::Wrappable<Menu>,
int positioning_item,
base::OnceClosure callback) = 0;
virtual void ClosePopupAt(int32_t window_id) = 0;
#if DCHECK_IS_ON()
virtual std::u16string GetAcceleratorTextAtForTesting(int index) const;
#endif

std::unique_ptr<ElectronMenuModel> model_;
Menu* parent_ = nullptr;
Expand Down
2 changes: 0 additions & 2 deletions shell/browser/api/electron_api_menu_mac.h
Expand Up @@ -34,9 +34,7 @@ class MenuMac : public Menu {
int positioning_item,
base::OnceClosure callback);
void ClosePopupAt(int32_t window_id) override;
#if DCHECK_IS_ON()
std::u16string GetAcceleratorTextAtForTesting(int index) const override;
#endif

private:
friend class Menu;
Expand Down
2 changes: 0 additions & 2 deletions shell/browser/api/electron_api_menu_mac.mm
Expand Up @@ -170,7 +170,6 @@
std::move(close_popup));
}

#if DCHECK_IS_ON()
std::u16string MenuMac::GetAcceleratorTextAtForTesting(int index) const {
// A least effort to get the real shortcut text of NSMenuItem, the code does
// not need to be perfect since it is test only.
Expand Down Expand Up @@ -206,7 +205,6 @@
text += key;
return text;
}
#endif

void MenuMac::ClosePopupOnUI(int32_t window_id) {
auto controller = popup_controllers_.find(window_id);
Expand Down
2 changes: 0 additions & 2 deletions shell/common/api/electron_api_v8_util.cc
Expand Up @@ -133,10 +133,8 @@ void Initialize(v8::Local<v8::Object> exports,
dict.SetMethod("requestGarbageCollectionForTesting",
&RequestGarbageCollectionForTesting);
dict.SetMethod("isSameOrigin", &IsSameOrigin);
#if DCHECK_IS_ON()
dict.SetMethod("triggerFatalErrorForTesting", &TriggerFatalErrorForTesting);
dict.SetMethod("runUntilIdle", &RunUntilIdle);
#endif
}

} // namespace
Expand Down
28 changes: 14 additions & 14 deletions spec-main/api-menu-item-spec.ts
Expand Up @@ -462,9 +462,9 @@ describe('MenuItems', () => {
{ label: 'text', accelerator: 'Alt+A' }
]);

expect(menu.getAcceleratorTextAt(0)).to.equal(isDarwin() ? 'Command+A' : 'Ctrl+A');
expect(menu.getAcceleratorTextAt(1)).to.equal('Shift+A');
expect(menu.getAcceleratorTextAt(2)).to.equal('Alt+A');
expect(menu._getAcceleratorTextAt(0)).to.equal(isDarwin() ? 'Command+A' : 'Ctrl+A');
expect(menu._getAcceleratorTextAt(1)).to.equal('Shift+A');
expect(menu._getAcceleratorTextAt(2)).to.equal('Alt+A');
});

it('should display modifiers correctly for special keys', () => {
Expand All @@ -474,9 +474,9 @@ describe('MenuItems', () => {
{ label: 'text', accelerator: 'Alt+Tab' }
]);

expect(menu.getAcceleratorTextAt(0)).to.equal(isDarwin() ? 'Command+Tab' : 'Ctrl+Tab');
expect(menu.getAcceleratorTextAt(1)).to.equal('Shift+Tab');
expect(menu.getAcceleratorTextAt(2)).to.equal('Alt+Tab');
expect(menu._getAcceleratorTextAt(0)).to.equal(isDarwin() ? 'Command+Tab' : 'Ctrl+Tab');
expect(menu._getAcceleratorTextAt(1)).to.equal('Shift+Tab');
expect(menu._getAcceleratorTextAt(2)).to.equal('Alt+Tab');
});

it('should not display modifiers twice', () => {
Expand All @@ -485,8 +485,8 @@ describe('MenuItems', () => {
{ label: 'text', accelerator: 'Shift+Shift+Tab' }
]);

expect(menu.getAcceleratorTextAt(0)).to.equal('Shift+A');
expect(menu.getAcceleratorTextAt(1)).to.equal('Shift+Tab');
expect(menu._getAcceleratorTextAt(0)).to.equal('Shift+A');
expect(menu._getAcceleratorTextAt(1)).to.equal('Shift+Tab');
});

it('should display correctly for shifted keys', () => {
Expand All @@ -499,12 +499,12 @@ describe('MenuItems', () => {
{ label: 'text', accelerator: 'Control+?' }
]);

expect(menu.getAcceleratorTextAt(0)).to.equal('Ctrl+Shift+=');
expect(menu.getAcceleratorTextAt(1)).to.equal('Ctrl++');
expect(menu.getAcceleratorTextAt(2)).to.equal('Ctrl+Shift+3');
expect(menu.getAcceleratorTextAt(3)).to.equal('Ctrl+#');
expect(menu.getAcceleratorTextAt(4)).to.equal('Ctrl+Shift+/');
expect(menu.getAcceleratorTextAt(5)).to.equal('Ctrl+?');
expect(menu._getAcceleratorTextAt(0)).to.equal('Ctrl+Shift+=');
expect(menu._getAcceleratorTextAt(1)).to.equal('Ctrl++');
expect(menu._getAcceleratorTextAt(2)).to.equal('Ctrl+Shift+3');
expect(menu._getAcceleratorTextAt(3)).to.equal('Ctrl+#');
expect(menu._getAcceleratorTextAt(4)).to.equal('Ctrl+Shift+/');
expect(menu._getAcceleratorTextAt(5)).to.equal('Ctrl+?');
});
});
});
2 changes: 1 addition & 1 deletion typings/internal-electron.d.ts
Expand Up @@ -125,7 +125,7 @@ declare namespace Electron {
insertSeparator(index: number): void;
insertSubMenu(index: number, commandId: number, label: string, submenu?: Menu): void;
delegate?: any;
getAcceleratorTextAt(index: number): string;
_getAcceleratorTextAt(index: number): string;
}

interface MenuItem {
Expand Down

0 comments on commit b62cef5

Please sign in to comment.