| 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 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 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 180 scoped_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(scoped_ptr<Action::ActionVector> i) { | 184 static void Arguments_Stripped(scoped_ptr<Action::ActionVector> i) { |
| 185 scoped_refptr<Action> last = i->front(); | 185 scoped_refptr<Action> last = i->front(); |
| 186 CheckAction(*last, "odlameecjipmbmbejkplpemijjgpljce", | 186 CheckAction(*last.get(), |
| 187 Action::ACTION_API_CALL, "extension.connect", | 187 "odlameecjipmbmbejkplpemijjgpljce", |
| 188 "[\"hello\",\"world\"]", "", "", "", 1); | 188 Action::ACTION_API_CALL, |
| 189 "extension.connect", |
| 190 "[\"hello\",\"world\"]", |
| 191 "", |
| 192 "", |
| 193 "", |
| 194 1); |
| 189 } | 195 } |
| 190 | 196 |
| 191 static void Arguments_GetSinglesAction( | 197 static void Arguments_GetSinglesAction( |
| 192 scoped_ptr<Action::ActionVector> actions) { | 198 scoped_ptr<Action::ActionVector> actions) { |
| 193 ASSERT_EQ(1, static_cast<int>(actions->size())); | 199 ASSERT_EQ(1, static_cast<int>(actions->size())); |
| 194 CheckAction(*actions->at(0), "punky", Action::ACTION_DOM_ACCESS, "lets", | 200 CheckAction(*actions->at(0).get(), |
| 195 "", "http://www.google.com/", "", "", 1); | 201 "punky", |
| 202 Action::ACTION_DOM_ACCESS, |
| 203 "lets", |
| 204 "", |
| 205 "http://www.google.com/", |
| 206 "", |
| 207 "", |
| 208 1); |
| 196 } | 209 } |
| 197 | 210 |
| 198 static void Arguments_GetTodaysActions( | 211 static void Arguments_GetTodaysActions( |
| 199 scoped_ptr<Action::ActionVector> actions) { | 212 scoped_ptr<Action::ActionVector> actions) { |
| 200 ASSERT_EQ(3, static_cast<int>(actions->size())); | 213 ASSERT_EQ(3, static_cast<int>(actions->size())); |
| 201 CheckAction(*actions->at(0), "punky", Action::ACTION_API_CALL, "brewster", | 214 CheckAction(*actions->at(0).get(), |
| 202 "", "", "", "", 2); | 215 "punky", |
| 203 CheckAction(*actions->at(1), "punky", Action::ACTION_DOM_ACCESS, "lets", | 216 Action::ACTION_API_CALL, |
| 204 "", "http://www.google.com/", "", "", 1); | 217 "brewster", |
| 205 CheckAction(*actions->at(2), "punky", Action::ACTION_API_CALL, | 218 "", |
| 206 "extension.sendMessage", "[\"not\",\"stripped\"]", "", "", "", | 219 "", |
| 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 "", |
| 207 1); | 240 1); |
| 208 } | 241 } |
| 209 | 242 |
| 210 static void Arguments_GetOlderActions( | 243 static void Arguments_GetOlderActions( |
| 211 scoped_ptr<Action::ActionVector> actions) { | 244 scoped_ptr<Action::ActionVector> actions) { |
| 212 ASSERT_EQ(2, static_cast<int>(actions->size())); | 245 ASSERT_EQ(2, static_cast<int>(actions->size())); |
| 213 CheckAction(*actions->at(0), "punky", Action::ACTION_DOM_ACCESS, "lets", | 246 CheckAction(*actions->at(0).get(), |
| 214 "", "http://www.google.com/", "", "", 1); | 247 "punky", |
| 215 CheckAction(*actions->at(1), "punky", Action::ACTION_API_CALL, "brewster", | 248 Action::ACTION_DOM_ACCESS, |
| 216 "", "", "", "", 1); | 249 "lets", |
| 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); |
| 217 } | 264 } |
| 218 | 265 |
| 219 static void Arguments_CheckMergeCount( | 266 static void Arguments_CheckMergeCount( |
| 220 int count, | 267 int count, |
| 221 scoped_ptr<Action::ActionVector> actions) { | 268 scoped_ptr<Action::ActionVector> actions) { |
| 222 if (count > 0) { | 269 if (count > 0) { |
| 223 ASSERT_EQ(1u, actions->size()); | 270 ASSERT_EQ(1u, actions->size()); |
| 224 CheckAction(*actions->at(0), "punky", Action::ACTION_API_CALL, "brewster", | 271 CheckAction(*actions->at(0).get(), |
| 225 "", "", "", "", count); | 272 "punky", |
| 273 Action::ACTION_API_CALL, |
| 274 "brewster", |
| 275 "", |
| 276 "", |
| 277 "", |
| 278 "", |
| 279 count); |
| 226 } else { | 280 } else { |
| 227 ASSERT_EQ(0u, actions->size()); | 281 ASSERT_EQ(0u, actions->size()); |
| 228 } | 282 } |
| 229 } | 283 } |
| 230 | 284 |
| 231 static void Arguments_CheckMergeCountAndTime( | 285 static void Arguments_CheckMergeCountAndTime( |
| 232 int count, | 286 int count, |
| 233 const base::Time& time, | 287 const base::Time& time, |
| 234 scoped_ptr<Action::ActionVector> actions) { | 288 scoped_ptr<Action::ActionVector> actions) { |
| 235 if (count > 0) { | 289 if (count > 0) { |
| 236 ASSERT_EQ(1u, actions->size()); | 290 ASSERT_EQ(1u, actions->size()); |
| 237 CheckAction(*actions->at(0), "punky", Action::ACTION_API_CALL, "brewster", | 291 CheckAction(*actions->at(0).get(), |
| 238 "", "", "", "", count); | 292 "punky", |
| 293 Action::ACTION_API_CALL, |
| 294 "brewster", |
| 295 "", |
| 296 "", |
| 297 "", |
| 298 "", |
| 299 count); |
| 239 ASSERT_EQ(time, actions->at(0)->time()); | 300 ASSERT_EQ(time, actions->at(0)->time()); |
| 240 } else { | 301 } else { |
| 241 ASSERT_EQ(0u, actions->size()); | 302 ASSERT_EQ(0u, actions->size()); |
| 242 } | 303 } |
| 243 } | 304 } |
| 244 | 305 |
| 245 static void AllURLsRemoved(scoped_ptr<Action::ActionVector> actions) { | 306 static void AllURLsRemoved(scoped_ptr<Action::ActionVector> actions) { |
| 246 ASSERT_EQ(2, static_cast<int>(actions->size())); | 307 ASSERT_EQ(2, static_cast<int>(actions->size())); |
| 247 CheckAction(*actions->at(0), "punky", Action::ACTION_DOM_ACCESS, "lets", | 308 CheckAction(*actions->at(0).get(), |
| 248 "", "", "", "", 1); | 309 "punky", |
| 249 CheckAction(*actions->at(1), "punky", Action::ACTION_DOM_ACCESS, "lets", | 310 Action::ACTION_DOM_ACCESS, |
| 250 "", "", "", "", 1); | 311 "lets", |
| 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); |
| 251 } | 326 } |
| 252 | 327 |
| 253 static void SomeURLsRemoved(scoped_ptr<Action::ActionVector> actions) { | 328 static void SomeURLsRemoved(scoped_ptr<Action::ActionVector> actions) { |
| 254 // These will be in the vector in reverse time order. | 329 // These will be in the vector in reverse time order. |
| 255 ASSERT_EQ(5, static_cast<int>(actions->size())); | 330 ASSERT_EQ(5, static_cast<int>(actions->size())); |
| 256 CheckAction(*actions->at(0), "punky", Action::ACTION_DOM_ACCESS, "lets", | 331 CheckAction(*actions->at(0).get(), |
| 257 "", "http://www.google.com/", "Google", | 332 "punky", |
| 258 "http://www.args-url.com/", 1); | 333 Action::ACTION_DOM_ACCESS, |
| 259 CheckAction(*actions->at(1), "punky", Action::ACTION_DOM_ACCESS, "lets", | 334 "lets", |
| 260 "", "http://www.google.com/", "Google", "", 1); | 335 "", |
| 261 CheckAction(*actions->at(2), "punky", Action::ACTION_DOM_ACCESS, "lets", | 336 "http://www.google.com/", |
| 262 "", "", "", "", 1); | 337 "Google", |
| 263 CheckAction(*actions->at(3), "punky", Action::ACTION_DOM_ACCESS, "lets", | 338 "http://www.args-url.com/", |
| 264 "", "", "", "http://www.google.com/", 1); | 339 1); |
| 265 CheckAction(*actions->at(4), "punky", Action::ACTION_DOM_ACCESS, "lets", | 340 CheckAction(*actions->at(1).get(), |
| 266 "", "", "", "", 1); | 341 "punky", |
| 342 Action::ACTION_DOM_ACCESS, |
| 343 "lets", |
| 344 "", |
| 345 "http://www.google.com/", |
| 346 "Google", |
| 347 "", |
| 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); |
| 267 } | 376 } |
| 268 | 377 |
| 269 static void CheckDuplicates(scoped_ptr<Action::ActionVector> actions) { | 378 static void CheckDuplicates(scoped_ptr<Action::ActionVector> actions) { |
| 270 ASSERT_EQ(2u, actions->size()); | 379 ASSERT_EQ(2u, actions->size()); |
| 271 int total_count = 0; | 380 int total_count = 0; |
| 272 for (size_t i = 0; i < actions->size(); i++) { | 381 for (size_t i = 0; i < actions->size(); i++) { |
| 273 total_count += actions->at(i)->count(); | 382 total_count += actions->at(i)->count(); |
| 274 } | 383 } |
| 275 ASSERT_EQ(3, total_count); | 384 ASSERT_EQ(3, total_count); |
| 276 } | 385 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 policy->DeleteDatabase(); | 459 policy->DeleteDatabase(); |
| 351 } | 460 } |
| 352 | 461 |
| 353 static void AllActionsDeleted(scoped_ptr<Action::ActionVector> actions) { | 462 static void AllActionsDeleted(scoped_ptr<Action::ActionVector> actions) { |
| 354 ASSERT_EQ(0, static_cast<int>(actions->size())); | 463 ASSERT_EQ(0, static_cast<int>(actions->size())); |
| 355 } | 464 } |
| 356 | 465 |
| 357 static void NoActionsDeleted(scoped_ptr<Action::ActionVector> actions) { | 466 static void NoActionsDeleted(scoped_ptr<Action::ActionVector> actions) { |
| 358 // These will be in the vector in reverse time order. | 467 // These will be in the vector in reverse time order. |
| 359 ASSERT_EQ(2, static_cast<int>(actions->size())); | 468 ASSERT_EQ(2, static_cast<int>(actions->size())); |
| 360 CheckAction(*actions->at(0), | 469 CheckAction(*actions->at(0).get(), |
| 361 "punky2", | 470 "punky2", |
| 362 Action::ACTION_API_CALL, | 471 Action::ACTION_API_CALL, |
| 363 "lets2", | 472 "lets2", |
| 364 "", | 473 "", |
| 365 "http://www.google2.com/", | 474 "http://www.google2.com/", |
| 366 "Google2", | 475 "Google2", |
| 367 "http://www.args-url2.com/", | 476 "http://www.args-url2.com/", |
| 368 2); | 477 2); |
| 369 ASSERT_EQ(2, actions->at(0)->action_id()); | 478 ASSERT_EQ(2, actions->at(0)->action_id()); |
| 370 CheckAction(*actions->at(1), | 479 CheckAction(*actions->at(1).get(), |
| 371 "punky1", | 480 "punky1", |
| 372 Action::ACTION_DOM_ACCESS, | 481 Action::ACTION_DOM_ACCESS, |
| 373 "lets1", | 482 "lets1", |
| 374 "", | 483 "", |
| 375 "http://www.google1.com/", | 484 "http://www.google1.com/", |
| 376 "Google1", | 485 "Google1", |
| 377 "http://www.args-url1.com/", | 486 "http://www.args-url1.com/", |
| 378 2); | 487 2); |
| 379 ASSERT_EQ(1, actions->at(1)->action_id()); | 488 ASSERT_EQ(1, actions->at(1)->action_id()); |
| 380 } | 489 } |
| 381 | 490 |
| 382 static void Action1Deleted(scoped_ptr<Action::ActionVector> actions) { | 491 static void Action1Deleted(scoped_ptr<Action::ActionVector> actions) { |
| 383 // These will be in the vector in reverse time order. | 492 // These will be in the vector in reverse time order. |
| 384 ASSERT_EQ(1, static_cast<int>(actions->size())); | 493 ASSERT_EQ(1, static_cast<int>(actions->size())); |
| 385 CheckAction(*actions->at(0), | 494 CheckAction(*actions->at(0).get(), |
| 386 "punky2", | 495 "punky2", |
| 387 Action::ACTION_API_CALL, | 496 Action::ACTION_API_CALL, |
| 388 "lets2", | 497 "lets2", |
| 389 "", | 498 "", |
| 390 "http://www.google2.com/", | 499 "http://www.google2.com/", |
| 391 "Google2", | 500 "Google2", |
| 392 "http://www.args-url2.com/", | 501 "http://www.args-url2.com/", |
| 393 2); | 502 2); |
| 394 ASSERT_EQ(2, actions->at(0)->action_id()); | 503 ASSERT_EQ(2, actions->at(0)->action_id()); |
| 395 } | 504 } |
| 396 | 505 |
| 397 static void Action2Deleted(scoped_ptr<Action::ActionVector> actions) { | 506 static void Action2Deleted(scoped_ptr<Action::ActionVector> actions) { |
| 398 // These will be in the vector in reverse time order. | 507 // These will be in the vector in reverse time order. |
| 399 ASSERT_EQ(1, static_cast<int>(actions->size())); | 508 ASSERT_EQ(1, static_cast<int>(actions->size())); |
| 400 CheckAction(*actions->at(0), | 509 CheckAction(*actions->at(0).get(), |
| 401 "punky1", | 510 "punky1", |
| 402 Action::ACTION_DOM_ACCESS, | 511 Action::ACTION_DOM_ACCESS, |
| 403 "lets1", | 512 "lets1", |
| 404 "", | 513 "", |
| 405 "http://www.google1.com/", | 514 "http://www.google1.com/", |
| 406 "Google1", | 515 "Google1", |
| 407 "http://www.args-url1.com/", | 516 "http://www.args-url1.com/", |
| 408 2); | 517 2); |
| 409 ASSERT_EQ(1, actions->at(0)->action_id()); | 518 ASSERT_EQ(1, actions->at(0)->action_id()); |
| 410 } | 519 } |
| (...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1305 | 1414 |
| 1306 action_ids.push_back(2); | 1415 action_ids.push_back(2); |
| 1307 CheckRemoveActions( | 1416 CheckRemoveActions( |
| 1308 policy, action_ids, base::Bind(&CountingPolicyTest::Action2Deleted)); | 1417 policy, action_ids, base::Bind(&CountingPolicyTest::Action2Deleted)); |
| 1309 action_ids.clear(); | 1418 action_ids.clear(); |
| 1310 | 1419 |
| 1311 policy->Close(); | 1420 policy->Close(); |
| 1312 } | 1421 } |
| 1313 | 1422 |
| 1314 } // namespace extensions | 1423 } // namespace extensions |
| OLD | NEW |