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> |
(...skipping 30 matching lines...) Expand all Loading... |
41 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 41 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
42 #endif | 42 #endif |
43 | 43 |
44 using content::BrowserThread; | 44 using content::BrowserThread; |
45 | 45 |
46 namespace extensions { | 46 namespace extensions { |
47 | 47 |
48 class CountingPolicyTest : public testing::Test { | 48 class CountingPolicyTest : public testing::Test { |
49 public: | 49 public: |
50 CountingPolicyTest() | 50 CountingPolicyTest() |
51 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 51 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { |
52 saved_cmdline_(base::CommandLine::NO_PROGRAM) { | |
53 #if defined OS_CHROMEOS | 52 #if defined OS_CHROMEOS |
54 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); | 53 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); |
55 #endif | 54 #endif |
56 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | |
57 saved_cmdline_ = *base::CommandLine::ForCurrentProcess(); | |
58 profile_.reset(new TestingProfile()); | 55 profile_.reset(new TestingProfile()); |
59 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 56 base::CommandLine::ForCurrentProcess()-> |
60 switches::kEnableExtensionActivityLogging); | 57 AppendSwitch(switches::kEnableExtensionActivityLogging); |
| 58 base::CommandLine no_program_command_line(base::CommandLine::NO_PROGRAM); |
61 extension_service_ = static_cast<TestExtensionSystem*>( | 59 extension_service_ = static_cast<TestExtensionSystem*>( |
62 ExtensionSystem::Get(profile_.get()))->CreateExtensionService | 60 ExtensionSystem::Get(profile_.get()))->CreateExtensionService |
63 (&command_line, base::FilePath(), false); | 61 (&no_program_command_line, base::FilePath(), false); |
64 } | 62 } |
65 | 63 |
66 ~CountingPolicyTest() override { | 64 ~CountingPolicyTest() override { |
67 #if defined OS_CHROMEOS | 65 #if defined OS_CHROMEOS |
68 test_user_manager_.reset(); | 66 test_user_manager_.reset(); |
69 #endif | 67 #endif |
70 base::RunLoop().RunUntilIdle(); | 68 base::RunLoop().RunUntilIdle(); |
71 profile_.reset(NULL); | 69 profile_.reset(NULL); |
72 base::RunLoop().RunUntilIdle(); | 70 base::RunLoop().RunUntilIdle(); |
73 // Restore the original command line and undo the affects of SetUp(). | |
74 *base::CommandLine::ForCurrentProcess() = saved_cmdline_; | |
75 } | 71 } |
76 | 72 |
77 // Wait for the task queue for the specified thread to empty. | 73 // Wait for the task queue for the specified thread to empty. |
78 void WaitOnThread(const BrowserThread::ID& thread) { | 74 void WaitOnThread(const BrowserThread::ID& thread) { |
79 BrowserThread::PostTaskAndReply( | 75 BrowserThread::PostTaskAndReply( |
80 thread, FROM_HERE, base::Bind(&base::DoNothing), | 76 thread, FROM_HERE, base::Bind(&base::DoNothing), |
81 base::MessageLoop::current()->QuitWhenIdleClosure()); | 77 base::MessageLoop::current()->QuitWhenIdleClosure()); |
82 base::MessageLoop::current()->Run(); | 78 base::MessageLoop::current()->Run(); |
83 } | 79 } |
84 | 80 |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 "Google1", | 515 "Google1", |
520 "http://www.args-url1.com/", | 516 "http://www.args-url1.com/", |
521 2); | 517 2); |
522 ASSERT_EQ(1, actions->at(0)->action_id()); | 518 ASSERT_EQ(1, actions->at(0)->action_id()); |
523 } | 519 } |
524 | 520 |
525 protected: | 521 protected: |
526 ExtensionService* extension_service_; | 522 ExtensionService* extension_service_; |
527 std::unique_ptr<TestingProfile> profile_; | 523 std::unique_ptr<TestingProfile> profile_; |
528 content::TestBrowserThreadBundle thread_bundle_; | 524 content::TestBrowserThreadBundle thread_bundle_; |
529 // Used to preserve a copy of the original command line. | |
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 | 525 |
535 #if defined OS_CHROMEOS | 526 #if defined OS_CHROMEOS |
536 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 527 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
537 chromeos::ScopedTestCrosSettings test_cros_settings_; | 528 chromeos::ScopedTestCrosSettings test_cros_settings_; |
538 std::unique_ptr<chromeos::ScopedTestUserManager> test_user_manager_; | 529 std::unique_ptr<chromeos::ScopedTestUserManager> test_user_manager_; |
539 #endif | 530 #endif |
540 }; | 531 }; |
541 | 532 |
542 TEST_F(CountingPolicyTest, Construct) { | 533 TEST_F(CountingPolicyTest, Construct) { |
543 ActivityLogDatabasePolicy* policy = new CountingPolicy(profile_.get()); | 534 ActivityLogDatabasePolicy* policy = new CountingPolicy(profile_.get()); |
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1421 | 1412 |
1422 action_ids.push_back(2); | 1413 action_ids.push_back(2); |
1423 CheckRemoveActions( | 1414 CheckRemoveActions( |
1424 policy, action_ids, base::Bind(&CountingPolicyTest::Action2Deleted)); | 1415 policy, action_ids, base::Bind(&CountingPolicyTest::Action2Deleted)); |
1425 action_ids.clear(); | 1416 action_ids.clear(); |
1426 | 1417 |
1427 policy->Close(); | 1418 policy->Close(); |
1428 } | 1419 } |
1429 | 1420 |
1430 } // namespace extensions | 1421 } // namespace extensions |
OLD | NEW |