Index: tests/phpunit/includes/testcase-ajax.php
===================================================================
--- tests/phpunit/includes/testcase-ajax.php	(revision 25508)
+++ tests/phpunit/includes/testcase-ajax.php	(working copy)
@@ -42,12 +42,12 @@
 		'oembed_cache', 'image-editor', 'delete-comment', 'delete-tag', 'delete-link',
 		'delete-meta', 'delete-post', 'trash-post', 'untrash-post', 'delete-page', 'dim-comment',
 		'add-link-category', 'add-tag', 'get-tagcloud', 'get-comments', 'replyto-comment',
-		'edit-comment', 'add-menu-item', 'add-meta', 'add-user', 'autosave', 'closed-postboxes',
+		'edit-comment', 'add-menu-item', 'add-meta', 'add-user', 'closed-postboxes',
 		'hidden-columns', 'update-welcome-panel', 'menu-get-metabox', 'wp-link-ajax',
 		'menu-locations-save', 'menu-quick-search', 'meta-box-order', 'get-permalink',
 		'sample-permalink', 'inline-save', 'inline-save-tax', 'find_posts', 'widgets-order',
 		'save-widget', 'set-post-thumbnail', 'date_format', 'time_format', 'wp-fullscreen-save-post',
-		'wp-remove-post-lock', 'dismiss-wp-pointer', 'nopriv_autosave'
+		'wp-remove-post-lock', 'dismiss-wp-pointer', 'heartbeat', 'nopriv_heartbeat',
 	);
 
 	/**
Index: tests/phpunit/tests/ajax/Autosave.php
===================================================================
--- tests/phpunit/tests/ajax/Autosave.php	(revision 25508)
+++ tests/phpunit/tests/ajax/Autosave.php	(working copy)
@@ -23,92 +23,158 @@
 	protected $_post = null;
 
 	/**
+	 * user_id
+	 * @var int
+	 */
+	protected $user_id = 0;
+
+	/**
 	 * Set up the test fixture
 	 */
 	public function setUp() {
 		parent::setUp();
+		// Set a user so the $post has 'post_author'
+		$this->user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
+		wp_set_current_user( $this->user_id );
+		
 		$post_id = $this->factory->post->create( array( 'post_status' => 'draft' ) );
 		$this->_post = get_post( $post_id );
 	}
 
 	/**
+	 * Tear down the test fixture.
+	 * Reset the current user
+	 */
+	public function tearDown() {
+		parent::tearDown();
+		wp_set_current_user( 0 );
+	}
+
+	/**
 	 * Test autosaving a post
 	 * @return void
 	 */
 	public function test_autosave_post() {
+		// The original post_author
+		wp_set_current_user( $this->user_id );
 
-		// Become an admin
-		$this->_setRole( 'administrator' );
-
 		// Set up the $_POST request
 		$md5 = md5( uniqid() );
 		$_POST = array(
-		    'post_id'       => $this->_post->ID,
-		    'autosavenonce' => wp_create_nonce( 'autosave' ),
-		    'post_content'  => $this->_post->post_content . PHP_EOL . $md5,
-			'post_type'     => 'post',
-		    'autosave'      => 1,
+			'action' =>	'heartbeat',
+			'_nonce' => wp_create_nonce( 'heartbeat-nonce' ),
+			'data' => array(
+				'autosave' => array(
+				    'post_id'       => $this->_post->ID,
+				    '_wpnonce'      => wp_create_nonce( 'update-post_' . $this->_post->ID ),
+				    'post_content'  => $this->_post->post_content . PHP_EOL . $md5,
+					'post_type'     => 'post',
+				),
+			),
 		);
 
 		// Make the request
 		try {
-			$this->_handleAjax( 'autosave' );
+			$this->_handleAjax( 'heartbeat' );
 		} catch ( WPAjaxDieContinueException $e ) {
 			unset( $e );
 		}
 
-		// Get the response
-		$xml = simplexml_load_string( $this->_last_response, 'SimpleXMLElement', LIBXML_NOCDATA );
+		// Get the response, it is in heartbeat's response
+		$response = json_decode( $this->_last_response, true );
 
 		// Ensure everything is correct
-		$this->assertEquals( $this->_post->ID, (int) $xml->response[0]->autosave['id'] );
-		$this->assertEquals( 'autosave_' . $this->_post->ID, (string) $xml->response['action']);
+		$this->assertNotEmpty( $response['autosave'] );
+		$this->assertTrue( $response['autosave']['success'] );
 
 		// Check that the edit happened
-		$post = get_post( $this->_post->ID) ;
+		$post = get_post( $this->_post->ID );
 		$this->assertGreaterThanOrEqual( 0, strpos( $post->post_content, $md5 ) );
 	}
