diff --git a/core/modules/system/lib/Drupal/system/Tests/Menu/TrailTest.php b/core/modules/system/lib/Drupal/system/Tests/Menu/TrailTest.php
index a3c024f..fa7f404 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Menu/TrailTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Menu/TrailTest.php
@@ -49,6 +49,19 @@ class TrailTest extends MenuTestBase {
       ->condition('module', 'system')
       ->condition('delta', 'management')
       ->execute();
+
+    // This test puts menu links in the Main menu and then tests for their
+    // presence on the page, so we need to ensure that the Main menu block will
+    // be displayed in all active themes.
+    db_update('block')
+      ->fields(array(
+        // Use a region that is valid for all themes.
+        'region' => 'content',
+        'status' => 1,
+      ))
+      ->condition('module', 'system')
+      ->condition('delta', 'main-menu')
+      ->execute();
   }
 
   /**
@@ -206,4 +219,82 @@ class TrailTest extends MenuTestBase {
       $this->assertBreadcrumb(NULL, $expected_trail[$status_code]['final']);
     }
   }
+
+  /**
+   * Tests active trails are properly affected by menu_set_active_menu_names().
+   */
+  function testMenuSetActiveMenuNames() {
+    // We will test active trails to path admin/config/development/menu-trail
+    // as its callback allows us to call menu_set_active_menu_names() by setting
+    // variable menu_test_menu_set_active_menu_names. The default link to this
+    // path resides in the Management menu.
+    $trees['management'] = array(
+      'admin' => t('Administration'),
+      'admin/config' => t('Configuration'),
+      'admin/config/development' => t('Development'),
+      'admin/config/development/menu-trail' => t('Menu trail - Case 2'),
+    );
+
+    // Create a parent link with a child leading to our test path, in each of
+    // the Navigation and Main menus.
+    foreach (array('navigation', 'main-menu') as $menu_name) {
+      $base_options = array(
+        'module' => 'menu_test',
+        'menu_name' => $menu_name,
+      );
+
+      $parent = $base_options + array(
+        'link_title' => $this->randomName(16),
+        'link_path' => 'menu-test',
+      );
+      menu_link_save($parent);
+
+      $link = $base_options + array(
+        'link_title' => $this->randomName(16),
+        'link_path' => 'admin/config/development/menu-trail',
+        'plid' => $parent['mlid'],
+      );
+      menu_link_save($link);
+
+      $trees[$menu_name] = array(
+        'menu-test' => $parent['link_title'],
+        'admin/config/development/menu-trail' => $link['link_title'],
+      );
+    }
+
+    // We now have a tree leading to our test path in each of the 3 menus.
+    // Build all possible permutations.
+    $permutations = array(
+      array('navigation', 'management', 'main-menu'),
+      array('navigation', 'main-menu', 'management'),
+      array('management', 'main-menu', 'navigation'),
+      array('management', 'navigation', 'main-menu'),
+      array('main-menu', 'navigation', 'management'),
+      array('main-menu', 'management', 'navigation'),
+    );
+
+    // Perform tests for each permutation.
+    $home = array('<front>' => 'Home');
+    foreach ($permutations as $menu_names) {
+      // Set the first menu as inactive by removing it from the list.
+      $inactive = array_shift($menu_names);
+      variable_set('menu_test_menu_set_active_menu_names', $menu_names);
+
+      // Verify that breadcrumb reflects the tree of the second menu.
+      $tree = $trees[$menu_names[0]];
+      $trail = $home + $tree;
+      $page_title = array_pop($trail);
+      $this->assertBreadcrumb('admin/config/development/menu-trail', $trail, $page_title, $tree, TRUE);
+
+      // Verify that the link to our test path in the first menu is not
+      // displayed (because its parent is collapsed).
+      $tree = $trees[$inactive];
+      $this->assertNoLink(end($tree));
+
+      // Verify that the link to our test path in the third menu is present.
+      $tree = $trees[$menu_names[1]];
+      $this->assertLink(end($tree));
+    }
+    variable_del('menu_test_menu_set_active_menu_names');
+  }
 }
diff --git a/core/modules/system/tests/modules/menu_test/menu_test.module b/core/modules/system/tests/modules/menu_test/menu_test.module
index 6e6bb4d..6e68f38 100644
--- a/core/modules/system/tests/modules/menu_test/menu_test.module
+++ b/core/modules/system/tests/modules/menu_test/menu_test.module
@@ -369,13 +369,20 @@ function menu_test_callback() {
 }
 
 /**
- * Callback that test menu_test_menu_tree_set_path().
+ * Callback that test menu_test_menu_tree_set_path() and
+ * menu_test_menu_set_active_menu_names().
  */
 function menu_test_menu_trail_callback() {
   $menu_path = variable_get('menu_test_menu_tree_set_path', array());
   if (!empty($menu_path)) {
     menu_tree_set_path($menu_path['menu_name'], $menu_path['path']);
   }
+
+  $menu_names = variable_get('menu_test_menu_set_active_menu_names', array());
+  if (!empty($menu_names)) {
+    menu_set_active_menu_names($menu_names);
+  }
+
   return 'This is menu_test_menu_trail_callback().';
 }
 
