Index: modules/simpletest/tests/bootstrap.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/bootstrap.test,v
retrieving revision 1.4
diff -u -p -r1.4 bootstrap.test
--- modules/simpletest/tests/bootstrap.test	2 Nov 2008 10:56:35 -0000	1.4
+++ modules/simpletest/tests/bootstrap.test	12 Nov 2008 22:38:15 -0000
@@ -158,5 +158,88 @@ class BootstrapVariableTestCase extends 
     $variable = variable_get('simpletest_bootstrap_variable_test', $default_value);
     $this->assertIdentical($variable, $default_value, t('Deleting variables'));
   }
+}
+
+class BootstrapCookieDomainTest extends DrupalWebTestCase {
+
+  function getInfo() {
+    return array(
+      'name' => t('Cookie Domain test'),
+      'description' => t('Tests if cookie domain is conform RFC2109 and RFC2965.'),
+      'group' => t('Bootstrap'),
+    );
+  }
+
+  function setUp() {
+    // save old settings as conf_init() resets them.
+    $this->old_server = $_SERVER;
+    $this->old_session_cookie_domain = ini_get('session.cookie_domain');
+    $this->old_cookie_domain = $GLOBALS['cookie_domain'];
+    $this->old_base_url = $GLOBALS['base_url'];
+    $this->old_base_path = $GLOBALS['base_path'];;
+    $this->old_base_root = $GLOBALS['base_root'];
+    $this->old_conf = $GLOBALS['conf'];
+    $this->old_databases = $GLOBALS['databases'];
+    $this->old_db_prefix = $GLOBALS['db_prefix'];
+    $this->old_installed_profile = $GLOBALS['installed_profile'];
+    $this->old_update_free_access = $GLOBALS['update_free_access'];
+    parent::setUp();
+  }
+
+  /**
+   * Test all sorts of domains.
+   */
+  function testCookieDomain() {
+
+    $cookie_domain_test_cases = array(
+      // Regular domains.
+      'drupal.org'             => '.drupal.org',
+      'www.drupal.org'         => '.drupal.org',
+      // 'www2.drupal.org'        => '.drupal.org',
+      'www.testing.drupal.org' => '.testing.drupal.org',
+      // 'app.testing.drupal.org' => '.testing.drupal.org',
+
+      // 2 level top domains.
+      'drupal.co.uk'           => '.drupal.co.uk',
+      'www.drupal.co.uk'       => '.drupal.co.uk',
+      // 'dev.drupal.co.uk'       => '.drupal.co.uk',
+      'www.dev.drupal.co.uk'   => '.dev.drupal.co.uk',
+      // 'app.dev.drupal.co.uk'   => '.dev.drupal.co.uk',
+
+      // Non domain cookies.
+      'localhost'              => '',
+      '127.0.0.1'              => '',
+      '12.34.56.78'            => '',
+      '10.0.0.1'               => '',
+    );
+
+    foreach ($cookie_domain_test_cases as $test_domain => $expected_cookie_domain) {
+      // First cleanup previous results.
+      $GLOBALS['cookie_domain'] = FALSE;
+      ini_set('session.cookie_domain', '');
+
+      // Perform test.
+      $_SERVER['HTTP_HOST'] = $test_domain;
+      conf_init();
+      $result = ini_get('session.cookie_domain');
+
+      $this->assertEqual($result,  $expected_cookie_domain, 'Test ' . $test_domain, t('Bootstrap'));
+    }
+  }
+
+  function tearDown() {
+    $_SERVER = $this->old_server;
+    ini_set('session.cookie_domain', $this->old_session_cookie_domain);
+    $GLOBALS['cookie_domain'] = $this->old_cookie_domain;
+    $GLOBALS['base_url'] = $this->old_base_url;
+    $GLOBALS['base_path'] = $this->old_base_path;
+    $GLOBALS['base_root'] = $this->old_base_root;
+    $GLOBALS['conf'] = $this->old_conf;
+    $GLOBALS['databases'] = $this->old_databases;
+    $GLOBALS['db_prefix'] = $this->old_db_prefix;
+    $GLOBALS['installed_profile'] = $this->old_installed_profile;
+    $GLOBALS['update_free_access'] = $this->old_update_free_access;
 
+    parent::tearDown();
+  }
 }
