diff --git a/core/includes/common.inc b/core/includes/common.inc
index 3d19d3e..2be9057 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -2957,8 +2957,13 @@ function drupal_get_css($css = NULL, $skip_alter = FALSE) {
 
   // Provide the page with information about the individual CSS files used,
   // information not otherwise available when CSS aggregation is enabled.
-  $setting['ajaxPageState']['css'] = array_fill_keys(array_keys($css), 1);
-  $styles['#attached']['js'][] = array('type' => 'setting', 'data' => $setting);
+  // Skip if no files were added to the page or jQuery.extend() will overwrite
+  // the Drupal.settings.ajaxPageState.css object with an empty array.
+  // Cast the array to an object to be on the safe side even if not empty.
+  if (!empty($css)) {
+    $setting['ajaxPageState']['css'] = (object) array_fill_keys(array_keys($css), 1);
+    $styles['#attached']['js'][] = array('type' => 'setting', 'data' => $setting);
+  }
 
   return drupal_render($styles);
 }
diff --git a/core/modules/simpletest/tests/ajax.test b/core/modules/simpletest/tests/ajax.test
index 9a76b96..8e731b8 100644
--- a/core/modules/simpletest/tests/ajax.test
+++ b/core/modules/simpletest/tests/ajax.test
@@ -127,6 +127,18 @@ class AJAXFrameworkTestCase extends AJAXTestCase {
       'css' => drupal_get_path('module', 'system') . '/system.admin.css',
       'js' => drupal_get_path('module', 'system') . '/system.js',
     );
+    // @todo D8: Add a drupal_css_defaults() helper function.
+    $expected_css_html = drupal_get_css(array($expected['css'] => array(
+      'type' => 'file',
+      'group' => CSS_DEFAULT,
+      'weight' => 0,
+      'every_page' => FALSE,
+      'media' => 'all',
+      'preprocess' => TRUE,
+      'data' => $expected['css'],
+      'browsers' => array('IE' => TRUE, '!IE' => TRUE),
+    )), TRUE);
+    $expected_js_html = drupal_get_js('header', array($expected['js'] => drupal_js_defaults($expected['js'])), TRUE);
 
     // Get the base page.
     $this->drupalGet('ajax_forms_test_lazy_load_form');
