Revert "Merged all Chromoting Host code into remoting_core.dll (Windows)."
[chromium-blink-merge.git] / webkit / database / database_util_unittest.cc
blob18c701402c5e3a33fb8722a8f349e3804ce4a187
1 // Copyright (c) 2011 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.
5 #include "base/utf_string_conversions.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "webkit/database/database_util.h"
9 using webkit_database::DatabaseUtil;
11 static void TestVfsFilePath(bool expected_result,
12 const char* vfs_file_name,
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,
20 DatabaseUtil::CrackVfsFileName(ASCIIToUTF16(vfs_file_name),
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);
29 static GURL ToAndFromOriginIdentifier(const GURL origin_url) {
30 string16 id = DatabaseUtil::GetOriginIdentifier(origin_url);
31 return DatabaseUtil::GetOriginFromIdentifier(id);
34 namespace webkit_database {
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");
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));
57 } // namespace webkit_database