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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 CheckAction(*actions->at(1), "punky", Action::ACTION_DOM_ACCESS, "lets", | 267 CheckAction(*actions->at(1), "punky", Action::ACTION_DOM_ACCESS, "lets", |
268 "[\"vamoose\"]", "http://www.google.com/", "Google", "", 1); | 268 "[\"vamoose\"]", "http://www.google.com/", "Google", "", 1); |
269 CheckAction(*actions->at(2), "punky", Action::ACTION_DOM_ACCESS, "lets", | 269 CheckAction(*actions->at(2), "punky", Action::ACTION_DOM_ACCESS, "lets", |
270 "[\"vamoose\"]", "", "", "", 1); | 270 "[\"vamoose\"]", "", "", "", 1); |
271 CheckAction(*actions->at(3), "punky", Action::ACTION_DOM_ACCESS, "lets", | 271 CheckAction(*actions->at(3), "punky", Action::ACTION_DOM_ACCESS, "lets", |
272 "[\"vamoose\"]", "", "", "http://www.google.com/", 1); | 272 "[\"vamoose\"]", "", "", "http://www.google.com/", 1); |
273 CheckAction(*actions->at(4), "punky", Action::ACTION_DOM_ACCESS, "lets", | 273 CheckAction(*actions->at(4), "punky", Action::ACTION_DOM_ACCESS, "lets", |
274 "[\"vamoose\"]", "", "", "", 1); | 274 "[\"vamoose\"]", "", "", "", 1); |
275 } | 275 } |
276 | 276 |
| 277 static void CheckDuplicates(scoped_ptr<Action::ActionVector> actions) { |
| 278 ASSERT_EQ(2u, actions->size()); |
| 279 int total_count = 0; |
| 280 for (size_t i = 0; i < actions->size(); i++) { |
| 281 total_count += actions->at(i)->count(); |
| 282 } |
| 283 ASSERT_EQ(3, total_count); |
| 284 } |
| 285 |
277 static void CheckAction(const Action& action, | 286 static void CheckAction(const Action& action, |
278 const std::string& expected_id, | 287 const std::string& expected_id, |
279 const Action::ActionType& expected_type, | 288 const Action::ActionType& expected_type, |
280 const std::string& expected_api_name, | 289 const std::string& expected_api_name, |
281 const std::string& expected_args_str, | 290 const std::string& expected_args_str, |
282 const std::string& expected_page_url, | 291 const std::string& expected_page_url, |
283 const std::string& expected_page_title, | 292 const std::string& expected_page_title, |
284 const std::string& expected_arg_url, | 293 const std::string& expected_arg_url, |
285 int expected_count) { | 294 int expected_count) { |
286 ASSERT_EQ(expected_id, action.extension_id()); | 295 ASSERT_EQ(expected_id, action.extension_id()); |
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 Action::ACTION_ANY, | 1002 Action::ACTION_ANY, |
994 "", | 1003 "", |
995 "", | 1004 "", |
996 "", | 1005 "", |
997 base::Bind( | 1006 base::Bind( |
998 &CountingPolicyTest::RetrieveActions_FetchFilteredActions0)); | 1007 &CountingPolicyTest::RetrieveActions_FetchFilteredActions0)); |
999 | 1008 |
1000 policy->Close(); | 1009 policy->Close(); |
1001 } | 1010 } |
1002 | 1011 |
| 1012 // Tests that duplicate rows in the activity log database are handled properly |
| 1013 // when updating counts. |
| 1014 TEST_F(CountingPolicyTest, DuplicateRows) { |
| 1015 CountingPolicy* policy = new CountingPolicy(profile_.get()); |
| 1016 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); |
| 1017 mock_clock->SetNow(base::Time::Now().LocalMidnight() + |
| 1018 base::TimeDelta::FromHours(12)); |
| 1019 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock)); |
| 1020 |
| 1021 // Record two actions with distinct URLs. |
| 1022 scoped_refptr<Action> action; |
| 1023 action = new Action( |
| 1024 "punky", mock_clock->Now(), Action::ACTION_API_CALL, "brewster"); |
| 1025 action->set_page_url(GURL("http://www.google.com")); |
| 1026 policy->ProcessAction(action); |
| 1027 |
| 1028 action = new Action( |
| 1029 "punky", mock_clock->Now(), Action::ACTION_API_CALL, "brewster"); |
| 1030 action->set_page_url(GURL("http://www.google.co.uk")); |
| 1031 policy->ProcessAction(action); |
| 1032 |
| 1033 // Manipulate the database to clear the URLs, so that we end up with |
| 1034 // duplicate rows. |
| 1035 std::vector<GURL> no_url_restrictions; |
| 1036 policy->RemoveURLs(no_url_restrictions); |
| 1037 |
| 1038 // Record one more action, with no URL. This should increment the count on |
| 1039 // one, and exactly one, of the existing rows. |
| 1040 action = new Action( |
| 1041 "punky", mock_clock->Now(), Action::ACTION_API_CALL, "brewster"); |
| 1042 policy->ProcessAction(action); |
| 1043 |
| 1044 CheckReadData( |
| 1045 policy, |
| 1046 "punky", |
| 1047 0, |
| 1048 base::Bind(&CountingPolicyTest::CheckDuplicates)); |
| 1049 policy->Close(); |
| 1050 } |
| 1051 |
1003 } // namespace extensions | 1052 } // namespace extensions |
OLD | NEW |