[email protected] | 8ca5150 | 2014-05-21 03:37:40 | [diff] [blame] | 1 | // Copyright 2014 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] | daf079a | 2013-04-17 21:42:40 | [diff] [blame] | 5 | #include "base/strings/string_piece.h" |
[email protected] | 90626587 | 2013-06-07 22:40:45 | [diff] [blame] | 6 | #include "base/strings/utf_string_conversions.h" |
pilgrim | e92c5fcd | 2014-09-10 23:31:23 | [diff] [blame] | 7 | #include "storage/browser/database/database_util.h" |
pilgrim | 1633055 | 2014-09-10 01:32:22 | [diff] [blame] | 8 | #include "storage/common/database/database_identifier.h" |
[email protected] | 3c5ed2c | 2009-11-13 01:30:45 | [diff] [blame] | 9 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 3c5ed2c | 2009-11-13 01:30:45 | [diff] [blame] | 10 | |
[email protected] | f729d7a | 2013-12-26 07:07:56 | [diff] [blame] | 11 | using base::ASCIIToUTF16; |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 12 | using storage::DatabaseUtil; |
[email protected] | 3c5ed2c | 2009-11-13 01:30:45 | [diff] [blame] | 13 | |
| 14 | static void TestVfsFilePath(bool expected_result, |
[email protected] | 60cba79 | 2009-11-13 06:37:03 | [diff] [blame] | 15 | const char* vfs_file_name, |
[email protected] | 3c5ed2c | 2009-11-13 01:30:45 | [diff] [blame] | 16 | const char* expected_origin_identifier = "", |
| 17 | const char* expected_database_name = "", |
| 18 | const char* expected_sqlite_suffix = "") { |
[email protected] | 5e30159 | 2013-06-18 06:36:05 | [diff] [blame] | 19 | std::string origin_identifier; |
[email protected] | 8275835 | 2013-03-29 19:21:31 | [diff] [blame] | 20 | base::string16 database_name; |
| 21 | base::string16 sqlite_suffix; |
[email protected] | 3c5ed2c | 2009-11-13 01:30:45 | [diff] [blame] | 22 | EXPECT_EQ(expected_result, |
[email protected] | 60cba79 | 2009-11-13 06:37:03 | [diff] [blame] | 23 | DatabaseUtil::CrackVfsFileName(ASCIIToUTF16(vfs_file_name), |
[email protected] | 3c5ed2c | 2009-11-13 01:30:45 | [diff] [blame] | 24 | &origin_identifier, |
| 25 | &database_name, |
| 26 | &sqlite_suffix)); |
[email protected] | 5e30159 | 2013-06-18 06:36:05 | [diff] [blame] | 27 | EXPECT_EQ(expected_origin_identifier, origin_identifier); |
[email protected] | 3c5ed2c | 2009-11-13 01:30:45 | [diff] [blame] | 28 | EXPECT_EQ(ASCIIToUTF16(expected_database_name), database_name); |
| 29 | EXPECT_EQ(ASCIIToUTF16(expected_sqlite_suffix), sqlite_suffix); |
| 30 | } |
| 31 | |
[email protected] | 8ca5150 | 2014-05-21 03:37:40 | [diff] [blame] | 32 | namespace content { |
[email protected] | 3c5ed2c | 2009-11-13 01:30:45 | [diff] [blame] | 33 | |
| 34 | // Test DatabaseUtil::CrackVfsFilePath on various inputs. |
| 35 | TEST(DatabaseUtilTest, CrackVfsFilePathTest) { |
[email protected] | 883fb98 | 2014-06-11 11:32:43 | [diff] [blame] | 36 | TestVfsFilePath(true, "http_origin_0/#", "http_origin_0", "", ""); |
| 37 | TestVfsFilePath(true, |
| 38 | "http_origin_0/#suffix", "http_origin_0", "", "suffix"); |
| 39 | TestVfsFilePath(true, |
| 40 | "http_origin_0/db_name#", "http_origin_0", "db_name", ""); |
| 41 | TestVfsFilePath(true, |
| 42 | "http_origin_0/db_name#suffix", "http_origin_0", "db_name", "suffix"); |
| 43 | TestVfsFilePath(false, "http_origin_0db_name#"); |
| 44 | TestVfsFilePath(false, "http_origin_0db_name#suffix"); |
| 45 | TestVfsFilePath(false, "http_origin_0/db_name"); |
| 46 | TestVfsFilePath(false, "http_origin_0#db_name/suffix"); |
[email protected] | 3c5ed2c | 2009-11-13 01:30:45 | [diff] [blame] | 47 | TestVfsFilePath(false, "/db_name#"); |
| 48 | TestVfsFilePath(false, "/db_name#suffix"); |
| 49 | } |
| 50 | |
[email protected] | ccfb891 | 2013-02-18 22:21:04 | [diff] [blame] | 51 | |
[email protected] | 8ca5150 | 2014-05-21 03:37:40 | [diff] [blame] | 52 | } // namespace content |