Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(640)

Side by Side Diff: chrome/browser/extensions/activity_log/activity_log_unittest.cc

Issue 18430004: Sets correct ActivityLog enabled status to the first renderer process (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 22 matching lines...) Expand all
33 namespace { 33 namespace {
34 34
35 const char kExtensionId[] = "abc"; 35 const char kExtensionId[] = "abc";
36 36
37 } // namespace 37 } // namespace
38 38
39 namespace extensions { 39 namespace extensions {
40 40
41 class ActivityLogTest : public ChromeRenderViewHostTestHarness { 41 class ActivityLogTest : public ChromeRenderViewHostTestHarness {
42 protected: 42 protected:
43 ActivityLogTest() : saved_cmdline_(CommandLine::NO_PROGRAM) {}
44
45 virtual void SetUp() OVERRIDE { 43 virtual void SetUp() OVERRIDE {
46 ChromeRenderViewHostTestHarness::SetUp(); 44 ChromeRenderViewHostTestHarness::SetUp();
47 #if defined OS_CHROMEOS 45 #if defined OS_CHROMEOS
48 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); 46 test_user_manager_.reset(new chromeos::ScopedTestUserManager());
49 #endif 47 #endif
50 CommandLine command_line(CommandLine::NO_PROGRAM); 48 CommandLine command_line(CommandLine::NO_PROGRAM);
51 saved_cmdline_ = *CommandLine::ForCurrentProcess();
felt 2013/07/23 06:37:34 why did you remove this? we're still mucking aroun
pmarch 2013/07/29 17:36:47 Comment below says saved_cmdline_ is used to prese
felt 2013/07/29 19:29:42 Ahh, I see, the problem was being caused by Recomp
52 CommandLine::ForCurrentProcess()->AppendSwitch( 49 CommandLine::ForCurrentProcess()->AppendSwitch(
53 switches::kEnableExtensionActivityLogging); 50 switches::kEnableExtensionActivityLogging);
54 CommandLine::ForCurrentProcess()->AppendSwitch( 51 CommandLine::ForCurrentProcess()->AppendSwitch(
55 switches::kEnableExtensionActivityLogTesting); 52 switches::kEnableExtensionActivityLogTesting);
56 ActivityLog::RecomputeLoggingIsEnabled(true); // Logging now enabled.
57 extension_service_ = static_cast<TestExtensionSystem*>( 53 extension_service_ = static_cast<TestExtensionSystem*>(
58 ExtensionSystem::Get(profile()))->CreateExtensionService 54 ExtensionSystem::Get(profile()))->CreateExtensionService
59 (&command_line, base::FilePath(), false); 55 (&command_line, base::FilePath(), false);
60 ActivityLog::GetInstance(profile())->Init();
61 base::RunLoop().RunUntilIdle(); 56 base::RunLoop().RunUntilIdle();
62 } 57 }
63 58
64 virtual void TearDown() OVERRIDE { 59 virtual void TearDown() OVERRIDE {
65 #if defined OS_CHROMEOS 60 #if defined OS_CHROMEOS
66 test_user_manager_.reset(); 61 test_user_manager_.reset();
67 #endif 62 #endif
68 base::RunLoop().RunUntilIdle(); 63 base::RunLoop().RunUntilIdle();
69 // Restore the original command line and undo the affects of SetUp(). 64 // Restore the original command line and undo the affects of SetUp().
felt 2013/07/29 21:05:23 PS please kill the comment too if removing the cod
pmarch 2013/08/08 14:42:42 Done.
70 *CommandLine::ForCurrentProcess() = saved_cmdline_;
71 ActivityLog::RecomputeLoggingIsEnabled(false); // Logging now disabled.
72 ChromeRenderViewHostTestHarness::TearDown(); 65 ChromeRenderViewHostTestHarness::TearDown();
73 } 66 }
74 67
75 static void RetrieveActions_LogAndFetchActions( 68 static void RetrieveActions_LogAndFetchActions(
76 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { 69 scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
77 ASSERT_EQ(2, static_cast<int>(i->size())); 70 ASSERT_EQ(2, static_cast<int>(i->size()));
78 } 71 }
79 72
80 static void RetrieveActions_LogAndFetchPathActions( 73 static void RetrieveActions_LogAndFetchPathActions(
81 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { 74 scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 ASSERT_EQ(1U, i->size()); 121 ASSERT_EQ(1U, i->size());
129 scoped_refptr<Action> last = i->front(); 122 scoped_refptr<Action> last = i->front();
130 std::string args = 123 std::string args =
131 "ID=odlameecjipmbmbejkplpemijjgpljce CATEGORY=content_script API= " 124 "ID=odlameecjipmbmbejkplpemijjgpljce CATEGORY=content_script API= "
132 "ARGS=[\"\\\"script \\\"\"] PAGE_URL=http://www.google.com/ " 125 "ARGS=[\"\\\"script \\\"\"] PAGE_URL=http://www.google.com/ "
133 "OTHER={\"dom_verb\":3,\"extra\":\"(prerender)\",\"page_title\":\"\"}"; 126 "OTHER={\"dom_verb\":3,\"extra\":\"(prerender)\",\"page_title\":\"\"}";
134 ASSERT_EQ(args, last->PrintForDebug()); 127 ASSERT_EQ(args, last->PrintForDebug());
135 } 128 }
136 129
137 ExtensionService* extension_service_; 130 ExtensionService* extension_service_;
138 // Used to preserve a copy of the original command line.
139 // The test framework will do this itself as well. However, by then,
140 // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in
141 // TearDown().
142 CommandLine saved_cmdline_;
143 131
144 #if defined OS_CHROMEOS 132 #if defined OS_CHROMEOS
145 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; 133 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
146 chromeos::ScopedTestCrosSettings test_cros_settings_; 134 chromeos::ScopedTestCrosSettings test_cros_settings_;
147 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; 135 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_;
148 #endif 136 #endif
149 }; 137 };
150 138
151 TEST_F(ActivityLogTest, Enabled) {
152 ASSERT_TRUE(ActivityLog::IsLogEnabledOnAnyProfile());
153 }
154
155 TEST_F(ActivityLogTest, Construct) { 139 TEST_F(ActivityLogTest, Construct) {
156 ActivityLog* activity_log = ActivityLog::GetInstance(profile()); 140 ActivityLog* activity_log = ActivityLog::GetInstance(profile());
157 scoped_ptr<base::ListValue> args(new base::ListValue()); 141 scoped_ptr<base::ListValue> args(new base::ListValue());
158 ASSERT_TRUE(activity_log->IsLogEnabled()); 142 ASSERT_TRUE(activity_log->IsLogEnabled());
159 activity_log->LogAPIAction( 143 activity_log->LogAPIAction(
160 kExtensionId, std::string("tabs.testMethod"), args.get(), std::string()); 144 kExtensionId, std::string("tabs.testMethod"), args.get(), std::string());
161 } 145 }
162 146
163 TEST_F(ActivityLogTest, LogAndFetchActions) { 147 TEST_F(ActivityLogTest, LogAndFetchActions) {
164 ActivityLog* activity_log = ActivityLog::GetInstance(profile()); 148 ActivityLog* activity_log = ActivityLog::GetInstance(profile());
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 OnScriptsExecuted(contents, executing_scripts, 0, url); 249 OnScriptsExecuted(contents, executing_scripts, 0, url);
266 250
267 activity_log->GetActions( 251 activity_log->GetActions(
268 extension->id(), 0, base::Bind(ActivityLogTest::Arguments_Prerender)); 252 extension->id(), 0, base::Bind(ActivityLogTest::Arguments_Prerender));
269 253
270 prerender_manager->CancelAllPrerenders(); 254 prerender_manager->CancelAllPrerenders();
271 } 255 }
272 256
273 } // namespace extensions 257 } // namespace extensions
274 258
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698