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	22 Nov 2008 09:03:46 -0000
@@ -158,5 +158,87 @@ 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('The generated cookie domain should be conform RFC2109 and RFC2965.'),
+      'group' => t('Bootstrap'),
+    );
+  }
+
+  function setUp() {
+    // Save 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.
+      'example.com'             => '.example.com',
+      'www.example.com'         => '.example.com',
+      // 'www2.example.com'        => '.example.com',
+      'www.testing.example.com' => '.testing.example.com',
+      // 'app.testing.example.com' => '.testing.example.com',
+
+      // 2 level top domains.
+      'example.co.uk'           => '.example.co.uk',
+      'www.example.co.uk'       => '.example.co.uk',
+      // 'dev.example.co.uk'       => '.example.co.uk',
+      'www.dev.example.co.uk'   => '.dev.example.co.uk',
+      // 'app.dev.example.co.uk'   => '.dev.example.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, t('Cookie domain of @test_domain should be \'@expected_domain\' (got \'@result\').', array('@test_domain' => $test_domain, '@expected_domain' => $expected_cookie_domain, '@result' => $result)));
+    }
+  }
+
+  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();
+  }
 }
