Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Unified Diff: webkit/fileapi/file_system_origin_database_unittest.cc

Issue 6903118: A database to hold mappings from origin identifiers to unique directory names. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Add a missing include that breaks windows. Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/fileapi/file_system_origin_database.cc ('k') | webkit/fileapi/webkit_fileapi.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/fileapi/file_system_origin_database_unittest.cc
diff --git a/webkit/fileapi/file_system_origin_database_unittest.cc b/webkit/fileapi/file_system_origin_database_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c7c4f71abbcd04aa0b303ef62b4d0c0deec60343
--- /dev/null
+++ b/webkit/fileapi/file_system_origin_database_unittest.cc
@@ -0,0 +1,166 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+#include <string>
+
+#include "base/file_util.h"
+#include "base/memory/scoped_temp_dir.h"
+#include "webkit/fileapi/file_system_origin_database.h"
+
+namespace fileapi {
+
+TEST(FileSystemOriginDatabaseTest, BasicTest) {
+ ScopedTempDir dir;
+ ASSERT_TRUE(dir.CreateUniqueTempDir());
+ const FilePath kDBFile = dir.path().AppendASCII("fsod.db");
+ EXPECT_FALSE(file_util::PathExists(kDBFile));
+
+ FileSystemOriginDatabase database(kDBFile);
+ std::string origin("origin");
+
+ EXPECT_FALSE(database.HasOriginPath(origin));
+ // Double-check to make sure that had no side effects.
+ EXPECT_FALSE(database.HasOriginPath(origin));
+
+ FilePath path0;
+ FilePath path1;
+
+ // Empty strings aren't valid origins.
+ EXPECT_FALSE(database.GetPathForOrigin(std::string(), &path0));
+
+ EXPECT_TRUE(database.GetPathForOrigin(origin, &path0));
+ EXPECT_TRUE(database.HasOriginPath(origin));
+ EXPECT_TRUE(database.GetPathForOrigin(origin, &path1));
+ EXPECT_FALSE(path0.empty());
+ EXPECT_FALSE(path1.empty());
+ EXPECT_EQ(path0, path1);
+
+ EXPECT_TRUE(file_util::PathExists(kDBFile));
+}
+
+TEST(FileSystemOriginDatabaseTest, TwoPathTest) {
+ ScopedTempDir dir;
+ ASSERT_TRUE(dir.CreateUniqueTempDir());
+ const FilePath kDBFile = dir.path().AppendASCII("fsod.db");
+ EXPECT_FALSE(file_util::PathExists(kDBFile));
+
+ FileSystemOriginDatabase database(kDBFile);
+ std::string origin0("origin0");
+ std::string origin1("origin1");
+
+ EXPECT_FALSE(database.HasOriginPath(origin0));
+ EXPECT_FALSE(database.HasOriginPath(origin1));
+
+ FilePath path0;
+ FilePath path1;
+ EXPECT_TRUE(database.GetPathForOrigin(origin0, &path0));
+ EXPECT_TRUE(database.HasOriginPath(origin0));
+ EXPECT_FALSE(database.HasOriginPath(origin1));
+ EXPECT_TRUE(database.GetPathForOrigin(origin1, &path1));
+ EXPECT_TRUE(database.HasOriginPath(origin1));
+ EXPECT_FALSE(path0.empty());
+ EXPECT_FALSE(path1.empty());
+ EXPECT_NE(path0, path1);
+
+ EXPECT_TRUE(file_util::PathExists(kDBFile));
+}
+
+TEST(FileSystemOriginDatabaseTest, DropDatabaseTest) {
+ ScopedTempDir dir;
+ ASSERT_TRUE(dir.CreateUniqueTempDir());
+ const FilePath kDBFile = dir.path().AppendASCII("fsod.db");
+ EXPECT_FALSE(file_util::PathExists(kDBFile));
+
+ FileSystemOriginDatabase database(kDBFile);
+ std::string origin("origin");
+
+ EXPECT_FALSE(database.HasOriginPath(origin));
+
+ FilePath path0;
+ EXPECT_TRUE(database.GetPathForOrigin(origin, &path0));
+ EXPECT_TRUE(database.HasOriginPath(origin));
+ EXPECT_FALSE(path0.empty());
+
+ EXPECT_TRUE(file_util::PathExists(kDBFile));
+
+ database.DropDatabase();
+
+ FilePath path1;
+ EXPECT_TRUE(database.HasOriginPath(origin));
+ EXPECT_TRUE(database.GetPathForOrigin(origin, &path1));
+ EXPECT_FALSE(path1.empty());
+ EXPECT_EQ(path0, path1);
+}
+
+TEST(FileSystemOriginDatabaseTest, DeleteOriginTest) {
+ ScopedTempDir dir;
+ ASSERT_TRUE(dir.CreateUniqueTempDir());
+ const FilePath kDBFile = dir.path().AppendASCII("fsod.db");
+ EXPECT_FALSE(file_util::PathExists(kDBFile));
+
+ FileSystemOriginDatabase database(kDBFile);
+ std::string origin("origin");
+
+ EXPECT_FALSE(database.HasOriginPath(origin));
+ EXPECT_TRUE(database.RemovePathForOrigin(origin));
+
+ FilePath path0;
+ EXPECT_TRUE(database.GetPathForOrigin(origin, &path0));
+ EXPECT_TRUE(database.HasOriginPath(origin));
+ EXPECT_FALSE(path0.empty());
+
+ EXPECT_TRUE(database.RemovePathForOrigin(origin));
+ EXPECT_FALSE(database.HasOriginPath(origin));
+
+ FilePath path1;
+ EXPECT_TRUE(database.GetPathForOrigin(origin, &path1));
+ EXPECT_FALSE(path1.empty());
+ EXPECT_NE(path0, path1);
+}
+
+TEST(FileSystemOriginDatabaseTest, ListOriginsTest) {
+ ScopedTempDir dir;
+ ASSERT_TRUE(dir.CreateUniqueTempDir());
+ const FilePath kDBFile = dir.path().AppendASCII("fsod.db");
+ EXPECT_FALSE(file_util::PathExists(kDBFile));
+
+ std::vector<FileSystemOriginDatabase::OriginRecord> origins;
+
+ FileSystemOriginDatabase database(kDBFile);
+ EXPECT_TRUE(database.ListAllOrigins(&origins));
+ EXPECT_TRUE(origins.empty());
+ origins.clear();
+
+ std::string origin0("origin0");
+ std::string origin1("origin1");
+
+ EXPECT_FALSE(database.HasOriginPath(origin0));
+ EXPECT_FALSE(database.HasOriginPath(origin1));
+
+ FilePath path0;
+ FilePath path1;
+ EXPECT_TRUE(database.GetPathForOrigin(origin0, &path0));
+ EXPECT_TRUE(database.ListAllOrigins(&origins));
+ EXPECT_EQ(origins.size(), 1UL);
+ EXPECT_EQ(origins[0].first, origin0);
+ EXPECT_EQ(origins[0].second, path0);
+ origins.clear();
+ EXPECT_TRUE(database.GetPathForOrigin(origin1, &path1));
+ EXPECT_TRUE(database.ListAllOrigins(&origins));
+ EXPECT_EQ(origins.size(), 2UL);
+ if (origins[0].first == origin0) {
+ EXPECT_EQ(origins[0].second, path0);
+ EXPECT_EQ(origins[1].first, origin1);
+ EXPECT_EQ(origins[1].second, path1);
+ } else {
+ EXPECT_EQ(origins[0].first, origin1);
+ EXPECT_EQ(origins[0].second, path1);
+ EXPECT_EQ(origins[1].first, origin0);
+ EXPECT_EQ(origins[1].second, path0);
+ }
+}
+
+} // namespace fileapi
« no previous file with comments | « webkit/fileapi/file_system_origin_database.cc ('k') | webkit/fileapi/webkit_fileapi.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698