-
+	
 	/**
-	 * Test with an invalid nonce
+	 * Test autosaving a locked post
 	 * @return void
 	 */
-	public function test_with_invalid_nonce( ) {
+	public function test_autosave_locked_post() {
+		// Lock the post to another user
+		$another_user_id = $this->factory->user->create( array( 'role' => 'editor' ) );
+		wp_set_current_user( $another_user_id );
+		wp_set_post_lock( $this->_post->ID );
+		
+		wp_set_current_user( $this->user_id );
 
-		// Become an administrator
-		$this->_setRole( 'administrator' );
+		// Ensure post is locked
+		$this->assertEquals( $another_user_id, wp_check_post_lock( $this->_post->ID ) );
 
 		// Set up the $_POST request
+		$md5 = md5( uniqid() );
 		$_POST = array(
-		    'post_id'       => $this->_post->ID,
-		    'autosavenonce' => md5( uniqid() ),
-		    'autosave'      => 1
+			'action' =>	'heartbeat',
+			'_nonce' => wp_create_nonce( 'heartbeat-nonce' ),
+			'data' => array(
+				'autosave' => array(
+				    'post_id'       => $this->_post->ID,
+				    '_wpnonce'      => wp_create_nonce( 'update-post_' . $this->_post->ID ),
+				    'post_content'  => $this->_post->post_content . PHP_EOL . $md5,
+					'post_type'     => 'post',
+				),
+			),
 		);
 
 		// Make the request
-		$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
-		$this->_handleAjax( 'autosave' );
+		try {
+			$this->_handleAjax( 'heartbeat' );
+		} catch ( WPAjaxDieContinueException $e ) {
+			unset( $e );
+		}
+
+		$response = json_decode( $this->_last_response, true );
+
+		// Ensure everything is correct
+		$this->assertNotEmpty( $response['autosave'] );
+		$this->assertTrue( $response['autosave']['success'] );
+
+		// Check that the original post was NOT edited
+		$post = get_post( $this->_post->ID );
+		$this->assertFalse( strpos( $post->post_content, $md5 ) );
+
+		// Check if the autosave post was created
+		$autosave = wp_get_post_autosave( $this->_post->ID, get_current_user_id() );
+		$this->assertNotEmpty( $autosave );
+		$this->assertGreaterThanOrEqual( 0, strpos( $autosave->post_content, $md5 ) );
 	}
 
 	/**
-	 * Test with a bad post id
+	 * Test with an invalid nonce
 	 * @return void
 	 */
-	public function test_with_invalid_post_id( ) {
+	public function test_with_invalid_nonce( ) {
 
-		// Become an administrator
-		$this->_setRole( 'administrator' );
+		wp_set_current_user( $this->user_id );
 
 		// Set up the $_POST request
 		$_POST = array(
-		    'post_id'       => 0,
-		    'autosavenonce' => wp_create_nonce( 'autosave' ),
-		    'autosave'      => 1,
-			'post_type'     => 'post'
+			'action' =>	'heartbeat',
+			'_nonce' => wp_create_nonce( 'heartbeat-nonce' ),
+			'data' => array(
+				'autosave' => array(
+				    'post_id'       => $this->_post->ID,
+				    '_wpnonce'      => substr( md5( uniqid() ), 0, 10 ),
+				),
+			),
 		);
 
 		// Make the request
-		$this->setExpectedException( 'WPAjaxDieStopException', 'You are not allowed to edit this post.' );
-		$this->_handleAjax( 'autosave' );
+		try {
+			$this->_handleAjax( 'heartbeat' );
+		} catch ( WPAjaxDieContinueException $e ) {
+			unset( $e );
+		}
+
+		$response = json_decode( $this->_last_response, true );
+
+		$this->assertNotEmpty( $response['autosave'] );
+		$this->assertFalse( $response['autosave']['success'] );
 	}
 }
