| 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 "base/strings/string_piece.h" | 5 #include "base/strings/string_piece.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "storage/browser/database/database_util.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 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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, |
| 25 &database_name, | 25 &database_name, |
| 26 &sqlite_suffix)); | 26 &sqlite_suffix)); |
| 27 EXPECT_EQ(expected_origin_identifier, origin_identifier); | 27 EXPECT_EQ(expected_origin_identifier, origin_identifier); |
| 28 EXPECT_EQ(ASCIIToUTF16(expected_database_name), database_name); | 28 EXPECT_EQ(ASCIIToUTF16(expected_database_name), database_name); |
| 29 EXPECT_EQ(ASCIIToUTF16(expected_sqlite_suffix), sqlite_suffix); | 29 EXPECT_EQ(ASCIIToUTF16(expected_sqlite_suffix), sqlite_suffix); |
| 30 } | 30 } |
| 31 | 31 |
| 32 static GURL ToAndFromOriginIdentifier(const GURL origin_url) { | |
| 33 std::string id = storage::GetIdentifierFromOrigin(origin_url); | |
| 34 return storage::GetOriginFromIdentifier(id); | |
| 35 } | |
| 36 | |
| 37 static void TestValidOriginIdentifier(bool expected_result, | |
| 38 const std::string& id) { | |
| 39 EXPECT_EQ(expected_result, | |
| 40 DatabaseUtil::IsValidOriginIdentifier(id)); | |
| 41 } | |
| 42 | |
| 43 namespace content { | 32 namespace content { |
| 44 | 33 |
| 45 // Test DatabaseUtil::CrackVfsFilePath on various inputs. | 34 // Test DatabaseUtil::CrackVfsFilePath on various inputs. |
| 46 TEST(DatabaseUtilTest, CrackVfsFilePathTest) { | 35 TEST(DatabaseUtilTest, CrackVfsFilePathTest) { |
| 47 TestVfsFilePath(true, "http_origin_0/#", "http_origin_0", "", ""); | 36 TestVfsFilePath(true, "http_origin_0/#", "http_origin_0", "", ""); |
| 48 TestVfsFilePath(true, | 37 TestVfsFilePath(true, |
| 49 "http_origin_0/#suffix", "http_origin_0", "", "suffix"); | 38 "http_origin_0/#suffix", "http_origin_0", "", "suffix"); |
| 50 TestVfsFilePath(true, | 39 TestVfsFilePath(true, |
| 51 "http_origin_0/db_name#", "http_origin_0", "db_name", ""); | 40 "http_origin_0/db_name#", "http_origin_0", "db_name", ""); |
| 52 TestVfsFilePath(true, | 41 TestVfsFilePath(true, |
| 53 "http_origin_0/db_name#suffix", "http_origin_0", "db_name", "suffix"); | 42 "http_origin_0/db_name#suffix", "http_origin_0", "db_name", "suffix"); |
| 54 TestVfsFilePath(false, "http_origin_0db_name#"); | 43 TestVfsFilePath(false, "http_origin_0db_name#"); |
| 55 TestVfsFilePath(false, "http_origin_0db_name#suffix"); | 44 TestVfsFilePath(false, "http_origin_0db_name#suffix"); |
| 56 TestVfsFilePath(false, "http_origin_0/db_name"); | 45 TestVfsFilePath(false, "http_origin_0/db_name"); |
| 57 TestVfsFilePath(false, "http_origin_0#db_name/suffix"); | 46 TestVfsFilePath(false, "http_origin_0#db_name/suffix"); |
| 58 TestVfsFilePath(false, "/db_name#"); | 47 TestVfsFilePath(false, "/db_name#"); |
| 59 TestVfsFilePath(false, "/db_name#suffix"); | 48 TestVfsFilePath(false, "/db_name#suffix"); |
| 60 } | 49 } |
| 61 | 50 |
| 62 TEST(DatabaseUtilTest, OriginIdentifiers) { | |
| 63 const GURL kFileOrigin(GURL("file:///").GetOrigin()); | |
| 64 const GURL kHttpOrigin(GURL("http://bar/").GetOrigin()); | |
| 65 EXPECT_EQ(kFileOrigin, ToAndFromOriginIdentifier(kFileOrigin)); | |
| 66 EXPECT_EQ(kHttpOrigin, ToAndFromOriginIdentifier(kHttpOrigin)); | |
| 67 } | |
| 68 | |
| 69 TEST(DatabaseUtilTest, IsValidOriginIdentifier) { | |
| 70 TestValidOriginIdentifier(true, "http_bar_0"); | |
| 71 TestValidOriginIdentifier(false, ""); | |
| 72 TestValidOriginIdentifier(false, "bad..id"); | |
| 73 TestValidOriginIdentifier(false, "bad/id"); | |
| 74 TestValidOriginIdentifier(false, "bad\\id"); | |
| 75 TestValidOriginIdentifier(false, "http_bad:0_2"); | |
| 76 TestValidOriginIdentifier(false, std::string("bad\0id", 6)); | |
| 77 } | |
| 78 | 51 |
| 79 } // namespace content | 52 } // namespace content |
| OLD | NEW |