| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "storage/browser/database/database_util.h" |
| 5 #include "base/strings/string_piece.h" | 6 #include "base/strings/string_piece.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 7 #include "storage/browser/database/database_util.h" | |
| 8 #include "storage/common/database/database_identifier.h" | 8 #include "storage/common/database/database_identifier.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 using base::ASCIIToUTF16; | 11 using base::ASCIIToUTF16; |
| 12 using storage::DatabaseUtil; | 12 using storage::DatabaseUtil; |
| 13 | 13 |
| 14 static void TestVfsFilePath(bool expected_result, | 14 static void TestVfsFilePath(bool expected_result, |
| 15 const char* vfs_file_name, | 15 const char* vfs_file_name, |
| 16 const char* expected_origin_identifier = "", | 16 const char* expected_origin_identifier = "", |
| 17 const char* expected_database_name = "", | 17 const char* expected_database_name = "", |
| 18 const char* expected_sqlite_suffix = "") { | 18 const char* expected_sqlite_suffix = "") { |
| 19 std::string origin_identifier; | 19 std::string origin_identifier; |
| 20 base::string16 database_name; | 20 base::string16 database_name; |
| 21 base::string16 sqlite_suffix; | 21 base::string16 sqlite_suffix; |
| 22 EXPECT_EQ(expected_result, | 22 EXPECT_EQ(expected_result, |
| 23 DatabaseUtil::CrackVfsFileName(ASCIIToUTF16(vfs_file_name), | 23 DatabaseUtil::CrackVfsFileName(ASCIIToUTF16(vfs_file_name), |
| 24 &origin_identifier, | 24 &origin_identifier, &database_name, |
| 25 &database_name, | |
| 26 &sqlite_suffix)); | 25 &sqlite_suffix)); |
| 27 EXPECT_EQ(expected_origin_identifier, origin_identifier); | 26 EXPECT_EQ(expected_origin_identifier, origin_identifier); |
| 28 EXPECT_EQ(ASCIIToUTF16(expected_database_name), database_name); | 27 EXPECT_EQ(ASCIIToUTF16(expected_database_name), database_name); |
| 29 EXPECT_EQ(ASCIIToUTF16(expected_sqlite_suffix), sqlite_suffix); | 28 EXPECT_EQ(ASCIIToUTF16(expected_sqlite_suffix), sqlite_suffix); |
| 30 } | 29 } |
| 31 | 30 |
| 32 namespace content { | 31 namespace content { |
| 33 | 32 |
| 34 // Test DatabaseUtil::CrackVfsFilePath on various inputs. | 33 // Test DatabaseUtil::CrackVfsFilePath on various inputs. |
| 35 TEST(DatabaseUtilTest, CrackVfsFilePathTest) { | 34 TEST(DatabaseUtilTest, CrackVfsFilePathTest) { |
| 36 TestVfsFilePath(true, "http_origin_0/#", "http_origin_0", "", ""); | 35 TestVfsFilePath(true, "http_origin_0/#", "http_origin_0", "", ""); |
| 37 TestVfsFilePath(true, | 36 TestVfsFilePath(true, "http_origin_0/#suffix", "http_origin_0", "", "suffix"); |
| 38 "http_origin_0/#suffix", "http_origin_0", "", "suffix"); | 37 TestVfsFilePath(true, "http_origin_0/db_name#", "http_origin_0", "db_name", |
| 39 TestVfsFilePath(true, | 38 ""); |
| 40 "http_origin_0/db_name#", "http_origin_0", "db_name", ""); | 39 TestVfsFilePath(true, "http_origin_0/db_name#suffix", "http_origin_0", |
| 41 TestVfsFilePath(true, | 40 "db_name", "suffix"); |
| 42 "http_origin_0/db_name#suffix", "http_origin_0", "db_name", "suffix"); | |
| 43 TestVfsFilePath(false, "http_origin_0db_name#"); | 41 TestVfsFilePath(false, "http_origin_0db_name#"); |
| 44 TestVfsFilePath(false, "http_origin_0db_name#suffix"); | 42 TestVfsFilePath(false, "http_origin_0db_name#suffix"); |
| 45 TestVfsFilePath(false, "http_origin_0/db_name"); | 43 TestVfsFilePath(false, "http_origin_0/db_name"); |
| 46 TestVfsFilePath(false, "http_origin_0#db_name/suffix"); | 44 TestVfsFilePath(false, "http_origin_0#db_name/suffix"); |
| 47 TestVfsFilePath(false, "/db_name#"); | 45 TestVfsFilePath(false, "/db_name#"); |
| 48 TestVfsFilePath(false, "/db_name#suffix"); | 46 TestVfsFilePath(false, "/db_name#suffix"); |
| 49 } | 47 } |
| 50 | 48 |
| 51 | |
| 52 } // namespace content | 49 } // namespace content |
| OLD | NEW |