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