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 "chrome/browser/extensions/activity_log/counting_policy.h" | 5 #include "chrome/browser/extensions/activity_log/counting_policy.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 ASSERT_EQ(2, static_cast<int>(i->size())); | 176 ASSERT_EQ(2, static_cast<int>(i->size())); |
177 } | 177 } |
178 | 178 |
179 static void RetrieveActions_FetchFilteredActions300( | 179 static void RetrieveActions_FetchFilteredActions300( |
180 std::unique_ptr<std::vector<scoped_refptr<Action>>> i) { | 180 std::unique_ptr<std::vector<scoped_refptr<Action>>> i) { |
181 ASSERT_EQ(300, static_cast<int>(i->size())); | 181 ASSERT_EQ(300, static_cast<int>(i->size())); |
182 } | 182 } |
183 | 183 |
184 static void Arguments_Stripped(std::unique_ptr<Action::ActionVector> i) { | 184 static void Arguments_Stripped(std::unique_ptr<Action::ActionVector> i) { |
185 scoped_refptr<Action> last = i->front(); | 185 scoped_refptr<Action> last = i->front(); |
186 CheckAction(*last.get(), | 186 CheckAction(*last, "odlameecjipmbmbejkplpemijjgpljce", |
187 "odlameecjipmbmbejkplpemijjgpljce", | 187 Action::ACTION_API_CALL, "extension.connect", |
188 Action::ACTION_API_CALL, | 188 "[\"hello\",\"world\"]", "", "", "", 1); |
189 "extension.connect", | |
190 "[\"hello\",\"world\"]", | |
191 "", | |
192 "", | |
193 "", | |
194 1); | |
195 } | 189 } |
196 | 190 |
197 static void Arguments_GetSinglesAction( | 191 static void Arguments_GetSinglesAction( |
198 std::unique_ptr<Action::ActionVector> actions) { | 192 std::unique_ptr<Action::ActionVector> actions) { |
199 ASSERT_EQ(1, static_cast<int>(actions->size())); | 193 ASSERT_EQ(1, static_cast<int>(actions->size())); |
200 CheckAction(*actions->at(0).get(), | 194 CheckAction(*actions->at(0), "punky", Action::ACTION_DOM_ACCESS, "lets", "", |
201 "punky", | 195 "http://www.google.com/", "", "", 1); |
202 Action::ACTION_DOM_ACCESS, | |
203 "lets", | |
204 "", | |
205 "http://www.google.com/", | |
206 "", | |
207 "", | |
208 1); | |
209 } | 196 } |
210 | 197 |
211 static void Arguments_GetTodaysActions( | 198 static void Arguments_GetTodaysActions( |
212 std::unique_ptr<Action::ActionVector> actions) { | 199 std::unique_ptr<Action::ActionVector> actions) { |
213 ASSERT_EQ(3, static_cast<int>(actions->size())); | 200 ASSERT_EQ(3, static_cast<int>(actions->size())); |
214 CheckAction(*actions->at(0).get(), | 201 CheckAction(*actions->at(0), "punky", Action::ACTION_API_CALL, "brewster", |
215 "punky", | 202 "", "", "", "", 2); |
216 Action::ACTION_API_CALL, | 203 CheckAction(*actions->at(1), "punky", Action::ACTION_DOM_ACCESS, "lets", "", |
217 "brewster", | 204 "http://www.google.com/", "", "", 1); |
218 "", | 205 CheckAction(*actions->at(2), "punky", Action::ACTION_API_CALL, |
219 "", | 206 "extension.sendMessage", "[\"not\",\"stripped\"]", "", "", "", |
220 "", | |
221 "", | |
222 2); | |
223 CheckAction(*actions->at(1).get(), | |
224 "punky", | |
225 Action::ACTION_DOM_ACCESS, | |
226 "lets", | |
227 "", | |
228 "http://www.google.com/", | |
229 "", | |
230 "", | |
231 1); | |
232 CheckAction(*actions->at(2).get(), | |
233 "punky", | |
234 Action::ACTION_API_CALL, | |
235 "extension.sendMessage", | |
236 "[\"not\",\"stripped\"]", | |
237 "", | |
238 "", | |
239 "", | |
240 1); | 207 1); |
241 } | 208 } |
242 | 209 |
243 static void Arguments_GetOlderActions( | 210 static void Arguments_GetOlderActions( |
244 std::unique_ptr<Action::ActionVector> actions) { | 211 std::unique_ptr<Action::ActionVector> actions) { |
245 ASSERT_EQ(2, static_cast<int>(actions->size())); | 212 ASSERT_EQ(2, static_cast<int>(actions->size())); |
246 CheckAction(*actions->at(0).get(), | 213 CheckAction(*actions->at(0), "punky", Action::ACTION_DOM_ACCESS, "lets", "", |
247 "punky", | 214 "http://www.google.com/", "", "", 1); |
248 Action::ACTION_DOM_ACCESS, | 215 CheckAction(*actions->at(1), "punky", Action::ACTION_API_CALL, "brewster", |
249 "lets", | 216 "", "", "", "", 1); |
250 "", | |
251 "http://www.google.com/", | |
252 "", | |
253 "", | |
254 1); | |
255 CheckAction(*actions->at(1).get(), | |
256 "punky", | |
257 Action::ACTION_API_CALL, | |
258 "brewster", | |
259 "", | |
260 "", | |
261 "", | |
262 "", | |
263 1); | |
264 } | 217 } |
265 | 218 |
266 static void Arguments_CheckMergeCount( | 219 static void Arguments_CheckMergeCount( |
267 int count, | 220 int count, |
268 std::unique_ptr<Action::ActionVector> actions) { | 221 std::unique_ptr<Action::ActionVector> actions) { |
269 if (count > 0) { | 222 if (count > 0) { |
270 ASSERT_EQ(1u, actions->size()); | 223 ASSERT_EQ(1u, actions->size()); |
271 CheckAction(*actions->at(0).get(), | 224 CheckAction(*actions->at(0), "punky", Action::ACTION_API_CALL, "brewster", |
272 "punky", | 225 "", "", "", "", count); |
273 Action::ACTION_API_CALL, | |
274 "brewster", | |
275 "", | |
276 "", | |
277 "", | |
278 "", | |
279 count); | |
280 } else { | 226 } else { |
281 ASSERT_EQ(0u, actions->size()); | 227 ASSERT_EQ(0u, actions->size()); |
282 } | 228 } |
283 } | 229 } |
284 | 230 |
285 static void Arguments_CheckMergeCountAndTime( | 231 static void Arguments_CheckMergeCountAndTime( |
286 int count, | 232 int count, |
287 const base::Time& time, | 233 const base::Time& time, |
288 std::unique_ptr<Action::ActionVector> actions) { | 234 std::unique_ptr<Action::ActionVector> actions) { |
289 if (count > 0) { | 235 if (count > 0) { |
290 ASSERT_EQ(1u, actions->size()); | 236 ASSERT_EQ(1u, actions->size()); |
291 CheckAction(*actions->at(0).get(), | 237 CheckAction(*actions->at(0), "punky", Action::ACTION_API_CALL, "brewster", |
292 "punky", | 238 "", "", "", "", count); |
293 Action::ACTION_API_CALL, | |
294 "brewster", | |
295 "", | |
296 "", | |
297 "", | |
298 "", | |
299 count); | |
300 ASSERT_EQ(time, actions->at(0)->time()); | 239 ASSERT_EQ(time, actions->at(0)->time()); |
301 } else { | 240 } else { |
302 ASSERT_EQ(0u, actions->size()); | 241 ASSERT_EQ(0u, actions->size()); |
303 } | 242 } |
304 } | 243 } |
305 | 244 |
306 static void AllURLsRemoved(std::unique_ptr<Action::ActionVector> actions) { | 245 static void AllURLsRemoved(std::unique_ptr<Action::ActionVector> actions) { |
307 ASSERT_EQ(2, static_cast<int>(actions->size())); | 246 ASSERT_EQ(2, static_cast<int>(actions->size())); |
308 CheckAction(*actions->at(0).get(), | 247 CheckAction(*actions->at(0), "punky", Action::ACTION_DOM_ACCESS, "lets", "", |
309 "punky", | 248 "", "", "", 1); |
310 Action::ACTION_DOM_ACCESS, | 249 CheckAction(*actions->at(1), "punky", Action::ACTION_DOM_ACCESS, "lets", "", |
311 "lets", | 250 "", "", "", 1); |
312 "", | |
313 "", | |
314 "", | |
315 "", | |
316 1); | |
317 CheckAction(*actions->at(1).get(), | |
318 "punky", | |
319 Action::ACTION_DOM_ACCESS, | |
320 "lets", | |
321 "", | |
322 "", | |
323 "", | |
324 "", | |
325 1); | |
326 } | 251 } |
327 | 252 |
328 static void SomeURLsRemoved(std::unique_ptr<Action::ActionVector> actions) { | 253 static void SomeURLsRemoved(std::unique_ptr<Action::ActionVector> actions) { |
329 // These will be in the vector in reverse time order. | 254 // These will be in the vector in reverse time order. |
330 ASSERT_EQ(5, static_cast<int>(actions->size())); | 255 ASSERT_EQ(5, static_cast<int>(actions->size())); |
331 CheckAction(*actions->at(0).get(), | 256 CheckAction(*actions->at(0), "punky", Action::ACTION_DOM_ACCESS, "lets", "", |
332 "punky", | 257 "http://www.google.com/", "Google", "http://www.args-url.com/", |
333 Action::ACTION_DOM_ACCESS, | |
334 "lets", | |
335 "", | |
336 "http://www.google.com/", | |
337 "Google", | |
338 "http://www.args-url.com/", | |
339 1); | 258 1); |
340 CheckAction(*actions->at(1).get(), | 259 CheckAction(*actions->at(1), "punky", Action::ACTION_DOM_ACCESS, "lets", "", |
341 "punky", | 260 "http://www.google.com/", "Google", "", 1); |
342 Action::ACTION_DOM_ACCESS, | 261 CheckAction(*actions->at(2), "punky", Action::ACTION_DOM_ACCESS, "lets", "", |
343 "lets", | 262 "", "", "", 1); |
344 "", | 263 CheckAction(*actions->at(3), "punky", Action::ACTION_DOM_ACCESS, "lets", "", |
345 "http://www.google.com/", | 264 "", "", "http://www.google.com/", 1); |
346 "Google", | 265 CheckAction(*actions->at(4), "punky", Action::ACTION_DOM_ACCESS, "lets", "", |
347 "", | 266 "", "", "", 1); |
348 1); | |
349 CheckAction(*actions->at(2).get(), | |
350 "punky", | |
351 Action::ACTION_DOM_ACCESS, | |
352 "lets", | |
353 "", | |
354 "", | |
355 "", | |
356 "", | |
357 1); | |
358 CheckAction(*actions->at(3).get(), | |
359 "punky", | |
360 Action::ACTION_DOM_ACCESS, | |
361 "lets", | |
362 "", | |
363 "", | |
364 "", | |
365 "http://www.google.com/", | |
366 1); | |
367 CheckAction(*actions->at(4).get(), | |
368 "punky", | |
369 Action::ACTION_DOM_ACCESS, | |
370 "lets", | |
371 "", | |
372 "", | |
373 "", | |
374 "", | |
375 1); | |
376 } | 267 } |
377 | 268 |
378 static void CheckDuplicates(std::unique_ptr<Action::ActionVector> actions) { | 269 static void CheckDuplicates(std::unique_ptr<Action::ActionVector> actions) { |
379 ASSERT_EQ(2u, actions->size()); | 270 ASSERT_EQ(2u, actions->size()); |
380 int total_count = 0; | 271 int total_count = 0; |
381 for (size_t i = 0; i < actions->size(); i++) { | 272 for (size_t i = 0; i < actions->size(); i++) { |
382 total_count += actions->at(i)->count(); | 273 total_count += actions->at(i)->count(); |
383 } | 274 } |
384 ASSERT_EQ(3, total_count); | 275 ASSERT_EQ(3, total_count); |
385 } | 276 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 policy->DeleteDatabase(); | 350 policy->DeleteDatabase(); |
460 } | 351 } |
461 | 352 |
462 static void AllActionsDeleted(std::unique_ptr<Action::ActionVector> actions) { | 353 static void AllActionsDeleted(std::unique_ptr<Action::ActionVector> actions) { |
463 ASSERT_EQ(0, static_cast<int>(actions->size())); | 354 ASSERT_EQ(0, static_cast<int>(actions->size())); |
464 } | 355 } |
465 | 356 |
466 static void NoActionsDeleted(std::unique_ptr<Action::ActionVector> actions) { | 357 static void NoActionsDeleted(std::unique_ptr<Action::ActionVector> actions) { |
467 // These will be in the vector in reverse time order. | 358 // These will be in the vector in reverse time order. |
468 ASSERT_EQ(2, static_cast<int>(actions->size())); | 359 ASSERT_EQ(2, static_cast<int>(actions->size())); |
469 CheckAction(*actions->at(0).get(), | 360 CheckAction(*actions->at(0), "punky2", Action::ACTION_API_CALL, "lets2", "", |
470 "punky2", | 361 "http://www.google2.com/", "Google2", |
471 Action::ACTION_API_CALL, | 362 "http://www.args-url2.com/", 2); |
472 "lets2", | |
473 "", | |
474 "http://www.google2.com/", | |
475 "Google2", | |
476 "http://www.args-url2.com/", | |
477 2); | |
478 ASSERT_EQ(2, actions->at(0)->action_id()); | 363 ASSERT_EQ(2, actions->at(0)->action_id()); |
479 CheckAction(*actions->at(1).get(), | 364 CheckAction(*actions->at(1), "punky1", Action::ACTION_DOM_ACCESS, "lets1", |
480 "punky1", | 365 "", "http://www.google1.com/", "Google1", |
481 Action::ACTION_DOM_ACCESS, | 366 "http://www.args-url1.com/", 2); |
482 "lets1", | |
483 "", | |
484 "http://www.google1.com/", | |
485 "Google1", | |
486 "http://www.args-url1.com/", | |
487 2); | |
488 ASSERT_EQ(1, actions->at(1)->action_id()); | 367 ASSERT_EQ(1, actions->at(1)->action_id()); |
489 } | 368 } |
490 | 369 |
491 static void Action1Deleted(std::unique_ptr<Action::ActionVector> actions) { | 370 static void Action1Deleted(std::unique_ptr<Action::ActionVector> actions) { |
492 // These will be in the vector in reverse time order. | 371 // These will be in the vector in reverse time order. |
493 ASSERT_EQ(1, static_cast<int>(actions->size())); | 372 ASSERT_EQ(1, static_cast<int>(actions->size())); |
494 CheckAction(*actions->at(0).get(), | 373 CheckAction(*actions->at(0), "punky2", Action::ACTION_API_CALL, "lets2", "", |
495 "punky2", | 374 "http://www.google2.com/", "Google2", |
496 Action::ACTION_API_CALL, | 375 "http://www.args-url2.com/", 2); |
497 "lets2", | |
498 "", | |
499 "http://www.google2.com/", | |
500 "Google2", | |
501 "http://www.args-url2.com/", | |
502 2); | |
503 ASSERT_EQ(2, actions->at(0)->action_id()); | 376 ASSERT_EQ(2, actions->at(0)->action_id()); |
504 } | 377 } |
505 | 378 |
506 static void Action2Deleted(std::unique_ptr<Action::ActionVector> actions) { | 379 static void Action2Deleted(std::unique_ptr<Action::ActionVector> actions) { |
507 // These will be in the vector in reverse time order. | 380 // These will be in the vector in reverse time order. |
508 ASSERT_EQ(1, static_cast<int>(actions->size())); | 381 ASSERT_EQ(1, static_cast<int>(actions->size())); |
509 CheckAction(*actions->at(0).get(), | 382 CheckAction(*actions->at(0), "punky1", Action::ACTION_DOM_ACCESS, "lets1", |
510 "punky1", | 383 "", "http://www.google1.com/", "Google1", |
511 Action::ACTION_DOM_ACCESS, | 384 "http://www.args-url1.com/", 2); |
512 "lets1", | |
513 "", | |
514 "http://www.google1.com/", | |
515 "Google1", | |
516 "http://www.args-url1.com/", | |
517 2); | |
518 ASSERT_EQ(1, actions->at(0)->action_id()); | 385 ASSERT_EQ(1, actions->at(0)->action_id()); |
519 } | 386 } |
520 | 387 |
521 protected: | 388 protected: |
522 ExtensionService* extension_service_; | 389 ExtensionService* extension_service_; |
523 std::unique_ptr<TestingProfile> profile_; | 390 std::unique_ptr<TestingProfile> profile_; |
524 content::TestBrowserThreadBundle thread_bundle_; | 391 content::TestBrowserThreadBundle thread_bundle_; |
525 | 392 |
526 #if defined OS_CHROMEOS | 393 #if defined OS_CHROMEOS |
527 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 394 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1412 | 1279 |
1413 action_ids.push_back(2); | 1280 action_ids.push_back(2); |
1414 CheckRemoveActions( | 1281 CheckRemoveActions( |
1415 policy, action_ids, base::Bind(&CountingPolicyTest::Action2Deleted)); | 1282 policy, action_ids, base::Bind(&CountingPolicyTest::Action2Deleted)); |
1416 action_ids.clear(); | 1283 action_ids.clear(); |
1417 | 1284 |
1418 policy->Close(); | 1285 policy->Close(); |
1419 } | 1286 } |
1420 | 1287 |
1421 } // namespace extensions | 1288 } // namespace extensions |
OLD | NEW |