diff options
author | dumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-22 23:04:30 +0000 |
---|---|---|
committer | dumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-22 23:04:30 +0000 |
commit | 373a46081a94ad850299876328b279e25f12e59f (patch) | |
tree | 103b2519dc9c376e555a483cb4a70f105792f0ea | |
parent | 1c1619682ce5dd4fbfc3caa8c76bdce0b13d09ca (diff) | |
download | chromium_src-373a46081a94ad850299876328b279e25f12e59f.zip chromium_src-373a46081a94ad850299876328b279e25f12e59f.tar.gz chromium_src-373a46081a94ad850299876328b279e25f12e59f.tar.bz2 |
Adds support for SetDatabaseQuota(). Also, should remove a lot of
flakiness from the database layout tests: when a DB test calls
ClearAllDatabases(), we force test_shell to wait for all DBs opened in
previous tests to close before running the test.
TEST=none
BUG=32016,32396,32206,32157,30081
Review URL: http://codereview.chromium.org/549095
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36919 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | webkit/database/database_connections.cc | 12 | ||||
-rw-r--r-- | webkit/database/database_connections.h | 5 | ||||
-rw-r--r-- | webkit/database/database_tracker.cc | 11 | ||||
-rw-r--r-- | webkit/database/database_tracker.h | 6 | ||||
-rw-r--r-- | webkit/tools/test_shell/layout_test_controller.cc | 18 | ||||
-rw-r--r-- | webkit/tools/test_shell/layout_test_controller.h | 13 | ||||
-rw-r--r-- | webkit/tools/test_shell/simple_database_system.cc | 23 | ||||
-rw-r--r-- | webkit/tools/test_shell/simple_database_system.h | 3 |
8 files changed, 78 insertions, 13 deletions
diff --git a/webkit/database/database_connections.cc b/webkit/database/database_connections.cc index a6e6d3d..c6e9609 100644 --- a/webkit/database/database_connections.cc +++ b/webkit/database/database_connections.cc @@ -15,8 +15,13 @@ DatabaseConnections::~DatabaseConnections() { DCHECK(connections_.empty()); } -bool DatabaseConnections::IsDatabaseOpened(const string16& origin_identifier, - const string16& database_name) { +bool DatabaseConnections::IsEmpty() const { + return connections_.empty(); +} + +bool DatabaseConnections::IsDatabaseOpened( + const string16& origin_identifier, + const string16& database_name) const { OriginConnections::const_iterator origin_it = connections_.find(origin_identifier); if (origin_it == connections_.end()) @@ -25,7 +30,8 @@ bool DatabaseConnections::IsDatabaseOpened(const string16& origin_identifier, return (origin_connections.find(database_name) != origin_connections.end()); } -bool DatabaseConnections::IsOriginUsed(const string16& origin_identifier) { +bool DatabaseConnections::IsOriginUsed( + const string16& origin_identifier) const { return (connections_.find(origin_identifier) != connections_.end()); } diff --git a/webkit/database/database_connections.h b/webkit/database/database_connections.h index e036940..02941c8 100644 --- a/webkit/database/database_connections.h +++ b/webkit/database/database_connections.h @@ -16,9 +16,10 @@ class DatabaseConnections { DatabaseConnections(); ~DatabaseConnections(); + bool IsEmpty() const; bool IsDatabaseOpened(const string16& origin_identifier, - const string16& database_name); - bool IsOriginUsed(const string16& origin_identifier); + const string16& database_name) const; + bool IsOriginUsed(const string16& origin_identifier) const; void AddConnection(const string16& origin_identifier, const string16& database_name); void RemoveConnection(const string16& origin_identifier, diff --git a/webkit/database/database_tracker.cc b/webkit/database/database_tracker.cc index 16766b4..01c3052 100644 --- a/webkit/database/database_tracker.cc +++ b/webkit/database/database_tracker.cc @@ -25,7 +25,6 @@ const FilePath::CharType kTrackerDatabaseFileName[] = FILE_PATH_LITERAL("Databases.db"); const int kCurrentVersion = 2; const int kCompatibleVersion = 1; -const int64 kDefaultQuota = 5 * 1024 * 1024; const int64 kDefaultExtensionQuota = 50 * 1024 * 1024; const char* kExtensionOriginIdentifierPrefix = "chrome-extension_"; @@ -34,13 +33,19 @@ DatabaseTracker::DatabaseTracker(const FilePath& profile_path) db_dir_(profile_path.Append(FilePath(kDatabaseDirectoryName))), db_(new sql::Connection()), databases_table_(NULL), - meta_table_(NULL) { + meta_table_(NULL), + default_quota_(5 * 1024 * 1024) { } DatabaseTracker::~DatabaseTracker() { DCHECK(observers_.size() == 0); } +void DatabaseTracker::SetDefaultQuota(int64 quota) { + default_quota_ = quota; + ClearAllCachedOriginInfo(); +} + void DatabaseTracker::DatabaseOpened(const string16& origin_identifier, const string16& database_name, const string16& database_description, @@ -291,7 +296,7 @@ DatabaseTracker::CachedOriginInfo* DatabaseTracker::GetCachedOriginInfo( true)) { origin_info.SetQuota(kDefaultExtensionQuota); } else { - origin_info.SetQuota(kDefaultQuota); + origin_info.SetQuota(default_quota_); } } diff --git a/webkit/database/database_tracker.h b/webkit/database/database_tracker.h index 24ea877..f3f6041 100644 --- a/webkit/database/database_tracker.h +++ b/webkit/database/database_tracker.h @@ -86,6 +86,9 @@ class DatabaseTracker explicit DatabaseTracker(const FilePath& profile_path); + // Sets the default quota for all origins. Should be used in tests only. + void SetDefaultQuota(int64 quota); + void DatabaseOpened(const string16& origin_identifier, const string16& database_name, const string16& database_details, @@ -160,6 +163,9 @@ class DatabaseTracker std::map<string16, CachedOriginInfo> origins_info_map_; DatabaseConnections database_connections_; + // Default quota for all origins; changed only by tests + int64 default_quota_; + FRIEND_TEST(DatabaseTrackerTest, TestIt); }; diff --git a/webkit/tools/test_shell/layout_test_controller.cc b/webkit/tools/test_shell/layout_test_controller.cc index 3c94a91..0dc1259 100644 --- a/webkit/tools/test_shell/layout_test_controller.cc +++ b/webkit/tools/test_shell/layout_test_controller.cc @@ -78,6 +78,7 @@ LayoutTestController::LayoutTestController(TestShell* shell) : BindMethod("dumpAsText", &LayoutTestController::dumpAsText); BindMethod("dumpChildFrameScrollPositions", &LayoutTestController::dumpChildFrameScrollPositions); BindMethod("dumpChildFramesAsText", &LayoutTestController::dumpChildFramesAsText); + BindMethod("dumpDatabaseCallbacks", &LayoutTestController::dumpDatabaseCallbacks); BindMethod("dumpEditingCallbacks", &LayoutTestController::dumpEditingCallbacks); BindMethod("dumpBackForwardList", &LayoutTestController::dumpBackForwardList); BindMethod("dumpFrameLoadCallbacks", &LayoutTestController::dumpFrameLoadCallbacks); @@ -122,6 +123,7 @@ LayoutTestController::LayoutTestController(TestShell* shell) : BindMethod("setWillSendRequestReturnsNull", &LayoutTestController::setWillSendRequestReturnsNull); BindMethod("whiteListAccessFromOrigin", &LayoutTestController::whiteListAccessFromOrigin); BindMethod("clearAllDatabases", &LayoutTestController::clearAllDatabases); + BindMethod("setDatabaseQuota", &LayoutTestController::setDatabaseQuota); BindMethod("setPOSIXLocale", &LayoutTestController::setPOSIXLocale); BindMethod("counterValueForElementById", &LayoutTestController::counterValueForElementById); @@ -213,6 +215,12 @@ void LayoutTestController::dumpAsText(const CppArgumentList& args, result->SetNull(); } +void LayoutTestController::dumpDatabaseCallbacks( + const CppArgumentList& args, CppVariant* result) { + // Do nothing; we don't use this flag anywhere for now + result->SetNull(); +} + void LayoutTestController::dumpEditingCallbacks( const CppArgumentList& args, CppVariant* result) { dump_editing_callbacks_ = true; @@ -455,6 +463,9 @@ void LayoutTestController::Reset() { SimpleResourceLoaderBridge::SetAcceptAllCookies(false); WebSecurityPolicy::resetOriginAccessWhiteLists(); + // Reset the default quota for each origin to 5MB + SimpleDatabaseSystem::GetInstance()->SetDatabaseQuota(5 * 1024 * 1024); + setlocale(LC_ALL, ""); if (close_remaining_windows_) { @@ -1018,6 +1029,13 @@ void LayoutTestController::clearAllDatabases( SimpleDatabaseSystem::GetInstance()->ClearAllDatabases(); } +void LayoutTestController::setDatabaseQuota( + const CppArgumentList& args, CppVariant* result) { + result->SetNull(); + if ((args.size() >= 1) && args[0].isInt32()) + SimpleDatabaseSystem::GetInstance()->SetDatabaseQuota(args[0].ToInt32()); +} + void LayoutTestController::setPOSIXLocale(const CppArgumentList& args, CppVariant* result) { result->SetNull(); diff --git a/webkit/tools/test_shell/layout_test_controller.h b/webkit/tools/test_shell/layout_test_controller.h index 67026867..0fe2df8 100644 --- a/webkit/tools/test_shell/layout_test_controller.h +++ b/webkit/tools/test_shell/layout_test_controller.h @@ -32,13 +32,20 @@ class LayoutTestController : public CppBoundClass { // It takes no arguments, and ignores any that may be present. void dumpAsText(const CppArgumentList& args, CppVariant* result); + // This function should set a flag that tells the test_shell to print a line + // of descriptive text for each database command. It should take no + // arguments, and ignore any that may be present. However, at the moment, we + // don't have any DB function that prints messages, so for now this function + // doesn't do anything. + void dumpDatabaseCallbacks(const CppArgumentList& args, CppVariant* result); + // This function sets a flag that tells the test_shell to print a line of - // descriptive test for each editing command. It takes no arguments, and + // descriptive text for each editing command. It takes no arguments, and // ignores any that may be present. void dumpEditingCallbacks(const CppArgumentList& args, CppVariant* result); // This function sets a flag that tells the test_shell to print a line of - // descriptive test for each frame load callback. It takes no arguments, and + // descriptive text for each frame load callback. It takes no arguments, and // ignores any that may be present. void dumpFrameLoadCallbacks(const CppArgumentList& args, CppVariant* result); @@ -205,6 +212,8 @@ class LayoutTestController : public CppBoundClass { // Clears all databases. void clearAllDatabases(const CppArgumentList& args, CppVariant* result); + // Sets the default quota for all origins + void setDatabaseQuota(const CppArgumentList& args, CppVariant* result); // Calls setlocale(LC_ALL, ...) for a specified locale. // Resets between tests. diff --git a/webkit/tools/test_shell/simple_database_system.cc b/webkit/tools/test_shell/simple_database_system.cc index 2b9afe3..a2cd8e3 100644 --- a/webkit/tools/test_shell/simple_database_system.cc +++ b/webkit/tools/test_shell/simple_database_system.cc @@ -10,7 +10,9 @@ #include "third_party/sqlite/preprocessed/sqlite3.h" #endif +#include "base/auto_reset.h" #include "base/file_util.h" +#include "base/message_loop.h" #include "base/platform_thread.h" #include "base/process_util.h" #include "third_party/WebKit/WebKit/chromium/public/WebDatabase.h" @@ -29,14 +31,17 @@ SimpleDatabaseSystem* SimpleDatabaseSystem::GetInstance() { return instance_; } -SimpleDatabaseSystem::SimpleDatabaseSystem() { +SimpleDatabaseSystem::SimpleDatabaseSystem() + : waiting_for_dbs_to_close_(false) { temp_dir_.CreateUniqueTempDir(); db_tracker_ = new DatabaseTracker(temp_dir_.path()); + db_tracker_->AddObserver(this); DCHECK(!instance_); instance_ = this; } SimpleDatabaseSystem::~SimpleDatabaseSystem() { + db_tracker_->RemoveObserver(this); instance_ = NULL; } @@ -113,6 +118,9 @@ void SimpleDatabaseSystem::DatabaseClosed(const string16& origin_identifier, origin_identifier, database_name)); db_tracker_->DatabaseClosed(origin_identifier, database_name); database_connections_.RemoveConnection(origin_identifier, database_name); + + if (waiting_for_dbs_to_close_ && database_connections_.IsEmpty()) + MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); } void SimpleDatabaseSystem::OnDatabaseSizeChanged( @@ -144,13 +152,22 @@ void SimpleDatabaseSystem::databaseClosed(const WebKit::WebDatabase& database) { } void SimpleDatabaseSystem::ClearAllDatabases() { - db_tracker_->CloseDatabases(database_connections_); - database_connections_.RemoveAllConnections(); + // Wait for all databases to be closed. + if (!database_connections_.IsEmpty()) { + AutoReset waiting_for_dbs_auto_reset(&waiting_for_dbs_to_close_, true); + MessageLoop::ScopedNestableTaskAllower nestable(MessageLoop::current()); + MessageLoop::current()->Run(); + } + db_tracker_->CloseTrackerDatabaseAndClearCaches(); file_util::Delete(db_tracker_->DatabaseDirectory(), true); file_names_.clear(); } +void SimpleDatabaseSystem::SetDatabaseQuota(int64 quota) { + db_tracker_->SetDefaultQuota(quota); +} + void SimpleDatabaseSystem::SetFullFilePathsForVfsFile( const string16& origin_identifier, const string16& database_name) { diff --git a/webkit/tools/test_shell/simple_database_system.h b/webkit/tools/test_shell/simple_database_system.h index ff92b3f..766940e 100644 --- a/webkit/tools/test_shell/simple_database_system.h +++ b/webkit/tools/test_shell/simple_database_system.h @@ -53,6 +53,7 @@ class SimpleDatabaseSystem : public webkit_database::DatabaseTracker::Observer, virtual void databaseClosed(const WebKit::WebDatabase& database); void ClearAllDatabases(); + void SetDatabaseQuota(int64 quota); private: // The calls that come from the database tracker run on the main thread. @@ -68,6 +69,8 @@ class SimpleDatabaseSystem : public webkit_database::DatabaseTracker::Observer, static SimpleDatabaseSystem* instance_; + bool waiting_for_dbs_to_close_; + ScopedTempDir temp_dir_; scoped_refptr<webkit_database::DatabaseTracker> db_tracker_; |