diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index 984739e..ca4a570 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@@ -587,6 +587,12 @@ function drupal_get_filename($type, $name, $filename = NULL) {
   else {
     try {
       if (function_exists('db_query')) {
+        // Profiles are saved as $type = 'module' in the {system} table, ensure
+        // that drupal_get_filename('profile', $name); works both with and
+        // without the database available by converting the argument here.
+        if ($type == 'profile') {
+          $type = 'module';
+        }
         $file = db_query("SELECT filename FROM {system} WHERE name = :name AND type = :type", array(':name' => $name, ':type' => $type))->fetchField();
         if (file_exists(DRUPAL_ROOT . '/' . $file)) {
           $files[$type][$name] = $file;
diff --git a/modules/simpletest/tests/bootstrap.test b/modules/simpletest/tests/bootstrap.test
index 14c16a9..93ba67f 100644
--- a/modules/simpletest/tests/bootstrap.test
+++ b/modules/simpletest/tests/bootstrap.test
@@ -327,7 +327,7 @@ class BootstrapGetFilenameTestCase extends DrupalUnitTestCase {
 
   public static function getInfo() {
     return array(
-      'name' => 'Get filename test',
+      'name' => 'Get filename without database',
       'description' => 'Test that drupal_get_filename() works correctly when the file is not found in the database.',
       'group' => 'Bootstrap',
     );
@@ -355,6 +355,23 @@ class BootstrapGetFilenameTestCase extends DrupalUnitTestCase {
   }
 }
 
+class BootstrapDrupalGetFileNameDatabaseTestCase extends DrupalWebTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => 'Get filename with database',
+      'description' => 'Test that drupal_get_filename() works with the database available',
+      'group' => 'Bootstrap',
+    );
+  }
+
+  /**
+   * Test drupal_get_filename() with an install profile.
+   */
+  function testDrupalGetFilenameInstallProfile() {
+    $this->assertIdentical(drupal_get_filename('profile', 'standard'), 'profiles/standard/standard.profile', t('Retrieve install profile location.'));
+  }
+}
+
 class BootstrapTimerTestCase extends DrupalUnitTestCase {
 
   public static function getInfo() {
