fix: running tests with release build (#31092)

This commit is contained in:
Milan Burda 2021-09-27 16:58:03 +02:00 committed by GitHub
parent c377fe4ba6
commit 98ac0ca52a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 16 additions and 28 deletions

View file

@ -236,13 +236,11 @@ std::u16string Menu::GetToolTipAt(int index) const {
return model_->GetToolTipAt(index); return model_->GetToolTipAt(index);
} }
#if DCHECK_IS_ON()
std::u16string Menu::GetAcceleratorTextAtForTesting(int index) const { std::u16string Menu::GetAcceleratorTextAtForTesting(int index) const {
ui::Accelerator accelerator; ui::Accelerator accelerator;
model_->GetAcceleratorAtWithParams(index, true, &accelerator); model_->GetAcceleratorAtWithParams(index, true, &accelerator);
return accelerator.GetShortcutText(); return accelerator.GetShortcutText();
} }
#endif
bool Menu::IsItemCheckedAt(int index) const { bool Menu::IsItemCheckedAt(int index) const {
return model_->IsItemCheckedAt(index); return model_->IsItemCheckedAt(index);
@ -297,9 +295,7 @@ v8::Local<v8::ObjectTemplate> Menu::FillObjectTemplate(
.SetMethod("isVisibleAt", &Menu::IsVisibleAt) .SetMethod("isVisibleAt", &Menu::IsVisibleAt)
.SetMethod("popupAt", &Menu::PopupAt) .SetMethod("popupAt", &Menu::PopupAt)
.SetMethod("closePopupAt", &Menu::ClosePopupAt) .SetMethod("closePopupAt", &Menu::ClosePopupAt)
#if DCHECK_IS_ON() .SetMethod("_getAcceleratorTextAt", &Menu::GetAcceleratorTextAtForTesting)
.SetMethod("getAcceleratorTextAt", &Menu::GetAcceleratorTextAtForTesting)
#endif
#if defined(OS_MAC) #if defined(OS_MAC)
.SetMethod("_getUserAcceleratorAt", &Menu::GetUserAcceleratorAt) .SetMethod("_getUserAcceleratorAt", &Menu::GetUserAcceleratorAt)
#endif #endif

View file

@ -79,9 +79,7 @@ class Menu : public gin::Wrappable<Menu>,
int positioning_item, int positioning_item,
base::OnceClosure callback) = 0; base::OnceClosure callback) = 0;
virtual void ClosePopupAt(int32_t window_id) = 0; virtual void ClosePopupAt(int32_t window_id) = 0;
#if DCHECK_IS_ON()
virtual std::u16string GetAcceleratorTextAtForTesting(int index) const; virtual std::u16string GetAcceleratorTextAtForTesting(int index) const;
#endif
std::unique_ptr<ElectronMenuModel> model_; std::unique_ptr<ElectronMenuModel> model_;
Menu* parent_ = nullptr; Menu* parent_ = nullptr;

View file

@ -34,9 +34,7 @@ class MenuMac : public Menu {
int positioning_item, int positioning_item,
base::OnceClosure callback); base::OnceClosure callback);
void ClosePopupAt(int32_t window_id) override; void ClosePopupAt(int32_t window_id) override;
#if DCHECK_IS_ON()
std::u16string GetAcceleratorTextAtForTesting(int index) const override; std::u16string GetAcceleratorTextAtForTesting(int index) const override;
#endif
private: private:
friend class Menu; friend class Menu;

View file

