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/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/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/extensions/test_extension_system.h" | 10 #include "chrome/browser/extensions/test_extension_system.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 } | 54 } |
55 | 55 |
56 static void RetrieveActions_LogAndFetchActions( | 56 static void RetrieveActions_LogAndFetchActions( |
57 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 57 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
58 ASSERT_EQ(2, static_cast<int>(i->size())); | 58 ASSERT_EQ(2, static_cast<int>(i->size())); |
59 } | 59 } |
60 | 60 |
61 static void Arguments_Missing( | 61 static void Arguments_Missing( |
62 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 62 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
63 scoped_refptr<Action> last = i->front(); | 63 scoped_refptr<Action> last = i->front(); |
64 std::string noargs = "ID: odlameecjipmbmbejkplpemijjgpljce, CATEGORY: " | 64 std::string noargs = "ID: abc, CATEGORY: " |
65 "CALL, API: tabs.testMethod, ARGS: "; | 65 "CALL, API: tabs.testMethod, ARGS: "; |
66 ASSERT_EQ(noargs, last->PrintForDebug()); | 66 ASSERT_EQ(noargs, last->PrintForDebug()); |
67 } | 67 } |
68 | 68 |
69 static void Arguments_Present( | 69 static void Arguments_Present( |
70 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 70 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
71 scoped_refptr<Action> last = i->front(); | 71 scoped_refptr<Action> last = i->front(); |
72 std::string args = "ID: odlameecjipmbmbejkplpemijjgpljce, CATEGORY: " | 72 std::string args = "ID: abc, CATEGORY: " |
73 "CALL, API: extension.connect, ARGS: \"hello\", \"world\""; | 73 "CALL, API: extension.connect, ARGS: \"hello\", \"world\""; |
74 ASSERT_EQ(args, last->PrintForDebug()); | 74 ASSERT_EQ(args, last->PrintForDebug()); |
75 } | 75 } |
76 | 76 |
77 protected: | 77 protected: |
78 ExtensionService* extension_service_; | 78 ExtensionService* extension_service_; |
79 Profile* profile_; | 79 Profile* profile_; |
80 | 80 |
81 private: | 81 private: |
82 content::TestBrowserThread ui_thread_; | 82 content::TestBrowserThread ui_thread_; |
83 content::TestBrowserThread db_thread_; | 83 content::TestBrowserThread db_thread_; |
84 content::TestBrowserThread file_thread_; | 84 content::TestBrowserThread file_thread_; |
85 | 85 |
86 #if defined OS_CHROMEOS | 86 #if defined OS_CHROMEOS |
87 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 87 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
88 chromeos::ScopedTestCrosSettings test_cros_settings_; | 88 chromeos::ScopedTestCrosSettings test_cros_settings_; |
89 chromeos::ScopedTestUserManager test_user_manager_; | 89 chromeos::ScopedTestUserManager test_user_manager_; |
90 #endif | 90 #endif |
91 }; | 91 }; |
92 | 92 |
93 TEST_F(ActivityLogTest, Enabled) { | 93 TEST_F(ActivityLogTest, Enabled) { |
94 ASSERT_TRUE(ActivityLog::IsLogEnabled()); | 94 ASSERT_TRUE(ActivityLog::IsLogEnabled()); |
95 } | 95 } |
96 | 96 |
97 TEST_F(ActivityLogTest, Construct) { | 97 TEST_F(ActivityLogTest, Construct) { |
98 ActivityLog* activity_log = ActivityLog::GetInstance(profile_); | 98 ActivityLog* activity_log = ActivityLog::GetInstance(profile_); |
99 scoped_refptr<const Extension> extension = | |
100 ExtensionBuilder() | |
101 .SetManifest(DictionaryBuilder() | |
102 .Set("name", "Test extension") | |
103 .Set("version", "1.0.0") | |
104 .Set("manifest_version", 2)) | |
105 .Build(); | |
106 extension_service_->AddExtension(extension); | |
107 scoped_ptr<ListValue> args(new ListValue()); | 99 scoped_ptr<ListValue> args(new ListValue()); |
108 ASSERT_TRUE(ActivityLog::IsLogEnabled()); | 100 ASSERT_TRUE(ActivityLog::IsLogEnabled()); |
109 activity_log->LogAPIAction( | 101 activity_log->LogAPIAction( |
110 extension, std::string("tabs.testMethod"), args.get(), std::string()); | 102 "abc", std::string("tabs.testMethod"), args.get(), std::string()); |
Matt Perry
2013/05/29 18:01:17
make "abc" a const at the top of the file
felt
2013/05/30 07:21:02
Done.
| |
111 } | 103 } |
112 | 104 |
113 TEST_F(ActivityLogTest, LogAndFetchActions) { | 105 TEST_F(ActivityLogTest, LogAndFetchActions) { |
114 ActivityLog* activity_log = ActivityLog::GetInstance(profile_); | 106 ActivityLog* activity_log = ActivityLog::GetInstance(profile_); |
115 scoped_refptr<const Extension> extension = | |
116 ExtensionBuilder() | |
117 .SetManifest(DictionaryBuilder() | |
118 .Set("name", "Test extension") | |
119 .Set("version", "1.0.0") | |
120 .Set("manifest_version", 2)) | |
121 .Build(); | |
122 extension_service_->AddExtension(extension); | |
123 scoped_ptr<ListValue> args(new ListValue()); | 107 scoped_ptr<ListValue> args(new ListValue()); |
124 ASSERT_TRUE(ActivityLog::IsLogEnabled()); | 108 ASSERT_TRUE(ActivityLog::IsLogEnabled()); |
125 | 109 |
126 // Write some API calls | 110 // Write some API calls |
127 activity_log->LogAPIAction( | 111 activity_log->LogAPIAction( |
128 extension, std::string("tabs.testMethod"), args.get(), std::string()); | 112 "abc", std::string("tabs.testMethod"), args.get(), std::string()); |
129 activity_log->LogDOMAction(extension, | 113 activity_log->LogDOMAction("abc", |
130 GURL("http://www.google.com"), | 114 GURL("http://www.google.com"), |
131 string16(), | 115 string16(), |
132 std::string("document.write"), | 116 std::string("document.write"), |
133 args.get(), | 117 args.get(), |
134 std::string("extra")); | 118 std::string("extra")); |
135 activity_log->GetActions( | 119 activity_log->GetActions( |
136 extension->id(), | 120 "abc", |
137 0, | 121 0, |
138 base::Bind(ActivityLogTest::RetrieveActions_LogAndFetchActions)); | 122 base::Bind(ActivityLogTest::RetrieveActions_LogAndFetchActions)); |
139 } | 123 } |
140 | 124 |
141 TEST_F(ActivityLogTest, LogWithoutArguments) { | 125 TEST_F(ActivityLogTest, LogWithoutArguments) { |
142 ActivityLog* activity_log = ActivityLog::GetInstance(profile_); | 126 ActivityLog* activity_log = ActivityLog::GetInstance(profile_); |
143 activity_log->SetArgumentLoggingForTesting(false); | 127 activity_log->SetArgumentLoggingForTesting(false); |
144 scoped_refptr<const Extension> extension = | |
145 ExtensionBuilder() | |
146 .SetManifest(DictionaryBuilder() | |
147 .Set("name", "Test extension") | |
148 .Set("version", "1.0.0") | |
149 .Set("manifest_version", 2)) | |
150 .Build(); | |
151 extension_service_->AddExtension(extension); | |
152 ASSERT_TRUE(ActivityLog::IsLogEnabled()); | 128 ASSERT_TRUE(ActivityLog::IsLogEnabled()); |
153 | 129 |
154 scoped_ptr<ListValue> args(new ListValue()); | 130 scoped_ptr<ListValue> args(new ListValue()); |
155 args->Set(0, new base::StringValue("hello")); | 131 args->Set(0, new base::StringValue("hello")); |
156 args->Set(1, new base::StringValue("world")); | 132 args->Set(1, new base::StringValue("world")); |
157 activity_log->LogAPIAction( | 133 activity_log->LogAPIAction( |
158 extension, std::string("tabs.testMethod"), args.get(), std::string()); | 134 "abc", std::string("tabs.testMethod"), args.get(), std::string()); |
159 activity_log->GetActions( | 135 activity_log->GetActions( |
160 extension->id(), 0, base::Bind(ActivityLogTest::Arguments_Missing)); | 136 "abc", 0, base::Bind(ActivityLogTest::Arguments_Missing)); |
161 } | 137 } |
162 | 138 |
163 TEST_F(ActivityLogTest, LogWithArguments) { | 139 TEST_F(ActivityLogTest, LogWithArguments) { |
164 ActivityLog* activity_log = ActivityLog::GetInstance(profile_); | 140 ActivityLog* activity_log = ActivityLog::GetInstance(profile_); |
165 scoped_refptr<const Extension> extension = | |
166 ExtensionBuilder() | |
167 .SetManifest(DictionaryBuilder() | |
168 .Set("name", "Test extension") | |
169 .Set("version", "1.0.0") | |
170 .Set("manifest_version", 2)) | |
171 .Build(); | |
172 extension_service_->AddExtension(extension); | |
173 ASSERT_TRUE(ActivityLog::IsLogEnabled()); | 141 ASSERT_TRUE(ActivityLog::IsLogEnabled()); |
174 | 142 |
175 scoped_ptr<ListValue> args(new ListValue()); | 143 scoped_ptr<ListValue> args(new ListValue()); |
176 args->Set(0, new base::StringValue("hello")); | 144 args->Set(0, new base::StringValue("hello")); |
177 args->Set(1, new base::StringValue("world")); | 145 args->Set(1, new base::StringValue("world")); |
178 activity_log->LogAPIAction( | 146 activity_log->LogAPIAction( |
179 extension, std::string("extension.connect"), args.get(), std::string()); | 147 "abc", std::string("extension.connect"), args.get(), std::string()); |
180 activity_log->GetActions( | 148 activity_log->GetActions( |
181 extension->id(), 0, base::Bind(ActivityLogTest::Arguments_Present)); | 149 "abc", 0, base::Bind(ActivityLogTest::Arguments_Present)); |
182 } | 150 } |
183 | 151 |
184 } // namespace extensions | 152 } // namespace extensions |
185 | 153 |
OLD | NEW |