| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "chrome/browser/extensions/activity_log/activity_log.h" | 10 #include "chrome/browser/extensions/activity_log/activity_log.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 const char kExtensionId[] = "abc"; | 34 const char kExtensionId[] = "abc"; |
| 35 | 35 |
| 36 } // namespace | 36 } // namespace |
| 37 | 37 |
| 38 namespace extensions { | 38 namespace extensions { |
| 39 | 39 |
| 40 class ActivityLogTest : public ChromeRenderViewHostTestHarness { | 40 class ActivityLogTest : public ChromeRenderViewHostTestHarness { |
| 41 protected: | 41 protected: |
| 42 ActivityLogTest() : saved_cmdline_(CommandLine::NO_PROGRAM) {} | |
| 43 | |
| 44 virtual void SetUp() OVERRIDE { | 42 virtual void SetUp() OVERRIDE { |
| 45 ChromeRenderViewHostTestHarness::SetUp(); | 43 ChromeRenderViewHostTestHarness::SetUp(); |
| 46 #if defined OS_CHROMEOS | 44 #if defined OS_CHROMEOS |
| 47 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); | 45 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); |
| 48 #endif | 46 #endif |
| 49 CommandLine command_line(CommandLine::NO_PROGRAM); | 47 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 50 saved_cmdline_ = *CommandLine::ForCurrentProcess(); | |
| 51 CommandLine::ForCurrentProcess()->AppendSwitch( | 48 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 52 switches::kEnableExtensionActivityLogging); | 49 switches::kEnableExtensionActivityLogging); |
| 53 CommandLine::ForCurrentProcess()->AppendSwitch( | 50 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 54 switches::kEnableExtensionActivityLogTesting); | 51 switches::kEnableExtensionActivityLogTesting); |
| 55 ActivityLog::RecomputeLoggingIsEnabled(true); // Logging now enabled. | |
| 56 extension_service_ = static_cast<TestExtensionSystem*>( | 52 extension_service_ = static_cast<TestExtensionSystem*>( |
| 57 ExtensionSystem::Get(profile()))->CreateExtensionService | 53 ExtensionSystem::Get(profile()))->CreateExtensionService |
| 58 (&command_line, base::FilePath(), false); | 54 (&command_line, base::FilePath(), false); |
| 59 ActivityLog::GetInstance(profile())->Init(); | |
| 60 base::RunLoop().RunUntilIdle(); | 55 base::RunLoop().RunUntilIdle(); |
| 61 } | 56 } |
| 62 | 57 |
| 63 virtual void TearDown() OVERRIDE { | 58 virtual void TearDown() OVERRIDE { |
| 64 #if defined OS_CHROMEOS | 59 #if defined OS_CHROMEOS |
| 65 test_user_manager_.reset(); | 60 test_user_manager_.reset(); |
| 66 #endif | 61 #endif |
| 67 base::RunLoop().RunUntilIdle(); | 62 base::RunLoop().RunUntilIdle(); |
| 68 // Restore the original command line and undo the affects of SetUp(). | |
| 69 *CommandLine::ForCurrentProcess() = saved_cmdline_; | |
| 70 ActivityLog::RecomputeLoggingIsEnabled(false); // Logging now disabled. | |
| 71 ChromeRenderViewHostTestHarness::TearDown(); | 63 ChromeRenderViewHostTestHarness::TearDown(); |
| 72 } | 64 } |
| 73 | 65 |
| 74 static void RetrieveActions_LogAndFetchActions( | 66 static void RetrieveActions_LogAndFetchActions( |
| 75 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 67 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
| 76 ASSERT_EQ(2, static_cast<int>(i->size())); | 68 ASSERT_EQ(2, static_cast<int>(i->size())); |
| 77 } | 69 } |
| 78 | 70 |
| 79 void SetPolicy(bool log_arguments) { | 71 void SetPolicy(bool log_arguments) { |
| 80 ActivityLog* activity_log = ActivityLog::GetInstance(profile()); | 72 ActivityLog* activity_log = ActivityLog::GetInstance(profile()); |
| 81 if (log_arguments) | 73 if (log_arguments) |
| 82 activity_log->SetDefaultPolicy(ActivityLogPolicy::POLICY_FULLSTREAM); | 74 activity_log->SetDefaultPolicy(ActivityLogPolicy::POLICY_FULLSTREAM); |
| 83 else | 75 else |
| 84 activity_log->SetDefaultPolicy(ActivityLogPolicy::POLICY_COUNTS); | 76 activity_log->SetDefaultPolicy(ActivityLogPolicy::POLICY_COUNTS); |
| 85 } | 77 } |
| 86 | 78 |
| 87 static void Arguments_Prerender( | 79 static void Arguments_Prerender( |
| 88 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 80 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
| 89 ASSERT_EQ(1U, i->size()); | 81 ASSERT_EQ(1U, i->size()); |
| 90 scoped_refptr<Action> last = i->front(); | 82 scoped_refptr<Action> last = i->front(); |
| 91 std::string args = | 83 std::string args = |
| 92 "ID=odlameecjipmbmbejkplpemijjgpljce CATEGORY=content_script API= " | 84 "ID=odlameecjipmbmbejkplpemijjgpljce CATEGORY=content_script API= " |
| 93 "ARGS=[\"script\"] PAGE_URL=http://www.google.com/ " | 85 "ARGS=[\"script\"] PAGE_URL=http://www.google.com/ " |
| 94 "OTHER={\"prerender\":true}"; | 86 "OTHER={\"prerender\":true}"; |
| 95 ASSERT_EQ(args, last->PrintForDebug()); | 87 ASSERT_EQ(args, last->PrintForDebug()); |
| 96 } | 88 } |
| 97 | 89 |
| 98 ExtensionService* extension_service_; | 90 ExtensionService* extension_service_; |
| 99 // Used to preserve a copy of the original command line. | |
| 100 // The test framework will do this itself as well. However, by then, | |
| 101 // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in | |
| 102 // TearDown(). | |
| 103 CommandLine saved_cmdline_; | |
| 104 | 91 |
| 105 #if defined OS_CHROMEOS | 92 #if defined OS_CHROMEOS |
| 106 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 93 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
| 107 chromeos::ScopedTestCrosSettings test_cros_settings_; | 94 chromeos::ScopedTestCrosSettings test_cros_settings_; |
| 108 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; | 95 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; |
| 109 #endif | 96 #endif |
| 110 }; | 97 }; |
| 111 | 98 |
| 112 TEST_F(ActivityLogTest, Enabled) { | |
| 113 ASSERT_TRUE(ActivityLog::IsLogEnabledOnAnyProfile()); | |
| 114 } | |
| 115 | |
| 116 TEST_F(ActivityLogTest, Construct) { | 99 TEST_F(ActivityLogTest, Construct) { |
| 117 ActivityLog* activity_log = ActivityLog::GetInstance(profile()); | 100 ActivityLog* activity_log = ActivityLog::GetInstance(profile()); |
| 118 ASSERT_TRUE(activity_log->IsLogEnabled()); | 101 ASSERT_TRUE(activity_log->IsLogEnabled()); |
| 119 | 102 |
| 120 scoped_refptr<Action> action = new Action(kExtensionId, | 103 scoped_refptr<Action> action = new Action(kExtensionId, |
| 121 base::Time::Now(), | 104 base::Time::Now(), |
| 122 Action::ACTION_API_CALL, | 105 Action::ACTION_API_CALL, |
| 123 "tabs.testMethod"); | 106 "tabs.testMethod"); |
| 124 activity_log->LogAction(action); | 107 activity_log->LogAction(action); |
| 125 } | 108 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 static_cast<TabHelper::ScriptExecutionObserver*>(activity_log)-> | 167 static_cast<TabHelper::ScriptExecutionObserver*>(activity_log)-> |
| 185 OnScriptsExecuted(contents, executing_scripts, 0, url); | 168 OnScriptsExecuted(contents, executing_scripts, 0, url); |
| 186 | 169 |
| 187 activity_log->GetActions( | 170 activity_log->GetActions( |
| 188 extension->id(), 0, base::Bind(ActivityLogTest::Arguments_Prerender)); | 171 extension->id(), 0, base::Bind(ActivityLogTest::Arguments_Prerender)); |
| 189 | 172 |
| 190 prerender_manager->CancelAllPrerenders(); | 173 prerender_manager->CancelAllPrerenders(); |
| 191 } | 174 } |
| 192 | 175 |
| 193 } // namespace extensions | 176 } // namespace extensions |
| OLD | NEW |