| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/extensions/activity_log/counting_policy.h" | 5 #include "chrome/browser/extensions/activity_log/counting_policy.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 |
| 10 #include <memory> |
| 9 #include <utility> | 11 #include <utility> |
| 10 | 12 |
| 11 #include "base/cancelable_callback.h" | 13 #include "base/cancelable_callback.h" |
| 12 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 13 #include "base/location.h" | 15 #include "base/location.h" |
| 14 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/ptr_util.h" |
| 15 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 16 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 17 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
| 18 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 19 #include "base/synchronization/waitable_event.h" | 21 #include "base/synchronization/waitable_event.h" |
| 20 #include "base/test/simple_test_clock.h" | 22 #include "base/test/simple_test_clock.h" |
| 21 #include "base/test/test_timeouts.h" | 23 #include "base/test/test_timeouts.h" |
| 22 #include "base/thread_task_runner_handle.h" | 24 #include "base/thread_task_runner_handle.h" |
| 23 #include "build/build_config.h" | 25 #include "build/build_config.h" |
| 24 #include "chrome/browser/extensions/activity_log/activity_log.h" | 26 #include "chrome/browser/extensions/activity_log/activity_log.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 // Wait for the task queue for the specified thread to empty. | 77 // Wait for the task queue for the specified thread to empty. |
| 76 void WaitOnThread(const BrowserThread::ID& thread) { | 78 void WaitOnThread(const BrowserThread::ID& thread) { |
| 77 BrowserThread::PostTaskAndReply( | 79 BrowserThread::PostTaskAndReply( |
| 78 thread, FROM_HERE, base::Bind(&base::DoNothing), | 80 thread, FROM_HERE, base::Bind(&base::DoNothing), |
| 79 base::MessageLoop::current()->QuitWhenIdleClosure()); | 81 base::MessageLoop::current()->QuitWhenIdleClosure()); |
| 80 base::MessageLoop::current()->Run(); | 82 base::MessageLoop::current()->Run(); |
| 81 } | 83 } |
| 82 | 84 |
| 83 // A wrapper function for CheckReadFilteredData, so that we don't need to | 85 // A wrapper function for CheckReadFilteredData, so that we don't need to |
| 84 // enter empty string values for parameters we don't care about. | 86 // enter empty string values for parameters we don't care about. |
| 85 void CheckReadData( | 87 void CheckReadData(ActivityLogDatabasePolicy* policy, |
| 86 ActivityLogDatabasePolicy* policy, | 88 const std::string& extension_id, |
| 87 const std::string& extension_id, | 89 int day, |
| 88 int day, | 90 const base::Callback<void( |
| 89 const base::Callback<void(scoped_ptr<Action::ActionVector>)>& checker) { | 91 std::unique_ptr<Action::ActionVector>)>& checker) { |
| 90 CheckReadFilteredData( | 92 CheckReadFilteredData( |
| 91 policy, extension_id, Action::ACTION_ANY, "", "", "", day, checker); | 93 policy, extension_id, Action::ACTION_ANY, "", "", "", day, checker); |
| 92 } | 94 } |
| 93 | 95 |
| 94 // A helper function to call ReadFilteredData on a policy object and wait for | 96 // A helper function to call ReadFilteredData on a policy object and wait for |
| 95 // the results to be processed. | 97 // the results to be processed. |
| 96 void CheckReadFilteredData( | 98 void CheckReadFilteredData( |
| 97 ActivityLogDatabasePolicy* policy, | 99 ActivityLogDatabasePolicy* policy, |
| 98 const std::string& extension_id, | 100 const std::string& extension_id, |
| 99 const Action::ActionType type, | 101 const Action::ActionType type, |
| 100 const std::string& api_name, | 102 const std::string& api_name, |
| 101 const std::string& page_url, | 103 const std::string& page_url, |
| 102 const std::string& arg_url, | 104 const std::string& arg_url, |
| 103 int day, | 105 int day, |
| 104 const base::Callback<void(scoped_ptr<Action::ActionVector>)>& checker) { | 106 const base::Callback<void(std::unique_ptr<Action::ActionVector>)>& |
| 107 checker) { |
| 105 // Submit a request to the policy to read back some data, and call the | 108 // Submit a request to the policy to read back some data, and call the |
| 106 // checker function when results are available. This will happen on the | 109 // checker function when results are available. This will happen on the |
| 107 // database thread. | 110 // database thread. |
| 108 policy->ReadFilteredData( | 111 policy->ReadFilteredData( |
| 109 extension_id, type, api_name, page_url, arg_url, day, | 112 extension_id, type, api_name, page_url, arg_url, day, |
| 110 base::Bind(&CountingPolicyTest::CheckWrapper, checker, | 113 base::Bind(&CountingPolicyTest::CheckWrapper, checker, |
| 111 base::MessageLoop::current()->QuitWhenIdleClosure())); | 114 base::MessageLoop::current()->QuitWhenIdleClosure())); |
| 112 | 115 |
| 113 // Set up a timeout for receiving results; if we haven't received anything | 116 // Set up a timeout for receiving results; if we haven't received anything |
| 114 // when the timeout triggers then assume that the test is broken. | 117 // when the timeout triggers then assume that the test is broken. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 142 } | 145 } |
| 143 | 146 |
| 144 // Checks that the number of queued actions to be written out does not exceed | 147 // Checks that the number of queued actions to be written out does not exceed |
| 145 // kSizeThresholdForFlush. Runs on the database thread. | 148 // kSizeThresholdForFlush. Runs on the database thread. |
| 146 static void CheckQueueSize(CountingPolicy* policy) { | 149 static void CheckQueueSize(CountingPolicy* policy) { |
| 147 // This should be updated if kSizeThresholdForFlush in activity_database.cc | 150 // This should be updated if kSizeThresholdForFlush in activity_database.cc |
| 148 // changes. | 151 // changes. |
| 149 ASSERT_LE(policy->queued_actions_.size(), 200U); | 152 ASSERT_LE(policy->queued_actions_.size(), 200U); |
| 150 } | 153 } |
| 151 | 154 |
| 152 static void CheckWrapper( | 155 static void CheckWrapper(const base::Callback<void( |
| 153 const base::Callback<void(scoped_ptr<Action::ActionVector>)>& checker, | 156 std::unique_ptr<Action::ActionVector>)>& checker, |
| 154 const base::Closure& done, | 157 const base::Closure& done, |
| 155 scoped_ptr<Action::ActionVector> results) { | 158 std::unique_ptr<Action::ActionVector> results) { |
| 156 checker.Run(std::move(results)); | 159 checker.Run(std::move(results)); |
| 157 done.Run(); | 160 done.Run(); |
| 158 } | 161 } |
| 159 | 162 |
| 160 static void TimeoutCallback() { | 163 static void TimeoutCallback() { |
| 161 base::MessageLoop::current()->QuitWhenIdle(); | 164 base::MessageLoop::current()->QuitWhenIdle(); |
| 162 FAIL() << "Policy test timed out waiting for results"; | 165 FAIL() << "Policy test timed out waiting for results"; |
| 163 } | 166 } |
| 164 | 167 |
| 165 static void RetrieveActions_FetchFilteredActions0( | 168 static void RetrieveActions_FetchFilteredActions0( |
| 166 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 169 std::unique_ptr<std::vector<scoped_refptr<Action>>> i) { |
| 167 ASSERT_EQ(0, static_cast<int>(i->size())); | 170 ASSERT_EQ(0, static_cast<int>(i->size())); |
| 168 } | 171 } |
| 169 | 172 |
| 170 static void RetrieveActions_FetchFilteredActions1( | 173 static void RetrieveActions_FetchFilteredActions1( |
| 171 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 174 std::unique_ptr<std::vector<scoped_refptr<Action>>> i) { |
| 172 ASSERT_EQ(1, static_cast<int>(i->size())); | 175 ASSERT_EQ(1, static_cast<int>(i->size())); |
| 173 } | 176 } |
| 174 | 177 |
| 175 static void RetrieveActions_FetchFilteredActions2( | 178 static void RetrieveActions_FetchFilteredActions2( |
| 176 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 179 std::unique_ptr<std::vector<scoped_refptr<Action>>> i) { |
| 177 ASSERT_EQ(2, static_cast<int>(i->size())); | 180 ASSERT_EQ(2, static_cast<int>(i->size())); |
| 178 } | 181 } |
| 179 | 182 |
| 180 static void RetrieveActions_FetchFilteredActions300( | 183 static void RetrieveActions_FetchFilteredActions300( |
| 181 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 184 std::unique_ptr<std::vector<scoped_refptr<Action>>> i) { |
| 182 ASSERT_EQ(300, static_cast<int>(i->size())); | 185 ASSERT_EQ(300, static_cast<int>(i->size())); |
| 183 } | 186 } |
| 184 | 187 |
| 185 static void Arguments_Stripped(scoped_ptr<Action::ActionVector> i) { | 188 static void Arguments_Stripped(std::unique_ptr<Action::ActionVector> i) { |
| 186 scoped_refptr<Action> last = i->front(); | 189 scoped_refptr<Action> last = i->front(); |
| 187 CheckAction(*last.get(), | 190 CheckAction(*last.get(), |
| 188 "odlameecjipmbmbejkplpemijjgpljce", | 191 "odlameecjipmbmbejkplpemijjgpljce", |
| 189 Action::ACTION_API_CALL, | 192 Action::ACTION_API_CALL, |
| 190 "extension.connect", | 193 "extension.connect", |
| 191 "[\"hello\",\"world\"]", | 194 "[\"hello\",\"world\"]", |
| 192 "", | 195 "", |
| 193 "", | 196 "", |
| 194 "", | 197 "", |
| 195 1); | 198 1); |
| 196 } | 199 } |
| 197 | 200 |
| 198 static void Arguments_GetSinglesAction( | 201 static void Arguments_GetSinglesAction( |
| 199 scoped_ptr<Action::ActionVector> actions) { | 202 std::unique_ptr<Action::ActionVector> actions) { |
| 200 ASSERT_EQ(1, static_cast<int>(actions->size())); | 203 ASSERT_EQ(1, static_cast<int>(actions->size())); |
| 201 CheckAction(*actions->at(0).get(), | 204 CheckAction(*actions->at(0).get(), |
| 202 "punky", | 205 "punky", |
| 203 Action::ACTION_DOM_ACCESS, | 206 Action::ACTION_DOM_ACCESS, |
| 204 "lets", | 207 "lets", |
| 205 "", | 208 "", |
| 206 "http://www.google.com/", | 209 "http://www.google.com/", |
| 207 "", | 210 "", |
| 208 "", | 211 "", |
| 209 1); | 212 1); |
| 210 } | 213 } |
| 211 | 214 |
| 212 static void Arguments_GetTodaysActions( | 215 static void Arguments_GetTodaysActions( |
| 213 scoped_ptr<Action::ActionVector> actions) { | 216 std::unique_ptr<Action::ActionVector> actions) { |
| 214 ASSERT_EQ(3, static_cast<int>(actions->size())); | 217 ASSERT_EQ(3, static_cast<int>(actions->size())); |
| 215 CheckAction(*actions->at(0).get(), | 218 CheckAction(*actions->at(0).get(), |
| 216 "punky", | 219 "punky", |
| 217 Action::ACTION_API_CALL, | 220 Action::ACTION_API_CALL, |
| 218 "brewster", | 221 "brewster", |
| 219 "", | 222 "", |
| 220 "", | 223 "", |
| 221 "", | 224 "", |
| 222 "", | 225 "", |
| 223 2); | 226 2); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 235 Action::ACTION_API_CALL, | 238 Action::ACTION_API_CALL, |
| 236 "extension.sendMessage", | 239 "extension.sendMessage", |
| 237 "[\"not\",\"stripped\"]", | 240 "[\"not\",\"stripped\"]", |
| 238 "", | 241 "", |
| 239 "", | 242 "", |
| 240 "", | 243 "", |
| 241 1); | 244 1); |
| 242 } | 245 } |
| 243 | 246 |
| 244 static void Arguments_GetOlderActions( | 247 static void Arguments_GetOlderActions( |
| 245 scoped_ptr<Action::ActionVector> actions) { | 248 std::unique_ptr<Action::ActionVector> actions) { |
| 246 ASSERT_EQ(2, static_cast<int>(actions->size())); | 249 ASSERT_EQ(2, static_cast<int>(actions->size())); |
| 247 CheckAction(*actions->at(0).get(), | 250 CheckAction(*actions->at(0).get(), |
| 248 "punky", | 251 "punky", |
| 249 Action::ACTION_DOM_ACCESS, | 252 Action::ACTION_DOM_ACCESS, |
| 250 "lets", | 253 "lets", |
| 251 "", | 254 "", |
| 252 "http://www.google.com/", | 255 "http://www.google.com/", |
| 253 "", | 256 "", |
| 254 "", | 257 "", |
| 255 1); | 258 1); |
| 256 CheckAction(*actions->at(1).get(), | 259 CheckAction(*actions->at(1).get(), |
| 257 "punky", | 260 "punky", |
| 258 Action::ACTION_API_CALL, | 261 Action::ACTION_API_CALL, |
| 259 "brewster", | 262 "brewster", |
| 260 "", | 263 "", |
| 261 "", | 264 "", |
| 262 "", | 265 "", |
| 263 "", | 266 "", |
| 264 1); | 267 1); |
| 265 } | 268 } |
| 266 | 269 |
| 267 static void Arguments_CheckMergeCount( | 270 static void Arguments_CheckMergeCount( |
| 268 int count, | 271 int count, |
| 269 scoped_ptr<Action::ActionVector> actions) { | 272 std::unique_ptr<Action::ActionVector> actions) { |
| 270 if (count > 0) { | 273 if (count > 0) { |
| 271 ASSERT_EQ(1u, actions->size()); | 274 ASSERT_EQ(1u, actions->size()); |
| 272 CheckAction(*actions->at(0).get(), | 275 CheckAction(*actions->at(0).get(), |
| 273 "punky", | 276 "punky", |
| 274 Action::ACTION_API_CALL, | 277 Action::ACTION_API_CALL, |
| 275 "brewster", | 278 "brewster", |
| 276 "", | 279 "", |
| 277 "", | 280 "", |
| 278 "", | 281 "", |
| 279 "", | 282 "", |
| 280 count); | 283 count); |
| 281 } else { | 284 } else { |
| 282 ASSERT_EQ(0u, actions->size()); | 285 ASSERT_EQ(0u, actions->size()); |
| 283 } | 286 } |
| 284 } | 287 } |
| 285 | 288 |
| 286 static void Arguments_CheckMergeCountAndTime( | 289 static void Arguments_CheckMergeCountAndTime( |
| 287 int count, | 290 int count, |
| 288 const base::Time& time, | 291 const base::Time& time, |
| 289 scoped_ptr<Action::ActionVector> actions) { | 292 std::unique_ptr<Action::ActionVector> actions) { |
| 290 if (count > 0) { | 293 if (count > 0) { |
| 291 ASSERT_EQ(1u, actions->size()); | 294 ASSERT_EQ(1u, actions->size()); |
| 292 CheckAction(*actions->at(0).get(), | 295 CheckAction(*actions->at(0).get(), |
| 293 "punky", | 296 "punky", |
| 294 Action::ACTION_API_CALL, | 297 Action::ACTION_API_CALL, |
| 295 "brewster", | 298 "brewster", |
| 296 "", | 299 "", |
| 297 "", | 300 "", |
| 298 "", | 301 "", |
| 299 "", | 302 "", |
| 300 count); | 303 count); |
| 301 ASSERT_EQ(time, actions->at(0)->time()); | 304 ASSERT_EQ(time, actions->at(0)->time()); |
| 302 } else { | 305 } else { |
| 303 ASSERT_EQ(0u, actions->size()); | 306 ASSERT_EQ(0u, actions->size()); |
| 304 } | 307 } |
| 305 } | 308 } |
| 306 | 309 |
| 307 static void AllURLsRemoved(scoped_ptr<Action::ActionVector> actions) { | 310 static void AllURLsRemoved(std::unique_ptr<Action::ActionVector> actions) { |
| 308 ASSERT_EQ(2, static_cast<int>(actions->size())); | 311 ASSERT_EQ(2, static_cast<int>(actions->size())); |
| 309 CheckAction(*actions->at(0).get(), | 312 CheckAction(*actions->at(0).get(), |
| 310 "punky", | 313 "punky", |
| 311 Action::ACTION_DOM_ACCESS, | 314 Action::ACTION_DOM_ACCESS, |
| 312 "lets", | 315 "lets", |
| 313 "", | 316 "", |
| 314 "", | 317 "", |
| 315 "", | 318 "", |
| 316 "", | 319 "", |
| 317 1); | 320 1); |
| 318 CheckAction(*actions->at(1).get(), | 321 CheckAction(*actions->at(1).get(), |
| 319 "punky", | 322 "punky", |
| 320 Action::ACTION_DOM_ACCESS, | 323 Action::ACTION_DOM_ACCESS, |
| 321 "lets", | 324 "lets", |
| 322 "", | 325 "", |
| 323 "", | 326 "", |
| 324 "", | 327 "", |
| 325 "", | 328 "", |
| 326 1); | 329 1); |
| 327 } | 330 } |
| 328 | 331 |
| 329 static void SomeURLsRemoved(scoped_ptr<Action::ActionVector> actions) { | 332 static void SomeURLsRemoved(std::unique_ptr<Action::ActionVector> actions) { |
| 330 // These will be in the vector in reverse time order. | 333 // These will be in the vector in reverse time order. |
| 331 ASSERT_EQ(5, static_cast<int>(actions->size())); | 334 ASSERT_EQ(5, static_cast<int>(actions->size())); |
| 332 CheckAction(*actions->at(0).get(), | 335 CheckAction(*actions->at(0).get(), |
| 333 "punky", | 336 "punky", |
| 334 Action::ACTION_DOM_ACCESS, | 337 Action::ACTION_DOM_ACCESS, |
| 335 "lets", | 338 "lets", |
| 336 "", | 339 "", |
| 337 "http://www.google.com/", | 340 "http://www.google.com/", |
| 338 "Google", | 341 "Google", |
| 339 "http://www.args-url.com/", | 342 "http://www.args-url.com/", |
| (...skipping 29 matching lines...) Expand all Loading... |
| 369 "punky", | 372 "punky", |
| 370 Action::ACTION_DOM_ACCESS, | 373 Action::ACTION_DOM_ACCESS, |
| 371 "lets", | 374 "lets", |
| 372 "", | 375 "", |
| 373 "", | 376 "", |
| 374 "", | 377 "", |
| 375 "", | 378 "", |
| 376 1); | 379 1); |
| 377 } | 380 } |
| 378 | 381 |
| 379 static void CheckDuplicates(scoped_ptr<Action::ActionVector> actions) { | 382 static void CheckDuplicates(std::unique_ptr<Action::ActionVector> actions) { |
| 380 ASSERT_EQ(2u, actions->size()); | 383 ASSERT_EQ(2u, actions->size()); |
| 381 int total_count = 0; | 384 int total_count = 0; |
| 382 for (size_t i = 0; i < actions->size(); i++) { | 385 for (size_t i = 0; i < actions->size(); i++) { |
| 383 total_count += actions->at(i)->count(); | 386 total_count += actions->at(i)->count(); |
| 384 } | 387 } |
| 385 ASSERT_EQ(3, total_count); | 388 ASSERT_EQ(3, total_count); |
| 386 } | 389 } |
| 387 | 390 |
| 388 static void CheckAction(const Action& action, | 391 static void CheckAction(const Action& action, |
| 389 const std::string& expected_id, | 392 const std::string& expected_id, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 405 ASSERT_EQ(expected_count, action.count()); | 408 ASSERT_EQ(expected_count, action.count()); |
| 406 ASSERT_NE(-1, action.action_id()); | 409 ASSERT_NE(-1, action.action_id()); |
| 407 } | 410 } |
| 408 | 411 |
| 409 // A helper function initializes the policy with a number of actions, calls | 412 // A helper function initializes the policy with a number of actions, calls |
| 410 // RemoveActions on a policy object and then checks the result of the | 413 // RemoveActions on a policy object and then checks the result of the |
| 411 // deletion. | 414 // deletion. |
| 412 void CheckRemoveActions( | 415 void CheckRemoveActions( |
| 413 ActivityLogDatabasePolicy* policy, | 416 ActivityLogDatabasePolicy* policy, |
| 414 const std::vector<int64_t>& action_ids, | 417 const std::vector<int64_t>& action_ids, |
| 415 const base::Callback<void(scoped_ptr<Action::ActionVector>)>& checker) { | 418 const base::Callback<void(std::unique_ptr<Action::ActionVector>)>& |
| 419 checker) { |
| 416 // Use a mock clock to ensure that events are not recorded on the wrong day | 420 // Use a mock clock to ensure that events are not recorded on the wrong day |
| 417 // when the test is run close to local midnight. | 421 // when the test is run close to local midnight. |
| 418 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); | 422 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); |
| 419 mock_clock->SetNow(base::Time::Now().LocalMidnight() + | 423 mock_clock->SetNow(base::Time::Now().LocalMidnight() + |
| 420 base::TimeDelta::FromHours(12)); | 424 base::TimeDelta::FromHours(12)); |
| 421 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock)); | 425 policy->SetClockForTesting(std::unique_ptr<base::Clock>(mock_clock)); |
| 422 | 426 |
| 423 // Record some actions | 427 // Record some actions |
| 424 scoped_refptr<Action> action = | 428 scoped_refptr<Action> action = |
| 425 new Action("punky1", | 429 new Action("punky1", |
| 426 mock_clock->Now() - base::TimeDelta::FromMinutes(40), | 430 mock_clock->Now() - base::TimeDelta::FromMinutes(40), |
| 427 Action::ACTION_DOM_ACCESS, | 431 Action::ACTION_DOM_ACCESS, |
| 428 "lets1"); | 432 "lets1"); |
| 429 action->mutable_args()->AppendString("vamoose1"); | 433 action->mutable_args()->AppendString("vamoose1"); |
| 430 action->set_page_url(GURL("http://www.google1.com")); | 434 action->set_page_url(GURL("http://www.google1.com")); |
| 431 action->set_page_title("Google1"); | 435 action->set_page_title("Google1"); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 452 policy->RemoveActions(action_ids); | 456 policy->RemoveActions(action_ids); |
| 453 | 457 |
| 454 // Check the result of the deletion. The checker function gets all | 458 // Check the result of the deletion. The checker function gets all |
| 455 // activities in the database. | 459 // activities in the database. |
| 456 CheckReadData(policy, "", -1, checker); | 460 CheckReadData(policy, "", -1, checker); |
| 457 | 461 |
| 458 // Clean database. | 462 // Clean database. |
| 459 policy->DeleteDatabase(); | 463 policy->DeleteDatabase(); |
| 460 } | 464 } |
| 461 | 465 |
| 462 static void AllActionsDeleted(scoped_ptr<Action::ActionVector> actions) { | 466 static void AllActionsDeleted(std::unique_ptr<Action::ActionVector> actions) { |
| 463 ASSERT_EQ(0, static_cast<int>(actions->size())); | 467 ASSERT_EQ(0, static_cast<int>(actions->size())); |
| 464 } | 468 } |
| 465 | 469 |
| 466 static void NoActionsDeleted(scoped_ptr<Action::ActionVector> actions) { | 470 static void NoActionsDeleted(std::unique_ptr<Action::ActionVector> actions) { |
| 467 // These will be in the vector in reverse time order. | 471 // These will be in the vector in reverse time order. |
| 468 ASSERT_EQ(2, static_cast<int>(actions->size())); | 472 ASSERT_EQ(2, static_cast<int>(actions->size())); |
| 469 CheckAction(*actions->at(0).get(), | 473 CheckAction(*actions->at(0).get(), |
| 470 "punky2", | 474 "punky2", |
| 471 Action::ACTION_API_CALL, | 475 Action::ACTION_API_CALL, |
| 472 "lets2", | 476 "lets2", |
| 473 "", | 477 "", |
| 474 "http://www.google2.com/", | 478 "http://www.google2.com/", |
| 475 "Google2", | 479 "Google2", |
| 476 "http://www.args-url2.com/", | 480 "http://www.args-url2.com/", |
| 477 2); | 481 2); |
| 478 ASSERT_EQ(2, actions->at(0)->action_id()); | 482 ASSERT_EQ(2, actions->at(0)->action_id()); |
| 479 CheckAction(*actions->at(1).get(), | 483 CheckAction(*actions->at(1).get(), |
| 480 "punky1", | 484 "punky1", |
| 481 Action::ACTION_DOM_ACCESS, | 485 Action::ACTION_DOM_ACCESS, |
| 482 "lets1", | 486 "lets1", |
| 483 "", | 487 "", |
| 484 "http://www.google1.com/", | 488 "http://www.google1.com/", |
| 485 "Google1", | 489 "Google1", |
| 486 "http://www.args-url1.com/", | 490 "http://www.args-url1.com/", |
| 487 2); | 491 2); |
| 488 ASSERT_EQ(1, actions->at(1)->action_id()); | 492 ASSERT_EQ(1, actions->at(1)->action_id()); |
| 489 } | 493 } |
| 490 | 494 |
| 491 static void Action1Deleted(scoped_ptr<Action::ActionVector> actions) { | 495 static void Action1Deleted(std::unique_ptr<Action::ActionVector> actions) { |
| 492 // These will be in the vector in reverse time order. | 496 // These will be in the vector in reverse time order. |
| 493 ASSERT_EQ(1, static_cast<int>(actions->size())); | 497 ASSERT_EQ(1, static_cast<int>(actions->size())); |
| 494 CheckAction(*actions->at(0).get(), | 498 CheckAction(*actions->at(0).get(), |
| 495 "punky2", | 499 "punky2", |
| 496 Action::ACTION_API_CALL, | 500 Action::ACTION_API_CALL, |
| 497 "lets2", | 501 "lets2", |
| 498 "", | 502 "", |
| 499 "http://www.google2.com/", | 503 "http://www.google2.com/", |
| 500 "Google2", | 504 "Google2", |
| 501 "http://www.args-url2.com/", | 505 "http://www.args-url2.com/", |
| 502 2); | 506 2); |
| 503 ASSERT_EQ(2, actions->at(0)->action_id()); | 507 ASSERT_EQ(2, actions->at(0)->action_id()); |
| 504 } | 508 } |
| 505 | 509 |
| 506 static void Action2Deleted(scoped_ptr<Action::ActionVector> actions) { | 510 static void Action2Deleted(std::unique_ptr<Action::ActionVector> actions) { |
| 507 // These will be in the vector in reverse time order. | 511 // These will be in the vector in reverse time order. |
| 508 ASSERT_EQ(1, static_cast<int>(actions->size())); | 512 ASSERT_EQ(1, static_cast<int>(actions->size())); |
| 509 CheckAction(*actions->at(0).get(), | 513 CheckAction(*actions->at(0).get(), |
| 510 "punky1", | 514 "punky1", |
| 511 Action::ACTION_DOM_ACCESS, | 515 Action::ACTION_DOM_ACCESS, |
| 512 "lets1", | 516 "lets1", |
| 513 "", | 517 "", |
| 514 "http://www.google1.com/", | 518 "http://www.google1.com/", |
| 515 "Google1", | 519 "Google1", |
| 516 "http://www.args-url1.com/", | 520 "http://www.args-url1.com/", |
| 517 2); | 521 2); |
| 518 ASSERT_EQ(1, actions->at(0)->action_id()); | 522 ASSERT_EQ(1, actions->at(0)->action_id()); |
| 519 } | 523 } |
| 520 | 524 |
| 521 protected: | 525 protected: |
| 522 ExtensionService* extension_service_; | 526 ExtensionService* extension_service_; |
| 523 scoped_ptr<TestingProfile> profile_; | 527 std::unique_ptr<TestingProfile> profile_; |
| 524 content::TestBrowserThreadBundle thread_bundle_; | 528 content::TestBrowserThreadBundle thread_bundle_; |
| 525 // Used to preserve a copy of the original command line. | 529 // Used to preserve a copy of the original command line. |
| 526 // The test framework will do this itself as well. However, by then, | 530 // The test framework will do this itself as well. However, by then, |
| 527 // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in | 531 // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in |
| 528 // TearDown(). | 532 // TearDown(). |
| 529 base::CommandLine saved_cmdline_; | 533 base::CommandLine saved_cmdline_; |
| 530 | 534 |
| 531 #if defined OS_CHROMEOS | 535 #if defined OS_CHROMEOS |
| 532 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 536 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
| 533 chromeos::ScopedTestCrosSettings test_cros_settings_; | 537 chromeos::ScopedTestCrosSettings test_cros_settings_; |
| 534 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; | 538 std::unique_ptr<chromeos::ScopedTestUserManager> test_user_manager_; |
| 535 #endif | 539 #endif |
| 536 }; | 540 }; |
| 537 | 541 |
| 538 TEST_F(CountingPolicyTest, Construct) { | 542 TEST_F(CountingPolicyTest, Construct) { |
| 539 ActivityLogDatabasePolicy* policy = new CountingPolicy(profile_.get()); | 543 ActivityLogDatabasePolicy* policy = new CountingPolicy(profile_.get()); |
| 540 policy->Init(); | 544 policy->Init(); |
| 541 scoped_refptr<const Extension> extension = | 545 scoped_refptr<const Extension> extension = |
| 542 ExtensionBuilder() | 546 ExtensionBuilder() |
| 543 .SetManifest(DictionaryBuilder() | 547 .SetManifest(DictionaryBuilder() |
| 544 .Set("name", "Test extension") | 548 .Set("name", "Test extension") |
| 545 .Set("version", "1.0.0") | 549 .Set("version", "1.0.0") |
| 546 .Set("manifest_version", 2) | 550 .Set("manifest_version", 2) |
| 547 .Build()) | 551 .Build()) |
| 548 .Build(); | 552 .Build(); |
| 549 extension_service_->AddExtension(extension.get()); | 553 extension_service_->AddExtension(extension.get()); |
| 550 scoped_ptr<base::ListValue> args(new base::ListValue()); | 554 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
| 551 scoped_refptr<Action> action = new Action(extension->id(), | 555 scoped_refptr<Action> action = new Action(extension->id(), |
| 552 base::Time::Now(), | 556 base::Time::Now(), |
| 553 Action::ACTION_API_CALL, | 557 Action::ACTION_API_CALL, |
| 554 "tabs.testMethod"); | 558 "tabs.testMethod"); |
| 555 action->set_args(std::move(args)); | 559 action->set_args(std::move(args)); |
| 556 policy->ProcessAction(action); | 560 policy->ProcessAction(action); |
| 557 policy->Close(); | 561 policy->Close(); |
| 558 } | 562 } |
| 559 | 563 |
| 560 TEST_F(CountingPolicyTest, LogWithStrippedArguments) { | 564 TEST_F(CountingPolicyTest, LogWithStrippedArguments) { |
| 561 ActivityLogDatabasePolicy* policy = new CountingPolicy(profile_.get()); | 565 ActivityLogDatabasePolicy* policy = new CountingPolicy(profile_.get()); |
| 562 policy->Init(); | 566 policy->Init(); |
| 563 scoped_refptr<const Extension> extension = | 567 scoped_refptr<const Extension> extension = |
| 564 ExtensionBuilder() | 568 ExtensionBuilder() |
| 565 .SetManifest(DictionaryBuilder() | 569 .SetManifest(DictionaryBuilder() |
| 566 .Set("name", "Test extension") | 570 .Set("name", "Test extension") |
| 567 .Set("version", "1.0.0") | 571 .Set("version", "1.0.0") |
| 568 .Set("manifest_version", 2) | 572 .Set("manifest_version", 2) |
| 569 .Build()) | 573 .Build()) |
| 570 .Build(); | 574 .Build(); |
| 571 extension_service_->AddExtension(extension.get()); | 575 extension_service_->AddExtension(extension.get()); |
| 572 | 576 |
| 573 scoped_ptr<base::ListValue> args(new base::ListValue()); | 577 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
| 574 args->Set(0, new base::StringValue("hello")); | 578 args->Set(0, new base::StringValue("hello")); |
| 575 args->Set(1, new base::StringValue("world")); | 579 args->Set(1, new base::StringValue("world")); |
| 576 scoped_refptr<Action> action = new Action(extension->id(), | 580 scoped_refptr<Action> action = new Action(extension->id(), |
| 577 base::Time::Now(), | 581 base::Time::Now(), |
| 578 Action::ACTION_API_CALL, | 582 Action::ACTION_API_CALL, |
| 579 "extension.connect"); | 583 "extension.connect"); |
| 580 action->set_args(std::move(args)); | 584 action->set_args(std::move(args)); |
| 581 | 585 |
| 582 policy->ProcessAction(action); | 586 policy->ProcessAction(action); |
| 583 CheckReadData(policy, | 587 CheckReadData(policy, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 595 policy->set_retention_time(base::TimeDelta::FromDays(14)); | 599 policy->set_retention_time(base::TimeDelta::FromDays(14)); |
| 596 | 600 |
| 597 // Use a mock clock to ensure that events are not recorded on the wrong day | 601 // Use a mock clock to ensure that events are not recorded on the wrong day |
| 598 // when the test is run close to local midnight. Note: Ownership is passed | 602 // when the test is run close to local midnight. Note: Ownership is passed |
| 599 // to the policy, but we still keep a pointer locally. The policy will take | 603 // to the policy, but we still keep a pointer locally. The policy will take |
| 600 // care of destruction; this is safe since the policy outlives all our | 604 // care of destruction; this is safe since the policy outlives all our |
| 601 // accesses to the mock clock. | 605 // accesses to the mock clock. |
| 602 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); | 606 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); |
| 603 mock_clock->SetNow(base::Time::Now().LocalMidnight() + | 607 mock_clock->SetNow(base::Time::Now().LocalMidnight() + |
| 604 base::TimeDelta::FromHours(12)); | 608 base::TimeDelta::FromHours(12)); |
| 605 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock)); | 609 policy->SetClockForTesting(std::unique_ptr<base::Clock>(mock_clock)); |
| 606 | 610 |
| 607 // Record some actions | 611 // Record some actions |
| 608 scoped_refptr<Action> action = | 612 scoped_refptr<Action> action = |
| 609 new Action("punky", | 613 new Action("punky", |
| 610 mock_clock->Now() - base::TimeDelta::FromMinutes(40), | 614 mock_clock->Now() - base::TimeDelta::FromMinutes(40), |
| 611 Action::ACTION_API_CALL, | 615 Action::ACTION_API_CALL, |
| 612 "brewster"); | 616 "brewster"); |
| 613 action->mutable_args()->AppendString("woof"); | 617 action->mutable_args()->AppendString("woof"); |
| 614 policy->ProcessAction(action); | 618 policy->ProcessAction(action); |
| 615 | 619 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 TEST_F(CountingPolicyTest, GetOlderActions) { | 656 TEST_F(CountingPolicyTest, GetOlderActions) { |
| 653 CountingPolicy* policy = new CountingPolicy(profile_.get()); | 657 CountingPolicy* policy = new CountingPolicy(profile_.get()); |
| 654 policy->Init(); | 658 policy->Init(); |
| 655 policy->set_retention_time(base::TimeDelta::FromDays(14)); | 659 policy->set_retention_time(base::TimeDelta::FromDays(14)); |
| 656 | 660 |
| 657 // Use a mock clock to ensure that events are not recorded on the wrong day | 661 // Use a mock clock to ensure that events are not recorded on the wrong day |
| 658 // when the test is run close to local midnight. | 662 // when the test is run close to local midnight. |
| 659 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); | 663 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); |
| 660 mock_clock->SetNow(base::Time::Now().LocalMidnight() + | 664 mock_clock->SetNow(base::Time::Now().LocalMidnight() + |
| 661 base::TimeDelta::FromHours(12)); | 665 base::TimeDelta::FromHours(12)); |
| 662 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock)); | 666 policy->SetClockForTesting(std::unique_ptr<base::Clock>(mock_clock)); |
| 663 | 667 |
| 664 // Record some actions | 668 // Record some actions |
| 665 scoped_refptr<Action> action = | 669 scoped_refptr<Action> action = |
| 666 new Action("punky", | 670 new Action("punky", |
| 667 mock_clock->Now() - base::TimeDelta::FromDays(3) - | 671 mock_clock->Now() - base::TimeDelta::FromDays(3) - |
| 668 base::TimeDelta::FromMinutes(40), | 672 base::TimeDelta::FromMinutes(40), |
| 669 Action::ACTION_API_CALL, | 673 Action::ACTION_API_CALL, |
| 670 "brewster"); | 674 "brewster"); |
| 671 action->mutable_args()->AppendString("woof"); | 675 action->mutable_args()->AppendString("woof"); |
| 672 policy->ProcessAction(action); | 676 policy->ProcessAction(action); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 .Build()) | 720 .Build()) |
| 717 .Build(); | 721 .Build(); |
| 718 extension_service_->AddExtension(extension.get()); | 722 extension_service_->AddExtension(extension.get()); |
| 719 GURL gurl("http://www.google.com"); | 723 GURL gurl("http://www.google.com"); |
| 720 | 724 |
| 721 // Write some API calls | 725 // Write some API calls |
| 722 scoped_refptr<Action> action_api = new Action(extension->id(), | 726 scoped_refptr<Action> action_api = new Action(extension->id(), |
| 723 base::Time::Now(), | 727 base::Time::Now(), |
| 724 Action::ACTION_API_CALL, | 728 Action::ACTION_API_CALL, |
| 725 "tabs.testMethod"); | 729 "tabs.testMethod"); |
| 726 action_api->set_args(make_scoped_ptr(new base::ListValue())); | 730 action_api->set_args(base::WrapUnique(new base::ListValue())); |
| 727 policy->ProcessAction(action_api); | 731 policy->ProcessAction(action_api); |
| 728 | 732 |
| 729 scoped_refptr<Action> action_dom = new Action(extension->id(), | 733 scoped_refptr<Action> action_dom = new Action(extension->id(), |
| 730 base::Time::Now(), | 734 base::Time::Now(), |
| 731 Action::ACTION_DOM_ACCESS, | 735 Action::ACTION_DOM_ACCESS, |
| 732 "document.write"); | 736 "document.write"); |
| 733 action_dom->set_args(make_scoped_ptr(new base::ListValue())); | 737 action_dom->set_args(base::WrapUnique(new base::ListValue())); |
| 734 action_dom->set_page_url(gurl); | 738 action_dom->set_page_url(gurl); |
| 735 policy->ProcessAction(action_dom); | 739 policy->ProcessAction(action_dom); |
| 736 | 740 |
| 737 CheckReadFilteredData( | 741 CheckReadFilteredData( |
| 738 policy, | 742 policy, |
| 739 extension->id(), | 743 extension->id(), |
| 740 Action::ACTION_API_CALL, | 744 Action::ACTION_API_CALL, |
| 741 "tabs.testMethod", | 745 "tabs.testMethod", |
| 742 "", | 746 "", |
| 743 "", | 747 "", |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 policy->Init(); | 814 policy->Init(); |
| 811 // Initially disable expiration by setting a retention time before any | 815 // Initially disable expiration by setting a retention time before any |
| 812 // actions we generate. | 816 // actions we generate. |
| 813 policy->set_retention_time(base::TimeDelta::FromDays(14)); | 817 policy->set_retention_time(base::TimeDelta::FromDays(14)); |
| 814 | 818 |
| 815 // Use a mock clock to ensure that events are not recorded on the wrong day | 819 // Use a mock clock to ensure that events are not recorded on the wrong day |
| 816 // when the test is run close to local midnight. | 820 // when the test is run close to local midnight. |
| 817 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); | 821 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); |
| 818 mock_clock->SetNow(base::Time::Now().LocalMidnight() + | 822 mock_clock->SetNow(base::Time::Now().LocalMidnight() + |
| 819 base::TimeDelta::FromHours(12)); | 823 base::TimeDelta::FromHours(12)); |
| 820 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock)); | 824 policy->SetClockForTesting(std::unique_ptr<base::Clock>(mock_clock)); |
| 821 | 825 |
| 822 // The first two actions should be merged; the last one is on a separate day | 826 // The first two actions should be merged; the last one is on a separate day |
| 823 // and should not be. | 827 // and should not be. |
| 824 scoped_refptr<Action> action = | 828 scoped_refptr<Action> action = |
| 825 new Action("punky", | 829 new Action("punky", |
| 826 mock_clock->Now() - base::TimeDelta::FromDays(3) - | 830 mock_clock->Now() - base::TimeDelta::FromDays(3) - |
| 827 base::TimeDelta::FromMinutes(40), | 831 base::TimeDelta::FromMinutes(40), |
| 828 Action::ACTION_API_CALL, | 832 Action::ACTION_API_CALL, |
| 829 "brewster"); | 833 "brewster"); |
| 830 policy->ProcessAction(action); | 834 policy->ProcessAction(action); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 // Test cleaning of old data in the string and URL tables. | 881 // Test cleaning of old data in the string and URL tables. |
| 878 TEST_F(CountingPolicyTest, StringTableCleaning) { | 882 TEST_F(CountingPolicyTest, StringTableCleaning) { |
| 879 CountingPolicy* policy = new CountingPolicy(profile_.get()); | 883 CountingPolicy* policy = new CountingPolicy(profile_.get()); |
| 880 policy->Init(); | 884 policy->Init(); |
| 881 // Initially disable expiration by setting a retention time before any | 885 // Initially disable expiration by setting a retention time before any |
| 882 // actions we generate. | 886 // actions we generate. |
| 883 policy->set_retention_time(base::TimeDelta::FromDays(14)); | 887 policy->set_retention_time(base::TimeDelta::FromDays(14)); |
| 884 | 888 |
| 885 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); | 889 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); |
| 886 mock_clock->SetNow(base::Time::Now()); | 890 mock_clock->SetNow(base::Time::Now()); |
| 887 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock)); | 891 policy->SetClockForTesting(std::unique_ptr<base::Clock>(mock_clock)); |
| 888 | 892 |
| 889 // Insert an action; this should create entries in both the string table (for | 893 // Insert an action; this should create entries in both the string table (for |
| 890 // the extension and API name) and the URL table (for page_url). | 894 // the extension and API name) and the URL table (for page_url). |
| 891 scoped_refptr<Action> action = | 895 scoped_refptr<Action> action = |
| 892 new Action("punky", | 896 new Action("punky", |
| 893 mock_clock->Now() - base::TimeDelta::FromDays(7), | 897 mock_clock->Now() - base::TimeDelta::FromDays(7), |
| 894 Action::ACTION_API_CALL, | 898 Action::ACTION_API_CALL, |
| 895 "brewster"); | 899 "brewster"); |
| 896 action->set_page_url(GURL("http://www.google.com/")); | 900 action->set_page_url(GURL("http://www.google.com/")); |
| 897 policy->ProcessAction(action); | 901 policy->ProcessAction(action); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 933 TEST_F(CountingPolicyTest, MoreMerging) { | 937 TEST_F(CountingPolicyTest, MoreMerging) { |
| 934 CountingPolicy* policy = new CountingPolicy(profile_.get()); | 938 CountingPolicy* policy = new CountingPolicy(profile_.get()); |
| 935 policy->Init(); | 939 policy->Init(); |
| 936 policy->set_retention_time(base::TimeDelta::FromDays(14)); | 940 policy->set_retention_time(base::TimeDelta::FromDays(14)); |
| 937 | 941 |
| 938 // Use a mock clock to ensure that events are not recorded on the wrong day | 942 // Use a mock clock to ensure that events are not recorded on the wrong day |
| 939 // when the test is run close to local midnight. | 943 // when the test is run close to local midnight. |
| 940 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); | 944 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); |
| 941 mock_clock->SetNow(base::Time::Now().LocalMidnight() + | 945 mock_clock->SetNow(base::Time::Now().LocalMidnight() + |
| 942 base::TimeDelta::FromHours(12)); | 946 base::TimeDelta::FromHours(12)); |
| 943 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock)); | 947 policy->SetClockForTesting(std::unique_ptr<base::Clock>(mock_clock)); |
| 944 | 948 |
| 945 // Create an action 2 days ago, then 1 day ago, then 2 days ago. Make sure | 949 // Create an action 2 days ago, then 1 day ago, then 2 days ago. Make sure |
| 946 // that we end up with two merged records (one for each day), and each has | 950 // that we end up with two merged records (one for each day), and each has |
| 947 // the appropriate timestamp. These merges should happen in the database | 951 // the appropriate timestamp. These merges should happen in the database |
| 948 // since the date keeps changing. | 952 // since the date keeps changing. |
| 949 base::Time time1 = | 953 base::Time time1 = |
| 950 mock_clock->Now() - base::TimeDelta::FromDays(2) - | 954 mock_clock->Now() - base::TimeDelta::FromDays(2) - |
| 951 base::TimeDelta::FromMinutes(40); | 955 base::TimeDelta::FromMinutes(40); |
| 952 base::Time time2 = | 956 base::Time time2 = |
| 953 mock_clock->Now() - base::TimeDelta::FromDays(1) - | 957 mock_clock->Now() - base::TimeDelta::FromDays(1) - |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1056 | 1060 |
| 1057 TEST_F(CountingPolicyTest, RemoveAllURLs) { | 1061 TEST_F(CountingPolicyTest, RemoveAllURLs) { |
| 1058 ActivityLogDatabasePolicy* policy = new CountingPolicy(profile_.get()); | 1062 ActivityLogDatabasePolicy* policy = new CountingPolicy(profile_.get()); |
| 1059 policy->Init(); | 1063 policy->Init(); |
| 1060 | 1064 |
| 1061 // Use a mock clock to ensure that events are not recorded on the wrong day | 1065 // Use a mock clock to ensure that events are not recorded on the wrong day |
| 1062 // when the test is run close to local midnight. | 1066 // when the test is run close to local midnight. |
| 1063 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); | 1067 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); |
| 1064 mock_clock->SetNow(base::Time::Now().LocalMidnight() + | 1068 mock_clock->SetNow(base::Time::Now().LocalMidnight() + |
| 1065 base::TimeDelta::FromHours(12)); | 1069 base::TimeDelta::FromHours(12)); |
| 1066 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock)); | 1070 policy->SetClockForTesting(std::unique_ptr<base::Clock>(mock_clock)); |
| 1067 | 1071 |
| 1068 // Record some actions | 1072 // Record some actions |
| 1069 scoped_refptr<Action> action = | 1073 scoped_refptr<Action> action = |
| 1070 new Action("punky", mock_clock->Now(), | 1074 new Action("punky", mock_clock->Now(), |
| 1071 Action::ACTION_DOM_ACCESS, "lets"); | 1075 Action::ACTION_DOM_ACCESS, "lets"); |
| 1072 action->mutable_args()->AppendString("vamoose"); | 1076 action->mutable_args()->AppendString("vamoose"); |
| 1073 action->set_page_url(GURL("http://www.google.com")); | 1077 action->set_page_url(GURL("http://www.google.com")); |
| 1074 action->set_page_title("Google"); | 1078 action->set_page_title("Google"); |
| 1075 action->set_arg_url(GURL("http://www.args-url.com")); | 1079 action->set_arg_url(GURL("http://www.args-url.com")); |
| 1076 policy->ProcessAction(action); | 1080 policy->ProcessAction(action); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1099 | 1103 |
| 1100 TEST_F(CountingPolicyTest, RemoveSpecificURLs) { | 1104 TEST_F(CountingPolicyTest, RemoveSpecificURLs) { |
| 1101 ActivityLogDatabasePolicy* policy = new CountingPolicy(profile_.get()); | 1105 ActivityLogDatabasePolicy* policy = new CountingPolicy(profile_.get()); |
| 1102 policy->Init(); | 1106 policy->Init(); |
| 1103 | 1107 |
| 1104 // Use a mock clock to ensure that events are not recorded on the wrong day | 1108 // Use a mock clock to ensure that events are not recorded on the wrong day |
| 1105 // when the test is run close to local midnight. | 1109 // when the test is run close to local midnight. |
| 1106 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); | 1110 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); |
| 1107 mock_clock->SetNow(base::Time::Now().LocalMidnight() + | 1111 mock_clock->SetNow(base::Time::Now().LocalMidnight() + |
| 1108 base::TimeDelta::FromHours(12)); | 1112 base::TimeDelta::FromHours(12)); |
| 1109 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock)); | 1113 policy->SetClockForTesting(std::unique_ptr<base::Clock>(mock_clock)); |
| 1110 | 1114 |
| 1111 // Record some actions | 1115 // Record some actions |
| 1112 // This should have the page url and args url cleared. | 1116 // This should have the page url and args url cleared. |
| 1113 scoped_refptr<Action> action = new Action("punky", mock_clock->Now(), | 1117 scoped_refptr<Action> action = new Action("punky", mock_clock->Now(), |
| 1114 Action::ACTION_DOM_ACCESS, "lets"); | 1118 Action::ACTION_DOM_ACCESS, "lets"); |
| 1115 action->mutable_args()->AppendString("vamoose"); | 1119 action->mutable_args()->AppendString("vamoose"); |
| 1116 action->set_page_url(GURL("http://www.google1.com")); | 1120 action->set_page_url(GURL("http://www.google1.com")); |
| 1117 action->set_page_title("Google"); | 1121 action->set_page_title("Google"); |
| 1118 action->set_arg_url(GURL("http://www.google1.com")); | 1122 action->set_arg_url(GURL("http://www.google1.com")); |
| 1119 policy->ProcessAction(action); | 1123 policy->ProcessAction(action); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1176 | 1180 |
| 1177 TEST_F(CountingPolicyTest, RemoveExtensionData) { | 1181 TEST_F(CountingPolicyTest, RemoveExtensionData) { |
| 1178 CountingPolicy* policy = new CountingPolicy(profile_.get()); | 1182 CountingPolicy* policy = new CountingPolicy(profile_.get()); |
| 1179 policy->Init(); | 1183 policy->Init(); |
| 1180 | 1184 |
| 1181 // Use a mock clock to ensure that events are not recorded on the wrong day | 1185 // Use a mock clock to ensure that events are not recorded on the wrong day |
| 1182 // when the test is run close to local midnight. | 1186 // when the test is run close to local midnight. |
| 1183 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); | 1187 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); |
| 1184 mock_clock->SetNow(base::Time::Now().LocalMidnight() + | 1188 mock_clock->SetNow(base::Time::Now().LocalMidnight() + |
| 1185 base::TimeDelta::FromHours(12)); | 1189 base::TimeDelta::FromHours(12)); |
| 1186 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock)); | 1190 policy->SetClockForTesting(std::unique_ptr<base::Clock>(mock_clock)); |
| 1187 | 1191 |
| 1188 // Record some actions | 1192 // Record some actions |
| 1189 scoped_refptr<Action> action = new Action("deleteextensiondata", | 1193 scoped_refptr<Action> action = new Action("deleteextensiondata", |
| 1190 mock_clock->Now(), | 1194 mock_clock->Now(), |
| 1191 Action::ACTION_DOM_ACCESS, | 1195 Action::ACTION_DOM_ACCESS, |
| 1192 "lets"); | 1196 "lets"); |
| 1193 action->mutable_args()->AppendString("vamoose"); | 1197 action->mutable_args()->AppendString("vamoose"); |
| 1194 action->set_page_title("Google"); | 1198 action->set_page_title("Google"); |
| 1195 action->set_arg_url(GURL("http://www.google.com")); | 1199 action->set_arg_url(GURL("http://www.google.com")); |
| 1196 policy->ProcessAction(action); | 1200 policy->ProcessAction(action); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1241 policy->set_retention_time(base::TimeDelta::FromDays(14)); | 1245 policy->set_retention_time(base::TimeDelta::FromDays(14)); |
| 1242 | 1246 |
| 1243 // Use a mock clock to ensure that events are not recorded on the wrong day | 1247 // Use a mock clock to ensure that events are not recorded on the wrong day |
| 1244 // when the test is run close to local midnight. Note: Ownership is passed | 1248 // when the test is run close to local midnight. Note: Ownership is passed |
| 1245 // to the policy, but we still keep a pointer locally. The policy will take | 1249 // to the policy, but we still keep a pointer locally. The policy will take |
| 1246 // care of destruction; this is safe since the policy outlives all our | 1250 // care of destruction; this is safe since the policy outlives all our |
| 1247 // accesses to the mock clock. | 1251 // accesses to the mock clock. |
| 1248 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); | 1252 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); |
| 1249 mock_clock->SetNow(base::Time::Now().LocalMidnight() + | 1253 mock_clock->SetNow(base::Time::Now().LocalMidnight() + |
| 1250 base::TimeDelta::FromHours(12)); | 1254 base::TimeDelta::FromHours(12)); |
| 1251 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock)); | 1255 policy->SetClockForTesting(std::unique_ptr<base::Clock>(mock_clock)); |
| 1252 | 1256 |
| 1253 // Record some actions | 1257 // Record some actions |
| 1254 scoped_refptr<Action> action = | 1258 scoped_refptr<Action> action = |
| 1255 new Action("punky", | 1259 new Action("punky", |
| 1256 mock_clock->Now() - base::TimeDelta::FromMinutes(40), | 1260 mock_clock->Now() - base::TimeDelta::FromMinutes(40), |
| 1257 Action::ACTION_API_CALL, | 1261 Action::ACTION_API_CALL, |
| 1258 "brewster"); | 1262 "brewster"); |
| 1259 action->mutable_args()->AppendString("woof"); | 1263 action->mutable_args()->AppendString("woof"); |
| 1260 policy->ProcessAction(action); | 1264 policy->ProcessAction(action); |
| 1261 | 1265 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1337 } | 1341 } |
| 1338 | 1342 |
| 1339 // Tests that duplicate rows in the activity log database are handled properly | 1343 // Tests that duplicate rows in the activity log database are handled properly |
| 1340 // when updating counts. | 1344 // when updating counts. |
| 1341 TEST_F(CountingPolicyTest, DuplicateRows) { | 1345 TEST_F(CountingPolicyTest, DuplicateRows) { |
| 1342 CountingPolicy* policy = new CountingPolicy(profile_.get()); | 1346 CountingPolicy* policy = new CountingPolicy(profile_.get()); |
| 1343 policy->Init(); | 1347 policy->Init(); |
| 1344 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); | 1348 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); |
| 1345 mock_clock->SetNow(base::Time::Now().LocalMidnight() + | 1349 mock_clock->SetNow(base::Time::Now().LocalMidnight() + |
| 1346 base::TimeDelta::FromHours(12)); | 1350 base::TimeDelta::FromHours(12)); |
| 1347 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock)); | 1351 policy->SetClockForTesting(std::unique_ptr<base::Clock>(mock_clock)); |
| 1348 | 1352 |
| 1349 // Record two actions with distinct URLs. | 1353 // Record two actions with distinct URLs. |
| 1350 scoped_refptr<Action> action; | 1354 scoped_refptr<Action> action; |
| 1351 action = new Action( | 1355 action = new Action( |
| 1352 "punky", mock_clock->Now(), Action::ACTION_API_CALL, "brewster"); | 1356 "punky", mock_clock->Now(), Action::ACTION_API_CALL, "brewster"); |
| 1353 action->set_page_url(GURL("http://www.google.com")); | 1357 action->set_page_url(GURL("http://www.google.com")); |
| 1354 policy->ProcessAction(action); | 1358 policy->ProcessAction(action); |
| 1355 | 1359 |
| 1356 action = new Action( | 1360 action = new Action( |
| 1357 "punky", mock_clock->Now(), Action::ACTION_API_CALL, "brewster"); | 1361 "punky", mock_clock->Now(), Action::ACTION_API_CALL, "brewster"); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1417 | 1421 |
| 1418 action_ids.push_back(2); | 1422 action_ids.push_back(2); |
| 1419 CheckRemoveActions( | 1423 CheckRemoveActions( |
| 1420 policy, action_ids, base::Bind(&CountingPolicyTest::Action2Deleted)); | 1424 policy, action_ids, base::Bind(&CountingPolicyTest::Action2Deleted)); |
| 1421 action_ids.clear(); | 1425 action_ids.clear(); |
| 1422 | 1426 |
| 1423 policy->Close(); | 1427 policy->Close(); |
| 1424 } | 1428 } |
| 1425 | 1429 |
| 1426 } // namespace extensions | 1430 } // namespace extensions |
| OLD | NEW |