testMenuItemKeyboardActivation() {
    popup.decorate(menu);
    popup.attach(anchor);
    // Check that if the ESC key is pressed the focus is on
    // the anchor element.
    events.fireKeySequence(menu, KeyCodes.ESC);
    assertEquals(anchor, document.activeElement);

    let menuitemListenerFired = false;
    function onMenuitemAction(event) {
      if (event.keyCode == KeyCodes.SPACE || event.keyCode == KeyCodes.ENTER) {
        menuitemListenerFired = true;
      }
    }
    handler.listen(menuitem1, EventType.KEYDOWN, onMenuitemAction);
    // Simulate opening a menu using the DOWN key, and pressing the SPACE/ENTER
    // key in order to activate the first menuitem.
    events.fireKeySequence(anchor, KeyCodes.DOWN);
    events.fireKeySequence(menu, KeyCodes.SPACE);
    assertTrue(menuitemListenerFired);
    menuitemListenerFired = false;
    events.fireKeySequence(anchor, KeyCodes.DOWN);
    events.fireKeySequence(menu, KeyCodes.ENTER);
    assertTrue(menuitemListenerFired);
    // Make sure the menu item's listener doesn't fire for any key.
    menuitemListenerFired = false;
    events.fireKeySequence(anchor, KeyCodes.DOWN);
    events.fireKeySequence(menu, KeyCodes.SHIFT);
    assertFalse(menuitemListenerFired);

    // Simulate opening menu and moving down to the third menu item using the
    // DOWN key, and then activating it using the SPACE key.
    menuitemListenerFired = false;
    handler.listen(menuitem3, EventType.KEYDOWN, onMenuitemAction);
    events.fireKeySequence(anchor, KeyCodes.DOWN);
    events.fireKeySequence(anchor, KeyCodes.DOWN);
    events.fireKeySequence(anchor, KeyCodes.DOWN);
    events.fireKeySequence(menu, KeyCodes.SPACE);
    assertTrue(menuitemListenerFired);
  }
Tests activation of menu items by keyboard.