| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "chrome/common/chrome_constants.h" | 23 #include "chrome/common/chrome_constants.h" |
| 24 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
| 25 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 25 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 26 #include "chrome/test/base/testing_profile.h" | 26 #include "chrome/test/base/testing_profile.h" |
| 27 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 28 #include "content/public/test/test_browser_thread.h" | 28 #include "content/public/test/test_browser_thread.h" |
| 29 #include "extensions/common/dom_action_types.h" | 29 #include "extensions/common/dom_action_types.h" |
| 30 #include "sql/statement.h" | 30 #include "sql/statement.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 32 | 32 |
| 33 #if defined(OS_CHROMEOS) | |
| 34 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" | |
| 35 #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" | |
| 36 #include "chrome/browser/chromeos/settings/cros_settings.h" | |
| 37 #include "chrome/browser/chromeos/settings/device_settings_service.h" | |
| 38 #include "chromeos/chromeos_switches.h" | |
| 39 #endif | |
| 40 | |
| 41 using content::BrowserThread; | 33 using content::BrowserThread; |
| 42 | 34 |
| 43 namespace constants = activity_log_constants; | 35 namespace constants = activity_log_constants; |
| 44 | 36 |
| 45 namespace extensions { | 37 namespace extensions { |
| 46 | 38 |
| 47 // A dummy implementation of ActivityDatabase::Delegate, sufficient for | 39 // A dummy implementation of ActivityDatabase::Delegate, sufficient for |
| 48 // the unit tests. | 40 // the unit tests. |
| 49 class ActivityDatabaseTestPolicy : public ActivityDatabase::Delegate { | 41 class ActivityDatabaseTestPolicy : public ActivityDatabase::Delegate { |
| 50 public: | 42 public: |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 void ActivityDatabaseTestPolicy::Record(ActivityDatabase* db, | 98 void ActivityDatabaseTestPolicy::Record(ActivityDatabase* db, |
| 107 scoped_refptr<Action> action) { | 99 scoped_refptr<Action> action) { |
| 108 queue_.push_back(action); | 100 queue_.push_back(action); |
| 109 db->AdviseFlush(queue_.size()); | 101 db->AdviseFlush(queue_.size()); |
| 110 } | 102 } |
| 111 | 103 |
| 112 class ActivityDatabaseTest : public ChromeRenderViewHostTestHarness { | 104 class ActivityDatabaseTest : public ChromeRenderViewHostTestHarness { |
| 113 protected: | 105 protected: |
| 114 void SetUp() override { | 106 void SetUp() override { |
| 115 ChromeRenderViewHostTestHarness::SetUp(); | 107 ChromeRenderViewHostTestHarness::SetUp(); |
| 116 #if defined OS_CHROMEOS | |
| 117 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); | |
| 118 #endif | |
| 119 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 108 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 120 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 109 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 121 switches::kEnableExtensionActivityLogTesting); | 110 switches::kEnableExtensionActivityLogTesting); |
| 122 } | 111 } |
| 123 | 112 |
| 124 void TearDown() override { | 113 void TearDown() override { |
| 125 #if defined OS_CHROMEOS | |
| 126 test_user_manager_.reset(); | |
| 127 #endif | |
| 128 ChromeRenderViewHostTestHarness::TearDown(); | 114 ChromeRenderViewHostTestHarness::TearDown(); |
| 129 } | 115 } |
| 130 | 116 |
| 131 // Creates a test database and initializes the table schema. | 117 // Creates a test database and initializes the table schema. |
| 132 ActivityDatabase* OpenDatabase(const base::FilePath& db_file) { | 118 ActivityDatabase* OpenDatabase(const base::FilePath& db_file) { |
| 133 db_delegate_ = new ActivityDatabaseTestPolicy(); | 119 db_delegate_ = new ActivityDatabaseTestPolicy(); |
| 134 ActivityDatabase* activity_db = new ActivityDatabase(db_delegate_); | 120 ActivityDatabase* activity_db = new ActivityDatabase(db_delegate_); |
| 135 activity_db->Init(db_file); | 121 activity_db->Init(db_file); |
| 136 CHECK(activity_db->is_db_valid()); | 122 CHECK(activity_db->is_db_valid()); |
| 137 return activity_db; | 123 return activity_db; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 156 " WHERE api_name LIKE ?"; | 142 " WHERE api_name LIKE ?"; |
| 157 sql::Statement statement(db->GetCachedStatement( | 143 sql::Statement statement(db->GetCachedStatement( |
| 158 sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); | 144 sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); |
| 159 statement.BindString(0, api_name_pattern); | 145 statement.BindString(0, api_name_pattern); |
| 160 if (!statement.Step()) | 146 if (!statement.Step()) |
| 161 return -1; | 147 return -1; |
| 162 return statement.ColumnInt(0); | 148 return statement.ColumnInt(0); |
| 163 } | 149 } |
| 164 | 150 |
| 165 private: | 151 private: |
| 166 #if defined OS_CHROMEOS | |
| 167 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | |
| 168 chromeos::ScopedTestCrosSettings test_cros_settings_; | |
| 169 std::unique_ptr<chromeos::ScopedTestUserManager> test_user_manager_; | |
| 170 #endif | |
| 171 | |
| 172 ActivityDatabaseTestPolicy* db_delegate_; | 152 ActivityDatabaseTestPolicy* db_delegate_; |
| 173 }; | 153 }; |
| 174 | 154 |
| 175 // Check that the database is initialized properly. | 155 // Check that the database is initialized properly. |
| 176 TEST_F(ActivityDatabaseTest, Init) { | 156 TEST_F(ActivityDatabaseTest, Init) { |
| 177 base::ScopedTempDir temp_dir; | 157 base::ScopedTempDir temp_dir; |
| 178 base::FilePath db_file; | 158 base::FilePath db_file; |
| 179 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 159 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 180 db_file = temp_dir.GetPath().AppendASCII("ActivityInit.db"); | 160 db_file = temp_dir.GetPath().AppendASCII("ActivityInit.db"); |
| 181 sql::Connection::Delete(db_file); | 161 sql::Connection::Delete(db_file); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 ActivityDatabaseTestPolicy* delegate = new ActivityDatabaseTestPolicy(); | 261 ActivityDatabaseTestPolicy* delegate = new ActivityDatabaseTestPolicy(); |
| 282 ActivityDatabase* activity_db = new ActivityDatabase(delegate); | 262 ActivityDatabase* activity_db = new ActivityDatabase(delegate); |
| 283 scoped_refptr<Action> action = new Action( | 263 scoped_refptr<Action> action = new Action( |
| 284 "punky", base::Time::Now(), Action::ACTION_API_CALL, "brewster"); | 264 "punky", base::Time::Now(), Action::ACTION_API_CALL, "brewster"); |
| 285 action->mutable_args()->AppendString("woof"); | 265 action->mutable_args()->AppendString("woof"); |
| 286 delegate->Record(activity_db, action); | 266 delegate->Record(activity_db, action); |
| 287 activity_db->Close(); | 267 activity_db->Close(); |
| 288 } | 268 } |
| 289 | 269 |
| 290 } // namespace extensions | 270 } // namespace extensions |
| OLD | NEW |