OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/srt_fetcher_win.h" | 5 #include "chrome/browser/safe_browsing/srt_fetcher_win.h" |
6 | 6 |
7 #include <iterator> | 7 #include <iterator> |
8 #include <memory> | 8 #include <memory> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 void SetUpOnMainThread() override { | 46 void SetUpOnMainThread() override { |
47 InProcessBrowserTest::SetUpOnMainThread(); | 47 InProcessBrowserTest::SetUpOnMainThread(); |
48 ClearLastTimeSentReport(); | 48 ClearLastTimeSentReport(); |
49 } | 49 } |
50 | 50 |
51 void TearDownInProcessBrowserTestFixture() override { | 51 void TearDownInProcessBrowserTestFixture() override { |
52 SetSwReporterTestingDelegate(nullptr); | 52 SetSwReporterTestingDelegate(nullptr); |
53 } | 53 } |
54 | 54 |
55 void RunReporter(const base::FilePath& exe_path = base::FilePath()) { | 55 void RunReporter(const base::FilePath& exe_path = base::FilePath()) { |
56 RunSwReporter(SwReporterInvocation::FromFilePath(exe_path), | 56 auto invocation = SwReporterInvocation::FromFilePath(exe_path); |
57 base::Version("1.2.3"), task_runner_, task_runner_); | 57 invocation.flags = SwReporterInvocation::FLAG_LOG_TO_RAPPOR | |
| 58 SwReporterInvocation::FLAG_LOG_EXIT_CODE_TO_PREFS | |
| 59 SwReporterInvocation::FLAG_TRIGGER_PROMPT | |
| 60 SwReporterInvocation::FLAG_SEND_REPORTER_LOGS; |
| 61 |
| 62 SwReporterQueue invocations; |
| 63 invocations.push(invocation); |
| 64 RunSwReporters(invocations, base::Version("1.2.3"), task_runner_, |
| 65 task_runner_); |
| 66 } |
| 67 |
| 68 void RunReporterQueue(const SwReporterQueue& invocations) { |
| 69 RunSwReporters(invocations, base::Version("1.2.3"), task_runner_, |
| 70 task_runner_); |
58 } | 71 } |
59 | 72 |
60 void TriggerPrompt(Browser* browser, const std::string& version) override { | 73 void TriggerPrompt(Browser* browser, const std::string& version) override { |
61 prompt_trigger_called_ = true; | 74 prompt_trigger_called_ = true; |
62 } | 75 } |
63 | 76 |
64 int LaunchReporter(const SwReporterInvocation& invocation) override { | 77 int LaunchReporter(const SwReporterInvocation& invocation) override { |
65 ++reporter_launch_count_; | 78 ++reporter_launch_count_; |
66 reporter_launch_parameters_ = invocation; | 79 reporter_launch_parameters_ = invocation; |
67 return exit_code_to_report_; | 80 return exit_code_to_report_; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 const base::Time now = base::Time::Now(); | 141 const base::Time now = base::Time::Now(); |
129 const base::Time last_time_sent_logs = base::Time::FromInternalValue( | 142 const base::Time last_time_sent_logs = base::Time::FromInternalValue( |
130 local_state->GetInt64(prefs::kSwReporterLastTimeSentReport)); | 143 local_state->GetInt64(prefs::kSwReporterLastTimeSentReport)); |
131 | 144 |
132 // Checks if the last time sent logs is set as no more than one hour ago, | 145 // Checks if the last time sent logs is set as no more than one hour ago, |
133 // which should be enough time if the execution does not fail. | 146 // which should be enough time if the execution does not fail. |
134 EXPECT_LT(now - base::TimeDelta::FromHours(1), last_time_sent_logs); | 147 EXPECT_LT(now - base::TimeDelta::FromHours(1), last_time_sent_logs); |
135 EXPECT_LT(last_time_sent_logs, now); | 148 EXPECT_LT(last_time_sent_logs, now); |
136 } | 149 } |
137 | 150 |
138 void TestReporterLaunchCycle(int expected_launch_count, | 151 // Run through the steps needed to launch the reporter, as many times as |
139 const base::FilePath& expected_launch_path) { | 152 // needed to launch all the reporters given in |expected_launch_paths|. Test |
| 153 // that each of those launches succeeded. But do not test that ONLY those |
| 154 // launches succeeded. |
| 155 // |
| 156 // After this, if more launches are expected you can call |
| 157 // |TestPartialLaunchCycle| again with another list of paths, to test that |
| 158 // the launch cycle will continue with those paths. |
| 159 // |
| 160 // To test that a list of paths are launched AND NO OTHERS, use |
| 161 // |TestReporterLaunchCycle|. |
| 162 void TestPartialLaunchCycle( |
| 163 const std::vector<base::FilePath>& expected_launch_paths) { |
140 // This test has an unfortunate amount of knowledge of the internals of | 164 // This test has an unfortunate amount of knowledge of the internals of |
141 // ReporterRunner, because it needs to pump the right message loops at the | 165 // ReporterRunner, because it needs to pump the right message loops at the |
142 // right time so that all its internal messages are delivered. This | 166 // right time so that all its internal messages are delivered. This |
143 // function might need to be updated if the internals change. | 167 // function might need to be updated if the internals change. |
144 // | 168 // |
145 // The basic sequence is: | 169 // The basic sequence is: |
146 | 170 // |
147 // 1. TryToRun kicks the whole thing off. If the reporter should not be | 171 // 1. TryToRun kicks the whole thing off. If the reporter should not be |
148 // launched now (eg. DaysSinceLastReport is too low) it posts a call to | 172 // launched now (eg. DaysSinceLastReport is too low) it posts a call to |
149 // itself again. (In a regular task runner this will be scheduled with a | 173 // itself again. (In a regular task runner this will be scheduled with a |
150 // delay, but the test task runner ignores delays so TryToRun will be | 174 // delay, but the test task runner ignores delays so TryToRun will be |
151 // called again on the next call to RunPendingTasks.) | 175 // called again on the next call to RunPendingTasks.) |
152 // | 176 // |
153 // 2. When it is time to run a reporter, TryToRun calls NotifyLaunchReady | 177 // 2. When it is time to run a reporter, TryToRun calls NotifyLaunchReady |
154 // and then posts a call to LaunchAndWait. | 178 // and then posts a call to LaunchAndWait. |
155 // | 179 // |
156 // 3. When the reporter returns, a call to ReporterDone is posted on the UI | 180 // 3. When the reporter returns, a call to ReporterDone is posted on the UI |
157 // thread. | 181 // thread. |
158 // | 182 // |
159 // 4. ReporterDone calls NotifyReporterDone and then posts another call to | 183 // 4. ReporterDone calls NotifyReporterDone and then posts another call to |
160 // TryToRun, which starts the whole process over for the next run. | 184 // TryToRun, which starts the whole process over for the next run. |
161 // | 185 // |
162 // Each call to RunPendingTasks only handles messages already on the queue. | 186 // Each call to RunPendingTasks only handles messages already on the queue. |
163 // It doesn't handle messages posted by those messages. So, we need to call | 187 // It doesn't handle messages posted by those messages. So, we need to call |
164 // it in a loop to make sure we're past all pending TryToRun calls before | 188 // it in a loop to make sure we're past all pending TryToRun calls before |
165 // LaunchAndWaitForExit will be called. | 189 // LaunchAndWaitForExit will be called. |
166 // | 190 // |
167 // Once a call to LaunchAndWaitForExit has been posted, TryToRun won't be | 191 // Once a call to LaunchAndWaitForExit has been posted, TryToRun won't be |
168 // called again until we pump the UI message loop in order to run | 192 // called again until we pump the UI message loop in order to run |
169 // ReporterDone. | 193 // ReporterDone. |
170 | 194 |
171 ASSERT_TRUE(task_runner_->HasPendingTask()); | 195 ASSERT_TRUE(task_runner_->HasPendingTask()); |
172 ASSERT_FALSE(reporter_done_notified_); | 196 ASSERT_FALSE(reporter_done_notified_); |
173 | 197 |
174 // Clear out any pending TryToRun calls. Use a bounded loop so that if the | 198 reporter_launch_count_ = 0; |
175 // reporter will never be called, we'll eventually continue. (If | 199 reporter_launch_parameters_ = SwReporterInvocation(); |
176 // LaunchAndWaitForExit was pending but TryToRun wasn't, this will call | 200 |
177 // it.) | 201 int current_launch_count = reporter_launch_count_; |
178 const int max_expected_launch_count = reporter_launch_count_ + 1; | 202 for (const auto& expected_launch_path : expected_launch_paths) { |
179 for (int i = 0; !launch_ready_notified_ && i < 100; ++i) | 203 // If RunReporter was called with no pending messages, and it was already |
| 204 // time to launch the reporter, then |launch_ready_notified_| will |
| 205 // already be true. Otherwise there will be a TryToRun message pending, |
| 206 // which must be processed first. |
| 207 if (!launch_ready_notified_) { |
| 208 task_runner_->RunPendingTasks(); |
| 209 // Since we're expecting a launch here, we expect it to schedule |
| 210 // LaunchAndWaitForExit. So NOW |launch_ready_notified_| should be |
| 211 // true. |
| 212 ASSERT_TRUE(task_runner_->HasPendingTask()); |
| 213 } |
| 214 ASSERT_TRUE(launch_ready_notified_); |
| 215 ASSERT_EQ(current_launch_count, reporter_launch_count_); |
| 216 |
| 217 // Reset |launch_ready_notified_| so that we can tell if TryToRun gets |
| 218 // called again unexpectedly. |
| 219 launch_ready_notified_ = false; |
| 220 |
| 221 // Call the pending LaunchAndWaitForExit. |
180 task_runner_->RunPendingTasks(); | 222 task_runner_->RunPendingTasks(); |
181 ASSERT_GE(max_expected_launch_count, reporter_launch_count_); | 223 ASSERT_FALSE(launch_ready_notified_); |
| 224 ASSERT_FALSE(reporter_done_notified_); |
182 | 225 |
183 // Reset launch_ready_notified_ so that we can tell if TryToRun gets called | 226 // At this point LaunchAndWaitForExit has definitely been called if |
184 // again unexpectedly. | 227 // it's going to be called at all. (If not, TryToRun will have been |
185 launch_ready_notified_ = false; | 228 // scheduled again.) |
| 229 EXPECT_EQ(current_launch_count + 1, reporter_launch_count_); |
| 230 EXPECT_EQ(expected_launch_path, |
| 231 reporter_launch_parameters_.command_line.GetProgram()); |
186 | 232 |
187 // This will trigger LaunchAndWaitForExit if it's on the queue and hasn't | 233 // Pump the UI message loop to process the ReporterDone call (which |
188 // been called already. If it was called already, this will do nothing. | 234 // will schedule the next TryToRun.) If LaunchAndWaitForExit wasn't |
189 // (There definitely isn't anything queued up yet after | 235 // called, this does nothing. |
190 // LaunchAndWaitForExit because ReporterDone wasn't called yet.) | 236 base::RunLoop().RunUntilIdle(); |
| 237 |
| 238 // At this point there are three things that could have happened: |
| 239 // |
| 240 // 1. LaunchAndWaitForExit was not called. There should be a TryToRun |
| 241 // scheduled. |
| 242 // |
| 243 // 2. ReporterDone was called and there was nothing left in the queue |
| 244 // of SwReporterInvocation's. There should be a TryToRun scheduled. |
| 245 // |
| 246 // 3. ReporterDone was called and there were more |
| 247 // SwReporterInvocation's in the queue to run immediately. There should |
| 248 // be a LaunchAndWaitForExit scheduled. |
| 249 // |
| 250 // So in all cases there should be a pending task, and if we are expecting |
| 251 // more launches in this loop, |launch_ready_notified_| will already be |
| 252 // true. |
| 253 ASSERT_TRUE(task_runner_->HasPendingTask()); |
| 254 |
| 255 // The test task runner does not actually advance the clock. Pretend that |
| 256 // one day has passed. (Otherwise, when we launch the last |
| 257 // SwReporterInvocation in the queue, the next call to TryToRun will |
| 258 // start a whole new launch cycle.) |
| 259 SetDaysSinceLastReport(1); |
| 260 |
| 261 reporter_done_notified_ = false; |
| 262 current_launch_count = reporter_launch_count_; |
| 263 } |
| 264 } |
| 265 |
| 266 // Run through the steps needed to launch the reporter, as many times as |
| 267 // needed to launch all the reporters given in |expected_launch_paths|. Test |
| 268 // that each of those launches succeeded. Then, run through the steps needed |
| 269 // to launch the reporter again, to test that the launch cycle is complete |
| 270 // (no more reporters will be launched). |
| 271 void TestReporterLaunchCycle( |
| 272 const std::vector<base::FilePath>& expected_launch_paths) { |
| 273 TestPartialLaunchCycle(expected_launch_paths); |
| 274 |
| 275 // Now that all expected launches have been tested, run the cycle once more |
| 276 // to make sure no more launches happen. |
| 277 ASSERT_TRUE(task_runner_->HasPendingTask()); |
| 278 ASSERT_FALSE(reporter_done_notified_); |
| 279 ASSERT_FALSE(launch_ready_notified_); |
| 280 |
| 281 int current_launch_count = reporter_launch_count_; |
| 282 |
| 283 // Call the pending TryToRun. |
191 task_runner_->RunPendingTasks(); | 284 task_runner_->RunPendingTasks(); |
192 ASSERT_GE(max_expected_launch_count, reporter_launch_count_); | 285 |
| 286 // We expect that this scheduled another TryToRun. If it scheduled |
| 287 // LaunchAndWaitForExit an unexpected launch is about to happen. |
| 288 ASSERT_TRUE(task_runner_->HasPendingTask()); |
193 ASSERT_FALSE(launch_ready_notified_); | 289 ASSERT_FALSE(launch_ready_notified_); |
194 ASSERT_FALSE(reporter_done_notified_); | 290 ASSERT_FALSE(reporter_done_notified_); |
195 | 291 ASSERT_EQ(current_launch_count, reporter_launch_count_); |
196 // At this point LaunchAndWaitForExit has definitely been called if it's | |
197 // going to be called at all. (If not, TryToRun will have been scheduled | |
198 // again.) | |
199 EXPECT_EQ(expected_launch_count, reporter_launch_count_); | |
200 EXPECT_EQ(expected_launch_path, | |
201 reporter_launch_parameters_.command_line.GetProgram()); | |
202 | |
203 // Pump the UI message loop to process the ReporterDone call (which will | |
204 // schedule the next TryToRun.) If LaunchAndWaitForExit wasn't called, this | |
205 // does nothing. | |
206 base::RunLoop().RunUntilIdle(); | |
207 | |
208 // At this point another call to TryToRun should be scheduled, whether or | |
209 // not LaunchAndWaitForExit was called. | |
210 ASSERT_TRUE(task_runner_->HasPendingTask()); | |
211 | |
212 // Make sure the flags are false for the next launch cycle test. | |
213 ASSERT_FALSE(launch_ready_notified_); | |
214 reporter_done_notified_ = false; | |
215 } | 292 } |
216 | 293 |
217 // Expects |reporter_launch_parameters_| to contain exactly the command line | 294 // Expects |reporter_launch_parameters_| to contain exactly the command line |
218 // switches specified in |expected_switches|. | 295 // switches specified in |expected_switches|. |
219 void ExpectLoggingSwitches(const std::set<std::string>& expected_switches) { | 296 void ExpectLoggingSwitches(const std::set<std::string>& expected_switches) { |
220 const base::CommandLine::SwitchMap& invocation_switches = | 297 const base::CommandLine::SwitchMap& invocation_switches = |
221 reporter_launch_parameters_.command_line.GetSwitches(); | 298 reporter_launch_parameters_.command_line.GetSwitches(); |
222 EXPECT_EQ(expected_switches.size(), invocation_switches.size()); | 299 EXPECT_EQ(expected_switches.size(), invocation_switches.size()); |
223 // Checks if all expected switches are in the invocation switches. It's not | 300 // Checks if all expected switches are in the invocation switches. It's not |
224 // necessary to check if all invocation switches are expected, since we | 301 // necessary to check if all invocation switches are expected, since we |
(...skipping 11 matching lines...) Expand all Loading... |
236 ASSERT_NE(profile, nullptr); | 313 ASSERT_NE(profile, nullptr); |
237 profile->GetPrefs()->SetBoolean( | 314 profile->GetPrefs()->SetBoolean( |
238 prefs::kSafeBrowsingExtendedReportingEnabled, true); | 315 prefs::kSafeBrowsingExtendedReportingEnabled, true); |
239 } | 316 } |
240 | 317 |
241 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | 318 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
242 bool prompt_trigger_called_ = false; | 319 bool prompt_trigger_called_ = false; |
243 int reporter_launch_count_ = 0; | 320 int reporter_launch_count_ = 0; |
244 SwReporterInvocation reporter_launch_parameters_; | 321 SwReporterInvocation reporter_launch_parameters_; |
245 int exit_code_to_report_ = kReporterFailureExitCode; | 322 int exit_code_to_report_ = kReporterFailureExitCode; |
| 323 |
| 324 // This will be set to true when a call to |LaunchAndWaitForExit| is next in |
| 325 // the task queue. |
246 bool launch_ready_notified_ = false; | 326 bool launch_ready_notified_ = false; |
| 327 |
247 bool reporter_done_notified_ = false; | 328 bool reporter_done_notified_ = false; |
248 }; | 329 }; |
249 | 330 |
250 } // namespace | 331 } // namespace |
251 | 332 |
252 IN_PROC_BROWSER_TEST_F(SRTFetcherTest, NothingFound) { | 333 IN_PROC_BROWSER_TEST_F(SRTFetcherTest, NothingFound) { |
253 exit_code_to_report_ = kSwReporterNothingFound; | 334 exit_code_to_report_ = kSwReporterNothingFound; |
254 RunReporter(); | 335 RunReporter(); |
255 task_runner_->RunPendingTasks(); | 336 task_runner_->RunPendingTasks(); |
256 EXPECT_EQ(1, reporter_launch_count_); | 337 EXPECT_EQ(1, reporter_launch_count_); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 const base::FilePath path2(L"path2"); | 426 const base::FilePath path2(L"path2"); |
346 const base::FilePath path3(L"path3"); | 427 const base::FilePath path3(L"path3"); |
347 | 428 |
348 // Schedule path1 with a day left in the reporting period. | 429 // Schedule path1 with a day left in the reporting period. |
349 // The reporter should not launch. | 430 // The reporter should not launch. |
350 constexpr int kDaysLeft = 1; | 431 constexpr int kDaysLeft = 1; |
351 { | 432 { |
352 SCOPED_TRACE("N days left until next reporter run"); | 433 SCOPED_TRACE("N days left until next reporter run"); |
353 SetDaysSinceLastReport(kDaysBetweenSuccessfulSwReporterRuns - kDaysLeft); | 434 SetDaysSinceLastReport(kDaysBetweenSuccessfulSwReporterRuns - kDaysLeft); |
354 RunReporter(path1); | 435 RunReporter(path1); |
355 TestReporterLaunchCycle(0, base::FilePath()); | 436 TestReporterLaunchCycle({}); |
356 } | 437 } |
357 | 438 |
358 // Schedule path2 just as we enter the next reporting period. | 439 // Schedule path2 just as we enter the next reporting period. |
359 // Now the reporter should launch, just once, using path2. | 440 // Now the reporter should launch, just once, using path2. |
360 { | 441 { |
361 SCOPED_TRACE("Reporter runs now"); | 442 SCOPED_TRACE("Reporter runs now"); |
362 SetDaysSinceLastReport(kDaysBetweenSuccessfulSwReporterRuns); | 443 SetDaysSinceLastReport(kDaysBetweenSuccessfulSwReporterRuns); |
363 RunReporter(path2); | 444 RunReporter(path2); |
364 // Schedule it twice; it should only actually run once. | 445 // Schedule it twice; it should only actually run once. |
365 RunReporter(path2); | 446 RunReporter(path2); |
366 TestReporterLaunchCycle(1, path2); | 447 TestReporterLaunchCycle({path2}); |
367 } | 448 } |
368 | 449 |
369 // Schedule path3 before any more time has passed. | 450 // Schedule path3 before any more time has passed. |
370 // The reporter should not launch. | 451 // The reporter should not launch. |
371 { | 452 { |
372 SCOPED_TRACE("No more time passed"); | 453 SCOPED_TRACE("No more time passed"); |
| 454 SetDaysSinceLastReport(0); |
373 RunReporter(path3); | 455 RunReporter(path3); |
374 TestReporterLaunchCycle(1, path2); | 456 TestReporterLaunchCycle({}); |
375 } | 457 } |
376 | 458 |
377 // Enter the next reporting period as path3 is still scheduled. | 459 // Enter the next reporting period as path3 is still scheduled. |
378 // Now the reporter should launch again using path3. (Tests that the | 460 // Now the reporter should launch again using path3. (Tests that the |
379 // parameters from the first launch aren't reused.) | 461 // parameters from the first launch aren't reused.) |
380 { | 462 { |
381 SCOPED_TRACE("Previous run still scheduled"); | 463 SCOPED_TRACE("Previous run still scheduled"); |
382 SetDaysSinceLastReport(kDaysBetweenSuccessfulSwReporterRuns); | 464 SetDaysSinceLastReport(kDaysBetweenSuccessfulSwReporterRuns); |
383 TestReporterLaunchCycle(2, path3); | 465 TestReporterLaunchCycle({path3}); |
384 } | 466 } |
385 | 467 |
386 // Schedule path3 again in the next reporting period. | 468 // Schedule path3 again in the next reporting period. |
387 // The reporter should launch again using path3, since enough time has | 469 // The reporter should launch again using path3, since enough time has |
388 // passed, even though the parameters haven't changed. | 470 // passed, even though the parameters haven't changed. |
389 { | 471 { |
390 SCOPED_TRACE("Run with same parameters"); | 472 SCOPED_TRACE("Run with same parameters"); |
391 SetDaysSinceLastReport(kDaysBetweenSuccessfulSwReporterRuns); | 473 SetDaysSinceLastReport(kDaysBetweenSuccessfulSwReporterRuns); |
392 RunReporter(path3); | 474 RunReporter(path3); |
393 TestReporterLaunchCycle(3, path3); | 475 TestReporterLaunchCycle({path3}); |
394 } | 476 } |
395 } | 477 } |
396 | 478 |
| 479 IN_PROC_BROWSER_TEST_F(SRTFetcherTest, MultipleLaunches) { |
| 480 exit_code_to_report_ = kSwReporterNothingFound; |
| 481 |
| 482 const base::FilePath path1(L"path1"); |
| 483 const base::FilePath path2(L"path2"); |
| 484 const base::FilePath path3(L"path3"); |
| 485 |
| 486 SwReporterQueue invocations; |
| 487 invocations.push(SwReporterInvocation::FromFilePath(path1)); |
| 488 invocations.push(SwReporterInvocation::FromFilePath(path2)); |
| 489 |
| 490 { |
| 491 SCOPED_TRACE("Launch 2 times"); |
| 492 SetDaysSinceLastReport(kDaysBetweenSuccessfulSwReporterRuns); |
| 493 RunReporterQueue(invocations); |
| 494 TestReporterLaunchCycle({path1, path2}); |
| 495 } |
| 496 |
| 497 // Schedule a launch with 2 elements, then another with the same 2. It should |
| 498 // just run 2 times, not 4. |
| 499 { |
| 500 SCOPED_TRACE("Launch 2 times with retry"); |
| 501 SetDaysSinceLastReport(kDaysBetweenSuccessfulSwReporterRuns); |
| 502 RunReporterQueue(invocations); |
| 503 RunReporterQueue(invocations); |
| 504 TestReporterLaunchCycle({path1, path2}); |
| 505 } |
| 506 |
| 507 // Schedule a launch with 2 elements, then add a third while the queue is |
| 508 // running. |
| 509 { |
| 510 SCOPED_TRACE("Add third launch while running"); |
| 511 SetDaysSinceLastReport(kDaysBetweenSuccessfulSwReporterRuns); |
| 512 RunReporterQueue(invocations); |
| 513 |
| 514 // Only test the cycle once, to process the first element in queue. |
| 515 TestPartialLaunchCycle({path1}); |
| 516 |
| 517 invocations.push(SwReporterInvocation::FromFilePath(path3)); |
| 518 RunReporterQueue(invocations); |
| 519 |
| 520 // There is still a 2nd element on the queue - that should execute, and |
| 521 // nothing more. |
| 522 TestReporterLaunchCycle({path2}); |
| 523 |
| 524 // Time passes... Now the 3-element queue should run. |
| 525 SetDaysSinceLastReport(kDaysBetweenSuccessfulSwReporterRuns); |
| 526 TestReporterLaunchCycle({path1, path2, path3}); |
| 527 } |
| 528 |
| 529 // Second launch should not occur after a failure. |
| 530 { |
| 531 SCOPED_TRACE("Launch multiple times with failure"); |
| 532 exit_code_to_report_ = kReporterFailureExitCode; |
| 533 SetDaysSinceLastReport(kDaysBetweenSuccessfulSwReporterRuns); |
| 534 RunReporterQueue(invocations); |
| 535 TestReporterLaunchCycle({path1}); |
| 536 |
| 537 // If we try again before the reporting period is up, it should not do |
| 538 // anything. |
| 539 TestReporterLaunchCycle({}); |
| 540 |
| 541 // After enough time has passed, should try the queue again. |
| 542 SetDaysSinceLastReport(kDaysBetweenSuccessfulSwReporterRuns); |
| 543 TestReporterLaunchCycle({path1}); |
| 544 } |
| 545 } |
| 546 |
397 IN_PROC_BROWSER_TEST_F(SRTFetcherTest, ReporterLogging_FeatureDisabled) { | 547 IN_PROC_BROWSER_TEST_F(SRTFetcherTest, ReporterLogging_FeatureDisabled) { |
398 exit_code_to_report_ = kSwReporterNothingFound; | 548 exit_code_to_report_ = kSwReporterNothingFound; |
399 base::test::ScopedFeatureList scoped_feature_list; | 549 base::test::ScopedFeatureList scoped_feature_list; |
400 scoped_feature_list.InitAndDisableFeature( | 550 scoped_feature_list.InitAndDisableFeature( |
401 kSwReporterExtendedSafeBrowsingFeature); | 551 kSwReporterExtendedSafeBrowsingFeature); |
402 RunReporter(); | 552 RunReporter(); |
403 TestReporterLaunchCycle(1, base::FilePath()); | 553 TestReporterLaunchCycle({base::FilePath()}); |
404 ExpectLoggingSwitches({/*expect no switches*/}); | 554 ExpectLoggingSwitches({/*expect no switches*/}); |
405 ExpectLastTimeSentReportNotSet(); | 555 ExpectLastTimeSentReportNotSet(); |
406 } | 556 } |
407 | 557 |
408 IN_PROC_BROWSER_TEST_F(SRTFetcherTest, ReporterLogging_NoSBExtendedReporting) { | 558 IN_PROC_BROWSER_TEST_F(SRTFetcherTest, ReporterLogging_NoSBExtendedReporting) { |
409 exit_code_to_report_ = kSwReporterNothingFound; | 559 exit_code_to_report_ = kSwReporterNothingFound; |
410 base::test::ScopedFeatureList scoped_feature_list; | 560 base::test::ScopedFeatureList scoped_feature_list; |
411 scoped_feature_list.InitAndEnableFeature( | 561 scoped_feature_list.InitAndEnableFeature( |
412 kSwReporterExtendedSafeBrowsingFeature); | 562 kSwReporterExtendedSafeBrowsingFeature); |
413 RunReporter(); | 563 RunReporter(); |
414 TestReporterLaunchCycle(1, base::FilePath()); | 564 TestReporterLaunchCycle({base::FilePath()}); |
415 ExpectLoggingSwitches({/*expect no switches*/}); | 565 ExpectLoggingSwitches({/*expect no switches*/}); |
416 ExpectLastTimeSentReportNotSet(); | 566 ExpectLastTimeSentReportNotSet(); |
417 } | 567 } |
418 | 568 |
419 IN_PROC_BROWSER_TEST_F(SRTFetcherTest, ReporterLogging_EnabledFirstRun) { | 569 IN_PROC_BROWSER_TEST_F(SRTFetcherTest, ReporterLogging_EnabledFirstRun) { |
420 exit_code_to_report_ = kSwReporterNothingFound; | 570 exit_code_to_report_ = kSwReporterNothingFound; |
421 base::test::ScopedFeatureList scoped_feature_list; | 571 base::test::ScopedFeatureList scoped_feature_list; |
422 scoped_feature_list.InitAndEnableFeature( | 572 scoped_feature_list.InitAndEnableFeature( |
423 kSwReporterExtendedSafeBrowsingFeature); | 573 kSwReporterExtendedSafeBrowsingFeature); |
424 EnableSBExtendedReporting(); | 574 EnableSBExtendedReporting(); |
425 // Note: don't set last time sent logs in the local state. | 575 // Note: don't set last time sent logs in the local state. |
426 // SBER is enabled and there is no record in the local state of the last time | 576 // SBER is enabled and there is no record in the local state of the last time |
427 // logs have been sent, so we should send logs in this run. | 577 // logs have been sent, so we should send logs in this run. |
428 RunReporter(); | 578 RunReporter(); |
429 TestReporterLaunchCycle(1, base::FilePath()); | 579 TestReporterLaunchCycle({base::FilePath()}); |
430 ExpectLoggingSwitches(std::set<std::string>(std::begin(kExpectedSwitches), | 580 ExpectLoggingSwitches(std::set<std::string>(std::begin(kExpectedSwitches), |
431 std::end(kExpectedSwitches))); | 581 std::end(kExpectedSwitches))); |
432 ExpectLastReportSentInTheLastHour(); | 582 ExpectLastReportSentInTheLastHour(); |
433 } | 583 } |
434 | 584 |
435 IN_PROC_BROWSER_TEST_F(SRTFetcherTest, ReporterLogging_EnabledNoRecentLogging) { | 585 IN_PROC_BROWSER_TEST_F(SRTFetcherTest, ReporterLogging_EnabledNoRecentLogging) { |
436 exit_code_to_report_ = kSwReporterNothingFound; | 586 exit_code_to_report_ = kSwReporterNothingFound; |
437 base::test::ScopedFeatureList scoped_feature_list; | 587 base::test::ScopedFeatureList scoped_feature_list; |
438 scoped_feature_list.InitAndEnableFeature( | 588 scoped_feature_list.InitAndEnableFeature( |
439 kSwReporterExtendedSafeBrowsingFeature); | 589 kSwReporterExtendedSafeBrowsingFeature); |
440 // SBER is enabled and last time logs were sent was more than | 590 // SBER is enabled and last time logs were sent was more than |
441 // |kDaysBetweenReporterLogsSent| day ago, so we should send logs in this run. | 591 // |kDaysBetweenReporterLogsSent| day ago, so we should send logs in this run. |
442 EnableSBExtendedReporting(); | 592 EnableSBExtendedReporting(); |
443 SetLastTimeSentReport(kDaysBetweenReporterLogsSent + 3); | 593 SetLastTimeSentReport(kDaysBetweenReporterLogsSent + 3); |
444 RunReporter(); | 594 RunReporter(); |
445 TestReporterLaunchCycle(1, base::FilePath()); | 595 TestReporterLaunchCycle({base::FilePath()}); |
446 ExpectLoggingSwitches(std::set<std::string>(std::begin(kExpectedSwitches), | 596 ExpectLoggingSwitches(std::set<std::string>(std::begin(kExpectedSwitches), |
447 std::end(kExpectedSwitches))); | 597 std::end(kExpectedSwitches))); |
448 ExpectLastReportSentInTheLastHour(); | 598 ExpectLastReportSentInTheLastHour(); |
449 } | 599 } |
450 | 600 |
451 IN_PROC_BROWSER_TEST_F(SRTFetcherTest, ReporterLogging_EnabledRecentlyLogged) { | 601 IN_PROC_BROWSER_TEST_F(SRTFetcherTest, ReporterLogging_EnabledRecentlyLogged) { |
452 exit_code_to_report_ = kSwReporterNothingFound; | 602 exit_code_to_report_ = kSwReporterNothingFound; |
453 base::test::ScopedFeatureList scoped_feature_list; | 603 base::test::ScopedFeatureList scoped_feature_list; |
454 scoped_feature_list.InitAndEnableFeature( | 604 scoped_feature_list.InitAndEnableFeature( |
455 kSwReporterExtendedSafeBrowsingFeature); | 605 kSwReporterExtendedSafeBrowsingFeature); |
456 // SBER is enabled, but logs have been sent less than | 606 // SBER is enabled, but logs have been sent less than |
457 // |kDaysBetweenReporterLogsSent| day ago, so we shouldn't send any logs in | 607 // |kDaysBetweenReporterLogsSent| day ago, so we shouldn't send any logs in |
458 // this run. | 608 // this run. |
459 EnableSBExtendedReporting(); | 609 EnableSBExtendedReporting(); |
460 SetLastTimeSentReport(kDaysBetweenReporterLogsSent - 1); | 610 SetLastTimeSentReport(kDaysBetweenReporterLogsSent - 1); |
461 int64_t last_time_sent_logs = GetLastTimeSentReport(); | 611 int64_t last_time_sent_logs = GetLastTimeSentReport(); |
462 RunReporter(); | 612 RunReporter(); |
463 TestReporterLaunchCycle(1, base::FilePath()); | 613 TestReporterLaunchCycle({base::FilePath()}); |
464 ExpectLoggingSwitches(std::set<std::string>{/*expect no switches*/}); | 614 ExpectLoggingSwitches(std::set<std::string>{/*expect no switches*/}); |
465 EXPECT_EQ(last_time_sent_logs, GetLastTimeSentReport()); | 615 EXPECT_EQ(last_time_sent_logs, GetLastTimeSentReport()); |
466 } | 616 } |
467 | 617 |
468 } // namespace safe_browsing | 618 } // namespace safe_browsing |
OLD | NEW |