blob: 18c701402c5e3a33fb8722a8f349e3804ce4a187 [file] [log] [blame]
[email protected]8ad0e6be2011-05-25 03:25:061// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]3c5ed2c2009-11-13 01:30:452// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]be1ce6a72010-08-03 14:35:225#include "base/utf_string_conversions.h"
[email protected]3c5ed2c2009-11-13 01:30:456#include "testing/gtest/include/gtest/gtest.h"
7#include "webkit/database/database_util.h"
8
9using webkit_database::DatabaseUtil;
10
11static void TestVfsFilePath(bool expected_result,
[email protected]60cba792009-11-13 06:37:0312 const char* vfs_file_name,
[email protected]3c5ed2c2009-11-13 01:30:4513 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]60cba792009-11-13 06:37:0320 DatabaseUtil::CrackVfsFileName(ASCIIToUTF16(vfs_file_name),
[email protected]3c5ed2c2009-11-13 01:30:4521 &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]8ad0e6be2011-05-25 03:25:0629static GURL ToAndFromOriginIdentifier(const GURL origin_url) {
30 string16 id = DatabaseUtil::GetOriginIdentifier(origin_url);
31 return DatabaseUtil::GetOriginFromIdentifier(id);
32}
33
[email protected]3c5ed2c2009-11-13 01:30:4534namespace webkit_database {
35
36// Test DatabaseUtil::CrackVfsFilePath on various inputs.
37TEST(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]8ad0e6be2011-05-25 03:25:0650TEST(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]3c5ed2c2009-11-13 01:30:4557} // namespace webkit_database