OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "base/string_piece.h" | 5 #include "base/string_piece.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "webkit/database/database_util.h" | 8 #include "webkit/database/database_util.h" |
9 | 9 |
10 using webkit_database::DatabaseUtil; | 10 using webkit_database::DatabaseUtil; |
11 | 11 |
12 static void TestVfsFilePath(bool expected_result, | 12 static void TestVfsFilePath(bool expected_result, |
13 const char* vfs_file_name, | 13 const char* vfs_file_name, |
14 const char* expected_origin_identifier = "", | 14 const char* expected_origin_identifier = "", |
15 const char* expected_database_name = "", | 15 const char* expected_database_name = "", |
16 const char* expected_sqlite_suffix = "") { | 16 const char* expected_sqlite_suffix = "") { |
17 string16 origin_identifier; | 17 base::string16 origin_identifier; |
18 string16 database_name; | 18 base::string16 database_name; |
19 string16 sqlite_suffix; | 19 base::string16 sqlite_suffix; |
20 EXPECT_EQ(expected_result, | 20 EXPECT_EQ(expected_result, |
21 DatabaseUtil::CrackVfsFileName(ASCIIToUTF16(vfs_file_name), | 21 DatabaseUtil::CrackVfsFileName(ASCIIToUTF16(vfs_file_name), |
22 &origin_identifier, | 22 &origin_identifier, |
23 &database_name, | 23 &database_name, |
24 &sqlite_suffix)); | 24 &sqlite_suffix)); |
25 EXPECT_EQ(ASCIIToUTF16(expected_origin_identifier), origin_identifier); | 25 EXPECT_EQ(ASCIIToUTF16(expected_origin_identifier), origin_identifier); |
26 EXPECT_EQ(ASCIIToUTF16(expected_database_name), database_name); | 26 EXPECT_EQ(ASCIIToUTF16(expected_database_name), database_name); |
27 EXPECT_EQ(ASCIIToUTF16(expected_sqlite_suffix), sqlite_suffix); | 27 EXPECT_EQ(ASCIIToUTF16(expected_sqlite_suffix), sqlite_suffix); |
28 } | 28 } |
29 | 29 |
30 static GURL ToAndFromOriginIdentifier(const GURL origin_url) { | 30 static GURL ToAndFromOriginIdentifier(const GURL origin_url) { |
31 string16 id = DatabaseUtil::GetOriginIdentifier(origin_url); | 31 base::string16 id = DatabaseUtil::GetOriginIdentifier(origin_url); |
32 return DatabaseUtil::GetOriginFromIdentifier(id); | 32 return DatabaseUtil::GetOriginFromIdentifier(id); |
33 } | 33 } |
34 | 34 |
35 static void TestValidOriginIdentifier(bool expected_result, | 35 static void TestValidOriginIdentifier(bool expected_result, |
36 const base::StringPiece id) { | 36 const base::StringPiece id) { |
37 EXPECT_EQ(expected_result, | 37 EXPECT_EQ(expected_result, |
38 DatabaseUtil::IsValidOriginIdentifier(ASCIIToUTF16(id))); | 38 DatabaseUtil::IsValidOriginIdentifier(ASCIIToUTF16(id))); |
39 } | 39 } |
40 | 40 |
41 namespace webkit_database { | 41 namespace webkit_database { |
(...skipping 22 matching lines...) Expand all Loading... |
64 TEST(DatabaseUtilTest, IsValidOriginIdentifier) { | 64 TEST(DatabaseUtilTest, IsValidOriginIdentifier) { |
65 TestValidOriginIdentifier(true, "http_bar_0"); | 65 TestValidOriginIdentifier(true, "http_bar_0"); |
66 TestValidOriginIdentifier(true, ""); | 66 TestValidOriginIdentifier(true, ""); |
67 TestValidOriginIdentifier(false, "bad..id"); | 67 TestValidOriginIdentifier(false, "bad..id"); |
68 TestValidOriginIdentifier(false, "bad/id"); | 68 TestValidOriginIdentifier(false, "bad/id"); |
69 TestValidOriginIdentifier(false, "bad\\id"); | 69 TestValidOriginIdentifier(false, "bad\\id"); |
70 TestValidOriginIdentifier(false, base::StringPiece("bad\0id", 6)); | 70 TestValidOriginIdentifier(false, base::StringPiece("bad\0id", 6)); |
71 } | 71 } |
72 | 72 |
73 } // namespace webkit_database | 73 } // namespace webkit_database |
OLD | NEW |