diff --git a/core/modules/taxonomy/src/Tests/TermAutocompleteTest.php b/core/modules/taxonomy/src/Tests/TermAutocompleteTest.php
new file mode 100644
index 0000000..d416abc
--- /dev/null
+++ b/core/modules/taxonomy/src/Tests/TermAutocompleteTest.php
@@ -0,0 +1,149 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\taxonomy\Tests\TermAutocompleteTest.
+ */
+
+namespace Drupal\taxonomy\Tests;
+
+use Drupal\Component\Utility\Unicode;
+use Drupal\Core\Field\FieldStorageDefinitionInterface;
+
+/**
+ * Tests the autocomplete implementation of the taxonomy class.
+ *
+ * @group taxonomy
+ */
+class TermAutocompleteTest extends TaxonomyTestBase {
+
+  /**
+   * @var \Drupal\taxonomy\Entity\Vocabulary
+   */
+  protected $vocabulary;
+
+  /**
+   * @var string
+   */
+  protected $field_name;
+
+  /**
+   * @var \Drupal\user\Entity\User
+   */
+  protected $admin_user;
+
+  protected function setUp() {
+    parent::setUp();
+
+    // Create a vocabulary.
+    $this->vocabulary = $this->createVocabulary();
+
+    // Create 11 terms, starting with the same prefix, in a non-alphabetical
+    // order.
+    $this->createTerm($this->vocabulary, ['name' => 'aaa 20']);
+    $this->createTerm($this->vocabulary, ['name' => 'aaa 70']);
+    $this->createTerm($this->vocabulary, ['name' => 'aaa 10']);
+    $this->createTerm($this->vocabulary, ['name' => 'aaa 12']);
+    $this->createTerm($this->vocabulary, ['name' => 'aaa 40']);
+    $this->createTerm($this->vocabulary, ['name' => 'aaa 11']);
+    $this->createTerm($this->vocabulary, ['name' => 'aaa 30']);
+    $this->createTerm($this->vocabulary, ['name' => 'aaa 50']);
+    $this->createTerm($this->vocabulary, ['name' => 'aaa 80']);
+    $this->createTerm($this->vocabulary, ['name' => 'aaa 90']);
+    $this->createTerm($this->vocabulary, ['name' => 'aaa 60']);
+
+    // Create a taxonomy_term_reference field on the article Content Type that
+    // uses a taxonomy_autocomplete widget.
+    $this->field_name = Unicode::strtolower($this->randomMachineName());
+    entity_create('field_storage_config', array(
+      'field_name' => $this->field_name,
+      'entity_type' => 'node',
+      'type' => 'taxonomy_term_reference',
+      'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
+      'settings' => array(
+        'allowed_values' => array(
+          array(
+            'vocabulary' => $this->vocabulary->id(),
+            'parent' => 0,
+          ),
+        ),
+      ),
+    ))->save();
+    entity_create('field_config', array(
+      'field_name' => $this->field_name,
+      'bundle' => 'article',
+      'entity_type' => 'node',
+    ))->save();
+    entity_get_form_display('node', 'article', 'default')
+      ->setComponent($this->field_name, array(
+        'type' => 'taxonomy_autocomplete',
+      ))
+      ->save();
+    entity_get_display('node', 'article', 'default')
+      ->setComponent($this->field_name, array(
+        'type' => 'taxonomy_term_reference_link',
+      ))
+      ->save();
+
+    // Create an user then login.
+    $this->admin_user = $this->drupalCreateUser(array('create article content'));
+    $this->drupalLogin($this->admin_user);
+  }
+
+  /**
+   * Tests that the autocomplete method returns the good number of results.
+   *
+   * @see \Drupal\taxonomy\Controller\TermAutocompleteController::autocomplete()
+   */
+  public function testAutocompleteCountResults() {
+    // No matching term found.
+    $data = $this->drupalGetJSON(
+      'taxonomy/autocomplete/node/' . $this->field_name,
+      ['query' => ['q' => 'zzz']]
+    );
+    $this->assertTrue(empty($data), 'Autocomplete returned no results');
+
+    // Only one matching term found.
+    $data = $this->drupalGetJSON(
+      'taxonomy/autocomplete/node/' . $this->field_name,
+      ['query' => ['q' => 'aaa 10']]
+    );
+    $this->assertEqual(1, count($data), 'Autocomplete returned 1 result');
+
+    // Less than 10 matching terms found.
+    $data = $this->drupalGetJSON(
+      'taxonomy/autocomplete/node/' . $this->field_name,
+      ['query' => ['q' => 'aaa 1']]
+    );
+    $this->assertEqual(3, count($data), 'Autocomplete returned 3 results');
+
+    // More than 10 matching terms found.
+    $data = $this->drupalGetJSON(
+      'taxonomy/autocomplete/node/' . $this->field_name,
+      ['query' => ['q' => 'aaa']]
+    );
+    $this->assertEqual(10, count($data), 'Autocomplete returned 10 results (over 11)');
+  }
+
+  /**
+   * Tests that the autocomplete method returns properly ordered results.
+   *
+   * @see \Drupal\taxonomy\Controller\TermAutocompleteController::autocomplete()
+   */
+  public function testAutocompleteOrderedResults() {
+    $data = $this->drupalGetJSON(
+      'taxonomy/autocomplete/node/' . $this->field_name,
+      ['query' => ['q' => 'aaa']]
+    );
+    $this->assertEqual('aaa 10', $data[0]['label']);
+    $this->assertEqual('aaa 11', $data[1]['label']);
+    $this->assertEqual('aaa 12', $data[2]['label']);
+    $this->assertEqual('aaa 20', $data[3]['label']);
+    $this->assertEqual('aaa 30', $data[4]['label']);
+    $this->assertEqual('aaa 40', $data[5]['label']);
+    $this->assertEqual('aaa 50', $data[6]['label']);
+    $this->assertEqual('aaa 60', $data[7]['label']);
+    $this->assertEqual('aaa 70', $data[8]['label']);
+    $this->assertEqual('aaa 80', $data[9]['label']);
+  }
+}
