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/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 #if defined OS_CHROMEOS | 54 #if defined OS_CHROMEOS |
55 test_user_manager_.reset(); | 55 test_user_manager_.reset(); |
56 #endif | 56 #endif |
57 base::RunLoop().RunUntilIdle(); | 57 base::RunLoop().RunUntilIdle(); |
58 profile_.reset(NULL); | 58 profile_.reset(NULL); |
59 base::RunLoop().RunUntilIdle(); | 59 base::RunLoop().RunUntilIdle(); |
60 // Restore the original command line and undo the affects of SetUp(). | 60 // Restore the original command line and undo the affects of SetUp(). |
61 *CommandLine::ForCurrentProcess() = saved_cmdline_; | 61 *CommandLine::ForCurrentProcess() = saved_cmdline_; |
62 } | 62 } |
63 | 63 |
64 // A helper function to call ReadData on a policy object and wait for the | 64 // A wrapper function for CheckReadFilteredData, so that we don't need to |
65 // results to be processed. | 65 // enter empty string values for parameters we don't care about. |
66 void CheckReadData( | 66 void CheckReadData( |
67 ActivityLogPolicy* policy, | 67 ActivityLogPolicy* policy, |
68 const std::string& extension_id, | 68 const std::string& extension_id, |
69 const int day, | 69 int day, |
70 const base::Callback<void(scoped_ptr<Action::ActionVector>)>& checker) { | 70 const base::Callback<void(scoped_ptr<Action::ActionVector>)>& checker) { |
71 // Submit a request to the policy to read back some data, and call the | 71 CheckReadFilteredData( |
72 // checker function when results are available. This will happen on the | 72 policy, extension_id, Action::ACTION_ANY, "", "", "", day, checker); |
73 // database thread. | |
74 policy->ReadData( | |
75 extension_id, | |
76 day, | |
77 base::Bind(&FullStreamUIPolicyTest::CheckWrapper, | |
78 checker, | |
79 base::MessageLoop::current()->QuitClosure())); | |
80 | |
81 // Set up a timeout that will trigger after 5 seconds; if we haven't | |
82 // received any results by then assume that the test is broken. | |
83 base::CancelableClosure timeout( | |
84 base::Bind(&FullStreamUIPolicyTest::TimeoutCallback)); | |
85 base::MessageLoop::current()->PostDelayedTask( | |
86 FROM_HERE, timeout.callback(), base::TimeDelta::FromSeconds(8)); | |
87 | |
88 // Wait for results; either the checker or the timeout callbacks should | |
89 // cause the main loop to exit. | |
90 base::MessageLoop::current()->Run(); | |
91 | |
92 timeout.Cancel(); | |
93 } | 73 } |
94 | 74 |
95 // A helper function to call ReadFilteredData on a policy object and wait for | 75 // A helper function to call ReadFilteredData on a policy object and wait for |
96 // the results to be processed. | 76 // the results to be processed. |
97 void CheckReadFilteredData( | 77 void CheckReadFilteredData( |
98 ActivityLogPolicy* policy, | 78 ActivityLogPolicy* policy, |
99 const std::string& extension_id, | 79 const std::string& extension_id, |
100 const Action::ActionType type, | 80 const Action::ActionType type, |
101 const std::string& api_name, | 81 const std::string& api_name, |
102 const std::string& page_url, | 82 const std::string& page_url, |
103 const std::string& arg_url, | 83 const std::string& arg_url, |
| 84 const int days_ago, |
104 const base::Callback<void(scoped_ptr<Action::ActionVector>)>& checker) { | 85 const base::Callback<void(scoped_ptr<Action::ActionVector>)>& checker) { |
105 // Submit a request to the policy to read back some data, and call the | 86 // Submit a request to the policy to read back some data, and call the |
106 // checker function when results are available. This will happen on the | 87 // checker function when results are available. This will happen on the |
107 // database thread. | 88 // database thread. |
108 policy->ReadFilteredData( | 89 policy->ReadFilteredData( |
109 extension_id, | 90 extension_id, |
110 type, | 91 type, |
111 api_name, | 92 api_name, |
112 page_url, | 93 page_url, |
113 arg_url, | 94 arg_url, |
| 95 days_ago, |
114 base::Bind(&FullStreamUIPolicyTest::CheckWrapper, | 96 base::Bind(&FullStreamUIPolicyTest::CheckWrapper, |
115 checker, | 97 checker, |
116 base::MessageLoop::current()->QuitClosure())); | 98 base::MessageLoop::current()->QuitClosure())); |
117 | 99 |
118 // Set up a timeout that will trigger after 8 seconds; if we haven't | 100 // Set up a timeout that will trigger after 8 seconds; if we haven't |
119 // received any results by then assume that the test is broken. | 101 // received any results by then assume that the test is broken. |
120 base::CancelableClosure timeout( | 102 base::CancelableClosure timeout( |
121 base::Bind(&FullStreamUIPolicyTest::TimeoutCallback)); | 103 base::Bind(&FullStreamUIPolicyTest::TimeoutCallback)); |
122 base::MessageLoop::current()->PostDelayedTask( | 104 base::MessageLoop::current()->PostDelayedTask( |
123 FROM_HERE, timeout.callback(), base::TimeDelta::FromSeconds(8)); | 105 FROM_HERE, timeout.callback(), base::TimeDelta::FromSeconds(8)); |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 action_dom->set_page_url(gurl); | 319 action_dom->set_page_url(gurl); |
338 policy->ProcessAction(action_dom); | 320 policy->ProcessAction(action_dom); |
339 | 321 |
340 CheckReadFilteredData( | 322 CheckReadFilteredData( |
341 policy, | 323 policy, |
342 extension->id(), | 324 extension->id(), |
343 Action::ACTION_API_CALL, | 325 Action::ACTION_API_CALL, |
344 "tabs.testMethod", | 326 "tabs.testMethod", |
345 "", | 327 "", |
346 "", | 328 "", |
| 329 -1, |
347 base::Bind( | 330 base::Bind( |
348 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions1)); | 331 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions1)); |
349 | 332 |
350 CheckReadFilteredData( | 333 CheckReadFilteredData( |
351 policy, | 334 policy, |
352 "", | 335 "", |
353 Action::ACTION_DOM_ACCESS, | 336 Action::ACTION_DOM_ACCESS, |
354 "", | 337 "", |
355 "", | 338 "", |
356 "", | 339 "", |
| 340 -1, |
357 base::Bind( | 341 base::Bind( |
358 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions1)); | 342 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions1)); |
359 | 343 |
360 CheckReadFilteredData( | 344 CheckReadFilteredData( |
361 policy, | 345 policy, |
362 "", | 346 "", |
363 Action::ACTION_DOM_ACCESS, | 347 Action::ACTION_DOM_ACCESS, |
364 "", | 348 "", |
365 "http://www.google.com/", | 349 "http://www.google.com/", |
366 "", | 350 "", |
| 351 -1, |
367 base::Bind( | 352 base::Bind( |
368 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions1)); | 353 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions1)); |
369 | 354 |
370 CheckReadFilteredData( | 355 CheckReadFilteredData( |
371 policy, | 356 policy, |
372 "", | 357 "", |
373 Action::ACTION_DOM_ACCESS, | 358 Action::ACTION_DOM_ACCESS, |
374 "", | 359 "", |
375 "http://www.google.com", | 360 "http://www.google.com", |
376 "", | 361 "", |
| 362 -1, |
377 base::Bind( | 363 base::Bind( |
378 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions1)); | 364 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions1)); |
379 | 365 |
380 CheckReadFilteredData( | 366 CheckReadFilteredData( |
381 policy, | 367 policy, |
382 "", | 368 "", |
383 Action::ACTION_DOM_ACCESS, | 369 Action::ACTION_DOM_ACCESS, |
384 "", | 370 "", |
385 "http://www.goo", | 371 "http://www.goo", |
386 "", | 372 "", |
| 373 -1, |
387 base::Bind( | 374 base::Bind( |
388 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions1)); | 375 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions1)); |
389 | 376 |
390 CheckReadFilteredData( | 377 CheckReadFilteredData( |
391 policy, | 378 policy, |
392 extension->id(), | 379 extension->id(), |
393 Action::ACTION_ANY, | 380 Action::ACTION_ANY, |
394 "", | 381 "", |
395 "", | 382 "", |
396 "", | 383 "", |
| 384 -1, |
397 base::Bind( | 385 base::Bind( |
398 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions2)); | 386 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions2)); |
399 | 387 |
400 policy->Close(); | 388 policy->Close(); |
401 } | 389 } |
402 | 390 |
403 TEST_F(FullStreamUIPolicyTest, LogWithArguments) { | 391 TEST_F(FullStreamUIPolicyTest, LogWithArguments) { |
404 ActivityLogPolicy* policy = new FullStreamUIPolicy(profile_.get()); | 392 ActivityLogPolicy* policy = new FullStreamUIPolicy(profile_.get()); |
405 scoped_refptr<const Extension> extension = | 393 scoped_refptr<const Extension> extension = |
406 ExtensionBuilder() | 394 ExtensionBuilder() |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 base::MessageLoop::current()->QuitClosure()); | 653 base::MessageLoop::current()->QuitClosure()); |
666 base::MessageLoop::current()->Run(); | 654 base::MessageLoop::current()->Run(); |
667 | 655 |
668 CheckReadFilteredData( | 656 CheckReadFilteredData( |
669 policy, | 657 policy, |
670 "punky", | 658 "punky", |
671 Action::ACTION_ANY, | 659 Action::ACTION_ANY, |
672 "", | 660 "", |
673 "", | 661 "", |
674 "", | 662 "", |
| 663 -1, |
675 base::Bind( | 664 base::Bind( |
676 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions300)); | 665 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions300)); |
677 policy->Close(); | 666 policy->Close(); |
678 } | 667 } |
679 | 668 |
680 TEST_F(FullStreamUIPolicyTest, DeleteActions) { | 669 TEST_F(FullStreamUIPolicyTest, DeleteActions) { |
681 ActivityLogPolicy* policy = new FullStreamUIPolicy(profile_.get()); | 670 ActivityLogPolicy* policy = new FullStreamUIPolicy(profile_.get()); |
682 scoped_refptr<const Extension> extension = | 671 scoped_refptr<const Extension> extension = |
683 ExtensionBuilder() | 672 ExtensionBuilder() |
684 .SetManifest(DictionaryBuilder() | 673 .SetManifest(DictionaryBuilder() |
(...skipping 29 matching lines...) Expand all Loading... |
714 // Now delete them. | 703 // Now delete them. |
715 policy->DeleteDatabase(); | 704 policy->DeleteDatabase(); |
716 | 705 |
717 CheckReadFilteredData( | 706 CheckReadFilteredData( |
718 policy, | 707 policy, |
719 "", | 708 "", |
720 Action::ACTION_ANY, | 709 Action::ACTION_ANY, |
721 "", | 710 "", |
722 "", | 711 "", |
723 "", | 712 "", |
| 713 -1, |
724 base::Bind( | 714 base::Bind( |
725 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions0)); | 715 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions0)); |
726 | 716 |
727 policy->Close(); | 717 policy->Close(); |
728 } | 718 } |
729 | 719 |
730 } // namespace extensions | 720 } // namespace extensions |
OLD | NEW |