| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/test/test_simple_task_runner.h" | 12 #include "base/test/test_simple_task_runner.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/test/base/in_process_browser_test.h" | 17 #include "chrome/test/base/in_process_browser_test.h" |
| 18 #include "components/component_updater/pref_names.h" | 18 #include "components/component_updater/pref_names.h" |
| 19 #include "content/public/test/test_browser_thread_bundle.h" | 19 #include "content/public/test/test_browser_thread_bundle.h" |
| 20 | 20 |
| 21 namespace safe_browsing { | 21 namespace safe_browsing { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 class SRTFetcherTest : public InProcessBrowserTest { | 25 class SRTFetcherTest : public InProcessBrowserTest { |
| 26 public: | 26 public: |
| 27 void SetUpInProcessBrowserTestFixture() override { | 27 void SetUpInProcessBrowserTestFixture() override { |
| 28 task_runner_ = new base::TestSimpleTaskRunner; | 28 task_runner_ = new base::TestSimpleTaskRunner; |
| 29 | 29 |
| 30 SetReporterLauncherForTesting( | 30 SetReporterLauncherForTesting(base::Bind( |
| 31 base::Bind(&SRTFetcherTest::ReporterLauncher, base::Unretained(this))); | 31 &SRTFetcherTest::ReporterLauncherForTesting, base::Unretained(this))); |
| 32 SetPromptTriggerForTesting( | 32 SetPromptTriggerForTesting(base::Bind( |
| 33 base::Bind(&SRTFetcherTest::PromptTrigger, base::Unretained(this))); | 33 &SRTFetcherTest::PromptTriggerForTesting, base::Unretained(this))); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void TearDownInProcessBrowserTestFixture() override { | 36 void TearDownInProcessBrowserTestFixture() override { |
| 37 SetReporterLauncherForTesting(safe_browsing::ReporterLauncher()); | 37 SetReporterLauncherForTesting(ReporterLauncher()); |
| 38 SetPromptTriggerForTesting(safe_browsing::PromptTrigger()); | 38 SetPromptTriggerForTesting(PromptTrigger()); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void RunReporter() { | 41 void RunReporter() { |
| 42 RunSwReporter(base::FilePath(), "bla", task_runner_, task_runner_); | 42 RunSwReporter(base::FilePath(), "bla", task_runner_, task_runner_); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void PromptTrigger(Browser* browser, const std::string& version) { | 45 void PromptTriggerForTesting(Browser* browser, const std::string& version) { |
| 46 prompt_trigger_called_ = true; | 46 prompt_trigger_called_ = true; |
| 47 } | 47 } |
| 48 | 48 |
| 49 int ReporterLauncher(const base::FilePath& exe_path, | 49 int ReporterLauncherForTesting(const base::FilePath& exe_path, |
| 50 const std::string& version) { | 50 const std::string& version) { |
| 51 reporter_launched_ = true; | 51 reporter_launched_ = true; |
| 52 return exit_code_to_report_; | 52 return exit_code_to_report_; |
| 53 } | 53 } |
| 54 | 54 |
| 55 void SetDaysSinceLastReport(int days) { | 55 void SetDaysSinceLastReport(int days) { |
| 56 PrefService* local_state = g_browser_process->local_state(); | 56 PrefService* local_state = g_browser_process->local_state(); |
| 57 local_state->SetInt64(prefs::kSwReporterLastTimeTriggered, | 57 local_state->SetInt64(prefs::kSwReporterLastTimeTriggered, |
| 58 (base::Time::Now() - base::TimeDelta::FromDays(days)) | 58 (base::Time::Now() - base::TimeDelta::FromDays(days)) |
| 59 .ToInternalValue()); | 59 .ToInternalValue()); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 ExpectToRunAgain(kDaysBetweenSwReporterRunsForPendingPrompt); | 156 ExpectToRunAgain(kDaysBetweenSwReporterRunsForPendingPrompt); |
| 157 | 157 |
| 158 local_state->SetBoolean(prefs::kSwReporterPendingPrompt, false); | 158 local_state->SetBoolean(prefs::kSwReporterPendingPrompt, false); |
| 159 task_runner_->RunPendingTasks(); | 159 task_runner_->RunPendingTasks(); |
| 160 EXPECT_FALSE(reporter_launched_); | 160 EXPECT_FALSE(reporter_launched_); |
| 161 base::MessageLoop::current()->RunUntilIdle(); | 161 base::MessageLoop::current()->RunUntilIdle(); |
| 162 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); | 162 ExpectToRunAgain(kDaysBetweenSuccessfulSwReporterRuns); |
| 163 } | 163 } |
| 164 | 164 |
| 165 } // namespace safe_browsing | 165 } // namespace safe_browsing |
| OLD | NEW |