[email protected] | 8ad0e6be | 2011-05-25 03:25:06 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 3c5ed2c | 2009-11-13 01:30:45 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | be1ce6a7 | 2010-08-03 14:35:22 | [diff] [blame] | 5 | #include "base/utf_string_conversions.h" |
[email protected] | 3c5ed2c | 2009-11-13 01:30:45 | [diff] [blame] | 6 | #include "testing/gtest/include/gtest/gtest.h" |
| 7 | #include "webkit/database/database_util.h" |
| 8 | |
| 9 | using webkit_database::DatabaseUtil; |
| 10 | |
| 11 | static void TestVfsFilePath(bool expected_result, |
[email protected] | 60cba79 | 2009-11-13 06:37:03 | [diff] [blame] | 12 | const char* vfs_file_name, |
[email protected] | 3c5ed2c | 2009-11-13 01:30:45 | [diff] [blame] | 13 | const char* expected_origin_identifier = "", |
| 14 | const char* expected_database_name = "", |
| 15 | const char* expected_sqlite_suffix = "") { |
| 16 | string16 origin_identifier; |
| 17 | string16 database_name; |
| 18 | string16 sqlite_suffix; |
| 19 | EXPECT_EQ(expected_result, |
[email protected] | 60cba79 | 2009-11-13 06:37:03 | [diff] [blame] | 20 | DatabaseUtil::CrackVfsFileName(ASCIIToUTF16(vfs_file_name), |
[email protected] | 3c5ed2c | 2009-11-13 01:30:45 | [diff] [blame] | 21 | &origin_identifier, |
| 22 | &database_name, |
| 23 | &sqlite_suffix)); |
| 24 | EXPECT_EQ(ASCIIToUTF16(expected_origin_identifier), origin_identifier); |
| 25 | EXPECT_EQ(ASCIIToUTF16(expected_database_name), database_name); |
| 26 | EXPECT_EQ(ASCIIToUTF16(expected_sqlite_suffix), sqlite_suffix); |
| 27 | } |
| 28 | |
[email protected] | 8ad0e6be | 2011-05-25 03:25:06 | [diff] [blame] | 29 | static GURL ToAndFromOriginIdentifier(const GURL origin_url) { |
| 30 | string16 id = DatabaseUtil::GetOriginIdentifier(origin_url); |
| 31 | return DatabaseUtil::GetOriginFromIdentifier(id); |
| 32 | } |
| 33 | |
[email protected] | 3c5ed2c | 2009-11-13 01:30:45 | [diff] [blame] | 34 | namespace webkit_database { |
| 35 | |
| 36 | // Test DatabaseUtil::CrackVfsFilePath on various inputs. |
| 37 | TEST(DatabaseUtilTest, CrackVfsFilePathTest) { |
| 38 | TestVfsFilePath(true, "origin/#", "origin", "", ""); |
| 39 | TestVfsFilePath(true, "origin/#suffix", "origin", "", "suffix"); |
| 40 | TestVfsFilePath(true, "origin/db_name#", "origin", "db_name", ""); |
| 41 | TestVfsFilePath(true, "origin/db_name#suffix", "origin", "db_name", "suffix"); |
| 42 | TestVfsFilePath(false, "origindb_name#"); |
| 43 | TestVfsFilePath(false, "origindb_name#suffix"); |
| 44 | TestVfsFilePath(false, "origin/db_name"); |
| 45 | TestVfsFilePath(false, "origin#db_name/suffix"); |
| 46 | TestVfsFilePath(false, "/db_name#"); |
| 47 | TestVfsFilePath(false, "/db_name#suffix"); |
| 48 | } |
| 49 | |
[email protected] | 8ad0e6be | 2011-05-25 03:25:06 | [diff] [blame] | 50 | TEST(DatabaseUtilTest, OriginIdentifiers) { |
| 51 | const GURL kFileOrigin(GURL("file:///").GetOrigin()); |
| 52 | const GURL kHttpOrigin(GURL("http://bar/").GetOrigin()); |
| 53 | EXPECT_EQ(kFileOrigin, ToAndFromOriginIdentifier(kFileOrigin)); |
| 54 | EXPECT_EQ(kHttpOrigin, ToAndFromOriginIdentifier(kHttpOrigin)); |
| 55 | } |
| 56 | |
[email protected] | 3c5ed2c | 2009-11-13 01:30:45 | [diff] [blame] | 57 | } // namespace webkit_database |