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

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

Issue 15573003: New architecture of the activity logging: Policies for summarization (and compression) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Adrienne's final comments. Created 7 years, 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright $YEAR The Chromium Authors. All rights reserved.
Matt Perry 2013/05/30 18:55:32 ?
dbabic 2013/05/30 21:51:25 Sorry, I took http://www.chromium.org/developers/c
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/synchronization/waitable_event.h" 7 #include "base/synchronization/waitable_event.h"
8 #include "chrome/browser/extensions/activity_log/activity_log.h" 8 #include "chrome/browser/extensions/activity_log/activity_log.h"
9 #include "chrome/browser/extensions/activity_log/stream_noargs_ui_policy.h"
9 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/test_extension_system.h" 11 #include "chrome/browser/extensions/test_extension_system.h"
11 #include "chrome/common/chrome_constants.h" 12 #include "chrome/common/chrome_constants.h"
12 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/extensions/extension_builder.h" 14 #include "chrome/common/extensions/extension_builder.h"
14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 15 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
15 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
16 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
17 #include "content/public/test/test_browser_thread.h" 18 #include "content/public/test/test_browser_thread.h"
18 #include "sql/statement.h" 19 #include "sql/statement.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 21
21 #if defined(OS_CHROMEOS) 22 #if defined(OS_CHROMEOS)
22 #include "chrome/browser/chromeos/login/user_manager.h" 23 #include "chrome/browser/chromeos/login/user_manager.h"
23 #include "chrome/browser/chromeos/settings/cros_settings.h" 24 #include "chrome/browser/chromeos/settings/cros_settings.h"
24 #include "chrome/browser/chromeos/settings/device_settings_service.h" 25 #include "chrome/browser/chromeos/settings/device_settings_service.h"
25 #endif 26 #endif
26 27
27 namespace extensions { 28 namespace extensions {
28 29
29 class ActivityLogTest : public ChromeRenderViewHostTestHarness { 30 class StreamWithoutArgsUIPolicyTest : public ChromeRenderViewHostTestHarness {
30 public: 31 public:
31 ActivityLogTest() 32 StreamWithoutArgsUIPolicyTest()
32 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()), 33 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()),
33 db_thread_(BrowserThread::DB, base::MessageLoop::current()), 34 db_thread_(BrowserThread::DB, base::MessageLoop::current()),
34 file_thread_(BrowserThread::FILE, base::MessageLoop::current()) {} 35 file_thread_(BrowserThread::FILE, base::MessageLoop::current()) {}
35 36
36 virtual void SetUp() OVERRIDE { 37 virtual void SetUp() OVERRIDE {
37 ChromeRenderViewHostTestHarness::SetUp(); 38 ChromeRenderViewHostTestHarness::SetUp();
38 CommandLine command_line(CommandLine::NO_PROGRAM); 39 CommandLine command_line(CommandLine::NO_PROGRAM);
39 profile_ = 40 profile_ =
40 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 41 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
41 extension_service_ = static_cast<TestExtensionSystem*>( 42 extension_service_ = static_cast<TestExtensionSystem*>(
42 ExtensionSystem::Get(profile_))->CreateExtensionService( 43 ExtensionSystem::Get(profile_))->CreateExtensionService(
43 &command_line, base::FilePath(), false); 44 &command_line, base::FilePath(), false);
44 CommandLine::ForCurrentProcess()->AppendSwitch( 45 CommandLine::ForCurrentProcess()->AppendSwitch(
45 switches::kEnableExtensionActivityLogging);
46 CommandLine::ForCurrentProcess()->AppendSwitch(
47 switches::kEnableExtensionActivityLogTesting); 46 switches::kEnableExtensionActivityLogTesting);
48 ActivityLog::RecomputeLoggingIsEnabled();
49 } 47 }
50 48
51 virtual ~ActivityLogTest() { 49 virtual ~StreamWithoutArgsUIPolicyTest() {
52 base::MessageLoop::current()->PostTask(FROM_HERE, 50 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
53 base::MessageLoop::QuitClosure()); 51 MessageLoop::current()->Run();
54 base::MessageLoop::current()->Run();
55 } 52 }
56 53
57 static void RetrieveActions_LogAndFetchActions( 54 static void RetrieveActions_LogAndFetchActions(
58 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { 55 scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
59 ASSERT_EQ(2, static_cast<int>(i->size())); 56 ASSERT_EQ(2, static_cast<int>(i->size()));
60 } 57 }
61 58
62 static void Arguments_Missing( 59 static void Arguments_Missing(
63 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { 60 scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
64 scoped_refptr<Action> last = i->front(); 61 scoped_refptr<Action> last = i->front();
65 std::string noargs = "ID: odlameecjipmbmbejkplpemijjgpljce, CATEGORY: " 62 std::string noargs = "ID: odlameecjipmbmbejkplpemijjgpljce, CATEGORY: "
66 "CALL, API: tabs.testMethod, ARGS: "; 63 "CALL, API: tabs.testMethod, ARGS: ";
67 ASSERT_EQ(noargs, last->PrintForDebug()); 64 ASSERT_EQ(noargs, last->PrintForDebug());
68 } 65 }
69 66
70 static void Arguments_Present(
71 scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
72 scoped_refptr<Action> last = i->front();
73 std::string args = "ID: odlameecjipmbmbejkplpemijjgpljce, CATEGORY: "
74 "CALL, API: extension.connect, ARGS: \"hello\", \"world\"";
75 ASSERT_EQ(args, last->PrintForDebug());
76 }
77
78 protected: 67 protected:
79 ExtensionService* extension_service_; 68 ExtensionService* extension_service_;
80 Profile* profile_; 69 Profile* profile_;
81 70
82 private: 71 private:
83 content::TestBrowserThread ui_thread_; 72 content::TestBrowserThread ui_thread_;
84 content::TestBrowserThread db_thread_; 73 content::TestBrowserThread db_thread_;
85 content::TestBrowserThread file_thread_; 74 content::TestBrowserThread file_thread_;
86 75
87 #if defined OS_CHROMEOS 76 #if defined OS_CHROMEOS
88 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; 77 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
89 chromeos::ScopedTestCrosSettings test_cros_settings_; 78 chromeos::ScopedTestCrosSettings test_cros_settings_;
90 chromeos::ScopedTestUserManager test_user_manager_; 79 chromeos::ScopedTestUserManager test_user_manager_;
91 #endif 80 #endif
92 }; 81 };
93 82
94 TEST_F(ActivityLogTest, Enabled) { 83 TEST_F(StreamWithoutArgsUIPolicyTest, Construct) {
95 ASSERT_TRUE(ActivityLog::IsLogEnabled()); 84 ActivityLogPolicy* policy = new StreamWithoutArgsUIPolicy(profile_,
96 } 85 BrowserThread::UI);
97
98 TEST_F(ActivityLogTest, Construct) {
99 ActivityLog* activity_log = ActivityLog::GetInstance(profile_);
100 scoped_refptr<const Extension> extension = 86 scoped_refptr<const Extension> extension =
101 ExtensionBuilder() 87 ExtensionBuilder()
102 .SetManifest(DictionaryBuilder() 88 .SetManifest(DictionaryBuilder()
103 .Set("name", "Test extension") 89 .Set("name", "Test extension")
104 .Set("version", "1.0.0") 90 .Set("version", "1.0.0")
105 .Set("manifest_version", 2)) 91 .Set("manifest_version", 2))
106 .Build(); 92 .Build();
107 extension_service_->AddExtension(extension); 93 extension_service_->AddExtension(extension);
108 scoped_ptr<ListValue> args(new ListValue()); 94 scoped_ptr<ListValue> args(new ListValue());
109 ASSERT_TRUE(ActivityLog::IsLogEnabled()); 95 policy->ProcessAction(ActivityLogPolicy::ACTION_API, *extension.get(),
110 activity_log->LogAPIAction( 96 std::string("tabs.testMethod"), NULL, args.get(), NULL);
111 extension, std::string("tabs.testMethod"), args.get(), std::string()); 97 delete policy;
112 } 98 }
113 99
114 TEST_F(ActivityLogTest, LogAndFetchActions) { 100 TEST_F(StreamWithoutArgsUIPolicyTest, LogAndFetchActions) {
115 ActivityLog* activity_log = ActivityLog::GetInstance(profile_); 101 ActivityLogPolicy* policy = new StreamWithoutArgsUIPolicy(profile_,
102 BrowserThread::UI);
116 scoped_refptr<const Extension> extension = 103 scoped_refptr<const Extension> extension =
117 ExtensionBuilder() 104 ExtensionBuilder()
118 .SetManifest(DictionaryBuilder() 105 .SetManifest(DictionaryBuilder()
119 .Set("name", "Test extension") 106 .Set("name", "Test extension")
120 .Set("version", "1.0.0") 107 .Set("version", "1.0.0")
121 .Set("manifest_version", 2)) 108 .Set("manifest_version", 2))
122 .Build(); 109 .Build();
123 extension_service_->AddExtension(extension); 110 extension_service_->AddExtension(extension);
124 scoped_ptr<ListValue> args(new ListValue()); 111 scoped_ptr<ListValue> args(new ListValue());
125 ASSERT_TRUE(ActivityLog::IsLogEnabled()); 112 GURL* gurl = new GURL("http://www.google.com");
126 113
127 // Write some API calls 114 // Write some API calls
128 activity_log->LogAPIAction( 115 policy->ProcessAction(ActivityLogPolicy::ACTION_API, *extension.get(),
129 extension, std::string("tabs.testMethod"), args.get(), std::string()); 116 std::string("tabs.testMethod"), NULL, args.get(), NULL);
130 activity_log->LogDOMAction(extension, 117 policy->ProcessAction(ActivityLogPolicy::ACTION_DOM,
131 GURL("http://www.google.com"), 118 *extension.get(), std::string("document.write"), gurl, args.get(), NULL);
132 string16(), 119 policy->ReadData(extension->id(), 0,
133 std::string("document.write"), 120 base::Bind(
134 args.get(), 121 StreamWithoutArgsUIPolicyTest::RetrieveActions_LogAndFetchActions));
135 std::string("extra")); 122 delete policy;
136 activity_log->GetActions( 123 delete gurl;
137 extension->id(),
138 0,
139 base::Bind(ActivityLogTest::RetrieveActions_LogAndFetchActions));
140 } 124 }
141 125
142 TEST_F(ActivityLogTest, LogWithoutArguments) { 126 TEST_F(StreamWithoutArgsUIPolicyTest, LogWithoutArguments) {
143 ActivityLog* activity_log = ActivityLog::GetInstance(profile_); 127 ActivityLogPolicy* policy = new StreamWithoutArgsUIPolicy(profile_,
144 activity_log->SetArgumentLoggingForTesting(false); 128 BrowserThread::UI);
145 scoped_refptr<const Extension> extension = 129 scoped_refptr<const Extension> extension =
146 ExtensionBuilder() 130 ExtensionBuilder()
147 .SetManifest(DictionaryBuilder() 131 .SetManifest(DictionaryBuilder()
148 .Set("name", "Test extension") 132 .Set("name", "Test extension")
149 .Set("version", "1.0.0") 133 .Set("version", "1.0.0")
150 .Set("manifest_version", 2)) 134 .Set("manifest_version", 2))
151 .Build(); 135 .Build();
152 extension_service_->AddExtension(extension); 136 extension_service_->AddExtension(extension);
153 ASSERT_TRUE(ActivityLog::IsLogEnabled());
154
155 scoped_ptr<ListValue> args(new ListValue()); 137 scoped_ptr<ListValue> args(new ListValue());
156 args->Set(0, new base::StringValue("hello")); 138 args->Set(0, new base::StringValue("hello"));
157 args->Set(1, new base::StringValue("world")); 139 args->Set(1, new base::StringValue("world"));
158 activity_log->LogAPIAction( 140 policy->ProcessAction(ActivityLogPolicy::ACTION_API, *extension.get(),
159 extension, std::string("tabs.testMethod"), args.get(), std::string()); 141 std::string("tabs.testMethod"), NULL, args.get(), NULL);
160 activity_log->GetActions( 142 policy->ReadData(extension->id(), 0,
161 extension->id(), 0, base::Bind(ActivityLogTest::Arguments_Missing)); 143 base::Bind(StreamWithoutArgsUIPolicyTest::Arguments_Missing));
144 delete policy;
162 } 145 }
163 146
164 TEST_F(ActivityLogTest, LogWithArguments) { 147 } // End of namespace extensions
165 ActivityLog* activity_log = ActivityLog::GetInstance(profile_);
166 scoped_refptr<const Extension> extension =
167 ExtensionBuilder()
168 .SetManifest(DictionaryBuilder()
169 .Set("name", "Test extension")
170 .Set("version", "1.0.0")
171 .Set("manifest_version", 2))
172 .Build();
173 extension_service_->AddExtension(extension);
174 ASSERT_TRUE(ActivityLog::IsLogEnabled());
175
176 scoped_ptr<ListValue> args(new ListValue());
177 args->Set(0, new base::StringValue("hello"));
178 args->Set(1, new base::StringValue("world"));
179 activity_log->LogAPIAction(
180 extension, std::string("extension.connect"), args.get(), std::string());
181 activity_log->GetActions(
182 extension->id(), 0, base::Bind(ActivityLogTest::Arguments_Present));
183 }
184
185 } // namespace extensions
186
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698