blob: 9534cb9848808cf95b36061ced250502dbd8c8b4 [file] [log] [blame]
[email protected]8ca51502014-05-21 03:37:401// Copyright 2014 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]daf079a2013-04-17 21:42:405#include "base/strings/string_piece.h"
[email protected]906265872013-06-07 22:40:456#include "base/strings/utf_string_conversions.h"
pilgrime92c5fcd2014-09-10 23:31:237#include "storage/browser/database/database_util.h"
pilgrim16330552014-09-10 01:32:228#include "storage/common/database/database_identifier.h"
[email protected]3c5ed2c2009-11-13 01:30:459#include "testing/gtest/include/gtest/gtest.h"
[email protected]3c5ed2c2009-11-13 01:30:4510
[email protected]f729d7a2013-12-26 07:07:5611using base::ASCIIToUTF16;
[email protected]cd501a72014-08-22 19:58:3112using storage::DatabaseUtil;
[email protected]3c5ed2c2009-11-13 01:30:4513
14static void TestVfsFilePath(bool expected_result,
[email protected]60cba792009-11-13 06:37:0315 const char* vfs_file_name,
[email protected]3c5ed2c2009-11-13 01:30:4516 const char* expected_origin_identifier = "",
17 const char* expected_database_name = "",
18 const char* expected_sqlite_suffix = "") {
[email protected]5e301592013-06-18 06:36:0519 std::string origin_identifier;
[email protected]82758352013-03-29 19:21:3120 base::string16 database_name;
21 base::string16 sqlite_suffix;
[email protected]3c5ed2c2009-11-13 01:30:4522 EXPECT_EQ(expected_result,
[email protected]60cba792009-11-13 06:37:0323 DatabaseUtil::CrackVfsFileName(ASCIIToUTF16(vfs_file_name),
[email protected]3c5ed2c2009-11-13 01:30:4524 &origin_identifier,
25 &database_name,
26 &sqlite_suffix));
[email protected]5e301592013-06-18 06:36:0527 EXPECT_EQ(expected_origin_identifier, origin_identifier);
[email protected]3c5ed2c2009-11-13 01:30:4528 EXPECT_EQ(ASCIIToUTF16(expected_database_name), database_name);
29 EXPECT_EQ(ASCIIToUTF16(expected_sqlite_suffix), sqlite_suffix);
30}
31
[email protected]8ca51502014-05-21 03:37:4032namespace content {
[email protected]3c5ed2c2009-11-13 01:30:4533
34// Test DatabaseUtil::CrackVfsFilePath on various inputs.
35TEST(DatabaseUtilTest, CrackVfsFilePathTest) {
[email protected]883fb982014-06-11 11:32:4336 TestVfsFilePath(true, "http_origin_0/#", "http_origin_0", "", "");
37 TestVfsFilePath(true,
38 "http_origin_0/#suffix", "http_origin_0", "", "suffix");
39 TestVfsFilePath(true,
40 "http_origin_0/db_name#", "http_origin_0", "db_name", "");
41 TestVfsFilePath(true,
42 "http_origin_0/db_name#suffix", "http_origin_0", "db_name", "suffix");
43 TestVfsFilePath(false, "http_origin_0db_name#");
44 TestVfsFilePath(false, "http_origin_0db_name#suffix");
45 TestVfsFilePath(false, "http_origin_0/db_name");
46 TestVfsFilePath(false, "http_origin_0#db_name/suffix");
[email protected]3c5ed2c2009-11-13 01:30:4547 TestVfsFilePath(false, "/db_name#");
48 TestVfsFilePath(false, "/db_name#suffix");
49}
50
[email protected]ccfb8912013-02-18 22:21:0451
[email protected]8ca51502014-05-21 03:37:4052} // namespace content