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" |
| 6 |
5 #include <stddef.h> | 7 #include <stddef.h> |
6 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <utility> |
7 | 10 |
8 #include "base/cancelable_callback.h" | 11 #include "base/cancelable_callback.h" |
9 #include "base/command_line.h" | 12 #include "base/command_line.h" |
10 #include "base/location.h" | 13 #include "base/location.h" |
11 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
12 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
13 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
14 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
15 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
16 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
17 #include "base/test/simple_test_clock.h" | 20 #include "base/test/simple_test_clock.h" |
18 #include "base/test/test_timeouts.h" | 21 #include "base/test/test_timeouts.h" |
19 #include "base/thread_task_runner_handle.h" | 22 #include "base/thread_task_runner_handle.h" |
20 #include "build/build_config.h" | 23 #include "build/build_config.h" |
21 #include "chrome/browser/extensions/activity_log/activity_log.h" | 24 #include "chrome/browser/extensions/activity_log/activity_log.h" |
22 #include "chrome/browser/extensions/activity_log/counting_policy.h" | |
23 #include "chrome/browser/extensions/extension_service.h" | 25 #include "chrome/browser/extensions/extension_service.h" |
24 #include "chrome/browser/extensions/test_extension_system.h" | 26 #include "chrome/browser/extensions/test_extension_system.h" |
25 #include "chrome/common/chrome_constants.h" | 27 #include "chrome/common/chrome_constants.h" |
26 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
27 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 29 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
28 #include "chrome/test/base/testing_profile.h" | 30 #include "chrome/test/base/testing_profile.h" |
29 #include "content/public/test/test_browser_thread_bundle.h" | 31 #include "content/public/test/test_browser_thread_bundle.h" |
30 #include "extensions/common/extension_builder.h" | 32 #include "extensions/common/extension_builder.h" |
31 #include "sql/statement.h" | 33 #include "sql/statement.h" |
32 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 static void CheckQueueSize(CountingPolicy* policy) { | 146 static void CheckQueueSize(CountingPolicy* policy) { |
145 // This should be updated if kSizeThresholdForFlush in activity_database.cc | 147 // This should be updated if kSizeThresholdForFlush in activity_database.cc |
146 // changes. | 148 // changes. |
147 ASSERT_LE(policy->queued_actions_.size(), 200U); | 149 ASSERT_LE(policy->queued_actions_.size(), 200U); |
148 } | 150 } |
149 | 151 |
150 static void CheckWrapper( | 152 static void CheckWrapper( |
151 const base::Callback<void(scoped_ptr<Action::ActionVector>)>& checker, | 153 const base::Callback<void(scoped_ptr<Action::ActionVector>)>& checker, |
152 const base::Closure& done, | 154 const base::Closure& done, |
153 scoped_ptr<Action::ActionVector> results) { | 155 scoped_ptr<Action::ActionVector> results) { |
154 checker.Run(results.Pass()); | 156 checker.Run(std::move(results)); |
155 done.Run(); | 157 done.Run(); |
156 } | 158 } |
157 | 159 |
158 static void TimeoutCallback() { | 160 static void TimeoutCallback() { |
159 base::MessageLoop::current()->QuitWhenIdle(); | 161 base::MessageLoop::current()->QuitWhenIdle(); |
160 FAIL() << "Policy test timed out waiting for results"; | 162 FAIL() << "Policy test timed out waiting for results"; |
161 } | 163 } |
162 | 164 |
163 static void RetrieveActions_FetchFilteredActions0( | 165 static void RetrieveActions_FetchFilteredActions0( |
164 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 166 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 .Set("name", "Test extension") | 544 .Set("name", "Test extension") |
543 .Set("version", "1.0.0") | 545 .Set("version", "1.0.0") |
544 .Set("manifest_version", 2))) | 546 .Set("manifest_version", 2))) |
545 .Build(); | 547 .Build(); |
546 extension_service_->AddExtension(extension.get()); | 548 extension_service_->AddExtension(extension.get()); |
547 scoped_ptr<base::ListValue> args(new base::ListValue()); | 549 scoped_ptr<base::ListValue> args(new base::ListValue()); |
548 scoped_refptr<Action> action = new Action(extension->id(), | 550 scoped_refptr<Action> action = new Action(extension->id(), |
549 base::Time::Now(), | 551 base::Time::Now(), |
550 Action::ACTION_API_CALL, | 552 Action::ACTION_API_CALL, |
551 "tabs.testMethod"); | 553 "tabs.testMethod"); |
552 action->set_args(args.Pass()); | 554 action->set_args(std::move(args)); |
553 policy->ProcessAction(action); | 555 policy->ProcessAction(action); |
554 policy->Close(); | 556 policy->Close(); |
555 } | 557 } |
556 | 558 |
557 TEST_F(CountingPolicyTest, LogWithStrippedArguments) { | 559 TEST_F(CountingPolicyTest, LogWithStrippedArguments) { |
558 ActivityLogDatabasePolicy* policy = new CountingPolicy(profile_.get()); | 560 ActivityLogDatabasePolicy* policy = new CountingPolicy(profile_.get()); |
559 policy->Init(); | 561 policy->Init(); |
560 scoped_refptr<const Extension> extension = | 562 scoped_refptr<const Extension> extension = |
561 ExtensionBuilder() | 563 ExtensionBuilder() |
562 .SetManifest(std::move(DictionaryBuilder() | 564 .SetManifest(std::move(DictionaryBuilder() |
563 .Set("name", "Test extension") | 565 .Set("name", "Test extension") |
564 .Set("version", "1.0.0") | 566 .Set("version", "1.0.0") |
565 .Set("manifest_version", 2))) | 567 .Set("manifest_version", 2))) |
566 .Build(); | 568 .Build(); |
567 extension_service_->AddExtension(extension.get()); | 569 extension_service_->AddExtension(extension.get()); |
568 | 570 |
569 scoped_ptr<base::ListValue> args(new base::ListValue()); | 571 scoped_ptr<base::ListValue> args(new base::ListValue()); |
570 args->Set(0, new base::StringValue("hello")); | 572 args->Set(0, new base::StringValue("hello")); |
571 args->Set(1, new base::StringValue("world")); | 573 args->Set(1, new base::StringValue("world")); |
572 scoped_refptr<Action> action = new Action(extension->id(), | 574 scoped_refptr<Action> action = new Action(extension->id(), |
573 base::Time::Now(), | 575 base::Time::Now(), |
574 Action::ACTION_API_CALL, | 576 Action::ACTION_API_CALL, |
575 "extension.connect"); | 577 "extension.connect"); |
576 action->set_args(args.Pass()); | 578 action->set_args(std::move(args)); |
577 | 579 |
578 policy->ProcessAction(action); | 580 policy->ProcessAction(action); |
579 CheckReadData(policy, | 581 CheckReadData(policy, |
580 extension->id(), | 582 extension->id(), |
581 0, | 583 0, |
582 base::Bind(&CountingPolicyTest::Arguments_Stripped)); | 584 base::Bind(&CountingPolicyTest::Arguments_Stripped)); |
583 policy->Close(); | 585 policy->Close(); |
584 } | 586 } |
585 | 587 |
586 TEST_F(CountingPolicyTest, GetTodaysActions) { | 588 TEST_F(CountingPolicyTest, GetTodaysActions) { |
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1412 | 1414 |
1413 action_ids.push_back(2); | 1415 action_ids.push_back(2); |
1414 CheckRemoveActions( | 1416 CheckRemoveActions( |
1415 policy, action_ids, base::Bind(&CountingPolicyTest::Action2Deleted)); | 1417 policy, action_ids, base::Bind(&CountingPolicyTest::Action2Deleted)); |
1416 action_ids.clear(); | 1418 action_ids.clear(); |
1417 | 1419 |
1418 policy->Close(); | 1420 policy->Close(); |
1419 } | 1421 } |
1420 | 1422 |
1421 } // namespace extensions | 1423 } // namespace extensions |
OLD | NEW |