@ -170,7 +170,6 @@ void MenuMac::ClosePopupAt(int32_t window_id) {
std::move(close_popup)); std::move(close_popup));
} }
#if DCHECK_IS_ON()
std::u16string MenuMac::GetAcceleratorTextAtForTesting(int index) const { std::u16string MenuMac::GetAcceleratorTextAtForTesting(int index) const {
// A least effort to get the real shortcut text of NSMenuItem, the code does // A least effort to get the real shortcut text of NSMenuItem, the code does
// not need to be perfect since it is test only. // not need to be perfect since it is test only.
@ -206,7 +205,6 @@ std::u16string MenuMac::GetAcceleratorTextAtForTesting(int index) const {
text += key; text += key;
return text; return text;
} }
#endif
void MenuMac::ClosePopupOnUI(int32_t window_id) { void MenuMac::ClosePopupOnUI(int32_t window_id) {
auto controller = popup_controllers_.find(window_id); auto controller = popup_controllers_.find(window_id);

View file

@ -156,13 +156,11 @@ void Initialize(v8::Local<v8::Object> exports,
dict.SetMethod("requestGarbageCollectionForTesting", dict.SetMethod("requestGarbageCollectionForTesting",
&RequestGarbageCollectionForTesting); &RequestGarbageCollectionForTesting);
dict.SetMethod("isSameOrigin", &IsSameOrigin); dict.SetMethod("isSameOrigin", &IsSameOrigin);
#if DCHECK_IS_ON()
dict.SetMethod("triggerFatalErrorForTesting", &TriggerFatalErrorForTesting); dict.SetMethod("triggerFatalErrorForTesting", &TriggerFatalErrorForTesting);
dict.SetMethod("getWeaklyTrackedValues", &GetWeaklyTrackedValues); dict.SetMethod("getWeaklyTrackedValues", &GetWeaklyTrackedValues);
dict.SetMethod("clearWeaklyTrackedValues", &ClearWeaklyTrackedValues); dict.SetMethod("clearWeaklyTrackedValues", &ClearWeaklyTrackedValues);
dict.SetMethod("weaklyTrackValue", &WeaklyTrackValue); dict.SetMethod("weaklyTrackValue", &WeaklyTrackValue);
dict.SetMethod("runUntilIdle", &RunUntilIdle); dict.SetMethod("runUntilIdle", &RunUntilIdle);
#endif
} }
} // namespace } // namespace

View file

@ -462,9 +462,9 @@ describe('MenuItems', () => {
{ label: 'text', accelerator: 'Alt+A' } { label: 'text', accelerator: 'Alt+A' }
]); ]);
expect(menu.getAcceleratorTextAt(0)).to.equal(isDarwin() ? 'Command+A' : 'Ctrl+A'); expect(menu._getAcceleratorTextAt(0)).to.equal(isDarwin() ? 'Command+A' : 'Ctrl+A');
expect(menu.getAcceleratorTextAt(1)).to.equal('Shift+A'); expect(menu._getAcceleratorTextAt(1)).to.equal('Shift+A');
expect(menu.getAcceleratorTextAt(2)).to.equal('Alt+A'); expect(menu._getAcceleratorTextAt(2)).to.equal('Alt+A');
}); });
it('should display modifiers correctly for special keys', () => { it('should display modifiers correctly for special keys', () => {
@ -474,9 +474,9 @@ describe('MenuItems', () => {
{ label: 'text', accelerator: 'Alt+Tab' } { label: 'text', accelerator: 'Alt+Tab' }
]); ]);
expect(menu.getAcceleratorTextAt(0)).to.equal(isDarwin() ? 'Command+Tab' : 'Ctrl+Tab'); expect(menu._getAcceleratorTextAt(0)).to.equal(isDarwin() ? 'Command+Tab' : 'Ctrl+Tab');
expect(menu.getAcceleratorTextAt(1)).to.equal('Shift+Tab'); expect(menu._getAcceleratorTextAt(1)).to.equal('Shift+Tab');
expect(menu.getAcceleratorTextAt(2)).to.equal('Alt+Tab'); expect(menu._getAcceleratorTextAt(2)).to.equal('Alt+Tab');
}); });
it('should not display modifiers twice', () => { it('should not display modifiers twice', () => {
@ -485,8 +485,8 @@ describe('MenuItems', () => {
{ label: 'text', accelerator: 'Shift+Shift+Tab' } { label: 'text', accelerator: 'Shift+Shift+Tab' }
]); ]);
expect(menu.getAcceleratorTextAt(0)).to.equal('Shift+A'); expect(menu._getAcceleratorTextAt(0)).to.equal('Shift+A');
expect(menu.getAcceleratorTextAt(1)).to.equal('Shift+Tab'); expect(menu._getAcceleratorTextAt(1)).to.equal('Shift+Tab');
}); });
it('should display correctly for shifted keys', () => { it('should display correctly for shifted keys', () => {
@ -499,12 +499,12 @@ describe('MenuItems', () => {
{ label: 'text', accelerator: 'Control+?' } { label: 'text', accelerator: 'Control+?' }
]); ]);
expect(menu.getAcceleratorTextAt(0)).to.equal('Ctrl+Shift+='); expect(menu._getAcceleratorTextAt(0)).to.equal('Ctrl+Shift+=');
expect(menu.getAcceleratorTextAt(1)).to.equal('Ctrl++'); expect(menu._getAcceleratorTextAt(1)).to.equal('Ctrl++');
expect(menu.getAcceleratorTextAt(2)).to.equal('Ctrl+Shift+3'); expect(menu._getAcceleratorTextAt(2)).to.equal('Ctrl+Shift+3');
expect(menu.getAcceleratorTextAt(3)).to.equal('Ctrl+#'); expect(menu._getAcceleratorTextAt(3)).to.equal('Ctrl+#');
expect(menu.getAcceleratorTextAt(4)).to.equal('Ctrl+Shift+/'); expect(menu._getAcceleratorTextAt(4)).to.equal('Ctrl+Shift+/');
expect(menu.getAcceleratorTextAt(5)).to.equal('Ctrl+?'); expect(menu._getAcceleratorTextAt(5)).to.equal('Ctrl+?');
}); });
}); });
}); });

View file

@ -123,7 +123,7 @@ declare namespace Electron {
insertSeparator(index: number): void; insertSeparator(index: number): void;
insertSubMenu(index: number, commandId: number, label: string, submenu?: Menu): void; insertSubMenu(index: number, commandId: number, label: string, submenu?: Menu): void;
delegate?: any; delegate?: any;
getAcceleratorTextAt(index: number): string; _getAcceleratorTextAt(index: number): string;
} }
interface MenuItem { interface MenuItem {