@@ -135,13 +147,34 @@ class AJAXFrameworkTestCase extends AJAXTestCase {
     $original_js = $original_settings['ajaxPageState']['js'];
 
     // Verify that the base page doesn't have the settings and files that are to
-    // be lazy loaded as part of the next request.
+    // be lazy loaded as part of the next requests.
     $this->assertTrue(!isset($original_settings[$expected['setting_name']]), t('Page originally lacks the %setting, as expected.', array('%setting' => $expected['setting_name'])));
     $this->assertTrue(!isset($original_settings[$expected['css']]), t('Page originally lacks the %css file, as expected.', array('%css' => $expected['css'])));
     $this->assertTrue(!isset($original_settings[$expected['js']]), t('Page originally lacks the %js file, as expected.', array('%js' => $expected['js'])));
 
-    // Submit the AJAX request.
-    $commands = $this->drupalPostAJAX(NULL, array(), array('op' => t('Submit')));
+    // Submit the AJAX request without triggering files getting added.
+    $commands = $this->drupalPostAJAX(NULL, array('add_files' => FALSE), array('op' => t('Submit')));
+    $new_settings = $this->drupalGetSettings();
+
+    // Verify the setting was not added when not expected.
+    $this->assertTrue(!isset($new_settings['setting_name']), t('Page still lacks the %setting, as expected.', array('%setting' => $expected['setting_name'])));
+    // Verify a settings command does not add CSS or scripts to Drupal.settings
+    // and no command inserts the corresponding tags on the page.
+    $found_settings_command = FALSE;
+    $found_markup_command = FALSE;
+    foreach ($commands as $command) {
+      if ($command['command'] == 'settings' && (array_key_exists('css', $command['settings']['ajaxPageState']) || array_key_exists('js', $command['settings']['ajaxPageState']))) {
+        $found_settings_command = TRUE;
+      }
+      if (isset($command['data']) && ($command['data'] == $expected_js_html || $command['data'] == $expected_css_html)) {
+        $found_markup_command = TRUE;
+      }
+    }
+    $this->assertFalse($found_settings_command, t('Page state still lacks the %css and %js files, as expected.', array('%css' => $expected['css'], '%js' => $expected['js'])));
+    $this->assertFalse($found_markup_command, t('Page still lacks the %css and %js files, as expected.', array('%css' => $expected['css'], '%js' => $expected['js'])));
+
+    // Submit the AJAX request and trigger adding files.
+    $commands = $this->drupalPostAJAX(NULL, array('add_files' => TRUE), array('op' => t('Submit')));
     $new_settings = $this->drupalGetSettings();
     $new_css = $new_settings['ajaxPageState']['css'];
     $new_js = $new_settings['ajaxPageState']['js'];
@@ -151,17 +184,6 @@ class AJAXFrameworkTestCase extends AJAXTestCase {
 
     // Verify the expected CSS file was added, both to Drupal.settings, and as
     // an AJAX command for inclusion into the HTML.
-    // @todo A drupal_css_defaults() function in Drupal 8 would be nice.
-    $expected_css_html = drupal_get_css(array($expected['css'] => array(
-      'type' => 'file',
-      'group' => CSS_DEFAULT,
-      'weight' => 0,
-      'every_page' => FALSE,
-      'media' => 'all',
-      'preprocess' => TRUE,
-      'data' => $expected['css'],
-      'browsers' => array('IE' => TRUE, '!IE' => TRUE),
-    )), TRUE);
     $this->assertEqual($new_css, $original_css + array($expected['css'] => 1), t('Page state now has the %css file.', array('%css' => $expected['css'])));
     $this->assertCommand($commands, array('data' => $expected_css_html), t('Page now has the %css file.', array('%css' => $expected['css'])));
 
@@ -170,7 +192,6 @@ class AJAXFrameworkTestCase extends AJAXTestCase {
     // string containing the SCRIPT tag, we also ensure that unexpected
     // JavaScript code, such as a jQuery.extend() that would potentially clobber
     // rather than properly merge settings, didn't accidentally get added.
-    $expected_js_html = drupal_get_js('header', array($expected['js'] => drupal_js_defaults($expected['js'])), TRUE);
     $this->assertEqual($new_js, $original_js + array($expected['js'] => 1), t('Page state now has the %js file.', array('%js' => $expected['js'])));
     $this->assertCommand($commands, array('data' => $expected_js_html), t('Page now has the %js file.', array('%js' => $expected['js'])));
   }
diff --git a/core/modules/simpletest/tests/ajax_forms_test.module b/core/modules/simpletest/tests/ajax_forms_test.module
index 075b005..6a95710 100644
--- a/core/modules/simpletest/tests/ajax_forms_test.module
+++ b/core/modules/simpletest/tests/ajax_forms_test.module
@@ -468,6 +468,10 @@ function ajax_forms_test_validation_form_callback($form, $form_state) {
  * Form builder: Builds a form that triggers a simple AJAX callback.
  */
 function ajax_forms_test_lazy_load_form($form, &$form_state) {
+  $form['add_files'] = array(
+    '#type' => 'checkbox',
+    '#default_value' => FALSE,
+  );
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Submit'),
@@ -482,9 +486,11 @@ function ajax_forms_test_lazy_load_form($form, &$form_state) {
  * Form submit handler: Adds JavaScript and CSS that wasn't on the original form.
  */
 function ajax_forms_test_lazy_load_form_submit($form, &$form_state) {
-  drupal_add_js(array('ajax_forms_test_lazy_load_form_submit' => 'executed'), 'setting');
-  drupal_add_css(drupal_get_path('module', 'system') . '/system.admin.css');
-  drupal_add_js(drupal_get_path('module', 'system') . '/system.js');
+  if ($form_state['values']['add_files']) {
+    drupal_add_js(array('ajax_forms_test_lazy_load_form_submit' => 'executed'), 'setting');
+    drupal_add_css(drupal_get_path('module', 'system') . '/system.admin.css');
+    drupal_add_js(drupal_get_path('module', 'system') . '/system.js');
+  }
   $form_state['rebuild'] = TRUE;
 }
 
