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/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
10 #include "base/test/simple_test_clock.h" | 10 #include "base/test/simple_test_clock.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 std::string api_print = | 134 std::string api_print = |
135 "ID=punky CATEGORY=api_call API=brewster ARGS=[\"woof\"]"; | 135 "ID=punky CATEGORY=api_call API=brewster ARGS=[\"woof\"]"; |
136 std::string dom_print = | 136 std::string dom_print = |
137 "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"] " | 137 "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"] " |
138 "PAGE_URL=http://www.google.com/"; | 138 "PAGE_URL=http://www.google.com/"; |
139 ASSERT_EQ(2, static_cast<int>(actions->size())); | 139 ASSERT_EQ(2, static_cast<int>(actions->size())); |
140 ASSERT_EQ(dom_print, actions->at(0)->PrintForDebug()); | 140 ASSERT_EQ(dom_print, actions->at(0)->PrintForDebug()); |
141 ASSERT_EQ(api_print, actions->at(1)->PrintForDebug()); | 141 ASSERT_EQ(api_print, actions->at(1)->PrintForDebug()); |
142 } | 142 } |
143 | 143 |
| 144 static void AllURLsRemoved(scoped_ptr<Action::ActionVector> actions) { |
| 145 std::string action_urls_cleared = |
| 146 "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"]"; |
| 147 ASSERT_EQ(2, static_cast<int>(actions->size())); |
| 148 ASSERT_EQ(action_urls_cleared, actions->at(0)->PrintForDebug()); |
| 149 ASSERT_EQ(action_urls_cleared, actions->at(1)->PrintForDebug()); |
| 150 } |
| 151 |
| 152 static void SomeURLsRemoved(scoped_ptr<Action::ActionVector> actions) { |
| 153 std::string action_urls_not_cleared = |
| 154 "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"] " |
| 155 "PAGE_URL=http://www.google.com/ PAGE_TITLE=\"Google\" " |
| 156 "ARG_URL=http://www.google.com/"; |
| 157 std::string action_urls_cleared = |
| 158 "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"]"; |
| 159 ASSERT_EQ(3, static_cast<int>(actions->size())); |
| 160 ASSERT_EQ(action_urls_cleared, actions->at(0)->PrintForDebug()); |
| 161 ASSERT_EQ(action_urls_cleared, actions->at(1)->PrintForDebug()); |
| 162 ASSERT_EQ(action_urls_not_cleared, actions->at(2)->PrintForDebug()); |
| 163 } |
| 164 |
144 protected: | 165 protected: |
145 ExtensionService* extension_service_; | 166 ExtensionService* extension_service_; |
146 scoped_ptr<TestingProfile> profile_; | 167 scoped_ptr<TestingProfile> profile_; |
147 content::TestBrowserThreadBundle thread_bundle_; | 168 content::TestBrowserThreadBundle thread_bundle_; |
148 // Used to preserve a copy of the original command line. | 169 // Used to preserve a copy of the original command line. |
149 // The test framework will do this itself as well. However, by then, | 170 // The test framework will do this itself as well. However, by then, |
150 // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in | 171 // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in |
151 // TearDown(). | 172 // TearDown(). |
152 CommandLine saved_cmdline_; | 173 CommandLine saved_cmdline_; |
153 | 174 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 action = | 289 action = |
269 new Action("punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); | 290 new Action("punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); |
270 action->mutable_args()->AppendString("vamoose"); | 291 action->mutable_args()->AppendString("vamoose"); |
271 action->set_page_url(GURL("http://www.google.com")); | 292 action->set_page_url(GURL("http://www.google.com")); |
272 policy->ProcessAction(action); | 293 policy->ProcessAction(action); |
273 | 294 |
274 action = new Action( | 295 action = new Action( |
275 "scoobydoo", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); | 296 "scoobydoo", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); |
276 action->mutable_args()->AppendString("vamoose"); | 297 action->mutable_args()->AppendString("vamoose"); |
277 action->set_page_url(GURL("http://www.google.com")); | 298 action->set_page_url(GURL("http://www.google.com")); |
| 299 action->set_arg_url(GURL("http://www.google2.com")); |
278 policy->ProcessAction(action); | 300 policy->ProcessAction(action); |
279 | 301 |
280 CheckReadData( | 302 CheckReadData( |
281 policy, | 303 policy, |
282 "punky", | 304 "punky", |
283 0, | 305 0, |
284 base::Bind(&FullStreamUIPolicyTest::Arguments_GetTodaysActions)); | 306 base::Bind(&FullStreamUIPolicyTest::Arguments_GetTodaysActions)); |
285 policy->Close(); | 307 policy->Close(); |
286 } | 308 } |
287 | 309 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 policy->ProcessAction(action); | 353 policy->ProcessAction(action); |
332 | 354 |
333 CheckReadData( | 355 CheckReadData( |
334 policy, | 356 policy, |
335 "punky", | 357 "punky", |
336 3, | 358 3, |
337 base::Bind(&FullStreamUIPolicyTest::Arguments_GetOlderActions)); | 359 base::Bind(&FullStreamUIPolicyTest::Arguments_GetOlderActions)); |
338 policy->Close(); | 360 policy->Close(); |
339 } | 361 } |
340 | 362 |
| 363 TEST_F(FullStreamUIPolicyTest, RemoveAllURLs) { |
| 364 ActivityLogPolicy* policy = new FullStreamUIPolicy(profile_.get()); |
| 365 |
| 366 // Use a mock clock to ensure that events are not recorded on the wrong day |
| 367 // when the test is run close to local midnight. |
| 368 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); |
| 369 mock_clock->SetNow(base::Time::Now().LocalMidnight() + |
| 370 base::TimeDelta::FromHours(12)); |
| 371 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock)); |
| 372 |
| 373 // Record some actions |
| 374 scoped_refptr<Action> action = |
| 375 new Action("punky", mock_clock->Now(), |
| 376 Action::ACTION_DOM_ACCESS, "lets"); |
| 377 action->mutable_args()->AppendString("vamoose"); |
| 378 action->set_page_url(GURL("http://www.google.com")); |
| 379 action->set_page_title("Google"); |
| 380 action->set_arg_url(GURL("http://www.google.com")); |
| 381 policy->ProcessAction(action); |
| 382 |
| 383 action = new Action( |
| 384 "punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); |
| 385 action->mutable_args()->AppendString("vamoose"); |
| 386 action->set_page_url(GURL("http://www.google2.com")); |
| 387 action->set_page_title("Google"); |
| 388 action->set_arg_url(GURL("http://www.google2.com")); |
| 389 policy->ProcessAction(action); |
| 390 |
| 391 // Clean all the URLs. |
| 392 std::vector<GURL> no_url_restrictions; |
| 393 policy->RemoveURLs(no_url_restrictions); |
| 394 |
| 395 CheckReadData( |
| 396 policy, |
| 397 "punky", |
| 398 0, |
| 399 base::Bind(&FullStreamUIPolicyTest::AllURLsRemoved)); |
| 400 policy->Close(); |
| 401 } |
| 402 |
| 403 TEST_F(FullStreamUIPolicyTest, RemoveSpecificURLs) { |
| 404 ActivityLogPolicy* policy = new FullStreamUIPolicy(profile_.get()); |
| 405 |
| 406 // Use a mock clock to ensure that events are not recorded on the wrong day |
| 407 // when the test is run close to local midnight. |
| 408 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); |
| 409 mock_clock->SetNow(base::Time::Now().LocalMidnight() + |
| 410 base::TimeDelta::FromHours(12)); |
| 411 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock)); |
| 412 |
| 413 // Record some actions |
| 414 scoped_refptr<Action> action = |
| 415 new Action("punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); |
| 416 action->mutable_args()->AppendString("vamoose"); |
| 417 action->set_page_url(GURL("http://www.google1.com")); |
| 418 action->set_page_title("Google"); |
| 419 action->set_arg_url(GURL("http://www.google.com")); |
| 420 policy->ProcessAction(action); |
| 421 |
| 422 action = new Action( |
| 423 "punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); |
| 424 action->mutable_args()->AppendString("vamoose"); |
| 425 action->set_page_url(GURL("http://www.google2.com")); |
| 426 action->set_page_title("Google"); |
| 427 policy->ProcessAction(action); |
| 428 |
| 429 action = new Action( |
| 430 "punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); |
| 431 action->mutable_args()->AppendString("vamoose"); |
| 432 action->set_page_url(GURL("http://www.google.com")); |
| 433 action->set_page_title("Google"); |
| 434 action->set_arg_url(GURL("http://www.google.com")); |
| 435 policy->ProcessAction(action); |
| 436 |
| 437 // Clean some URLs. |
| 438 std::vector<GURL> urls; |
| 439 urls.push_back(GURL("http://www.google1.com")); |
| 440 urls.push_back(GURL("http://www.google2.com")); |
| 441 urls.push_back(GURL("http://www.url_not_in_db.com")); |
| 442 policy->RemoveURLs(urls); |
| 443 |
| 444 CheckReadData( |
| 445 policy, |
| 446 "punky", |
| 447 0, |
| 448 base::Bind(&FullStreamUIPolicyTest::SomeURLsRemoved)); |
| 449 policy->Close(); |
| 450 } |
| 451 |
341 } // namespace extensions | 452 } // namespace extensions |
OLD | NEW |