| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/update_client/test/test_configurator.h" | |
| 6 | |
| 7 #include "base/run_loop.h" | |
| 8 #include "base/version.h" | |
| 9 #include "components/update_client/component_patcher_operation.h" | |
| 10 #include "url/gurl.h" | |
| 11 | |
| 12 namespace update_client { | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 std::vector<GURL> MakeDefaultUrls() { | |
| 17 std::vector<GURL> urls; | |
| 18 urls.push_back(GURL(POST_INTERCEPT_SCHEME | |
| 19 "://" POST_INTERCEPT_HOSTNAME POST_INTERCEPT_PATH)); | |
| 20 return urls; | |
| 21 } | |
| 22 | |
| 23 } // namespace | |
| 24 | |
| 25 TestConfigurator::TestConfigurator( | |
| 26 const scoped_refptr<base::SequencedTaskRunner>& worker_task_runner, | |
| 27 const scoped_refptr<base::SingleThreadTaskRunner>& network_task_runner) | |
| 28 : worker_task_runner_(worker_task_runner), | |
| 29 initial_time_(0), | |
| 30 times_(1), | |
| 31 recheck_time_(0), | |
| 32 ondemand_time_(0), | |
| 33 context_(new net::TestURLRequestContextGetter(network_task_runner)) { | |
| 34 } | |
| 35 | |
| 36 TestConfigurator::~TestConfigurator() { | |
| 37 } | |
| 38 | |
| 39 int TestConfigurator::InitialDelay() const { | |
| 40 return initial_time_; | |
| 41 } | |
| 42 | |
| 43 int TestConfigurator::NextCheckDelay() { | |
| 44 // This is called when a new full cycle of checking for updates is going | |
| 45 // to happen. In test we normally only test one cycle so it is a good | |
| 46 // time to break from the test messageloop Run() method so the test can | |
| 47 // finish. | |
| 48 if (--times_ <= 0) { | |
| 49 quit_closure_.Run(); | |
| 50 return 0; | |
| 51 } | |
| 52 return 1; | |
| 53 } | |
| 54 | |
| 55 int TestConfigurator::StepDelay() const { | |
| 56 return 0; | |
| 57 } | |
| 58 | |
| 59 int TestConfigurator::StepDelayMedium() { | |
| 60 return NextCheckDelay(); | |
| 61 } | |
| 62 | |
| 63 int TestConfigurator::MinimumReCheckWait() const { | |
| 64 return recheck_time_; | |
| 65 } | |
| 66 | |
| 67 int TestConfigurator::OnDemandDelay() const { | |
| 68 return ondemand_time_; | |
| 69 } | |
| 70 | |
| 71 int TestConfigurator::UpdateDelay() const { | |
| 72 return 1; | |
| 73 } | |
| 74 | |
| 75 std::vector<GURL> TestConfigurator::UpdateUrl() const { | |
| 76 return MakeDefaultUrls(); | |
| 77 } | |
| 78 | |
| 79 std::vector<GURL> TestConfigurator::PingUrl() const { | |
| 80 return UpdateUrl(); | |
| 81 } | |
| 82 | |
| 83 base::Version TestConfigurator::GetBrowserVersion() const { | |
| 84 // Needs to be larger than the required version in tested component manifests. | |
| 85 return base::Version("30.0"); | |
| 86 } | |
| 87 | |
| 88 std::string TestConfigurator::GetChannel() const { | |
| 89 return "fake_channel_string"; | |
| 90 } | |
| 91 | |
| 92 std::string TestConfigurator::GetLang() const { | |
| 93 return "fake_lang"; | |
| 94 } | |
| 95 | |
| 96 std::string TestConfigurator::GetOSLongName() const { | |
| 97 return "Fake Operating System"; | |
| 98 } | |
| 99 | |
| 100 std::string TestConfigurator::ExtraRequestParams() const { | |
| 101 return "extra=\"foo\""; | |
| 102 } | |
| 103 | |
| 104 size_t TestConfigurator::UrlSizeLimit() const { | |
| 105 return 256; | |
| 106 } | |
| 107 | |
| 108 net::URLRequestContextGetter* TestConfigurator::RequestContext() const { | |
| 109 return context_.get(); | |
| 110 } | |
| 111 | |
| 112 scoped_refptr<OutOfProcessPatcher> TestConfigurator::CreateOutOfProcessPatcher() | |
| 113 const { | |
| 114 return NULL; | |
| 115 } | |
| 116 | |
| 117 bool TestConfigurator::DeltasEnabled() const { | |
| 118 return true; | |
| 119 } | |
| 120 | |
| 121 bool TestConfigurator::UseBackgroundDownloader() const { | |
| 122 return false; | |
| 123 } | |
| 124 | |
| 125 // Set how many update checks are called, the default value is just once. | |
| 126 void TestConfigurator::SetLoopCount(int times) { | |
| 127 times_ = times; | |
| 128 } | |
| 129 | |
| 130 void TestConfigurator::SetRecheckTime(int seconds) { | |
| 131 recheck_time_ = seconds; | |
| 132 } | |
| 133 | |
| 134 void TestConfigurator::SetOnDemandTime(int seconds) { | |
| 135 ondemand_time_ = seconds; | |
| 136 } | |
| 137 | |
| 138 void TestConfigurator::SetQuitClosure(const base::Closure& quit_closure) { | |
| 139 quit_closure_ = quit_closure; | |
| 140 } | |
| 141 | |
| 142 void TestConfigurator::SetInitialDelay(int seconds) { | |
| 143 initial_time_ = seconds; | |
| 144 } | |
| 145 | |
| 146 scoped_refptr<base::SequencedTaskRunner> | |
| 147 TestConfigurator::GetSequencedTaskRunner() const { | |
| 148 DCHECK(worker_task_runner_.get()); | |
| 149 return worker_task_runner_; | |
| 150 } | |
| 151 | |
| 152 scoped_refptr<base::SingleThreadTaskRunner> | |
| 153 TestConfigurator::GetSingleThreadTaskRunner() const { | |
| 154 // This is NULL because tests do not use the background downloader. | |
| 155 return NULL; | |
| 156 } | |
| 157 | |
| 158 } // namespace update_client | |
| OLD | NEW |