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