diff --git a/modules/user/tests/user_session_test.info b/modules/user/tests/user_session_test.info
new file mode 100644
index 0000000000..91f2f20c7c
--- /dev/null
+++ b/modules/user/tests/user_session_test.info
@@ -0,0 +1,6 @@
+name = "User module session tests"
+description = "Support module for user session testing."
+package = Testing
+version = VERSION
+core = 7.x
+hidden = TRUE
diff --git a/modules/user/tests/user_session_test.module b/modules/user/tests/user_session_test.module
new file mode 100644
index 0000000000..3743c78059
--- /dev/null
+++ b/modules/user/tests/user_session_test.module
@@ -0,0 +1,31 @@
+<?php
+
+/**
+ * @file
+ * Dummy module implementing a page callback to create an anon session.
+ */
+
+/**
+ * Implements hook_menu().
+ *
+ * Sets up a form that allows a user to validate password.
+ */
+function user_session_test_menu() {
+  $items = array();
+  $items['user_session_test_anon_session'] = array(
+    'page callback' => 'user_session_test_anon_session',
+    'access callback' => TRUE,
+  );
+  return $items;
+}
+
+/**
+ * Page callback.
+ *
+ * Creates an anonymous user session.
+ */
+function user_session_test_anon_session() {
+  $data = 'This dummy data will be stored in a user session.';
+  $_SESSION[__FUNCTION__] = $data;
+  return $data;
+}
diff --git a/modules/user/user.test b/modules/user/user.test
index fb82c93c22..835154b25f 100644
--- a/modules/user/user.test
+++ b/modules/user/user.test
@@ -321,6 +321,10 @@ class UserLoginTestCase extends DrupalWebTestCase {
     );
   }
 
+  function setUp() {
+    parent::setUp('user_session_test');
+  }
+
   /**
    * Test the global login flood control.
    */
@@ -421,6 +425,17 @@ class UserLoginTestCase extends DrupalWebTestCase {
     $this->assertIdentical(_password_get_count_log2($account->pass), DRUPAL_HASH_COUNT + 1);
   }
 
+  /**
+   * Test logging in when an anon session already exists.
+   */
+  function testLoginWithAnonSession() {
+    // Visit the callback to generate a session for this anon user.
+    $this->drupalGet('user_session_test_anon_session');
+    // Now login.
+    $account = $this->drupalCreateUser(array());
+    $this->drupalLogin($account);
+  }
+
   /**
    * Make an unsuccessful login attempt.
    *
