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 "base/cancelable_callback.h" | 5 #include "base/cancelable_callback.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 ASSERT_EQ(2, static_cast<int>(i->size())); | 186 ASSERT_EQ(2, static_cast<int>(i->size())); |
187 } | 187 } |
188 | 188 |
189 static void RetrieveActions_FetchFilteredActions300( | 189 static void RetrieveActions_FetchFilteredActions300( |
190 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 190 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
191 ASSERT_EQ(300, static_cast<int>(i->size())); | 191 ASSERT_EQ(300, static_cast<int>(i->size())); |
192 } | 192 } |
193 | 193 |
194 static void Arguments_Stripped(scoped_ptr<Action::ActionVector> i) { | 194 static void Arguments_Stripped(scoped_ptr<Action::ActionVector> i) { |
195 scoped_refptr<Action> last = i->front(); | 195 scoped_refptr<Action> last = i->front(); |
196 std::string args = | 196 CheckAction(*last, "odlameecjipmbmbejkplpemijjgpljce", |
197 "ID=odlameecjipmbmbejkplpemijjgpljce CATEGORY=api_call " | 197 Action::ACTION_API_CALL, "extension.connect", |
198 "API=extension.connect ARGS=[\"hello\",\"world\"] COUNT=1"; | 198 "[\"hello\",\"world\"]", "", "", "", 1); |
199 ASSERT_EQ(args, last->PrintForDebug()); | |
200 } | 199 } |
201 | 200 |
202 static void Arguments_GetTodaysActions( | 201 static void Arguments_GetTodaysActions( |
203 scoped_ptr<Action::ActionVector> actions) { | 202 scoped_ptr<Action::ActionVector> actions) { |
204 std::string api_stripped_print = | |
205 "ID=punky CATEGORY=api_call API=brewster COUNT=2"; | |
206 std::string api_print = | |
207 "ID=punky CATEGORY=api_call API=extension.sendMessage " | |
208 "ARGS=[\"not\",\"stripped\"] COUNT=1"; | |
209 std::string dom_print = | |
210 "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"] " | |
211 "PAGE_URL=http://www.google.com/ COUNT=1"; | |
212 ASSERT_EQ(3, static_cast<int>(actions->size())); | 203 ASSERT_EQ(3, static_cast<int>(actions->size())); |
213 ASSERT_EQ(dom_print, actions->at(0)->PrintForDebug()); | 204 CheckAction(*actions->at(0), "punky", Action::ACTION_DOM_ACCESS, "lets", |
214 ASSERT_EQ(api_print, actions->at(1)->PrintForDebug()); | 205 "[\"vamoose\"]", "http://www.google.com/", "", "", 1); |
215 ASSERT_EQ(api_stripped_print, actions->at(2)->PrintForDebug()); | 206 CheckAction(*actions->at(1), "punky", Action::ACTION_API_CALL, |
| 207 "extension.sendMessage", "[\"not\",\"stripped\"]", "", "", "", |
| 208 1); |
| 209 CheckAction(*actions->at(2), "punky", Action::ACTION_API_CALL, "brewster", |
| 210 "", "", "", "", 2); |
216 } | 211 } |
217 | 212 |
218 static void Arguments_GetOlderActions( | 213 static void Arguments_GetOlderActions( |
219 scoped_ptr<Action::ActionVector> actions) { | 214 scoped_ptr<Action::ActionVector> actions) { |
220 std::string api_print = | |
221 "ID=punky CATEGORY=api_call API=brewster COUNT=1"; | |
222 std::string dom_print = | |
223 "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"] " | |
224 "PAGE_URL=http://www.google.com/ COUNT=1"; | |
225 ASSERT_EQ(2, static_cast<int>(actions->size())); | 215 ASSERT_EQ(2, static_cast<int>(actions->size())); |
226 ASSERT_EQ(dom_print, actions->at(0)->PrintForDebug()); | 216 CheckAction(*actions->at(0), "punky", Action::ACTION_DOM_ACCESS, "lets", |
227 ASSERT_EQ(api_print, actions->at(1)->PrintForDebug()); | 217 "[\"vamoose\"]", "http://www.google.com/", "", "", 1); |
| 218 CheckAction(*actions->at(1), "punky", Action::ACTION_API_CALL, "brewster", |
| 219 "", "", "", "", 1); |
228 } | 220 } |
229 | 221 |
230 static void Arguments_CheckMergeCount( | 222 static void Arguments_CheckMergeCount( |
231 int count, | 223 int count, |
232 scoped_ptr<Action::ActionVector> actions) { | 224 scoped_ptr<Action::ActionVector> actions) { |
233 std::string api_print = base::StringPrintf( | |
234 "ID=punky CATEGORY=api_call API=brewster COUNT=%d", count); | |
235 if (count > 0) { | 225 if (count > 0) { |
236 ASSERT_EQ(1u, actions->size()); | 226 ASSERT_EQ(1u, actions->size()); |
237 ASSERT_EQ(api_print, actions->at(0)->PrintForDebug()); | 227 CheckAction(*actions->at(0), "punky", Action::ACTION_API_CALL, "brewster", |
| 228 "", "", "", "", count); |
238 } else { | 229 } else { |
239 ASSERT_EQ(0u, actions->size()); | 230 ASSERT_EQ(0u, actions->size()); |
240 } | 231 } |
241 } | 232 } |
242 | 233 |
243 static void Arguments_CheckMergeCountAndTime( | 234 static void Arguments_CheckMergeCountAndTime( |
244 int count, | 235 int count, |
245 const base::Time& time, | 236 const base::Time& time, |
246 scoped_ptr<Action::ActionVector> actions) { | 237 scoped_ptr<Action::ActionVector> actions) { |
247 std::string api_print = base::StringPrintf( | |
248 "ID=punky CATEGORY=api_call API=brewster COUNT=%d", count); | |
249 if (count > 0) { | 238 if (count > 0) { |
250 ASSERT_EQ(1u, actions->size()); | 239 ASSERT_EQ(1u, actions->size()); |
251 ASSERT_EQ(api_print, actions->at(0)->PrintForDebug()); | 240 CheckAction(*actions->at(0), "punky", Action::ACTION_API_CALL, "brewster", |
| 241 "", "", "", "", count); |
252 ASSERT_EQ(time, actions->at(0)->time()); | 242 ASSERT_EQ(time, actions->at(0)->time()); |
253 } else { | 243 } else { |
254 ASSERT_EQ(0u, actions->size()); | 244 ASSERT_EQ(0u, actions->size()); |
255 } | 245 } |
256 } | 246 } |
257 | 247 |
258 static void AllURLsRemoved(scoped_ptr<Action::ActionVector> actions) { | 248 static void AllURLsRemoved(scoped_ptr<Action::ActionVector> actions) { |
259 ASSERT_EQ(2, static_cast<int>(actions->size())); | 249 ASSERT_EQ(2, static_cast<int>(actions->size())); |
260 CheckAction(*actions->at(0), "punky", Action::ACTION_DOM_ACCESS, "lets", | 250 CheckAction(*actions->at(0), "punky", Action::ACTION_DOM_ACCESS, "lets", |
261 "[\"vamoose\"]", "", "", ""); | 251 "[\"vamoose\"]", "", "", "", 1); |
262 CheckAction(*actions->at(1), "punky", Action::ACTION_DOM_ACCESS, "lets", | 252 CheckAction(*actions->at(1), "punky", Action::ACTION_DOM_ACCESS, "lets", |
263 "[\"vamoose\"]", "", "", ""); | 253 "[\"vamoose\"]", "", "", "", 1); |
264 } | 254 } |
265 | 255 |
266 static void SomeURLsRemoved(scoped_ptr<Action::ActionVector> actions) { | 256 static void SomeURLsRemoved(scoped_ptr<Action::ActionVector> actions) { |
267 // These will be in the vector in reverse time order. | 257 // These will be in the vector in reverse time order. |
268 ASSERT_EQ(5, static_cast<int>(actions->size())); | 258 ASSERT_EQ(5, static_cast<int>(actions->size())); |
269 CheckAction(*actions->at(0), "punky", Action::ACTION_DOM_ACCESS, "lets", | 259 CheckAction(*actions->at(0), "punky", Action::ACTION_DOM_ACCESS, "lets", |
270 "[\"vamoose\"]", "http://www.google.com/", "Google", | 260 "[\"vamoose\"]", "http://www.google.com/", "Google", |
271 "http://www.args-url.com/"); | 261 "http://www.args-url.com/", 1); |
272 CheckAction(*actions->at(1), "punky", Action::ACTION_DOM_ACCESS, "lets", | 262 CheckAction(*actions->at(1), "punky", Action::ACTION_DOM_ACCESS, "lets", |
273 "[\"vamoose\"]", "http://www.google.com/", "Google", ""); | 263 "[\"vamoose\"]", "http://www.google.com/", "Google", "", 1); |
274 CheckAction(*actions->at(2), "punky", Action::ACTION_DOM_ACCESS, "lets", | 264 CheckAction(*actions->at(2), "punky", Action::ACTION_DOM_ACCESS, "lets", |
275 "[\"vamoose\"]", "", "", ""); | 265 "[\"vamoose\"]", "", "", "", 1); |
276 CheckAction(*actions->at(3), "punky", Action::ACTION_DOM_ACCESS, "lets", | 266 CheckAction(*actions->at(3), "punky", Action::ACTION_DOM_ACCESS, "lets", |
277 "[\"vamoose\"]", "", "", "http://www.google.com/"); | 267 "[\"vamoose\"]", "", "", "http://www.google.com/", 1); |
278 CheckAction(*actions->at(4), "punky", Action::ACTION_DOM_ACCESS, "lets", | 268 CheckAction(*actions->at(4), "punky", Action::ACTION_DOM_ACCESS, "lets", |
279 "[\"vamoose\"]", "", "", ""); | 269 "[\"vamoose\"]", "", "", "", 1); |
280 } | 270 } |
281 | 271 |
282 // TODO(karenlees): add checking for the count value. | |
283 static void CheckAction(const Action& action, | 272 static void CheckAction(const Action& action, |
284 const std::string& expected_id, | 273 const std::string& expected_id, |
285 const Action::ActionType& expected_type, | 274 const Action::ActionType& expected_type, |
286 const std::string& expected_api_name, | 275 const std::string& expected_api_name, |
287 const std::string& expected_args_str, | 276 const std::string& expected_args_str, |
288 const std::string& expected_page_url, | 277 const std::string& expected_page_url, |
289 const std::string& expected_page_title, | 278 const std::string& expected_page_title, |
290 const std::string& expected_arg_url) { | 279 const std::string& expected_arg_url, |
| 280 int expected_count) { |
291 ASSERT_EQ(expected_id, action.extension_id()); | 281 ASSERT_EQ(expected_id, action.extension_id()); |
292 ASSERT_EQ(expected_type, action.action_type()); | 282 ASSERT_EQ(expected_type, action.action_type()); |
293 ASSERT_EQ(expected_api_name, action.api_name()); | 283 ASSERT_EQ(expected_api_name, action.api_name()); |
294 ASSERT_EQ(expected_args_str, | 284 ASSERT_EQ(expected_args_str, |
295 ActivityLogPolicy::Util::Serialize(action.args())); | 285 ActivityLogPolicy::Util::Serialize(action.args())); |
296 ASSERT_EQ(expected_page_url, action.SerializePageUrl()); | 286 ASSERT_EQ(expected_page_url, action.SerializePageUrl()); |
297 ASSERT_EQ(expected_page_title, action.page_title()); | 287 ASSERT_EQ(expected_page_title, action.page_title()); |
298 ASSERT_EQ(expected_arg_url, action.SerializeArgUrl()); | 288 ASSERT_EQ(expected_arg_url, action.SerializeArgUrl()); |
| 289 ASSERT_EQ(expected_count, action.count()); |
299 } | 290 } |
300 | 291 |
301 protected: | 292 protected: |
302 ExtensionService* extension_service_; | 293 ExtensionService* extension_service_; |
303 scoped_ptr<TestingProfile> profile_; | 294 scoped_ptr<TestingProfile> profile_; |
304 content::TestBrowserThreadBundle thread_bundle_; | 295 content::TestBrowserThreadBundle thread_bundle_; |
305 // Used to preserve a copy of the original command line. | 296 // Used to preserve a copy of the original command line. |
306 // The test framework will do this itself as well. However, by then, | 297 // The test framework will do this itself as well. However, by then, |
307 // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in | 298 // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in |
308 // TearDown(). | 299 // TearDown(). |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
923 | 914 |
924 CheckReadData( | 915 CheckReadData( |
925 policy, | 916 policy, |
926 "punky", | 917 "punky", |
927 0, | 918 0, |
928 base::Bind(&CountingPolicyTest::SomeURLsRemoved)); | 919 base::Bind(&CountingPolicyTest::SomeURLsRemoved)); |
929 policy->Close(); | 920 policy->Close(); |
930 } | 921 } |
931 | 922 |
932 } // namespace extensions | 923 } // namespace extensions |
OLD | NEW |