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 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/cancelable_callback.h" | 13 #include "base/cancelable_callback.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/location.h" | 15 #include "base/location.h" |
16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
19 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
21 #include "base/synchronization/waitable_event.h" | 21 #include "base/synchronization/waitable_event.h" |
22 #include "base/test/command_line_test_util.h" | |
22 #include "base/test/simple_test_clock.h" | 23 #include "base/test/simple_test_clock.h" |
23 #include "base/test/test_timeouts.h" | 24 #include "base/test/test_timeouts.h" |
24 #include "base/thread_task_runner_handle.h" | 25 #include "base/thread_task_runner_handle.h" |
25 #include "build/build_config.h" | 26 #include "build/build_config.h" |
26 #include "chrome/browser/extensions/activity_log/activity_log.h" | 27 #include "chrome/browser/extensions/activity_log/activity_log.h" |
27 #include "chrome/browser/extensions/extension_service.h" | 28 #include "chrome/browser/extensions/extension_service.h" |
28 #include "chrome/browser/extensions/test_extension_system.h" | 29 #include "chrome/browser/extensions/test_extension_system.h" |
29 #include "chrome/common/chrome_constants.h" | 30 #include "chrome/common/chrome_constants.h" |
30 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
31 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 32 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
32 #include "chrome/test/base/testing_profile.h" | 33 #include "chrome/test/base/testing_profile.h" |
33 #include "content/public/test/test_browser_thread_bundle.h" | 34 #include "content/public/test/test_browser_thread_bundle.h" |
34 #include "extensions/common/extension_builder.h" | 35 #include "extensions/common/extension_builder.h" |
35 #include "sql/statement.h" | 36 #include "sql/statement.h" |
36 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
37 | 38 |
38 #if defined(OS_CHROMEOS) | 39 #if defined(OS_CHROMEOS) |
39 #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" | 40 #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" |
40 #include "chrome/browser/chromeos/settings/cros_settings.h" | 41 #include "chrome/browser/chromeos/settings/cros_settings.h" |
41 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 42 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
42 #endif | 43 #endif |
43 | 44 |
44 using content::BrowserThread; | 45 using content::BrowserThread; |
45 | 46 |
46 namespace extensions { | 47 namespace extensions { |
47 | 48 |
48 class CountingPolicyTest : public testing::Test { | 49 class CountingPolicyTest : public testing::Test { |
49 public: | 50 public: |
50 CountingPolicyTest() | 51 CountingPolicyTest() |
51 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 52 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { |
52 saved_cmdline_(base::CommandLine::NO_PROGRAM) { | |
53 #if defined OS_CHROMEOS | 53 #if defined OS_CHROMEOS |
54 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); | 54 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); |
55 #endif | 55 #endif |
56 profile_.reset(new TestingProfile()); | |
57 scoped_command_line_.GetProcessCommandLine()-> | |
58 AppendSwitch(switches::kEnableExtensionActivityLogging); | |
56 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 59 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
57 saved_cmdline_ = *base::CommandLine::ForCurrentProcess(); | |
58 profile_.reset(new TestingProfile()); | |
59 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
60 switches::kEnableExtensionActivityLogging); | |
61 extension_service_ = static_cast<TestExtensionSystem*>( | 60 extension_service_ = static_cast<TestExtensionSystem*>( |
62 ExtensionSystem::Get(profile_.get()))->CreateExtensionService | 61 ExtensionSystem::Get(profile_.get()))->CreateExtensionService |
63 (&command_line, base::FilePath(), false); | 62 (&command_line, base::FilePath(), false); |
64 } | 63 } |
65 | 64 |
66 ~CountingPolicyTest() override { | 65 ~CountingPolicyTest() override { |
67 #if defined OS_CHROMEOS | 66 #if defined OS_CHROMEOS |
68 test_user_manager_.reset(); | 67 test_user_manager_.reset(); |
69 #endif | 68 #endif |
70 base::RunLoop().RunUntilIdle(); | 69 base::RunLoop().RunUntilIdle(); |
71 profile_.reset(NULL); | 70 profile_.reset(NULL); |
72 base::RunLoop().RunUntilIdle(); | 71 base::RunLoop().RunUntilIdle(); |
73 // Restore the original command line and undo the affects of SetUp(). | |
74 *base::CommandLine::ForCurrentProcess() = saved_cmdline_; | |
75 } | 72 } |
76 | 73 |
77 // Wait for the task queue for the specified thread to empty. | 74 // Wait for the task queue for the specified thread to empty. |
78 void WaitOnThread(const BrowserThread::ID& thread) { | 75 void WaitOnThread(const BrowserThread::ID& thread) { |
79 BrowserThread::PostTaskAndReply( | 76 BrowserThread::PostTaskAndReply( |
80 thread, FROM_HERE, base::Bind(&base::DoNothing), | 77 thread, FROM_HERE, base::Bind(&base::DoNothing), |
81 base::MessageLoop::current()->QuitWhenIdleClosure()); | 78 base::MessageLoop::current()->QuitWhenIdleClosure()); |
82 base::MessageLoop::current()->Run(); | 79 base::MessageLoop::current()->Run(); |
83 } | 80 } |
84 | 81 |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
519 "Google1", | 516 "Google1", |
520 "http://www.args-url1.com/", | 517 "http://www.args-url1.com/", |
521 2); | 518 2); |
522 ASSERT_EQ(1, actions->at(0)->action_id()); | 519 ASSERT_EQ(1, actions->at(0)->action_id()); |
523 } | 520 } |
524 | 521 |
525 protected: | 522 protected: |
526 ExtensionService* extension_service_; | 523 ExtensionService* extension_service_; |
527 std::unique_ptr<TestingProfile> profile_; | 524 std::unique_ptr<TestingProfile> profile_; |
528 content::TestBrowserThreadBundle thread_bundle_; | 525 content::TestBrowserThreadBundle thread_bundle_; |
529 // Used to preserve a copy of the original command line. | 526 base::test::ScopedCommandLine scoped_command_line_; |
Devlin
2016/04/22 17:22:33
I don't understand this comment (there's no TearDo
robliao
2016/04/22 19:28:30
Looks like CountingPolicyTest never had a TearDown
Devlin
2016/04/22 20:35:21
Personally, I'm in favor of just having the test i
danakj
2016/04/22 20:37:52
Which infrastructure? TestSuite could do it but th
robliao
2016/04/22 20:41:19
The current infrastructure is TestClientInitialize
| |
530 // The test framework will do this itself as well. However, by then, | |
531 // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in | |
532 // TearDown(). | |
533 base::CommandLine saved_cmdline_; | |
534 | 527 |
535 #if defined OS_CHROMEOS | 528 #if defined OS_CHROMEOS |
536 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 529 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
537 chromeos::ScopedTestCrosSettings test_cros_settings_; | 530 chromeos::ScopedTestCrosSettings test_cros_settings_; |
538 std::unique_ptr<chromeos::ScopedTestUserManager> test_user_manager_; | 531 std::unique_ptr<chromeos::ScopedTestUserManager> test_user_manager_; |
539 #endif | 532 #endif |
540 }; | 533 }; |
541 | 534 |
542 TEST_F(CountingPolicyTest, Construct) { | 535 TEST_F(CountingPolicyTest, Construct) { |
543 ActivityLogDatabasePolicy* policy = new CountingPolicy(profile_.get()); | 536 ActivityLogDatabasePolicy* policy = new CountingPolicy(profile_.get()); |
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1421 | 1414 |
1422 action_ids.push_back(2); | 1415 action_ids.push_back(2); |
1423 CheckRemoveActions( | 1416 CheckRemoveActions( |
1424 policy, action_ids, base::Bind(&CountingPolicyTest::Action2Deleted)); | 1417 policy, action_ids, base::Bind(&CountingPolicyTest::Action2Deleted)); |
1425 action_ids.clear(); | 1418 action_ids.clear(); |
1426 | 1419 |
1427 policy->Close(); | 1420 policy->Close(); |
1428 } | 1421 } |
1429 | 1422 |
1430 } // namespace extensions | 1423 } // namespace extensions |
OLD | NEW |