OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/safe_browsing/incident_reporting/incident_reporting_ser
vice.h" | 5 #include "chrome/browser/safe_browsing/incident_reporting/incident_reporting_ser
vice.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "chrome/browser/safe_browsing/incident_reporting/tracked_preference_inc
ident.h" | 23 #include "chrome/browser/safe_browsing/incident_reporting/tracked_preference_inc
ident.h" |
24 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
25 #include "chrome/common/safe_browsing/csd.pb.h" | 25 #include "chrome/common/safe_browsing/csd.pb.h" |
26 #include "chrome/test/base/testing_browser_process.h" | 26 #include "chrome/test/base/testing_browser_process.h" |
27 #include "chrome/test/base/testing_pref_service_syncable.h" | 27 #include "chrome/test/base/testing_pref_service_syncable.h" |
28 #include "chrome/test/base/testing_profile.h" | 28 #include "chrome/test/base/testing_profile.h" |
29 #include "chrome/test/base/testing_profile_manager.h" | 29 #include "chrome/test/base/testing_profile_manager.h" |
30 #include "net/url_request/url_request_context_getter.h" | 30 #include "net/url_request/url_request_context_getter.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
32 | 32 |
| 33 #if defined(OS_WIN) |
| 34 #include "base/test/test_reg_util_win.h" |
| 35 #endif |
| 36 |
33 // A test fixture that sets up a test task runner and makes it the thread's | 37 // A test fixture that sets up a test task runner and makes it the thread's |
34 // runner. The fixture implements a fake envrionment data collector and a fake | 38 // runner. The fixture implements a fake envrionment data collector and a fake |
35 // report uploader. | 39 // report uploader. |
36 class IncidentReportingServiceTest : public testing::Test { | 40 class IncidentReportingServiceTest : public testing::Test { |
37 protected: | 41 protected: |
38 // An IRS class that allows a test harness to provide a fake environment | 42 // An IRS class that allows a test harness to provide a fake environment |
39 // collector and report uploader via callbacks. | 43 // collector and report uploader via callbacks. |
40 class TestIncidentReportingService | 44 class TestIncidentReportingService |
41 : public safe_browsing::IncidentReportingService { | 45 : public safe_browsing::IncidentReportingService { |
42 public: | 46 public: |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 on_delayed_analysis_action_(ON_DELAYED_ANALYSIS_NO_ACTION), | 177 on_delayed_analysis_action_(ON_DELAYED_ANALYSIS_NO_ACTION), |
174 upload_result_(safe_browsing::IncidentReportUploader::UPLOAD_SUCCESS), | 178 upload_result_(safe_browsing::IncidentReportUploader::UPLOAD_SUCCESS), |
175 environment_collected_(), | 179 environment_collected_(), |
176 download_finder_created_(), | 180 download_finder_created_(), |
177 download_finder_destroyed_(), | 181 download_finder_destroyed_(), |
178 uploader_destroyed_(), | 182 uploader_destroyed_(), |
179 delayed_analysis_ran_() {} | 183 delayed_analysis_ran_() {} |
180 | 184 |
181 void SetUp() override { | 185 void SetUp() override { |
182 testing::Test::SetUp(); | 186 testing::Test::SetUp(); |
| 187 #if defined(OS_WIN) |
| 188 // Redirect HKCU so that the platform state store used by the test doesn't |
| 189 // collide with existing Chrome installs or other tests running in parallel. |
| 190 registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER); |
| 191 #endif |
183 ASSERT_TRUE(profile_manager_.SetUp()); | 192 ASSERT_TRUE(profile_manager_.SetUp()); |
184 } | 193 } |
185 | 194 |
186 // Sets the action to be taken by the test fixture when the service creates a | 195 // Sets the action to be taken by the test fixture when the service creates a |
187 // LastDownloadFinder. | 196 // LastDownloadFinder. |
188 void SetCreateDownloadFinderAction(OnCreateDownloadFinderAction action) { | 197 void SetCreateDownloadFinderAction(OnCreateDownloadFinderAction action) { |
189 on_create_download_finder_action_ = action; | 198 on_create_download_finder_action_ = action; |
190 } | 199 } |
191 | 200 |
192 // Creates and returns a profile (owned by the profile manager) with or | 201 // Creates and returns a profile (owned by the profile manager) with or |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 | 473 |
465 void OnDownloadFinderDestroyed() { download_finder_destroyed_ = true; } | 474 void OnDownloadFinderDestroyed() { download_finder_destroyed_ = true; } |
466 void OnUploaderDestroyed() { uploader_destroyed_ = true; } | 475 void OnUploaderDestroyed() { uploader_destroyed_ = true; } |
467 | 476 |
468 void OnDelayedAnalysis(scoped_ptr<safe_browsing::IncidentReceiver> receiver) { | 477 void OnDelayedAnalysis(scoped_ptr<safe_browsing::IncidentReceiver> receiver) { |
469 delayed_analysis_ran_ = true; | 478 delayed_analysis_ran_ = true; |
470 if (on_delayed_analysis_action_ == ON_DELAYED_ANALYSIS_ADD_INCIDENT) | 479 if (on_delayed_analysis_action_ == ON_DELAYED_ANALYSIS_ADD_INCIDENT) |
471 receiver->AddIncidentForProcess(MakeTestIncident(nullptr)); | 480 receiver->AddIncidentForProcess(MakeTestIncident(nullptr)); |
472 } | 481 } |
473 | 482 |
| 483 #if defined(OS_WIN) |
| 484 registry_util::RegistryOverrideManager registry_override_manager_; |
| 485 #endif |
| 486 |
474 // A mapping of profile name to its corresponding properties. | 487 // A mapping of profile name to its corresponding properties. |
475 std::map<std::string, ProfileProperties> profile_properties_; | 488 std::map<std::string, ProfileProperties> profile_properties_; |
476 }; | 489 }; |
477 | 490 |
478 // static | 491 // static |
479 base::LazyInstance<base::ThreadLocalPointer< | 492 base::LazyInstance<base::ThreadLocalPointer< |
480 IncidentReportingServiceTest::TestIncidentReportingService> >::Leaky | 493 IncidentReportingServiceTest::TestIncidentReportingService> >::Leaky |
481 IncidentReportingServiceTest::TestIncidentReportingService::test_instance_ = | 494 IncidentReportingServiceTest::TestIncidentReportingService::test_instance_ = |
482 LAZY_INSTANCE_INITIALIZER; | 495 LAZY_INSTANCE_INITIALIZER; |
483 | 496 |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 ASSERT_FALSE(new_state->HasKey(omnibox_type)); | 1078 ASSERT_FALSE(new_state->HasKey(omnibox_type)); |
1066 // But other data must be untouched. | 1079 // But other data must be untouched. |
1067 ASSERT_TRUE(new_state->HasKey(preference_type)); | 1080 ASSERT_TRUE(new_state->HasKey(preference_type)); |
1068 } | 1081 } |
1069 | 1082 |
1070 // Parallel uploads | 1083 // Parallel uploads |
1071 // Shutdown during processing | 1084 // Shutdown during processing |
1072 // environment colection taking longer than incident delay timer | 1085 // environment colection taking longer than incident delay timer |
1073 // environment colection taking longer than incident delay timer, and then | 1086 // environment colection taking longer than incident delay timer, and then |
1074 // another incident arriving | 1087 // another incident arriving |
OLD | NEW |