diff --git a/core/modules/system/tests/modules/entity_reference_selection_test/config/schema/entity_reference_selection_test.schema.yml b/core/modules/system/tests/modules/entity_reference_selection_test/config/schema/entity_reference_selection_test.schema.yml
new file mode 100644
index 0000000000..af69ac5574
--- /dev/null
+++ b/core/modules/system/tests/modules/entity_reference_selection_test/config/schema/entity_reference_selection_test.schema.yml
@@ -0,0 +1,3 @@
+# Schema for the entity reference 'entity_test_all_except_host' selection handler settings.
+entity_reference_selection.entity_test_all_except_host:
+  type: entity_reference_selection.default
diff --git a/core/modules/system/tests/modules/entity_reference_selection_test/entity_reference_selection_test.info.yml b/core/modules/system/tests/modules/entity_reference_selection_test/entity_reference_selection_test.info.yml
new file mode 100644
index 0000000000..e7ea55f005
--- /dev/null
+++ b/core/modules/system/tests/modules/entity_reference_selection_test/entity_reference_selection_test.info.yml
@@ -0,0 +1,8 @@
+name: "Entity Reference Selection plugin test"
+type: module
+description: "Support module for testing entity reference selection plugins."
+core: 8.x
+package: Testing
+version: VERSION
+dependencies:
+  - entity_test
diff --git a/core/modules/system/tests/modules/entity_reference_selection_test/src/Plugin/EntityReferenceSelection/AllExceptHostEntity.php b/core/modules/system/tests/modules/entity_reference_selection_test/src/Plugin/EntityReferenceSelection/AllExceptHostEntity.php
new file mode 100644
index 0000000000..4a8c006602
--- /dev/null
+++ b/core/modules/system/tests/modules/entity_reference_selection_test/src/Plugin/EntityReferenceSelection/AllExceptHostEntity.php
@@ -0,0 +1,40 @@
+<?php
+
+namespace Drupal\entity_reference_selection_test\Plugin\EntityReferenceSelection;
+
+use Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection;
+use Drupal\entity_test\Entity\EntityTest;
+
+/**
+ * Allows access to all entities except for the host entity.
+ *
+ * @EntityReferenceSelection(
+ *   id = "entity_test_all_except_host",
+ *   label = @Translation("All except host entity."),
+ *   entity_types = {"entity_test"},
+ *   group = "entity_test_all_except_host"
+ * )
+ */
+class AllExceptHostEntity extends DefaultSelection {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
+    $query = parent::buildEntityQuery($match, $match_operator);
+
+    /** @var \Drupal\Core\Entity\EntityInterface $entity */
+    $entity = $this->configuration['entity'];
+
+    // The host entity should be the same type as the entity type this plugin
+    // supports.
+    if ($entity instanceof EntityTest) {
+      $target_type = $this->configuration['target_type'];
+      $entity_type = $this->entityManager->getDefinition($target_type);
+      $query->condition($entity_type->getKey('id'), $entity->id(), '<>');
+    }
+
+    return $query;
+  }
+
+}
diff --git a/core/tests/Drupal/FunctionalJavascriptTests/EntityReference/EntityReferenceAutocompleteWidgetTest.php b/core/tests/Drupal/FunctionalJavascriptTests/EntityReference/EntityReferenceAutocompleteWidgetTest.php
index 511dee6e32..4cab2afc34 100644
--- a/core/tests/Drupal/FunctionalJavascriptTests/EntityReference/EntityReferenceAutocompleteWidgetTest.php
+++ b/core/tests/Drupal/FunctionalJavascriptTests/EntityReference/EntityReferenceAutocompleteWidgetTest.php
@@ -6,6 +6,8 @@ use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
 use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
 use Drupal\simpletest\ContentTypeCreationTrait;
 use Drupal\simpletest\NodeCreationTrait;
+use Drupal\Core\Entity\Entity\EntityFormDisplay;
+use Drupal\entity_test\Entity\EntityTest;
 
 /**
  * Tests the output of entity reference autocomplete widgets.
@@ -21,7 +23,7 @@ class EntityReferenceAutocompleteWidgetTest extends JavascriptTestBase {
   /**
    * {@inheritdoc}
    */
-  public static $modules = ['node'];
+  public static $modules = ['node', 'entity_test', 'entity_reference_selection_test'];
 
   /**
    * {@inheritdoc}
@@ -99,4 +101,49 @@ class EntityReferenceAutocompleteWidgetTest extends JavascriptTestBase {
     $assert_session->pageTextNotContains('Page test');
   }
 
+  /**
+   * Tests that the autocomplete widget knows about the entity its attached to.
+   *
+   * Ensures that the entity the autocomplete widget stores the entity it is
+   * rendered on, and is available in the autocomplete results AJAX request.
+   */
+  public function testEntityReferenceAutocompleteWidgetAttachedEntity() {
+    $user = $this->drupalCreateUser([
+      'administer entity_test content',
+    ]);
+    $this->drupalLogin($user);
+
+    $field_name = 'field_test';
+    $this->createEntityReferenceField('entity_test', 'entity_test', $field_name, $field_name, 'entity_test', 'entity_test_all_except_host', ['target_bundles' => ['entity_test']]);
+    $form_display = EntityFormDisplay::load('entity_test.entity_test.default');
+    $form_display->setComponent($field_name, [
+      'type' => 'entity_reference_autocomplete',
+      'settings' => [
+        'match_operator' => 'CONTAINS',
+      ],
+    ]);
+    $form_display->save();
+
+    $host = EntityTest::create(['name' => 'dark green']);
+    $host->save();
+    $other = EntityTest::create(['name' => 'dark blue']);
+    $other->save();
+
+    $this->drupalGet($host->toUrl('edit-form'));
+    $this->assertSession()->statusCodeEquals(200);
+
+    // Trigger the autocomplete.
+    $page = $this->getSession()->getPage();
+    $autocomplete_field = $page->findField($field_name . '[0][target_id]');
+    $autocomplete_field->setValue('dark');
+    $this->getSession()->getDriver()->keyDown($autocomplete_field->getXpath(), ' ');
+    $this->assertSession()->waitOnAutocomplete();
+
+    // Check the autocomplete results.
+    $results = $page->findAll('css', '.ui-autocomplete li');
+    $this->assertCount(1, $results);
+    $this->assertSession()->elementTextNotContains('css', '.ui-autocomplete li', 'dark green');
+    $this->assertSession()->elementTextContains('css', '.ui-autocomplete li', 'dark blue');
+  }
+
 }
