diff --git a/includes/common.inc b/includes/common.inc
index f1e8cb6..ca2e8ee 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -5134,8 +5134,6 @@ function drupal_cron_cleanup() {
 function drupal_system_listing($mask, $directory, $key = 'name', $min_depth = 1) {
   $config = conf_path();
 
-  $profile = drupal_get_profile();
-
   $searchdir = array($directory);
   $files = array();
 
@@ -5143,8 +5141,14 @@ function drupal_system_listing($mask, $directory, $key = 'name', $min_depth = 1)
   // themes as organized by a distribution. It is pristine in the same way
   // that /modules is pristine for core; users should avoid changing anything
   // there in favor of sites/all or sites/<domain> directories.
-  if (file_exists("profiles/$profile/$directory")) {
-    $searchdir[] = "profiles/$profile/$directory";
+  //
+  // For SimpleTest to be able to test modules packaged together with a
+  // distribution we need to include the parent profile's search path.
+  $profiles = array(drupal_get_profile(), variable_get('simpletest_parent_profile', ''));
+  foreach ($profiles as $profile) {
+    if ($profile && file_exists("profiles/$profile/$directory")) {
+      $searchdir[] = "profiles/$profile/$directory";
+    }
   }
 
   // Always search sites/all/* as well as the global directories
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index 5c39cfc..5a94833 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
@@ -1304,7 +1304,10 @@ class DrupalWebTestCase extends DrupalTestCase {
     variable_set('file_private_path', $private_files_directory);
     variable_set('file_temporary_path', $temp_files_directory);
 
-    // Include the testing profile.
+    // Include the testing profile and set the simpletest_parent_profile
+    // variable which is used to add the parent profile's search path to the
+    // child site's search paths. See drupal_system_listing().
+    variable_set('simpletest_parent_profile', $this->originalProfile);
     variable_set('install_profile', $this->profile);
     $profile_details = install_profile_info($this->profile, 'en');
 
@@ -1499,6 +1502,9 @@ class DrupalWebTestCase extends DrupalTestCase {
       $GLOBALS['conf']['language_default'] = $this->originalLanguageDefault;
     }
 
+    // Delete 'simpletest_parent_profile' variable.
+    variable_del('simpletest_parent_profile');
+
     // Close the CURL handler.
     $this->curlClose();
   }
