Index: browser.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/browser/Attic/browser.info,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 browser.info
--- browser.info	4 Nov 2009 17:00:01 -0000	1.1.2.1
+++ browser.info	9 Nov 2009 21:19:47 -0000
@@ -6,3 +6,4 @@
 core = 7.x
 files[] = browser.module
 files[] = browser.inc
+files[] = browser.test
Index: tests/browser_test.module
===================================================================
RCS file: tests/browser_test.module
diff -N tests/browser_test.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/browser_test.module	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,82 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Provide various pages for testing the internal browser.
+ */
+
+/**
+ * Implement hook_menu().
+ */
+function browser_test_menu() {
+  $items['browser_test/print/get'] = array(
+    'page callback' => 'browser_test_print_get',
+    'access arguments' => array('access content'),
+  );
+  $items['browser_test/print/post'] = array(
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('browser_test_print_post_form'),
+    'access arguments' => array('access content'),
+  );
+
+  $items['browser_test/refresh/meta'] = array(
+    'page callback' => 'browser_test_refresh_meta',
+    'access arguments' => array('access content'),
+  );
+  $items['browser_test/refresh/header'] = array(
+    'page callback' => 'browser_test_refresh_header',
+    'access arguments' => array('access content'),
+  );
+
+  return $items;
+}
+
+function browser_test_print_get() {
+  echo $_GET['foo'];
+  exit;
+}
+
+function browser_test_print_post_form($form, &$form_state) {
+  $form['foo'] = array(
+    '#type' => 'textfield',
+  );
+  $form['op'] = array(
+    '#type' => 'submit',
+    '#value' => t('Submit'),
+  );
+
+  return $form;
+}
+
+function browser_test_print_post_form_submit($form, &$form_state) {
+  echo $form_state['values']['foo'];
+  exit;
+}
+
+function browser_test_refresh_meta() {
+  if (!isset($_GET['refresh'])) {
+    $url = url('browser_test/refresh/meta', array('absolute' => TRUE, 'query' => array('refresh' => 'true')));
+    $element = array(
+      '#tag' => 'meta',
+      '#attributes' => array(
+        'http-equiv' => 'Refresh',
+        'content' => '0; URL=' . $url,
+      ),
+    );
+    drupal_add_html_head($element, 'browser_test_refresh_meta');
+    return '';
+  }
+  echo 'Refresh successful';
+  exit;
+}
+
+function browser_test_refresh_header() {
+  if (!isset($_GET['refresh'])) {
+    $url = url('browser_test/refresh/header', array('absolute' => TRUE, 'query' => array('refresh' => 'true')));
+    drupal_add_http_header('Location', $url);
+    return '';
+  }
+  echo 'Refresh successful';
+  exit;
+}
Index: tests/browser_test.info
===================================================================
RCS file: tests/browser_test.info
diff -N tests/browser_test.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/browser_test.info	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,8 @@
+; $Id$
+name = Browser test
+description = Provide various pages for testing the browser.
+package = Testing
+version = VERSION
+core = 7.x
+files[] = browser_test.module
+hidden = TRUE
Index: .project
===================================================================
RCS file: .project
diff -N .project
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ .project	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>browser</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.php.core.PhpIncrementalProjectBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.php.core.ValidationManagerWrapper</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.php.core.PHPNature</nature>
+	</natures>
+</projectDescription>
Index: browser.test
===================================================================
RCS file: browser.test
diff -N browser.test
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ browser.test	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,123 @@
+<?php
+// $Id: browser.test,v 1.2 2009/09/20 17:40:41 dries Exp $
+
+/**
+ * @file
+ * Tests for the internal web browser.
+ */
+
+/**
+ * Test general browser functionality.
+ */
+class BrowserTestCase extends DrupalWebTestCase {
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Browser',
+      'description' => 'Test general browser functionality.',
+      'group' => 'Browser',
+    );
+  }
+
+  public function setUp() {
+    parent::setUp('browser_test');
+  }
+
+  /**
+   * Test general browser functionality.
+   */
+  public function testBrowserBackend() {
+    global $db_prefix;
+
+    $browser = new Browser();
+    $browser->setUserAgent(drupal_generate_test_ua($db_prefix));
+
+    // Check browser refresh, both meta tag and HTTP header.
+    $request = $browser->get(url('browser_test/refresh/meta', array('absolute' => TRUE)));
+    $this->assertEqual($request['content'], 'Refresh successful', 'Meta refresh successful ($request)');
+    $this->assertEqual($browser->getContent(), 'Refresh successful', 'Meta refresh successful ($browser)');
+
+    $request = $browser->get(url('browser_test/refresh/header', array('absolute' => TRUE)));
+    $this->assertEqual($request['content'], 'Refresh successful', 'Meta refresh successful ($request)');
+    $this->assertEqual($browser->getContent(), 'Refresh successful', 'Meta refresh successful ($browser)');
+  }
+}
+
+/**
+ * Test browser backend wrappers.
+ */
+class BrowserBackendTestCase extends DrupalWebTestCase {
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Browser - wrapper backends',
+      'description' => 'Test stream and curl backends execution of GET and POST requests.',
+      'group' => 'Browser',
+    );
+  }
+
+  public function setUp() {
+    parent::setUp('browser_test');
+  }
+
+  /**
+   * Test stream and curl backends execution of GET and POST requests.
+   */
+  public function testBrowserBackend() {
+    global $db_prefix;
+
+    foreach (array('stream', 'curl') as $wrapper) {
+      $browser = new Browser($wrapper == 'stream');
+      $browser->setUserAgent(drupal_generate_test_ua($db_prefix));
+
+      $string = $this->randomName();
+      $edit = array(
+        'foo' => $string,
+      );
+
+      // Test GET method.
+      $request = $browser->get(url('browser_test/print/get', array('absolute' => TRUE, 'query' => $edit)));
+      $this->assertEqual($string, $request['content'], t('String found during GET request ($request)'), $wrapper);
+      $this->assertEqual($string, $browser->getContent(), t('String found during GET request ($browser)'), $wrapper);
+
+      // Test POST method.
+      $request = $browser->post(url('browser_test/print/post', array('absolute' => TRUE)), $edit, t('Submit'));
+      $this->assertEqual($string, $request['content'], t('String found during POST request ($request)'), $wrapper);
+      $this->assertEqual($string, $browser->getContent(), t('String found during POST request ($browser)'), $wrapper);
+    }
+  }
+}
+
+/**
+ * Test browser page manipulation functionality.
+ */
+class BrowserPageTestCase extends DrupalWebTestCase {
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Browser - page',
+      'description' => 'Check "BrowserPage" class functionality.',
+      'group' => 'Browser',
+    );
+  }
+
+  public function setUp() {
+    parent::setUp('browser_test');
+  }
+
+  /**
+   * Check "BrowserPage" class functionality.
+   */
+  public function testBrowserPage() {
+    global $db_prefix;
+
+    $browser = new Browser();
+    $browser->setUserAgent(drupal_generate_test_ua($db_prefix));
+
+    $browser->get(url('browser_test/print/post', array('absolute' => TRUE)));
+    $page = $browser->getPage();
+    $input = $page->xpath('//input[@name="foo"]');
+    $input = $input[0];
+    $this->assertEqual('foo', $input['name'], t('Field "foo" found'));
+  }
+}
