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
3 // found in the LICENSE file.
4
5 #include "storage/browser/database/database_util.h"
6 #include "base/strings/string_piece.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "storage/common/database/database_identifier.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 using base::ASCIIToUTF16;
12
13 namespace storage {
14
15 namespace {
16
TestVfsFilePath(bool expected_result,const char * vfs_file_name,const char * expected_origin_identifier="",const char * expected_database_name="",const char * expected_sqlite_suffix="")17 void TestVfsFilePath(bool expected_result,
18 const char* vfs_file_name,
19 const char* expected_origin_identifier = "",
20 const char* expected_database_name = "",
21 const char* expected_sqlite_suffix = "") {
22 std::string origin_identifier;
23 base::string16 database_name;
24 base::string16 sqlite_suffix;
25 EXPECT_EQ(expected_result,
26 DatabaseUtil::CrackVfsFileName(ASCIIToUTF16(vfs_file_name),
27 &origin_identifier, &database_name,
28 &sqlite_suffix));
29 EXPECT_EQ(expected_origin_identifier, origin_identifier);
30 EXPECT_EQ(ASCIIToUTF16(expected_database_name), database_name);
31 EXPECT_EQ(ASCIIToUTF16(expected_sqlite_suffix), sqlite_suffix);
32 }
33
34 } // namespace
35
36 // Test DatabaseUtil::CrackVfsFilePath on various inputs.
TEST(DatabaseUtilTest,CrackVfsFilePathTest)37 TEST(DatabaseUtilTest, CrackVfsFilePathTest) {
38 TestVfsFilePath(true, "http_origin_0/#", "http_origin_0", "", "");
39 TestVfsFilePath(true, "http_origin_0/#suffix", "http_origin_0", "", "suffix");
40 TestVfsFilePath(true, "http_origin_0/db_name#", "http_origin_0", "db_name",
41 "");
42 TestVfsFilePath(true, "http_origin_0/db_name#suffix", "http_origin_0",
43 "db_name", "suffix");
44 TestVfsFilePath(false, "http_origin_0db_name#");
45 TestVfsFilePath(false, "http_origin_0db_name#suffix");
46 TestVfsFilePath(false, "http_origin_0/db_name");
47 TestVfsFilePath(false, "http_origin_0#db_name/suffix");
48 TestVfsFilePath(false, "/db_name#");
49 TestVfsFilePath(false, "/db_name#suffix");
50 }
51
52 } // namespace storage
53