diff --git a/atom/browser/ui/views/menu_bar.cc b/atom/browser/ui/views/menu_bar.cc index 47626176d350..18bb5c23278f 100644 --- a/atom/browser/ui/views/menu_bar.cc +++ b/atom/browser/ui/views/menu_bar.cc @@ -10,6 +10,7 @@ #include "atom/browser/ui/views/submenu_button.h" #include "atom/common/keyboard_util.h" +#include "ui/aura/window.h" #include "ui/base/models/menu_model.h" #include "ui/views/background.h" #include "ui/views/layout/box_layout.h" @@ -174,6 +175,27 @@ bool MenuBar::AcceleratorPressed(const ui::Accelerator& accelerator) { } bool MenuBar::SetPaneFocus(views::View* initial_focus) { + // TODO(zcbenz): Submit patch to upstream Chromium to fix the crash. + // + // Without this check, Electron would crash when running tests. + // + // Check failed: rules_->CanFocusWindow(window, nullptr). + // logging::LogMessage::~LogMessage + // wm::FocusController::SetFocusedWindow + // wm::FocusController::ResetFocusWithinActiveWindow + // views::View::OnFocus + // views::Button::OnFocus + // views::LabelButton::OnFocus + // views::View::Focus + // views::FocusManager::SetFocusedViewWithReason + // views::AccessiblePaneView::SetPaneFocus + // atom::MenuBar::SetPaneFocus + if (initial_focus && initial_focus->GetWidget()) { + aura::Window* window = initial_focus->GetWidget()->GetNativeWindow(); + if (!window || !window->GetRootWindow()) + return false; + } + bool result = views::AccessiblePaneView::SetPaneFocus(initial_focus); if (result) {