| Index: chrome/browser/extensions/activity_log/activity_database_unittest.cc
|
| diff --git a/chrome/browser/extensions/activity_log/activity_database_unittest.cc b/chrome/browser/extensions/activity_log/activity_database_unittest.cc
|
| index edd14dd7fca825634b270474527980d5d96032c3..125175a7197f6f88aec8b5a2309d92a5522de107 100644
|
| --- a/chrome/browser/extensions/activity_log/activity_database_unittest.cc
|
| +++ b/chrome/browser/extensions/activity_log/activity_database_unittest.cc
|
| @@ -8,6 +8,8 @@
|
| #include "base/files/file_path.h"
|
| #include "base/files/scoped_temp_dir.h"
|
| #include "base/run_loop.h"
|
| +#include "base/strings/stringprintf.h"
|
| +#include "base/strings/utf_string_conversions.h"
|
| #include "base/test/simple_test_clock.h"
|
| #include "base/time/time.h"
|
| #include "chrome/browser/extensions/activity_log/activity_database.h"
|
| @@ -451,5 +453,138 @@ TEST_F(ActivityDatabaseTest, InitFailure) {
|
| activity_db->Close();
|
| }
|
|
|
| +TEST_F(ActivityDatabaseTest, ConstructClearURLQuery) {
|
| + std::string query;
|
| + ActivityDatabase::ConstructRemoveURLQuery("", &query);
|
| + ASSERT_EQ("UPDATE activitylog_urls SET url_tld='',url_title='',url_path=''",
|
| + query);
|
| +
|
| + ActivityDatabase::ConstructRemoveURLQuery(
|
| + "http://www.somewebsite.com", &query);
|
| + ASSERT_EQ("UPDATE activitylog_urls SET url_tld='',url_title='',url_path='' "
|
| + "WHERE url_tld='http://www.somewebsite.com'", query);
|
| +}
|
| +
|
| +TEST_F(ActivityDatabaseTest, RemoveAllURLs) {
|
| + base::ScopedTempDir temp_dir;
|
| + base::FilePath db_file;
|
| + ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
|
| + db_file = temp_dir.path().AppendASCII("ActivityRecord.db");
|
| + base::Delete(db_file, false);
|
| +
|
| + // Use a mock clock to ensure that events are not recorded on the wrong day
|
| + // when the test is run close to local midnight.
|
| + base::SimpleTestClock mock_clock;
|
| + mock_clock.SetNow(base::Time::Now().LocalMidnight() +
|
| + base::TimeDelta::FromHours(12));
|
| +
|
| + // Record some actions
|
| + ActivityDatabase* activity_db = OpenDatabase(db_file);
|
| + activity_db->Init(db_file);
|
| + activity_db->SetBatchModeForTesting(false);
|
| + ASSERT_TRUE(activity_db->is_db_valid());
|
| +
|
| + for (int i = 0; i < 3; ++i) {
|
| + scoped_refptr<DOMAction> action = new DOMAction(
|
| + "punky",
|
| + base::Time::Now(),
|
| + DomActionType::MODIFIED,
|
| + GURL(base::StringPrintf("http://www.google%d.com/foo?bar", i)),
|
| + base::ASCIIToUTF16("Title"),
|
| + "lets",
|
| + "vamoose",
|
| + "extra");
|
| + activity_db->RecordAction(action);
|
| + }
|
| + // Clear all the urls.
|
| + activity_db->RemoveAllURLs();
|
| + activity_db->Close();
|
| +
|
| + sql::Connection db;
|
| + ASSERT_TRUE(db.Open(db_file));
|
| + ASSERT_TRUE(db.DoesTableExist(APIAction::kTableName));
|
| + std::string sql_str = "SELECT * FROM " +
|
| + std::string(DOMAction::kTableName);
|
| + sql::Statement statement(db.GetUniqueStatement(sql_str.c_str()));
|
| +
|
| + while (statement.Step()) {
|
| + ASSERT_TRUE(statement.Succeeded());
|
| + ASSERT_EQ("punky", statement.ColumnString(0));
|
| + ASSERT_EQ(DomActionType::MODIFIED, statement.ColumnInt(2));
|
| + // These fields should be set to empty string for all rows.
|
| + ASSERT_EQ("", statement.ColumnString(3));
|
| + ASSERT_EQ("", statement.ColumnString(4));
|
| + ASSERT_EQ("", statement.ColumnString(5));
|
| + }
|
| +}
|
| +
|
| +TEST_F(ActivityDatabaseTest, RemoveURL) {
|
| + base::ScopedTempDir temp_dir;
|
| + base::FilePath db_file;
|
| + ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
|
| + db_file = temp_dir.path().AppendASCII("ActivityRecord.db");
|
| + base::Delete(db_file, false);
|
| +
|
| + // Use a mock clock to ensure that events are not recorded on the wrong day
|
| + // when the test is run close to local midnight.
|
| + base::SimpleTestClock mock_clock;
|
| + mock_clock.SetNow(base::Time::Now().LocalMidnight() +
|
| + base::TimeDelta::FromHours(12));
|
| +
|
| + // Record some actions
|
| + ActivityDatabase* activity_db = OpenDatabase(db_file);
|
| + activity_db->Init(db_file);
|
| + activity_db->SetBatchModeForTesting(false);
|
| + ASSERT_TRUE(activity_db->is_db_valid());
|
| +
|
| + for (int i = 1; i < 4; ++i) {
|
| + scoped_refptr<DOMAction> action = new DOMAction(
|
| + "punky",
|
| + base::Time::Now(),
|
| + DomActionType::MODIFIED,
|
| + GURL(base::StringPrintf("http://www.google%d.com/foo?bar", i)),
|
| + base::ASCIIToUTF16("Title"),
|
| + "lets",
|
| + "vamoose",
|
| + "extra");
|
| + activity_db->RecordAction(action);
|
| + }
|
| + activity_db->RemoveURL(GURL("http://www.google3.com/foo?"));
|
| + activity_db->Close();
|
| +
|
| + sql::Connection db;
|
| + ASSERT_TRUE(db.Open(db_file));
|
| + ASSERT_TRUE(db.DoesTableExist(APIAction::kTableName));
|
| + std::string sql_str = "SELECT * FROM " +
|
| + std::string(DOMAction::kTableName);
|
| + sql::Statement statement(db.GetUniqueStatement(sql_str.c_str()));
|
| +
|
| + // These rows should still contain the URLs.
|
| + for (int i = 1; i < 3; ++i) {
|
| + ASSERT_TRUE(statement.Step());
|
| + ASSERT_TRUE(statement.Succeeded());
|
| + ASSERT_EQ("punky", statement.ColumnString(0));
|
| + ASSERT_EQ(DomActionType::MODIFIED, statement.ColumnInt(2));
|
| + ASSERT_EQ(base::StringPrintf("http://www.google%d.com", i),
|
| + statement.ColumnString(3));
|
| + ASSERT_EQ("Title", statement.ColumnString(5));
|
| + ASSERT_EQ("lets", statement.ColumnString(6));
|
| + ASSERT_EQ("vamoose", statement.ColumnString(7));
|
| + ASSERT_EQ("extra", statement.ColumnString(8));
|
| + }
|
| +
|
| + // This one should have the cleaned URLs fields.
|
| + ASSERT_TRUE(statement.Step());
|
| + ASSERT_TRUE(statement.Succeeded());
|
| + ASSERT_EQ("punky", statement.ColumnString(0));
|
| + ASSERT_EQ(DomActionType::MODIFIED, statement.ColumnInt(2));
|
| + ASSERT_EQ("", statement.ColumnString(3));
|
| + ASSERT_EQ("", statement.ColumnString(4));
|
| + ASSERT_EQ("", statement.ColumnString(5));
|
| + ASSERT_EQ("lets", statement.ColumnString(6));
|
| + ASSERT_EQ("vamoose", statement.ColumnString(7));
|
| + ASSERT_EQ("extra", statement.ColumnString(8));
|
| +}
|
| +
|
| } // namespace extensions
|
|
|
|
|