| 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 <memory> | 5 #include <memory> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 return true; | 64 return true; |
| 65 } | 65 } |
| 66 | 66 |
| 67 using Events = UpdateClient::Observer::Events; | 67 using Events = UpdateClient::Observer::Events; |
| 68 | 68 |
| 69 class MockObserver : public UpdateClient::Observer { | 69 class MockObserver : public UpdateClient::Observer { |
| 70 public: | 70 public: |
| 71 MOCK_METHOD2(OnEvent, void(Events event, const std::string&)); | 71 MOCK_METHOD2(OnEvent, void(Events event, const std::string&)); |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 class OnDemandTester { | 74 } // namespace |
| 75 public: | |
| 76 OnDemandTester(const scoped_refptr<UpdateClient>& update_client, | |
| 77 bool expected_value); | |
| 78 | 75 |
| 79 void CheckOnDemand(Events event, const std::string&); | 76 using ::testing::_; |
| 77 using ::testing::AtLeast; |
| 78 using ::testing::AnyNumber; |
| 79 using ::testing::DoAll; |
| 80 using ::testing::InSequence; |
| 81 using ::testing::Invoke; |
| 82 using ::testing::Mock; |
| 83 using ::testing::Return; |
| 80 | 84 |
| 81 private: | 85 using std::string; |
| 82 const scoped_refptr<UpdateClient> update_client_; | |
| 83 const bool expected_value_; | |
| 84 }; | |
| 85 | |
| 86 OnDemandTester::OnDemandTester(const scoped_refptr<UpdateClient>& update_client, | |
| 87 bool expected_value) | |
| 88 : update_client_(update_client), expected_value_(expected_value) { | |
| 89 } | |
| 90 | |
| 91 void OnDemandTester::CheckOnDemand(Events event, const std::string& id) { | |
| 92 if (event == Events::COMPONENT_CHECKING_FOR_UPDATES) { | |
| 93 CrxUpdateItem update_item; | |
| 94 EXPECT_TRUE(update_client_->GetCrxUpdateState(id, &update_item)); | |
| 95 EXPECT_EQ(update_item.on_demand, expected_value_); | |
| 96 } | |
| 97 } | |
| 98 | 86 |
| 99 class FakePingManagerImpl : public PingManager { | 87 class FakePingManagerImpl : public PingManager { |
| 100 public: | 88 public: |
| 89 struct PingData { |
| 90 std::string id; |
| 91 base::Version previous_version; |
| 92 base::Version next_version; |
| 93 int error_category = 0; |
| 94 int error_code = 0; |
| 95 int extra_code1 = 0; |
| 96 int diff_error_category = 0; |
| 97 int diff_error_code = 0; |
| 98 bool diff_update_failed = false; |
| 99 }; |
| 100 |
| 101 explicit FakePingManagerImpl(const scoped_refptr<Configurator>& config); | 101 explicit FakePingManagerImpl(const scoped_refptr<Configurator>& config); |
| 102 ~FakePingManagerImpl() override; | 102 ~FakePingManagerImpl() override; |
| 103 | 103 |
| 104 bool SendPing(const CrxUpdateItem* item) override; | 104 bool SendPing(const Component& component) override; |
| 105 | 105 |
| 106 const std::vector<CrxUpdateItem>& items() const; | 106 const std::vector<PingData>& ping_data() const; |
| 107 | 107 |
| 108 private: | 108 private: |
| 109 std::vector<CrxUpdateItem> items_; | 109 std::vector<PingData> ping_data_; |
| 110 DISALLOW_COPY_AND_ASSIGN(FakePingManagerImpl); | 110 DISALLOW_COPY_AND_ASSIGN(FakePingManagerImpl); |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 FakePingManagerImpl::FakePingManagerImpl( | 113 FakePingManagerImpl::FakePingManagerImpl( |
| 114 const scoped_refptr<Configurator>& config) | 114 const scoped_refptr<Configurator>& config) |
| 115 : PingManager(config) {} | 115 : PingManager(config) {} |
| 116 | 116 |
| 117 FakePingManagerImpl::~FakePingManagerImpl() { | 117 FakePingManagerImpl::~FakePingManagerImpl() { |
| 118 } | 118 } |
| 119 | 119 |
| 120 bool FakePingManagerImpl::SendPing(const CrxUpdateItem* item) { | 120 bool FakePingManagerImpl::SendPing(const Component& component) { |
| 121 items_.push_back(*item); | 121 PingData ping_data; |
| 122 ping_data.id = component.id_; |
| 123 ping_data.previous_version = component.previous_version_; |
| 124 ping_data.next_version = component.next_version_; |
| 125 ping_data.error_category = component.error_category_; |
| 126 ping_data.error_code = component.error_code_; |
| 127 ping_data.extra_code1 = component.extra_code1_; |
| 128 ping_data.diff_error_category = component.diff_error_category_; |
| 129 ping_data.diff_error_code = component.diff_error_code_; |
| 130 ping_data.diff_update_failed = component.diff_update_failed(); |
| 131 ping_data_.push_back(ping_data); |
| 122 return true; | 132 return true; |
| 123 } | 133 } |
| 124 | 134 |
| 125 const std::vector<CrxUpdateItem>& FakePingManagerImpl::items() const { | 135 const std::vector<FakePingManagerImpl::PingData>& |
| 126 return items_; | 136 FakePingManagerImpl::ping_data() const { |
| 137 return ping_data_; |
| 127 } | 138 } |
| 128 | 139 |
| 129 } // namespace | |
| 130 | |
| 131 using ::testing::_; | |
| 132 using ::testing::AnyNumber; | |
| 133 using ::testing::DoAll; | |
| 134 using ::testing::InSequence; | |
| 135 using ::testing::Invoke; | |
| 136 using ::testing::Mock; | |
| 137 using ::testing::Return; | |
| 138 | |
| 139 using std::string; | |
| 140 | |
| 141 class UpdateClientTest : public testing::Test { | 140 class UpdateClientTest : public testing::Test { |
| 142 public: | 141 public: |
| 143 UpdateClientTest(); | 142 UpdateClientTest(); |
| 144 ~UpdateClientTest() override; | 143 ~UpdateClientTest() override; |
| 145 | 144 |
| 146 protected: | 145 protected: |
| 147 void RunThreads(); | 146 void RunThreads(); |
| 148 | 147 |
| 149 // Returns the full path to a test file. | 148 // Returns the full path to a test file. |
| 150 static base::FilePath TestFilePath(const char* file); | 149 static base::FilePath TestFilePath(const char* file); |
| 151 | 150 |
| 152 scoped_refptr<update_client::TestConfigurator> config() { return config_; } | 151 scoped_refptr<update_client::TestConfigurator> config() { return config_; } |
| 153 update_client::PersistedData* metadata() { return metadata_.get(); } | 152 update_client::PersistedData* metadata() { return metadata_.get(); } |
| 154 | 153 |
| 155 base::Closure quit_closure() { return quit_closure_; } | 154 base::Closure quit_closure() { return quit_closure_; } |
| 156 | 155 |
| 157 private: | 156 private: |
| 158 static const int kNumWorkerThreads_ = 2; | 157 static constexpr int kNumWorkerThreads_ = 2; |
| 159 | 158 |
| 160 base::MessageLoopForUI message_loop_; | 159 base::MessageLoopForUI message_loop_; |
| 161 base::RunLoop runloop_; | 160 base::RunLoop runloop_; |
| 162 base::Closure quit_closure_; | 161 base::Closure quit_closure_; |
| 163 | 162 |
| 164 std::unique_ptr<base::SequencedWorkerPoolOwner> worker_pool_; | 163 std::unique_ptr<base::SequencedWorkerPoolOwner> worker_pool_; |
| 165 | 164 |
| 166 scoped_refptr<update_client::TestConfigurator> config_; | 165 scoped_refptr<update_client::TestConfigurator> config_; |
| 167 std::unique_ptr<TestingPrefServiceSimple> pref_; | 166 std::unique_ptr<TestingPrefServiceSimple> pref_; |
| 168 std::unique_ptr<update_client::PersistedData> metadata_; | 167 std::unique_ptr<update_client::PersistedData> metadata_; |
| 169 | 168 |
| 170 DISALLOW_COPY_AND_ASSIGN(UpdateClientTest); | 169 DISALLOW_COPY_AND_ASSIGN(UpdateClientTest); |
| 171 }; | 170 }; |
| 172 | 171 |
| 172 constexpr int UpdateClientTest::kNumWorkerThreads_; |
| 173 |
| 173 UpdateClientTest::UpdateClientTest() | 174 UpdateClientTest::UpdateClientTest() |
| 174 : worker_pool_( | 175 : worker_pool_( |
| 175 new base::SequencedWorkerPoolOwner(kNumWorkerThreads_, "test")) { | 176 base::MakeUnique<base::SequencedWorkerPoolOwner>(kNumWorkerThreads_, |
| 177 "test")), |
| 178 pref_(base::MakeUnique<TestingPrefServiceSimple>()) { |
| 176 quit_closure_ = runloop_.QuitClosure(); | 179 quit_closure_ = runloop_.QuitClosure(); |
| 177 | 180 |
| 178 auto pool = worker_pool_->pool(); | 181 auto pool = worker_pool_->pool(); |
| 179 config_ = new TestConfigurator( | 182 config_ = base::MakeShared<TestConfigurator>( |
| 180 pool->GetSequencedTaskRunner(pool->GetSequenceToken()), | 183 pool->GetSequencedTaskRunner(pool->GetSequenceToken()), |
| 181 message_loop_.task_runner()); | 184 message_loop_.task_runner()); |
| 182 pref_.reset(new TestingPrefServiceSimple()); | |
| 183 PersistedData::RegisterPrefs(pref_->registry()); | 185 PersistedData::RegisterPrefs(pref_->registry()); |
| 184 metadata_.reset(new PersistedData(pref_.get())); | 186 metadata_ = base::MakeUnique<PersistedData>(pref_.get()); |
| 185 } | 187 } |
| 186 | 188 |
| 187 UpdateClientTest::~UpdateClientTest() { | 189 UpdateClientTest::~UpdateClientTest() { |
| 188 } | 190 } |
| 189 | 191 |
| 190 void UpdateClientTest::RunThreads() { | 192 void UpdateClientTest::RunThreads() { |
| 191 runloop_.Run(); | 193 runloop_.Run(); |
| 192 } | 194 } |
| 193 | 195 |
| 194 base::FilePath UpdateClientTest::TestFilePath(const char* file) { | 196 base::FilePath UpdateClientTest::TestFilePath(const char* file) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 205 // has no update. | 207 // has no update. |
| 206 TEST_F(UpdateClientTest, OneCrxNoUpdate) { | 208 TEST_F(UpdateClientTest, OneCrxNoUpdate) { |
| 207 class DataCallbackFake { | 209 class DataCallbackFake { |
| 208 public: | 210 public: |
| 209 static void Callback(const std::vector<std::string>& ids, | 211 static void Callback(const std::vector<std::string>& ids, |
| 210 std::vector<CrxComponent>* components) { | 212 std::vector<CrxComponent>* components) { |
| 211 CrxComponent crx; | 213 CrxComponent crx; |
| 212 crx.name = "test_jebg"; | 214 crx.name = "test_jebg"; |
| 213 crx.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); | 215 crx.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
| 214 crx.version = base::Version("0.9"); | 216 crx.version = base::Version("0.9"); |
| 215 crx.installer = new TestInstaller; | 217 crx.installer = base::MakeShared<TestInstaller>(); |
| 216 components->push_back(crx); | 218 components->push_back(crx); |
| 217 } | 219 } |
| 218 }; | 220 }; |
| 219 | 221 |
| 220 class CompletionCallbackFake { | 222 class CompletionCallbackFake { |
| 221 public: | 223 public: |
| 222 static void Callback(const base::Closure& quit_closure, Error error) { | 224 static void Callback(const base::Closure& quit_closure, Error error) { |
| 223 EXPECT_EQ(Error::NONE, error); | 225 EXPECT_EQ(Error::NONE, error); |
| 224 quit_closure.Run(); | 226 quit_closure.Run(); |
| 225 } | 227 } |
| 226 }; | 228 }; |
| 227 | 229 |
| 228 class FakeUpdateChecker : public UpdateChecker { | 230 class FakeUpdateChecker : public UpdateChecker { |
| 229 public: | 231 public: |
| 230 static std::unique_ptr<UpdateChecker> Create( | 232 static std::unique_ptr<UpdateChecker> Create( |
| 231 const scoped_refptr<Configurator>& config, | 233 const scoped_refptr<Configurator>& config, |
| 232 PersistedData* metadata) { | 234 PersistedData* metadata) { |
| 233 return std::unique_ptr<UpdateChecker>(new FakeUpdateChecker()); | 235 return base::MakeUnique<FakeUpdateChecker>(); |
| 234 } | 236 } |
| 235 | 237 |
| 236 bool CheckForUpdates( | 238 bool CheckForUpdates( |
| 237 const IdToCrxUpdateItemMap& items_to_check, | 239 const std::vector<std::string>& ids_to_check, |
| 240 const IdToComponentPtrMap& components, |
| 238 const std::string& additional_attributes, | 241 const std::string& additional_attributes, |
| 239 bool enabled_component_updates, | 242 bool enabled_component_updates, |
| 240 const UpdateCheckCallback& update_check_callback) override { | 243 const UpdateCheckCallback& update_check_callback) override { |
| 241 EXPECT_TRUE(enabled_component_updates); | 244 EXPECT_TRUE(enabled_component_updates); |
| 245 EXPECT_EQ(1u, ids_to_check.size()); |
| 246 const std::string id = "jebgalgnebhfojomionfpkfelancnnkf"; |
| 247 EXPECT_EQ(id, ids_to_check.front()); |
| 248 EXPECT_EQ(1u, components.count(id)); |
| 249 |
| 250 auto& component = components.at(id); |
| 251 |
| 252 EXPECT_FALSE(component->on_demand()); |
| 253 |
| 254 UpdateResponse::Result result; |
| 255 result.extension_id = id; |
| 256 result.status = "noupdate"; |
| 257 component->SetParseResult(result); |
| 258 |
| 242 base::ThreadTaskRunnerHandle::Get()->PostTask( | 259 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 243 FROM_HERE, | 260 FROM_HERE, base::Bind(update_check_callback, 0, 0)); |
| 244 base::Bind(update_check_callback, 0, UpdateResponse::Results(), 0)); | 261 |
| 245 return true; | 262 return true; |
| 246 } | 263 } |
| 247 }; | 264 }; |
| 248 | 265 |
| 249 class FakeCrxDownloader : public CrxDownloader { | 266 class FakeCrxDownloader : public CrxDownloader { |
| 250 public: | 267 public: |
| 251 static std::unique_ptr<CrxDownloader> Create( | 268 static std::unique_ptr<CrxDownloader> Create( |
| 252 bool is_background_download, | 269 bool is_background_download, |
| 253 net::URLRequestContextGetter* context_getter, | 270 net::URLRequestContextGetter* context_getter, |
| 254 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 271 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| 255 return std::unique_ptr<CrxDownloader>(new FakeCrxDownloader()); | 272 return base::MakeUnique<FakeCrxDownloader>(); |
| 256 } | 273 } |
| 257 | 274 |
| 258 private: | |
| 259 FakeCrxDownloader() | 275 FakeCrxDownloader() |
| 260 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} | 276 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} |
| 261 ~FakeCrxDownloader() override {} | |
| 262 | 277 |
| 278 private: |
| 263 void DoStartDownload(const GURL& url) override { EXPECT_TRUE(false); } | 279 void DoStartDownload(const GURL& url) override { EXPECT_TRUE(false); } |
| 264 }; | 280 }; |
| 265 | 281 |
| 266 class FakePingManager : public FakePingManagerImpl { | 282 class FakePingManager : public FakePingManagerImpl { |
| 267 public: | 283 public: |
| 268 explicit FakePingManager(const scoped_refptr<Configurator>& config) | 284 explicit FakePingManager(const scoped_refptr<Configurator>& config) |
| 269 : FakePingManagerImpl(config) {} | 285 : FakePingManagerImpl(config) {} |
| 270 ~FakePingManager() override { EXPECT_TRUE(items().empty()); } | 286 ~FakePingManager() override { EXPECT_TRUE(ping_data().empty()); } |
| 271 }; | 287 }; |
| 272 | 288 |
| 273 std::unique_ptr<PingManager> ping_manager(new FakePingManager(config())); | 289 scoped_refptr<UpdateClient> update_client = |
| 274 scoped_refptr<UpdateClient> update_client(new UpdateClientImpl( | 290 base::MakeShared<UpdateClientImpl>( |
| 275 config(), std::move(ping_manager), &FakeUpdateChecker::Create, | 291 config(), base::MakeUnique<FakePingManager>(config()), |
| 276 &FakeCrxDownloader::Create)); | 292 &FakeUpdateChecker::Create, &FakeCrxDownloader::Create); |
| 277 | |
| 278 // Verify that calling Update does not set ondemand. | |
| 279 OnDemandTester ondemand_tester(update_client, false); | |
| 280 | 293 |
| 281 MockObserver observer; | 294 MockObserver observer; |
| 282 ON_CALL(observer, OnEvent(_, _)) | |
| 283 .WillByDefault(Invoke(&ondemand_tester, &OnDemandTester::CheckOnDemand)); | |
| 284 | |
| 285 InSequence seq; | 295 InSequence seq; |
| 286 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, | 296 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, |
| 287 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 297 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); |
| 288 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, | 298 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, |
| 289 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 299 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); |
| 290 | 300 |
| 291 update_client->AddObserver(&observer); | 301 update_client->AddObserver(&observer); |
| 292 | 302 |
| 293 std::vector<std::string> ids; | 303 const std::vector<std::string> ids = {"jebgalgnebhfojomionfpkfelancnnkf"}; |
| 294 ids.push_back(std::string("jebgalgnebhfojomionfpkfelancnnkf")); | |
| 295 | |
| 296 update_client->Update( | 304 update_client->Update( |
| 297 ids, base::Bind(&DataCallbackFake::Callback), | 305 ids, base::Bind(&DataCallbackFake::Callback), |
| 298 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); | 306 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
| 299 | 307 |
| 300 RunThreads(); | 308 RunThreads(); |
| 301 | 309 |
| 302 update_client->RemoveObserver(&observer); | 310 update_client->RemoveObserver(&observer); |
| 303 } | 311 } |
| 304 | 312 |
| 305 // Tests the scenario where two CRXs are checked for updates. On CRX has | 313 // Tests the scenario where two CRXs are checked for updates. On CRX has |
| 306 // an update, the other CRX does not. | 314 // an update, the other CRX does not. |
| 307 TEST_F(UpdateClientTest, TwoCrxUpdateNoUpdate) { | 315 TEST_F(UpdateClientTest, TwoCrxUpdateNoUpdate) { |
| 308 class DataCallbackFake { | 316 class DataCallbackFake { |
| 309 public: | 317 public: |
| 310 static void Callback(const std::vector<std::string>& ids, | 318 static void Callback(const std::vector<std::string>& ids, |
| 311 std::vector<CrxComponent>* components) { | 319 std::vector<CrxComponent>* components) { |
| 312 CrxComponent crx1; | 320 CrxComponent crx1; |
| 313 crx1.name = "test_jebg"; | 321 crx1.name = "test_jebg"; |
| 314 crx1.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); | 322 crx1.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
| 315 crx1.version = base::Version("0.9"); | 323 crx1.version = base::Version("0.9"); |
| 316 crx1.installer = new TestInstaller; | 324 crx1.installer = base::MakeShared<TestInstaller>(); |
| 317 | 325 |
| 318 CrxComponent crx2; | 326 CrxComponent crx2; |
| 319 crx2.name = "test_abag"; | 327 crx2.name = "test_abag"; |
| 320 crx2.pk_hash.assign(abag_hash, abag_hash + arraysize(abag_hash)); | 328 crx2.pk_hash.assign(abag_hash, abag_hash + arraysize(abag_hash)); |
| 321 crx2.version = base::Version("2.2"); | 329 crx2.version = base::Version("2.2"); |
| 322 crx2.installer = new TestInstaller; | 330 crx2.installer = base::MakeShared<TestInstaller>(); |
| 323 | 331 |
| 324 components->push_back(crx1); | 332 components->push_back(crx1); |
| 325 components->push_back(crx2); | 333 components->push_back(crx2); |
| 326 } | 334 } |
| 327 }; | 335 }; |
| 328 | 336 |
| 329 class CompletionCallbackFake { | 337 class CompletionCallbackFake { |
| 330 public: | 338 public: |
| 331 static void Callback(const base::Closure& quit_closure, Error error) { | 339 static void Callback(const base::Closure& quit_closure, Error error) { |
| 332 EXPECT_EQ(Error::NONE, error); | 340 EXPECT_EQ(Error::NONE, error); |
| 333 quit_closure.Run(); | 341 quit_closure.Run(); |
| 334 } | 342 } |
| 335 }; | 343 }; |
| 336 | 344 |
| 337 class FakeUpdateChecker : public UpdateChecker { | 345 class FakeUpdateChecker : public UpdateChecker { |
| 338 public: | 346 public: |
| 339 static std::unique_ptr<UpdateChecker> Create( | 347 static std::unique_ptr<UpdateChecker> Create( |
| 340 const scoped_refptr<Configurator>& config, | 348 const scoped_refptr<Configurator>& config, |
| 341 PersistedData* metadata) { | 349 PersistedData* metadata) { |
| 342 return std::unique_ptr<UpdateChecker>(new FakeUpdateChecker()); | 350 return base::MakeUnique<FakeUpdateChecker>(); |
| 343 } | 351 } |
| 344 | 352 |
| 345 bool CheckForUpdates( | 353 bool CheckForUpdates( |
| 346 const IdToCrxUpdateItemMap& items_to_check, | 354 const std::vector<std::string>& ids_to_check, |
| 355 const IdToComponentPtrMap& components, |
| 347 const std::string& additional_attributes, | 356 const std::string& additional_attributes, |
| 348 bool enabled_component_updates, | 357 bool enabled_component_updates, |
| 349 const UpdateCheckCallback& update_check_callback) override { | 358 const UpdateCheckCallback& update_check_callback) override { |
| 350 /* | 359 /* |
| 351 Fake the following response: | 360 Fake the following response: |
| 352 | 361 |
| 353 <?xml version='1.0' encoding='UTF-8'?> | 362 <?xml version='1.0' encoding='UTF-8'?> |
| 354 <response protocol='3.0'> | 363 <response protocol='3.0'> |
| 355 <app appid='jebgalgnebhfojomionfpkfelancnnkf'> | 364 <app appid='jebgalgnebhfojomionfpkfelancnnkf'> |
| 356 <updatecheck status='ok'> | 365 <updatecheck status='ok'> |
| 357 <urls> | 366 <urls> |
| 358 <url codebase='http://localhost/download/'/> | 367 <url codebase='http://localhost/download/'/> |
| 359 </urls> | 368 </urls> |
| 360 <manifest version='1.0' prodversionmin='11.0.1.0'> | 369 <manifest version='1.0' prodversionmin='11.0.1.0'> |
| 361 <packages> | 370 <packages> |
| 362 <package name='jebgalgnebhfojomionfpkfelancnnkf.crx' | 371 <package name='jebgalgnebhfojomionfpkfelancnnkf.crx' |
| 363 hash_sha256='6fc4b93fd11134de1300c2c0bb88c12b644a4ec0fd | 372 hash_sha256='6fc4b93fd11134de1300c2c0bb88c12b644a4ec0fd |
| 364 7c9b12cb7cc067667bde87'/> | 373 7c9b12cb7cc067667bde87'/> |
| 365 </packages> | 374 </packages> |
| 366 </manifest> | 375 </manifest> |
| 367 </updatecheck> | 376 </updatecheck> |
| 368 </app> | 377 </app> |
| 369 </response> | 378 </response> |
| 370 */ | 379 */ |
| 371 UpdateResponse::Result::Manifest::Package package; | |
| 372 package.name = "jebgalgnebhfojomionfpkfelancnnkf.crx"; | |
| 373 package.hash_sha256 = | |
| 374 "6fc4b93fd11134de1300c2c0bb88c12b644a4ec0fd7c9b12cb7cc067667bde87"; | |
| 375 | 380 |
| 376 UpdateResponse::Result result; | 381 EXPECT_TRUE(enabled_component_updates); |
| 377 result.extension_id = "jebgalgnebhfojomionfpkfelancnnkf"; | 382 EXPECT_EQ(2u, ids_to_check.size()); |
| 378 result.status = "ok"; | |
| 379 result.crx_urls.push_back(GURL("http://localhost/download/")); | |
| 380 result.manifest.version = "1.0"; | |
| 381 result.manifest.browser_min_version = "11.0.1.0"; | |
| 382 result.manifest.packages.push_back(package); | |
| 383 | 383 |
| 384 UpdateResponse::Results results; | 384 { |
| 385 results.list.push_back(result); | 385 const std::string id = "jebgalgnebhfojomionfpkfelancnnkf"; |
| 386 EXPECT_EQ(id, ids_to_check[0]); |
| 387 EXPECT_EQ(1u, components.count(id)); |
| 388 |
| 389 UpdateResponse::Result::Manifest::Package package; |
| 390 package.name = "jebgalgnebhfojomionfpkfelancnnkf.crx"; |
| 391 package.hash_sha256 = |
| 392 "6fc4b93fd11134de1300c2c0bb88c12b644a4ec0fd7c9b12cb7cc067667bde87"; |
| 393 |
| 394 UpdateResponse::Result result; |
| 395 result.extension_id = "jebgalgnebhfojomionfpkfelancnnkf"; |
| 396 result.status = "ok"; |
| 397 result.crx_urls.push_back(GURL("http://localhost/download/")); |
| 398 result.manifest.version = "1.0"; |
| 399 result.manifest.browser_min_version = "11.0.1.0"; |
| 400 result.manifest.packages.push_back(package); |
| 401 |
| 402 auto& component = components.at(id); |
| 403 component->SetParseResult(result); |
| 404 |
| 405 EXPECT_FALSE(component->on_demand()); |
| 406 } |
| 407 |
| 408 { |
| 409 const std::string id = "abagagagagagagagagagagagagagagag"; |
| 410 EXPECT_EQ(id, ids_to_check[1]); |
| 411 EXPECT_EQ(1u, components.count(id)); |
| 412 |
| 413 UpdateResponse::Result result; |
| 414 result.extension_id = id; |
| 415 result.status = "noupdate"; |
| 416 |
| 417 auto& component = components.at(id); |
| 418 component->SetParseResult(result); |
| 419 |
| 420 EXPECT_FALSE(component->on_demand()); |
| 421 } |
| 386 | 422 |
| 387 base::ThreadTaskRunnerHandle::Get()->PostTask( | 423 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 388 FROM_HERE, base::Bind(update_check_callback, 0, results, 0)); | 424 FROM_HERE, base::Bind(update_check_callback, 0, 0)); |
| 389 return true; | 425 return true; |
| 390 } | 426 } |
| 391 }; | 427 }; |
| 392 | 428 |
| 393 class FakeCrxDownloader : public CrxDownloader { | 429 class FakeCrxDownloader : public CrxDownloader { |
| 394 public: | 430 public: |
| 395 static std::unique_ptr<CrxDownloader> Create( | 431 static std::unique_ptr<CrxDownloader> Create( |
| 396 bool is_background_download, | 432 bool is_background_download, |
| 397 net::URLRequestContextGetter* context_getter, | 433 net::URLRequestContextGetter* context_getter, |
| 398 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 434 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| 399 return std::unique_ptr<CrxDownloader>(new FakeCrxDownloader()); | 435 return base::MakeUnique<FakeCrxDownloader>(); |
| 400 } | 436 } |
| 401 | 437 |
| 402 private: | |
| 403 FakeCrxDownloader() | 438 FakeCrxDownloader() |
| 404 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} | 439 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} |
| 405 ~FakeCrxDownloader() override {} | |
| 406 | 440 |
| 441 private: |
| 407 void DoStartDownload(const GURL& url) override { | 442 void DoStartDownload(const GURL& url) override { |
| 408 DownloadMetrics download_metrics; | 443 DownloadMetrics download_metrics; |
| 409 download_metrics.url = url; | 444 download_metrics.url = url; |
| 410 download_metrics.downloader = DownloadMetrics::kNone; | 445 download_metrics.downloader = DownloadMetrics::kNone; |
| 411 download_metrics.error = 0; | 446 download_metrics.error = 0; |
| 412 download_metrics.downloaded_bytes = 1843; | 447 download_metrics.downloaded_bytes = 1843; |
| 413 download_metrics.total_bytes = 1843; | 448 download_metrics.total_bytes = 1843; |
| 414 download_metrics.download_time_ms = 1000; | 449 download_metrics.download_time_ms = 1000; |
| 415 | 450 |
| 416 FilePath path; | 451 FilePath path; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 432 base::Bind(&FakeCrxDownloader::OnDownloadComplete, | 467 base::Bind(&FakeCrxDownloader::OnDownloadComplete, |
| 433 base::Unretained(this), true, result, download_metrics)); | 468 base::Unretained(this), true, result, download_metrics)); |
| 434 } | 469 } |
| 435 }; | 470 }; |
| 436 | 471 |
| 437 class FakePingManager : public FakePingManagerImpl { | 472 class FakePingManager : public FakePingManagerImpl { |
| 438 public: | 473 public: |
| 439 explicit FakePingManager(const scoped_refptr<Configurator>& config) | 474 explicit FakePingManager(const scoped_refptr<Configurator>& config) |
| 440 : FakePingManagerImpl(config) {} | 475 : FakePingManagerImpl(config) {} |
| 441 ~FakePingManager() override { | 476 ~FakePingManager() override { |
| 442 const auto& ping_items = items(); | 477 const auto ping_data = FakePingManagerImpl::ping_data(); |
| 443 EXPECT_EQ(1U, ping_items.size()); | 478 EXPECT_EQ(1u, ping_data.size()); |
| 444 EXPECT_EQ("jebgalgnebhfojomionfpkfelancnnkf", ping_items[0].id); | 479 EXPECT_EQ("jebgalgnebhfojomionfpkfelancnnkf", ping_data[0].id); |
| 445 EXPECT_EQ(base::Version("0.9"), ping_items[0].previous_version); | 480 EXPECT_EQ(base::Version("0.9"), ping_data[0].previous_version); |
| 446 EXPECT_EQ(base::Version("1.0"), ping_items[0].next_version); | 481 EXPECT_EQ(base::Version("1.0"), ping_data[0].next_version); |
| 447 EXPECT_EQ(0, ping_items[0].error_category); | 482 EXPECT_EQ(0, ping_data[0].error_category); |
| 448 EXPECT_EQ(0, ping_items[0].error_code); | 483 EXPECT_EQ(0, ping_data[0].error_code); |
| 449 } | 484 } |
| 450 }; | 485 }; |
| 451 | 486 |
| 452 std::unique_ptr<PingManager> ping_manager(new FakePingManager(config())); | 487 scoped_refptr<UpdateClient> update_client = |
| 453 scoped_refptr<UpdateClient> update_client(new UpdateClientImpl( | 488 base::MakeShared<UpdateClientImpl>( |
| 454 config(), std::move(ping_manager), &FakeUpdateChecker::Create, | 489 config(), base::MakeUnique<FakePingManager>(config()), |
| 455 &FakeCrxDownloader::Create)); | 490 &FakeUpdateChecker::Create, &FakeCrxDownloader::Create); |
| 456 | 491 |
| 457 MockObserver observer; | 492 MockObserver observer; |
| 458 { | 493 { |
| 459 InSequence seq; | 494 InSequence seq; |
| 460 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, | 495 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, |
| 461 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 496 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); |
| 462 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, | 497 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, |
| 463 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 498 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); |
| 464 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, | 499 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, |
| 465 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 500 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 501 .Times(AtLeast(1)); |
| 466 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_READY, | 502 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_READY, |
| 467 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 503 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); |
| 468 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATED, | 504 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATED, |
| 469 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 505 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); |
| 470 } | 506 } |
| 471 { | 507 { |
| 472 InSequence seq; | 508 InSequence seq; |
| 473 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, | 509 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, |
| 474 "abagagagagagagagagagagagagagagag")).Times(1); | 510 "abagagagagagagagagagagagagagagag")).Times(1); |
| 475 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, | 511 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, |
| 476 "abagagagagagagagagagagagagagagag")).Times(1); | 512 "abagagagagagagagagagagagagagagag")).Times(1); |
| 477 } | 513 } |
| 478 | 514 |
| 479 update_client->AddObserver(&observer); | 515 update_client->AddObserver(&observer); |
| 480 | 516 |
| 481 std::vector<std::string> ids; | 517 const std::vector<std::string> ids = {"jebgalgnebhfojomionfpkfelancnnkf", |
| 482 ids.push_back(std::string("jebgalgnebhfojomionfpkfelancnnkf")); | 518 "abagagagagagagagagagagagagagagag"}; |
| 483 ids.push_back(std::string("abagagagagagagagagagagagagagagag")); | |
| 484 | |
| 485 update_client->Update( | 519 update_client->Update( |
| 486 ids, base::Bind(&DataCallbackFake::Callback), | 520 ids, base::Bind(&DataCallbackFake::Callback), |
| 487 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); | 521 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
| 488 | 522 |
| 489 RunThreads(); | 523 RunThreads(); |
| 490 | 524 |
| 491 update_client->RemoveObserver(&observer); | 525 update_client->RemoveObserver(&observer); |
| 492 } | 526 } |
| 493 | 527 |
| 494 // Tests the update check for two CRXs scenario. Both CRXs have updates. | 528 // Tests the update check for two CRXs scenario. Both CRXs have updates. |
| 495 TEST_F(UpdateClientTest, TwoCrxUpdate) { | 529 TEST_F(UpdateClientTest, TwoCrxUpdate) { |
| 496 class DataCallbackFake { | 530 class DataCallbackFake { |
| 497 public: | 531 public: |
| 498 static void Callback(const std::vector<std::string>& ids, | 532 static void Callback(const std::vector<std::string>& ids, |
| 499 std::vector<CrxComponent>* components) { | 533 std::vector<CrxComponent>* components) { |
| 500 CrxComponent crx1; | 534 CrxComponent crx1; |
| 501 crx1.name = "test_jebg"; | 535 crx1.name = "test_jebg"; |
| 502 crx1.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); | 536 crx1.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
| 503 crx1.version = base::Version("0.9"); | 537 crx1.version = base::Version("0.9"); |
| 504 crx1.installer = new TestInstaller; | 538 crx1.installer = base::MakeShared<TestInstaller>(); |
| 505 | 539 |
| 506 CrxComponent crx2; | 540 CrxComponent crx2; |
| 507 crx2.name = "test_ihfo"; | 541 crx2.name = "test_ihfo"; |
| 508 crx2.pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash)); | 542 crx2.pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash)); |
| 509 crx2.version = base::Version("0.8"); | 543 crx2.version = base::Version("0.8"); |
| 510 crx2.installer = new TestInstaller; | 544 crx2.installer = base::MakeShared<TestInstaller>(); |
| 511 | 545 |
| 512 components->push_back(crx1); | 546 components->push_back(crx1); |
| 513 components->push_back(crx2); | 547 components->push_back(crx2); |
| 514 } | 548 } |
| 515 }; | 549 }; |
| 516 | 550 |
| 517 class CompletionCallbackFake { | 551 class CompletionCallbackFake { |
| 518 public: | 552 public: |
| 519 static void Callback(const base::Closure& quit_closure, Error error) { | 553 static void Callback(const base::Closure& quit_closure, Error error) { |
| 520 EXPECT_EQ(Error::NONE, error); | 554 EXPECT_EQ(Error::NONE, error); |
| 521 quit_closure.Run(); | 555 quit_closure.Run(); |
| 522 } | 556 } |
| 523 }; | 557 }; |
| 524 | 558 |
| 525 class FakeUpdateChecker : public UpdateChecker { | 559 class FakeUpdateChecker : public UpdateChecker { |
| 526 public: | 560 public: |
| 527 static std::unique_ptr<UpdateChecker> Create( | 561 static std::unique_ptr<UpdateChecker> Create( |
| 528 const scoped_refptr<Configurator>& config, | 562 const scoped_refptr<Configurator>& config, |
| 529 PersistedData* metadata) { | 563 PersistedData* metadata) { |
| 530 return std::unique_ptr<UpdateChecker>(new FakeUpdateChecker()); | 564 return base::MakeUnique<FakeUpdateChecker>(); |
| 531 } | 565 } |
| 532 | 566 |
| 533 bool CheckForUpdates( | 567 bool CheckForUpdates( |
| 534 const IdToCrxUpdateItemMap& items_to_check, | 568 const std::vector<std::string>& ids_to_check, |
| 569 const IdToComponentPtrMap& components, |
| 535 const std::string& additional_attributes, | 570 const std::string& additional_attributes, |
| 536 bool enabled_component_updates, | 571 bool enabled_component_updates, |
| 537 const UpdateCheckCallback& update_check_callback) override { | 572 const UpdateCheckCallback& update_check_callback) override { |
| 538 /* | 573 /* |
| 539 Fake the following response: | 574 Fake the following response: |
| 540 | 575 |
| 541 <?xml version='1.0' encoding='UTF-8'?> | 576 <?xml version='1.0' encoding='UTF-8'?> |
| 542 <response protocol='3.0'> | 577 <response protocol='3.0'> |
| 543 <app appid='jebgalgnebhfojomionfpkfelancnnkf'> | 578 <app appid='jebgalgnebhfojomionfpkfelancnnkf'> |
| 544 <updatecheck status='ok'> | 579 <updatecheck status='ok'> |
| (...skipping 18 matching lines...) Expand all Loading... |
| 563 <packages> | 598 <packages> |
| 564 <package name='ihfokbkgjpifnbbojhneepfflplebdkc_1.crx' | 599 <package name='ihfokbkgjpifnbbojhneepfflplebdkc_1.crx' |
| 565 hash_sha256='813c59747e139a608b3b5fc49633affc6db574373f | 600 hash_sha256='813c59747e139a608b3b5fc49633affc6db574373f |
| 566 309f156ea6d27229c0b3f9'/> | 601 309f156ea6d27229c0b3f9'/> |
| 567 </packages> | 602 </packages> |
| 568 </manifest> | 603 </manifest> |
| 569 </updatecheck> | 604 </updatecheck> |
| 570 </app> | 605 </app> |
| 571 </response> | 606 </response> |
| 572 */ | 607 */ |
| 573 UpdateResponse::Result::Manifest::Package package1; | 608 EXPECT_TRUE(enabled_component_updates); |
| 574 package1.name = "jebgalgnebhfojomionfpkfelancnnkf.crx"; | 609 EXPECT_EQ(2u, ids_to_check.size()); |
| 575 package1.hash_sha256 = | |
| 576 "6fc4b93fd11134de1300c2c0bb88c12b644a4ec0fd7c9b12cb7cc067667bde87"; | |
| 577 | 610 |
| 578 UpdateResponse::Result result1; | 611 { |
| 579 result1.extension_id = "jebgalgnebhfojomionfpkfelancnnkf"; | 612 const std::string id = "jebgalgnebhfojomionfpkfelancnnkf"; |
| 580 result1.status = "ok"; | 613 EXPECT_EQ(id, ids_to_check[0]); |
| 581 result1.crx_urls.push_back(GURL("http://localhost/download/")); | 614 EXPECT_EQ(1u, components.count(id)); |
| 582 result1.manifest.version = "1.0"; | |
| 583 result1.manifest.browser_min_version = "11.0.1.0"; | |
| 584 result1.manifest.packages.push_back(package1); | |
| 585 | 615 |
| 586 UpdateResponse::Result::Manifest::Package package2; | 616 UpdateResponse::Result::Manifest::Package package; |
| 587 package2.name = "ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"; | 617 package.name = "jebgalgnebhfojomionfpkfelancnnkf.crx"; |
| 588 package2.hash_sha256 = | 618 package.hash_sha256 = |
| 589 "813c59747e139a608b3b5fc49633affc6db574373f309f156ea6d27229c0b3f9"; | 619 "6fc4b93fd11134de1300c2c0bb88c12b644a4ec0fd7c9b12cb7cc067667bde87"; |
| 590 | 620 |
| 591 UpdateResponse::Result result2; | 621 UpdateResponse::Result result; |
| 592 result2.extension_id = "ihfokbkgjpifnbbojhneepfflplebdkc"; | 622 result.extension_id = id; |
| 593 result2.status = "ok"; | 623 result.status = "ok"; |
| 594 result2.crx_urls.push_back(GURL("http://localhost/download/")); | 624 result.crx_urls.push_back(GURL("http://localhost/download/")); |
| 595 result2.manifest.version = "1.0"; | 625 result.manifest.version = "1.0"; |
| 596 result2.manifest.browser_min_version = "11.0.1.0"; | 626 result.manifest.browser_min_version = "11.0.1.0"; |
| 597 result2.manifest.packages.push_back(package2); | 627 result.manifest.packages.push_back(package); |
| 598 | 628 |
| 599 UpdateResponse::Results results; | 629 auto& component = components.at(id); |
| 600 results.list.push_back(result1); | 630 component->SetParseResult(result); |
| 601 results.list.push_back(result2); | 631 |
| 632 EXPECT_FALSE(component->on_demand()); |
| 633 } |
| 634 |
| 635 { |
| 636 const std::string id = "ihfokbkgjpifnbbojhneepfflplebdkc"; |
| 637 EXPECT_EQ(id, ids_to_check[1]); |
| 638 EXPECT_EQ(1u, components.count(id)); |
| 639 |
| 640 UpdateResponse::Result::Manifest::Package package; |
| 641 package.name = "ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"; |
| 642 package.hash_sha256 = |
| 643 "813c59747e139a608b3b5fc49633affc6db574373f309f156ea6d27229c0b3f9"; |
| 644 |
| 645 UpdateResponse::Result result; |
| 646 result.extension_id = id; |
| 647 result.status = "ok"; |
| 648 result.crx_urls.push_back(GURL("http://localhost/download/")); |
| 649 result.manifest.version = "1.0"; |
| 650 result.manifest.browser_min_version = "11.0.1.0"; |
| 651 result.manifest.packages.push_back(package); |
| 652 |
| 653 auto& component = components.at(id); |
| 654 component->SetParseResult(result); |
| 655 |
| 656 EXPECT_FALSE(component->on_demand()); |
| 657 } |
| 602 | 658 |
| 603 base::ThreadTaskRunnerHandle::Get()->PostTask( | 659 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 604 FROM_HERE, base::Bind(update_check_callback, 0, results, 0)); | 660 FROM_HERE, base::Bind(update_check_callback, 0, 0)); |
| 605 return true; | 661 return true; |
| 606 } | 662 } |
| 607 }; | 663 }; |
| 608 | 664 |
| 609 class FakeCrxDownloader : public CrxDownloader { | 665 class FakeCrxDownloader : public CrxDownloader { |
| 610 public: | 666 public: |
| 611 static std::unique_ptr<CrxDownloader> Create( | 667 static std::unique_ptr<CrxDownloader> Create( |
| 612 bool is_background_download, | 668 bool is_background_download, |
| 613 net::URLRequestContextGetter* context_getter, | 669 net::URLRequestContextGetter* context_getter, |
| 614 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 670 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| 615 return std::unique_ptr<CrxDownloader>(new FakeCrxDownloader()); | 671 return base::MakeUnique<FakeCrxDownloader>(); |
| 616 } | 672 } |
| 617 | 673 |
| 618 private: | |
| 619 FakeCrxDownloader() | 674 FakeCrxDownloader() |
| 620 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} | 675 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} |
| 621 ~FakeCrxDownloader() override {} | |
| 622 | 676 |
| 677 private: |
| 623 void DoStartDownload(const GURL& url) override { | 678 void DoStartDownload(const GURL& url) override { |
| 624 DownloadMetrics download_metrics; | 679 DownloadMetrics download_metrics; |
| 625 FilePath path; | 680 FilePath path; |
| 626 Result result; | 681 Result result; |
| 627 if (url.path() == "/download/jebgalgnebhfojomionfpkfelancnnkf.crx") { | 682 if (url.path() == "/download/jebgalgnebhfojomionfpkfelancnnkf.crx") { |
| 628 download_metrics.url = url; | 683 download_metrics.url = url; |
| 629 download_metrics.downloader = DownloadMetrics::kNone; | 684 download_metrics.downloader = DownloadMetrics::kNone; |
| 630 download_metrics.error = 0; | 685 download_metrics.error = 0; |
| 631 download_metrics.downloaded_bytes = 1843; | 686 download_metrics.downloaded_bytes = 1843; |
| 632 download_metrics.total_bytes = 1843; | 687 download_metrics.total_bytes = 1843; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 base::Bind(&FakeCrxDownloader::OnDownloadComplete, | 723 base::Bind(&FakeCrxDownloader::OnDownloadComplete, |
| 669 base::Unretained(this), true, result, download_metrics)); | 724 base::Unretained(this), true, result, download_metrics)); |
| 670 } | 725 } |
| 671 }; | 726 }; |
| 672 | 727 |
| 673 class FakePingManager : public FakePingManagerImpl { | 728 class FakePingManager : public FakePingManagerImpl { |
| 674 public: | 729 public: |
| 675 explicit FakePingManager(const scoped_refptr<Configurator>& config) | 730 explicit FakePingManager(const scoped_refptr<Configurator>& config) |
| 676 : FakePingManagerImpl(config) {} | 731 : FakePingManagerImpl(config) {} |
| 677 ~FakePingManager() override { | 732 ~FakePingManager() override { |
| 678 const auto& ping_items = items(); | 733 const auto ping_data = FakePingManagerImpl::ping_data(); |
| 679 EXPECT_EQ(2U, ping_items.size()); | 734 EXPECT_EQ(2u, ping_data.size()); |
| 680 EXPECT_EQ("jebgalgnebhfojomionfpkfelancnnkf", ping_items[0].id); | 735 EXPECT_EQ("jebgalgnebhfojomionfpkfelancnnkf", ping_data[0].id); |
| 681 EXPECT_EQ(base::Version("0.9"), ping_items[0].previous_version); | 736 EXPECT_EQ(base::Version("0.9"), ping_data[0].previous_version); |
| 682 EXPECT_EQ(base::Version("1.0"), ping_items[0].next_version); | 737 EXPECT_EQ(base::Version("1.0"), ping_data[0].next_version); |
| 683 EXPECT_EQ(0, ping_items[0].error_category); | 738 EXPECT_EQ(0, ping_data[0].error_category); |
| 684 EXPECT_EQ(0, ping_items[0].error_code); | 739 EXPECT_EQ(0, ping_data[0].error_code); |
| 685 EXPECT_EQ("ihfokbkgjpifnbbojhneepfflplebdkc", ping_items[1].id); | 740 EXPECT_EQ("ihfokbkgjpifnbbojhneepfflplebdkc", ping_data[1].id); |
| 686 EXPECT_EQ(base::Version("0.8"), ping_items[1].previous_version); | 741 EXPECT_EQ(base::Version("0.8"), ping_data[1].previous_version); |
| 687 EXPECT_EQ(base::Version("1.0"), ping_items[1].next_version); | 742 EXPECT_EQ(base::Version("1.0"), ping_data[1].next_version); |
| 688 EXPECT_EQ(0, ping_items[1].error_category); | 743 EXPECT_EQ(0, ping_data[1].error_category); |
| 689 EXPECT_EQ(0, ping_items[1].error_code); | 744 EXPECT_EQ(0, ping_data[1].error_code); |
| 690 } | 745 } |
| 691 }; | 746 }; |
| 692 | 747 |
| 693 std::unique_ptr<FakePingManager> ping_manager(new FakePingManager(config())); | 748 scoped_refptr<UpdateClient> update_client = |
| 694 scoped_refptr<UpdateClient> update_client(new UpdateClientImpl( | 749 base::MakeShared<UpdateClientImpl>( |
| 695 config(), std::move(ping_manager), &FakeUpdateChecker::Create, | 750 config(), base::MakeUnique<FakePingManager>(config()), |
| 696 &FakeCrxDownloader::Create)); | 751 &FakeUpdateChecker::Create, &FakeCrxDownloader::Create); |
| 697 | 752 |
| 698 MockObserver observer; | 753 MockObserver observer; |
| 699 { | 754 { |
| 700 InSequence seq; | 755 InSequence seq; |
| 701 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, | 756 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, |
| 702 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 757 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); |
| 703 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, | 758 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, |
| 704 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 759 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); |
| 705 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, | 760 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, |
| 706 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 761 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 762 .Times(AtLeast(1)); |
| 707 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_READY, | 763 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_READY, |
| 708 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 764 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); |
| 709 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATED, | 765 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATED, |
| 710 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 766 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); |
| 711 } | 767 } |
| 712 { | 768 { |
| 713 InSequence seq; | 769 InSequence seq; |
| 714 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, | 770 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, |
| 715 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 771 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); |
| 716 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, | 772 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, |
| 717 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 773 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); |
| 718 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_WAIT, | 774 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_WAIT, |
| 719 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 775 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); |
| 720 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, | 776 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, |
| 721 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 777 "ihfokbkgjpifnbbojhneepfflplebdkc")) |
| 778 .Times(AtLeast(1)); |
| 722 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_READY, | 779 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_READY, |
| 723 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 780 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); |
| 724 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATED, | 781 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATED, |
| 725 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 782 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); |
| 726 } | 783 } |
| 727 | 784 |
| 728 update_client->AddObserver(&observer); | 785 update_client->AddObserver(&observer); |
| 729 | 786 |
| 730 std::vector<std::string> ids; | 787 const std::vector<std::string> ids = {"jebgalgnebhfojomionfpkfelancnnkf", |
| 731 ids.push_back(std::string("jebgalgnebhfojomionfpkfelancnnkf")); | 788 "ihfokbkgjpifnbbojhneepfflplebdkc"}; |
| 732 ids.push_back(std::string("ihfokbkgjpifnbbojhneepfflplebdkc")); | |
| 733 | |
| 734 update_client->Update( | 789 update_client->Update( |
| 735 ids, base::Bind(&DataCallbackFake::Callback), | 790 ids, base::Bind(&DataCallbackFake::Callback), |
| 736 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); | 791 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
| 737 | 792 |
| 738 RunThreads(); | 793 RunThreads(); |
| 739 | 794 |
| 740 update_client->RemoveObserver(&observer); | 795 update_client->RemoveObserver(&observer); |
| 741 } | 796 } |
| 742 | 797 |
| 743 // Tests the scenario where there is a download timeout for the first | 798 // Tests the scenario where there is a download timeout for the first |
| 744 // CRX. The update for the first CRX fails. The update client waits before | 799 // CRX. The update for the first CRX fails. The update client waits before |
| 745 // attempting the update for the second CRX. This update succeeds. | 800 // attempting the update for the second CRX. This update succeeds. |
| 746 TEST_F(UpdateClientTest, TwoCrxUpdateDownloadTimeout) { | 801 TEST_F(UpdateClientTest, TwoCrxUpdateDownloadTimeout) { |
| 747 class DataCallbackFake { | 802 class DataCallbackFake { |
| 748 public: | 803 public: |
| 749 static void Callback(const std::vector<std::string>& ids, | 804 static void Callback(const std::vector<std::string>& ids, |
| 750 std::vector<CrxComponent>* components) { | 805 std::vector<CrxComponent>* components) { |
| 751 CrxComponent crx1; | 806 CrxComponent crx1; |
| 752 crx1.name = "test_jebg"; | 807 crx1.name = "test_jebg"; |
| 753 crx1.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); | 808 crx1.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
| 754 crx1.version = base::Version("0.9"); | 809 crx1.version = base::Version("0.9"); |
| 755 crx1.installer = new TestInstaller; | 810 crx1.installer = base::MakeShared<TestInstaller>(); |
| 756 | 811 |
| 757 CrxComponent crx2; | 812 CrxComponent crx2; |
| 758 crx2.name = "test_ihfo"; | 813 crx2.name = "test_ihfo"; |
| 759 crx2.pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash)); | 814 crx2.pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash)); |
| 760 crx2.version = base::Version("0.8"); | 815 crx2.version = base::Version("0.8"); |
| 761 crx2.installer = new TestInstaller; | 816 crx2.installer = base::MakeShared<TestInstaller>(); |
| 762 | 817 |
| 763 components->push_back(crx1); | 818 components->push_back(crx1); |
| 764 components->push_back(crx2); | 819 components->push_back(crx2); |
| 765 } | 820 } |
| 766 }; | 821 }; |
| 767 | 822 |
| 768 class CompletionCallbackFake { | 823 class CompletionCallbackFake { |
| 769 public: | 824 public: |
| 770 static void Callback(const base::Closure& quit_closure, Error error) { | 825 static void Callback(const base::Closure& quit_closure, Error error) { |
| 771 EXPECT_EQ(Error::NONE, error); | 826 EXPECT_EQ(Error::NONE, error); |
| 772 quit_closure.Run(); | 827 quit_closure.Run(); |
| 773 } | 828 } |
| 774 }; | 829 }; |
| 775 | 830 |
| 776 class FakeUpdateChecker : public UpdateChecker { | 831 class FakeUpdateChecker : public UpdateChecker { |
| 777 public: | 832 public: |
| 778 static std::unique_ptr<UpdateChecker> Create( | 833 static std::unique_ptr<UpdateChecker> Create( |
| 779 const scoped_refptr<Configurator>& config, | 834 const scoped_refptr<Configurator>& config, |
| 780 PersistedData* metadata) { | 835 PersistedData* metadata) { |
| 781 return std::unique_ptr<UpdateChecker>(new FakeUpdateChecker()); | 836 return base::MakeUnique<FakeUpdateChecker>(); |
| 782 } | 837 } |
| 783 | 838 |
| 784 bool CheckForUpdates( | 839 bool CheckForUpdates( |
| 785 const IdToCrxUpdateItemMap& items_to_check, | 840 const std::vector<std::string>& ids_to_check, |
| 841 const IdToComponentPtrMap& components, |
| 786 const std::string& additional_attributes, | 842 const std::string& additional_attributes, |
| 787 bool enabled_component_updates, | 843 bool enabled_component_updates, |
| 788 const UpdateCheckCallback& update_check_callback) override { | 844 const UpdateCheckCallback& update_check_callback) override { |
| 789 /* | 845 /* |
| 790 Fake the following response: | 846 Fake the following response: |
| 791 | 847 |
| 792 <?xml version='1.0' encoding='UTF-8'?> | 848 <?xml version='1.0' encoding='UTF-8'?> |
| 793 <response protocol='3.0'> | 849 <response protocol='3.0'> |
| 794 <app appid='jebgalgnebhfojomionfpkfelancnnkf'> | 850 <app appid='jebgalgnebhfojomionfpkfelancnnkf'> |
| 795 <updatecheck status='ok'> | 851 <updatecheck status='ok'> |
| (...skipping 18 matching lines...) Expand all Loading... |
| 814 <packages> | 870 <packages> |
| 815 <package name='ihfokbkgjpifnbbojhneepfflplebdkc_1.crx' | 871 <package name='ihfokbkgjpifnbbojhneepfflplebdkc_1.crx' |
| 816 hash_sha256='813c59747e139a608b3b5fc49633affc6db574373f | 872 hash_sha256='813c59747e139a608b3b5fc49633affc6db574373f |
| 817 309f156ea6d27229c0b3f9'/> | 873 309f156ea6d27229c0b3f9'/> |
| 818 </packages> | 874 </packages> |
| 819 </manifest> | 875 </manifest> |
| 820 </updatecheck> | 876 </updatecheck> |
| 821 </app> | 877 </app> |
| 822 </response> | 878 </response> |
| 823 */ | 879 */ |
| 824 UpdateResponse::Result::Manifest::Package package1; | |
| 825 package1.name = "jebgalgnebhfojomionfpkfelancnnkf.crx"; | |
| 826 package1.hash_sha256 = | |
| 827 "6fc4b93fd11134de1300c2c0bb88c12b644a4ec0fd7c9b12cb7cc067667bde87"; | |
| 828 | 880 |
| 829 UpdateResponse::Result result1; | 881 EXPECT_TRUE(enabled_component_updates); |
| 830 result1.extension_id = "jebgalgnebhfojomionfpkfelancnnkf"; | 882 EXPECT_EQ(2u, ids_to_check.size()); |
| 831 result1.status = "ok"; | |
| 832 result1.crx_urls.push_back(GURL("http://localhost/download/")); | |
| 833 result1.manifest.version = "1.0"; | |
| 834 result1.manifest.browser_min_version = "11.0.1.0"; | |
| 835 result1.manifest.packages.push_back(package1); | |
| 836 | 883 |
| 837 UpdateResponse::Result::Manifest::Package package2; | 884 { |
| 838 package2.name = "ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"; | 885 const std::string id = "jebgalgnebhfojomionfpkfelancnnkf"; |
| 839 package2.hash_sha256 = | 886 EXPECT_EQ(id, ids_to_check[0]); |
| 840 "813c59747e139a608b3b5fc49633affc6db574373f309f156ea6d27229c0b3f9"; | 887 EXPECT_EQ(1u, components.count(id)); |
| 841 | 888 |
| 842 UpdateResponse::Result result2; | 889 UpdateResponse::Result::Manifest::Package package; |
| 843 result2.extension_id = "ihfokbkgjpifnbbojhneepfflplebdkc"; | 890 package.name = "jebgalgnebhfojomionfpkfelancnnkf.crx"; |
| 844 result2.status = "ok"; | 891 package.hash_sha256 = |
| 845 result2.crx_urls.push_back(GURL("http://localhost/download/")); | 892 "6fc4b93fd11134de1300c2c0bb88c12b644a4ec0fd7c9b12cb7cc067667bde87"; |
| 846 result2.manifest.version = "1.0"; | |
| 847 result2.manifest.browser_min_version = "11.0.1.0"; | |
| 848 result2.manifest.packages.push_back(package2); | |
| 849 | 893 |
| 850 UpdateResponse::Results results; | 894 UpdateResponse::Result result; |
| 851 results.list.push_back(result1); | 895 result.extension_id = id; |
| 852 results.list.push_back(result2); | 896 result.status = "ok"; |
| 897 result.crx_urls.push_back(GURL("http://localhost/download/")); |
| 898 result.manifest.version = "1.0"; |
| 899 result.manifest.browser_min_version = "11.0.1.0"; |
| 900 result.manifest.packages.push_back(package); |
| 901 |
| 902 auto& component = components.at(id); |
| 903 component->SetParseResult(result); |
| 904 } |
| 905 |
| 906 { |
| 907 const std::string id = "ihfokbkgjpifnbbojhneepfflplebdkc"; |
| 908 EXPECT_EQ(id, ids_to_check[1]); |
| 909 EXPECT_EQ(1u, components.count(id)); |
| 910 |
| 911 UpdateResponse::Result::Manifest::Package package; |
| 912 package.name = "ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"; |
| 913 package.hash_sha256 = |
| 914 "813c59747e139a608b3b5fc49633affc6db574373f309f156ea6d27229c0b3f9"; |
| 915 |
| 916 UpdateResponse::Result result; |
| 917 result.extension_id = id; |
| 918 result.status = "ok"; |
| 919 result.crx_urls.push_back(GURL("http://localhost/download/")); |
| 920 result.manifest.version = "1.0"; |
| 921 result.manifest.browser_min_version = "11.0.1.0"; |
| 922 result.manifest.packages.push_back(package); |
| 923 |
| 924 auto& component = components.at(id); |
| 925 component->SetParseResult(result); |
| 926 } |
| 853 | 927 |
| 854 base::ThreadTaskRunnerHandle::Get()->PostTask( | 928 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 855 FROM_HERE, base::Bind(update_check_callback, 0, results, 0)); | 929 FROM_HERE, base::Bind(update_check_callback, 0, 0)); |
| 856 return true; | 930 return true; |
| 857 } | 931 } |
| 858 }; | 932 }; |
| 859 | 933 |
| 860 class FakeCrxDownloader : public CrxDownloader { | 934 class FakeCrxDownloader : public CrxDownloader { |
| 861 public: | 935 public: |
| 862 static std::unique_ptr<CrxDownloader> Create( | 936 static std::unique_ptr<CrxDownloader> Create( |
| 863 bool is_background_download, | 937 bool is_background_download, |
| 864 net::URLRequestContextGetter* context_getter, | 938 net::URLRequestContextGetter* context_getter, |
| 865 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 939 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| 866 return std::unique_ptr<CrxDownloader>(new FakeCrxDownloader()); | 940 return base::MakeUnique<FakeCrxDownloader>(); |
| 867 } | 941 } |
| 868 | 942 |
| 869 private: | |
| 870 FakeCrxDownloader() | 943 FakeCrxDownloader() |
| 871 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} | 944 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} |
| 872 ~FakeCrxDownloader() override {} | |
| 873 | 945 |
| 946 private: |
| 874 void DoStartDownload(const GURL& url) override { | 947 void DoStartDownload(const GURL& url) override { |
| 875 DownloadMetrics download_metrics; | 948 DownloadMetrics download_metrics; |
| 876 FilePath path; | 949 FilePath path; |
| 877 Result result; | 950 Result result; |
| 878 if (url.path() == "/download/jebgalgnebhfojomionfpkfelancnnkf.crx") { | 951 if (url.path() == "/download/jebgalgnebhfojomionfpkfelancnnkf.crx") { |
| 879 download_metrics.url = url; | 952 download_metrics.url = url; |
| 880 download_metrics.downloader = DownloadMetrics::kNone; | 953 download_metrics.downloader = DownloadMetrics::kNone; |
| 881 download_metrics.error = -118; | 954 download_metrics.error = -118; |
| 882 download_metrics.downloaded_bytes = 0; | 955 download_metrics.downloaded_bytes = 0; |
| 883 download_metrics.total_bytes = 0; | 956 download_metrics.total_bytes = 0; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 base::Bind(&FakeCrxDownloader::OnDownloadComplete, | 992 base::Bind(&FakeCrxDownloader::OnDownloadComplete, |
| 920 base::Unretained(this), true, result, download_metrics)); | 993 base::Unretained(this), true, result, download_metrics)); |
| 921 } | 994 } |
| 922 }; | 995 }; |
| 923 | 996 |
| 924 class FakePingManager : public FakePingManagerImpl { | 997 class FakePingManager : public FakePingManagerImpl { |
| 925 public: | 998 public: |
| 926 explicit FakePingManager(const scoped_refptr<Configurator>& config) | 999 explicit FakePingManager(const scoped_refptr<Configurator>& config) |
| 927 : FakePingManagerImpl(config) {} | 1000 : FakePingManagerImpl(config) {} |
| 928 ~FakePingManager() override { | 1001 ~FakePingManager() override { |
| 929 const auto& ping_items = items(); | 1002 const auto ping_data = FakePingManagerImpl::ping_data(); |
| 930 EXPECT_EQ(2U, ping_items.size()); | 1003 EXPECT_EQ(2u, ping_data.size()); |
| 931 EXPECT_EQ("jebgalgnebhfojomionfpkfelancnnkf", ping_items[0].id); | 1004 EXPECT_EQ("jebgalgnebhfojomionfpkfelancnnkf", ping_data[0].id); |
| 932 EXPECT_EQ(base::Version("0.9"), ping_items[0].previous_version); | 1005 EXPECT_EQ(base::Version("0.9"), ping_data[0].previous_version); |
| 933 EXPECT_EQ(base::Version("1.0"), ping_items[0].next_version); | 1006 EXPECT_EQ(base::Version("1.0"), ping_data[0].next_version); |
| 934 EXPECT_EQ(1, ping_items[0].error_category); // Network error. | 1007 EXPECT_EQ(1, ping_data[0].error_category); |
| 935 EXPECT_EQ(-118, ping_items[0].error_code); | 1008 EXPECT_EQ(-118, ping_data[0].error_code); |
| 936 EXPECT_EQ("ihfokbkgjpifnbbojhneepfflplebdkc", ping_items[1].id); | 1009 EXPECT_EQ("ihfokbkgjpifnbbojhneepfflplebdkc", ping_data[1].id); |
| 937 EXPECT_EQ(base::Version("0.8"), ping_items[1].previous_version); | 1010 EXPECT_EQ(base::Version("0.8"), ping_data[1].previous_version); |
| 938 EXPECT_EQ(base::Version("1.0"), ping_items[1].next_version); | 1011 EXPECT_EQ(base::Version("1.0"), ping_data[1].next_version); |
| 939 EXPECT_EQ(0, ping_items[1].error_category); | 1012 EXPECT_EQ(0, ping_data[1].error_category); |
| 940 EXPECT_EQ(0, ping_items[1].error_code); | 1013 EXPECT_EQ(0, ping_data[1].error_code); |
| 941 } | 1014 } |
| 942 }; | 1015 }; |
| 943 | 1016 |
| 944 std::unique_ptr<FakePingManager> ping_manager(new FakePingManager(config())); | 1017 scoped_refptr<UpdateClient> update_client = |
| 945 scoped_refptr<UpdateClient> update_client(new UpdateClientImpl( | 1018 base::MakeShared<UpdateClientImpl>( |
| 946 config(), std::move(ping_manager), &FakeUpdateChecker::Create, | 1019 config(), base::MakeUnique<FakePingManager>(config()), |
| 947 &FakeCrxDownloader::Create)); | 1020 &FakeUpdateChecker::Create, &FakeCrxDownloader::Create); |
| 948 | 1021 |
| 949 MockObserver observer; | 1022 MockObserver observer; |
| 950 { | 1023 { |
| 951 InSequence seq; | 1024 InSequence seq; |
| 952 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, | 1025 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, |
| 953 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 1026 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); |
| 954 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, | 1027 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, |
| 955 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 1028 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); |
| 956 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, | 1029 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, |
| 957 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 1030 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 1031 .Times(AtLeast(1)); |
| 958 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, | 1032 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, |
| 959 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 1033 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); |
| 960 } | 1034 } |
| 961 { | 1035 { |
| 962 InSequence seq; | 1036 InSequence seq; |
| 963 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, | 1037 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, |
| 964 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 1038 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); |
| 965 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, | 1039 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, |
| 966 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 1040 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); |
| 967 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_WAIT, | 1041 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_WAIT, |
| 968 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 1042 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); |
| 969 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, | 1043 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, |
| 970 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 1044 "ihfokbkgjpifnbbojhneepfflplebdkc")) |
| 1045 .Times(AtLeast(1)); |
| 971 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_READY, | 1046 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_READY, |
| 972 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 1047 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); |
| 973 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATED, | 1048 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATED, |
| 974 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 1049 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); |
| 975 } | 1050 } |
| 976 | 1051 |
| 977 update_client->AddObserver(&observer); | 1052 update_client->AddObserver(&observer); |
| 978 | 1053 |
| 979 std::vector<std::string> ids; | 1054 const std::vector<std::string> ids = {"jebgalgnebhfojomionfpkfelancnnkf", |
| 980 ids.push_back(std::string("jebgalgnebhfojomionfpkfelancnnkf")); | 1055 "ihfokbkgjpifnbbojhneepfflplebdkc"}; |
| 981 ids.push_back(std::string("ihfokbkgjpifnbbojhneepfflplebdkc")); | |
| 982 | 1056 |
| 983 update_client->Update( | 1057 update_client->Update( |
| 984 ids, base::Bind(&DataCallbackFake::Callback), | 1058 ids, base::Bind(&DataCallbackFake::Callback), |
| 985 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); | 1059 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
| 986 | 1060 |
| 987 RunThreads(); | 1061 RunThreads(); |
| 988 | 1062 |
| 989 update_client->RemoveObserver(&observer); | 1063 update_client->RemoveObserver(&observer); |
| 990 } | 1064 } |
| 991 | 1065 |
| 992 // Tests the differential update scenario for one CRX. | 1066 // Tests the differential update scenario for one CRX. |
| 993 TEST_F(UpdateClientTest, OneCrxDiffUpdate) { | 1067 TEST_F(UpdateClientTest, OneCrxDiffUpdate) { |
| 994 class DataCallbackFake { | 1068 class DataCallbackFake { |
| 995 public: | 1069 public: |
| 996 static void Callback(const std::vector<std::string>& ids, | 1070 static void Callback(const std::vector<std::string>& ids, |
| 997 std::vector<CrxComponent>* components) { | 1071 std::vector<CrxComponent>* components) { |
| 998 static int num_calls = 0; | 1072 static int num_calls = 0; |
| 999 | 1073 |
| 1000 // Must use the same stateful installer object. | 1074 // Must use the same stateful installer object. |
| 1001 static scoped_refptr<CrxInstaller> installer( | 1075 static scoped_refptr<CrxInstaller> installer = |
| 1002 new VersionedTestInstaller()); | 1076 base::MakeShared<VersionedTestInstaller>(); |
| 1003 | 1077 |
| 1004 ++num_calls; | 1078 ++num_calls; |
| 1005 | 1079 |
| 1006 CrxComponent crx; | 1080 CrxComponent crx; |
| 1007 crx.name = "test_ihfo"; | 1081 crx.name = "test_ihfo"; |
| 1008 crx.pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash)); | 1082 crx.pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash)); |
| 1009 crx.installer = installer; | 1083 crx.installer = installer; |
| 1010 if (num_calls == 1) { | 1084 if (num_calls == 1) { |
| 1011 crx.version = base::Version("0.8"); | 1085 crx.version = base::Version("0.8"); |
| 1012 } else if (num_calls == 2) { | 1086 } else if (num_calls == 2) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1025 EXPECT_EQ(Error::NONE, error); | 1099 EXPECT_EQ(Error::NONE, error); |
| 1026 quit_closure.Run(); | 1100 quit_closure.Run(); |
| 1027 } | 1101 } |
| 1028 }; | 1102 }; |
| 1029 | 1103 |
| 1030 class FakeUpdateChecker : public UpdateChecker { | 1104 class FakeUpdateChecker : public UpdateChecker { |
| 1031 public: | 1105 public: |
| 1032 static std::unique_ptr<UpdateChecker> Create( | 1106 static std::unique_ptr<UpdateChecker> Create( |
| 1033 const scoped_refptr<Configurator>& config, | 1107 const scoped_refptr<Configurator>& config, |
| 1034 PersistedData* metadata) { | 1108 PersistedData* metadata) { |
| 1035 return std::unique_ptr<UpdateChecker>(new FakeUpdateChecker()); | 1109 return base::MakeUnique<FakeUpdateChecker>(); |
| 1036 } | 1110 } |
| 1037 | 1111 |
| 1038 bool CheckForUpdates( | 1112 bool CheckForUpdates( |
| 1039 const IdToCrxUpdateItemMap& items_to_check, | 1113 const std::vector<std::string>& ids_to_check, |
| 1114 const IdToComponentPtrMap& components, |
| 1040 const std::string& additional_attributes, | 1115 const std::string& additional_attributes, |
| 1041 bool enabled_component_updates, | 1116 bool enabled_component_updates, |
| 1042 const UpdateCheckCallback& update_check_callback) override { | 1117 const UpdateCheckCallback& update_check_callback) override { |
| 1043 static int num_call = 0; | 1118 static int num_call = 0; |
| 1044 ++num_call; | 1119 ++num_call; |
| 1045 | 1120 |
| 1046 UpdateResponse::Results results; | 1121 UpdateResponse::Results results; |
| 1047 | 1122 |
| 1048 if (num_call == 1) { | 1123 if (num_call == 1) { |
| 1049 /* | 1124 /* |
| 1050 Fake the following response: | 1125 Fake the following response: |
| 1051 <?xml version='1.0' encoding='UTF-8'?> | 1126 <?xml version='1.0' encoding='UTF-8'?> |
| 1052 <response protocol='3.0'> | 1127 <response protocol='3.0'> |
| 1053 <app appid='ihfokbkgjpifnbbojhneepfflplebdkc'> | 1128 <app appid='ihfokbkgjpifnbbojhneepfflplebdkc'> |
| 1054 <updatecheck status='ok'> | 1129 <updatecheck status='ok'> |
| 1055 <urls> | 1130 <urls> |
| 1056 <url codebase='http://localhost/download/'/> | 1131 <url codebase='http://localhost/download/'/> |
| 1057 </urls> | 1132 </urls> |
| 1058 <manifest version='1.0' prodversionmin='11.0.1.0'> | 1133 <manifest version='1.0' prodversionmin='11.0.1.0'> |
| 1059 <packages> | 1134 <packages> |
| 1060 <package name='ihfokbkgjpifnbbojhneepfflplebdkc_1.crx' | 1135 <package name='ihfokbkgjpifnbbojhneepfflplebdkc_1.crx' |
| 1061 hash_sha256='813c59747e139a608b3b5fc49633affc6db57437 | 1136 hash_sha256='813c59747e139a608b3b5fc49633affc6db57437 |
| 1062 3f309f156ea6d27229c0b3f9'/> | 1137 3f309f156ea6d27229c0b3f9'/> |
| 1063 </packages> | 1138 </packages> |
| 1064 </manifest> | 1139 </manifest> |
| 1065 </updatecheck> | 1140 </updatecheck> |
| 1066 </app> | 1141 </app> |
| 1067 </response> | 1142 </response> |
| 1068 */ | 1143 */ |
| 1144 const std::string id = "ihfokbkgjpifnbbojhneepfflplebdkc"; |
| 1145 EXPECT_EQ(id, ids_to_check[0]); |
| 1146 EXPECT_EQ(1u, components.count(id)); |
| 1147 |
| 1069 UpdateResponse::Result::Manifest::Package package; | 1148 UpdateResponse::Result::Manifest::Package package; |
| 1070 package.name = "ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"; | 1149 package.name = "ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"; |
| 1071 package.hash_sha256 = | 1150 package.hash_sha256 = |
| 1072 "813c59747e139a608b3b5fc49633affc6db574373f309f156ea6d27229c0b3f9"; | 1151 "813c59747e139a608b3b5fc49633affc6db574373f309f156ea6d27229c0b3f9"; |
| 1073 package.fingerprint = "1"; | 1152 |
| 1074 UpdateResponse::Result result; | 1153 UpdateResponse::Result result; |
| 1075 result.extension_id = "ihfokbkgjpifnbbojhneepfflplebdkc"; | 1154 result.extension_id = id; |
| 1076 result.status = "ok"; | 1155 result.status = "ok"; |
| 1077 result.crx_urls.push_back(GURL("http://localhost/download/")); | 1156 result.crx_urls.push_back(GURL("http://localhost/download/")); |
| 1078 result.manifest.version = "1.0"; | 1157 result.manifest.version = "1.0"; |
| 1079 result.manifest.browser_min_version = "11.0.1.0"; | 1158 result.manifest.browser_min_version = "11.0.1.0"; |
| 1080 result.manifest.packages.push_back(package); | 1159 result.manifest.packages.push_back(package); |
| 1081 results.list.push_back(result); | 1160 |
| 1161 auto& component = components.at(id); |
| 1162 component->SetParseResult(result); |
| 1082 } else if (num_call == 2) { | 1163 } else if (num_call == 2) { |
| 1083 /* | 1164 /* |
| 1084 Fake the following response: | 1165 Fake the following response: |
| 1085 <?xml version='1.0' encoding='UTF-8'?> | 1166 <?xml version='1.0' encoding='UTF-8'?> |
| 1086 <response protocol='3.0'> | 1167 <response protocol='3.0'> |
| 1087 <app appid='ihfokbkgjpifnbbojhneepfflplebdkc'> | 1168 <app appid='ihfokbkgjpifnbbojhneepfflplebdkc'> |
| 1088 <updatecheck status='ok'> | 1169 <updatecheck status='ok'> |
| 1089 <urls> | 1170 <urls> |
| 1090 <url codebase='http://localhost/download/'/> | 1171 <url codebase='http://localhost/download/'/> |
| 1091 <url codebasediff='http://localhost/download/'/> | 1172 <url codebasediff='http://localhost/download/'/> |
| 1092 </urls> | 1173 </urls> |
| 1093 <manifest version='2.0' prodversionmin='11.0.1.0'> | 1174 <manifest version='2.0' prodversionmin='11.0.1.0'> |
| 1094 <packages> | 1175 <packages> |
| 1095 <package name='ihfokbkgjpifnbbojhneepfflplebdkc_2.crx' | 1176 <package name='ihfokbkgjpifnbbojhneepfflplebdkc_2.crx' |
| 1096 namediff='ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx' | 1177 namediff='ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx' |
| 1097 hash_sha256='1af337fbd19c72db0f870753bcd7711c3ae9dcaa | 1178 hash_sha256='1af337fbd19c72db0f870753bcd7711c3ae9dcaa |
| 1098 0ecde26c262bad942b112990' | 1179 0ecde26c262bad942b112990' |
| 1099 fp='22' | 1180 fp='22' |
| 1100 hashdiff_sha256='73c6e2d4f783fc4ca5481e89e0b8bfce7aec | 1181 hashdiff_sha256='73c6e2d4f783fc4ca5481e89e0b8bfce7aec |
| 1101 8ead3686290c94792658ec06f2f2'/> | 1182 8ead3686290c94792658ec06f2f2'/> |
| 1102 </packages> | 1183 </packages> |
| 1103 </manifest> | 1184 </manifest> |
| 1104 </updatecheck> | 1185 </updatecheck> |
| 1105 </app> | 1186 </app> |
| 1106 </response> | 1187 </response> |
| 1107 */ | 1188 */ |
| 1189 const std::string id = "ihfokbkgjpifnbbojhneepfflplebdkc"; |
| 1190 EXPECT_EQ(id, ids_to_check[0]); |
| 1191 EXPECT_EQ(1u, components.count(id)); |
| 1192 |
| 1108 UpdateResponse::Result::Manifest::Package package; | 1193 UpdateResponse::Result::Manifest::Package package; |
| 1109 package.name = "ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"; | 1194 package.name = "ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"; |
| 1110 package.namediff = "ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"; | 1195 package.namediff = "ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"; |
| 1111 package.hash_sha256 = | 1196 package.hash_sha256 = |
| 1112 "1af337fbd19c72db0f870753bcd7711c3ae9dcaa0ecde26c262bad942b112990"; | 1197 "1af337fbd19c72db0f870753bcd7711c3ae9dcaa0ecde26c262bad942b112990"; |
| 1113 package.hashdiff_sha256 = | 1198 package.hashdiff_sha256 = |
| 1114 "73c6e2d4f783fc4ca5481e89e0b8bfce7aec8ead3686290c94792658ec06f2f2"; | 1199 "73c6e2d4f783fc4ca5481e89e0b8bfce7aec8ead3686290c94792658ec06f2f2"; |
| 1115 package.fingerprint = "22"; | 1200 package.fingerprint = "22"; |
| 1201 |
| 1116 UpdateResponse::Result result; | 1202 UpdateResponse::Result result; |
| 1117 result.extension_id = "ihfokbkgjpifnbbojhneepfflplebdkc"; | 1203 result.extension_id = id; |
| 1118 result.status = "ok"; | 1204 result.status = "ok"; |
| 1119 result.crx_urls.push_back(GURL("http://localhost/download/")); | 1205 result.crx_urls.push_back(GURL("http://localhost/download/")); |
| 1120 result.crx_diffurls.push_back(GURL("http://localhost/download/")); | 1206 result.crx_diffurls.push_back(GURL("http://localhost/download/")); |
| 1121 result.manifest.version = "2.0"; | 1207 result.manifest.version = "2.0"; |
| 1122 result.manifest.browser_min_version = "11.0.1.0"; | 1208 result.manifest.browser_min_version = "11.0.1.0"; |
| 1123 result.manifest.packages.push_back(package); | 1209 result.manifest.packages.push_back(package); |
| 1124 results.list.push_back(result); | 1210 |
| 1211 auto& component = components.at(id); |
| 1212 component->SetParseResult(result); |
| 1125 } else { | 1213 } else { |
| 1126 NOTREACHED(); | 1214 NOTREACHED(); |
| 1127 } | 1215 } |
| 1128 | 1216 |
| 1129 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1217 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1130 FROM_HERE, base::Bind(update_check_callback, 0, results, 0)); | 1218 FROM_HERE, base::Bind(update_check_callback, 0, 0)); |
| 1131 return true; | 1219 return true; |
| 1132 } | 1220 } |
| 1133 }; | 1221 }; |
| 1134 | 1222 |
| 1135 class FakeCrxDownloader : public CrxDownloader { | 1223 class FakeCrxDownloader : public CrxDownloader { |
| 1136 public: | 1224 public: |
| 1137 static std::unique_ptr<CrxDownloader> Create( | 1225 static std::unique_ptr<CrxDownloader> Create( |
| 1138 bool is_background_download, | 1226 bool is_background_download, |
| 1139 net::URLRequestContextGetter* context_getter, | 1227 net::URLRequestContextGetter* context_getter, |
| 1140 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 1228 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| 1141 return std::unique_ptr<CrxDownloader>(new FakeCrxDownloader()); | 1229 return base::MakeUnique<FakeCrxDownloader>(); |
| 1142 } | 1230 } |
| 1143 | 1231 |
| 1144 private: | |
| 1145 FakeCrxDownloader() | 1232 FakeCrxDownloader() |
| 1146 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} | 1233 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} |
| 1147 ~FakeCrxDownloader() override {} | |
| 1148 | 1234 |
| 1235 private: |
| 1149 void DoStartDownload(const GURL& url) override { | 1236 void DoStartDownload(const GURL& url) override { |
| 1150 DownloadMetrics download_metrics; | 1237 DownloadMetrics download_metrics; |
| 1151 FilePath path; | 1238 FilePath path; |
| 1152 Result result; | 1239 Result result; |
| 1153 if (url.path() == "/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx") { | 1240 if (url.path() == "/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx") { |
| 1154 download_metrics.url = url; | 1241 download_metrics.url = url; |
| 1155 download_metrics.downloader = DownloadMetrics::kNone; | 1242 download_metrics.downloader = DownloadMetrics::kNone; |
| 1156 download_metrics.error = 0; | 1243 download_metrics.error = 0; |
| 1157 download_metrics.downloaded_bytes = 53638; | 1244 download_metrics.downloaded_bytes = 53638; |
| 1158 download_metrics.total_bytes = 53638; | 1245 download_metrics.total_bytes = 53638; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1194 base::Bind(&FakeCrxDownloader::OnDownloadComplete, | 1281 base::Bind(&FakeCrxDownloader::OnDownloadComplete, |
| 1195 base::Unretained(this), true, result, download_metrics)); | 1282 base::Unretained(this), true, result, download_metrics)); |
| 1196 } | 1283 } |
| 1197 }; | 1284 }; |
| 1198 | 1285 |
| 1199 class FakePingManager : public FakePingManagerImpl { | 1286 class FakePingManager : public FakePingManagerImpl { |
| 1200 public: | 1287 public: |
| 1201 explicit FakePingManager(const scoped_refptr<Configurator>& config) | 1288 explicit FakePingManager(const scoped_refptr<Configurator>& config) |
| 1202 : FakePingManagerImpl(config) {} | 1289 : FakePingManagerImpl(config) {} |
| 1203 ~FakePingManager() override { | 1290 ~FakePingManager() override { |
| 1204 const auto& ping_items = items(); | 1291 const auto ping_data = FakePingManagerImpl::ping_data(); |
| 1205 EXPECT_EQ(2U, ping_items.size()); | 1292 EXPECT_EQ(2u, ping_data.size()); |
| 1206 EXPECT_EQ("ihfokbkgjpifnbbojhneepfflplebdkc", ping_items[0].id); | 1293 EXPECT_EQ("ihfokbkgjpifnbbojhneepfflplebdkc", ping_data[0].id); |
| 1207 EXPECT_EQ(base::Version("0.8"), ping_items[0].previous_version); | 1294 EXPECT_EQ(base::Version("0.8"), ping_data[0].previous_version); |
| 1208 EXPECT_EQ(base::Version("1.0"), ping_items[0].next_version); | 1295 EXPECT_EQ(base::Version("1.0"), ping_data[0].next_version); |
| 1209 EXPECT_EQ(0, ping_items[0].error_category); | 1296 EXPECT_EQ(0, ping_data[0].error_category); |
| 1210 EXPECT_EQ(0, ping_items[0].error_code); | 1297 EXPECT_EQ(0, ping_data[0].error_code); |
| 1211 EXPECT_EQ("ihfokbkgjpifnbbojhneepfflplebdkc", ping_items[1].id); | 1298 EXPECT_EQ("ihfokbkgjpifnbbojhneepfflplebdkc", ping_data[1].id); |
| 1212 EXPECT_EQ(base::Version("1.0"), ping_items[1].previous_version); | 1299 EXPECT_EQ(base::Version("1.0"), ping_data[1].previous_version); |
| 1213 EXPECT_EQ(base::Version("2.0"), ping_items[1].next_version); | 1300 EXPECT_EQ(base::Version("2.0"), ping_data[1].next_version); |
| 1214 EXPECT_EQ(0, ping_items[1].diff_error_category); | 1301 EXPECT_FALSE(ping_data[1].diff_update_failed); |
| 1215 EXPECT_EQ(0, ping_items[1].diff_error_code); | 1302 EXPECT_EQ(0, ping_data[1].diff_error_category); |
| 1303 EXPECT_EQ(0, ping_data[1].diff_error_code); |
| 1304 EXPECT_EQ(0, ping_data[1].error_category); |
| 1305 EXPECT_EQ(0, ping_data[1].error_code); |
| 1216 } | 1306 } |
| 1217 }; | 1307 }; |
| 1218 | 1308 |
| 1219 std::unique_ptr<FakePingManager> ping_manager(new FakePingManager(config())); | 1309 scoped_refptr<UpdateClient> update_client = |
| 1220 scoped_refptr<UpdateClient> update_client(new UpdateClientImpl( | 1310 base::MakeShared<UpdateClientImpl>( |
| 1221 config(), std::move(ping_manager), &FakeUpdateChecker::Create, | 1311 config(), base::MakeUnique<FakePingManager>(config()), |
| 1222 &FakeCrxDownloader::Create)); | 1312 &FakeUpdateChecker::Create, &FakeCrxDownloader::Create); |
| 1223 | 1313 |
| 1224 MockObserver observer; | 1314 MockObserver observer; |
| 1225 { | 1315 { |
| 1226 InSequence seq; | 1316 InSequence seq; |
| 1227 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, | 1317 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, |
| 1228 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 1318 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); |
| 1229 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, | 1319 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, |
| 1230 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 1320 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); |
| 1231 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, | 1321 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, |
| 1232 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 1322 "ihfokbkgjpifnbbojhneepfflplebdkc")) |
| 1323 .Times(AtLeast(1)); |
| 1233 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_READY, | 1324 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_READY, |
| 1234 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 1325 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); |
| 1235 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATED, | 1326 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATED, |
| 1236 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 1327 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); |
| 1237 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, | 1328 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, |
| 1238 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 1329 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); |
| 1239 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, | 1330 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, |
| 1240 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 1331 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); |
| 1241 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, | 1332 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, |
| 1242 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 1333 "ihfokbkgjpifnbbojhneepfflplebdkc")) |
| 1334 .Times(AtLeast(1)); |
| 1243 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_READY, | 1335 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_READY, |
| 1244 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 1336 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); |
| 1245 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATED, | 1337 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATED, |
| 1246 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 1338 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); |
| 1247 } | 1339 } |
| 1248 | 1340 |
| 1249 update_client->AddObserver(&observer); | 1341 update_client->AddObserver(&observer); |
| 1250 | 1342 |
| 1251 std::vector<std::string> ids; | 1343 const std::vector<std::string> ids = {"ihfokbkgjpifnbbojhneepfflplebdkc"}; |
| 1252 ids.push_back(std::string("ihfokbkgjpifnbbojhneepfflplebdkc")); | |
| 1253 | |
| 1254 { | 1344 { |
| 1255 base::RunLoop runloop; | 1345 base::RunLoop runloop; |
| 1256 update_client->Update( | 1346 update_client->Update( |
| 1257 ids, base::Bind(&DataCallbackFake::Callback), | 1347 ids, base::Bind(&DataCallbackFake::Callback), |
| 1258 base::Bind(&CompletionCallbackFake::Callback, runloop.QuitClosure())); | 1348 base::Bind(&CompletionCallbackFake::Callback, runloop.QuitClosure())); |
| 1259 runloop.Run(); | 1349 runloop.Run(); |
| 1260 } | 1350 } |
| 1261 | 1351 |
| 1262 { | 1352 { |
| 1263 base::RunLoop runloop; | 1353 base::RunLoop runloop; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1289 } | 1379 } |
| 1290 | 1380 |
| 1291 protected: | 1381 protected: |
| 1292 ~MockInstaller() override {} | 1382 ~MockInstaller() override {} |
| 1293 }; | 1383 }; |
| 1294 | 1384 |
| 1295 class DataCallbackFake { | 1385 class DataCallbackFake { |
| 1296 public: | 1386 public: |
| 1297 static void Callback(const std::vector<std::string>& ids, | 1387 static void Callback(const std::vector<std::string>& ids, |
| 1298 std::vector<CrxComponent>* components) { | 1388 std::vector<CrxComponent>* components) { |
| 1299 scoped_refptr<MockInstaller> installer(new MockInstaller()); | 1389 scoped_refptr<MockInstaller> installer = |
| 1390 base::MakeShared<MockInstaller>(); |
| 1300 | 1391 |
| 1301 EXPECT_CALL(*installer, OnUpdateError(_)).Times(0); | 1392 EXPECT_CALL(*installer, OnUpdateError(_)).Times(0); |
| 1302 EXPECT_CALL(*installer, Install(_, _)) | 1393 EXPECT_CALL(*installer, Install(_, _)) |
| 1303 .WillOnce( | 1394 .WillOnce( |
| 1304 DoAll(Invoke(MockInstaller::OnInstall), | 1395 DoAll(Invoke(MockInstaller::OnInstall), |
| 1305 Return(CrxInstaller::Result(InstallError::GENERIC_ERROR)))); | 1396 Return(CrxInstaller::Result(InstallError::GENERIC_ERROR)))); |
| 1306 EXPECT_CALL(*installer, GetInstalledFile(_, _)).Times(0); | 1397 EXPECT_CALL(*installer, GetInstalledFile(_, _)).Times(0); |
| 1307 EXPECT_CALL(*installer, Uninstall()).Times(0); | 1398 EXPECT_CALL(*installer, Uninstall()).Times(0); |
| 1308 | 1399 |
| 1309 CrxComponent crx; | 1400 CrxComponent crx; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1321 EXPECT_EQ(Error::NONE, error); | 1412 EXPECT_EQ(Error::NONE, error); |
| 1322 quit_closure.Run(); | 1413 quit_closure.Run(); |
| 1323 } | 1414 } |
| 1324 }; | 1415 }; |
| 1325 | 1416 |
| 1326 class FakeUpdateChecker : public UpdateChecker { | 1417 class FakeUpdateChecker : public UpdateChecker { |
| 1327 public: | 1418 public: |
| 1328 static std::unique_ptr<UpdateChecker> Create( | 1419 static std::unique_ptr<UpdateChecker> Create( |
| 1329 const scoped_refptr<Configurator>& config, | 1420 const scoped_refptr<Configurator>& config, |
| 1330 PersistedData* metadata) { | 1421 PersistedData* metadata) { |
| 1331 return std::unique_ptr<UpdateChecker>(new FakeUpdateChecker()); | 1422 return base::MakeUnique<FakeUpdateChecker>(); |
| 1332 } | 1423 } |
| 1333 | 1424 |
| 1334 bool CheckForUpdates( | 1425 bool CheckForUpdates( |
| 1335 const IdToCrxUpdateItemMap& items_to_check, | 1426 const std::vector<std::string>& ids_to_check, |
| 1427 const IdToComponentPtrMap& components, |
| 1336 const std::string& additional_attributes, | 1428 const std::string& additional_attributes, |
| 1337 bool enabled_component_updates, | 1429 bool enabled_component_updates, |
| 1338 const UpdateCheckCallback& update_check_callback) override { | 1430 const UpdateCheckCallback& update_check_callback) override { |
| 1339 /* | 1431 /* |
| 1340 Fake the following response: | 1432 Fake the following response: |
| 1341 | 1433 |
| 1342 <?xml version='1.0' encoding='UTF-8'?> | 1434 <?xml version='1.0' encoding='UTF-8'?> |
| 1343 <response protocol='3.0'> | 1435 <response protocol='3.0'> |
| 1344 <app appid='jebgalgnebhfojomionfpkfelancnnkf'> | 1436 <app appid='jebgalgnebhfojomionfpkfelancnnkf'> |
| 1345 <updatecheck status='ok'> | 1437 <updatecheck status='ok'> |
| 1346 <urls> | 1438 <urls> |
| 1347 <url codebase='http://localhost/download/'/> | 1439 <url codebase='http://localhost/download/'/> |
| 1348 </urls> | 1440 </urls> |
| 1349 <manifest version='1.0' prodversionmin='11.0.1.0'> | 1441 <manifest version='1.0' prodversionmin='11.0.1.0'> |
| 1350 <packages> | 1442 <packages> |
| 1351 <package name='jebgalgnebhfojomionfpkfelancnnkf.crx' | 1443 <package name='jebgalgnebhfojomionfpkfelancnnkf.crx' |
| 1352 hash_sha256='6fc4b93fd11134de1300c2c0bb88c12b644a4ec0fd | 1444 hash_sha256='6fc4b93fd11134de1300c2c0bb88c12b644a4ec0fd |
| 1353 7c9b12cb7cc067667bde87'/> | 1445 7c9b12cb7cc067667bde87'/> |
| 1354 </packages> | 1446 </packages> |
| 1355 </manifest> | 1447 </manifest> |
| 1356 </updatecheck> | 1448 </updatecheck> |
| 1357 </app> | 1449 </app> |
| 1358 </response> | 1450 </response> |
| 1359 */ | 1451 */ |
| 1452 const std::string id = "jebgalgnebhfojomionfpkfelancnnkf"; |
| 1453 EXPECT_EQ(id, ids_to_check[0]); |
| 1454 EXPECT_EQ(1u, components.count(id)); |
| 1455 |
| 1360 UpdateResponse::Result::Manifest::Package package; | 1456 UpdateResponse::Result::Manifest::Package package; |
| 1361 package.name = "jebgalgnebhfojomionfpkfelancnnkf.crx"; | 1457 package.name = "jebgalgnebhfojomionfpkfelancnnkf.crx"; |
| 1362 package.hash_sha256 = | 1458 package.hash_sha256 = |
| 1363 "6fc4b93fd11134de1300c2c0bb88c12b644a4ec0fd7c9b12cb7cc067667bde87"; | 1459 "6fc4b93fd11134de1300c2c0bb88c12b644a4ec0fd7c9b12cb7cc067667bde87"; |
| 1460 |
| 1364 UpdateResponse::Result result; | 1461 UpdateResponse::Result result; |
| 1365 result.extension_id = "jebgalgnebhfojomionfpkfelancnnkf"; | 1462 result.extension_id = id; |
| 1366 result.status = "ok"; | 1463 result.status = "ok"; |
| 1367 result.crx_urls.push_back(GURL("http://localhost/download/")); | 1464 result.crx_urls.push_back(GURL("http://localhost/download/")); |
| 1368 result.manifest.version = "1.0"; | 1465 result.manifest.version = "1.0"; |
| 1369 result.manifest.browser_min_version = "11.0.1.0"; | 1466 result.manifest.browser_min_version = "11.0.1.0"; |
| 1370 result.manifest.packages.push_back(package); | 1467 result.manifest.packages.push_back(package); |
| 1371 | 1468 |
| 1372 UpdateResponse::Results results; | 1469 auto& component = components.at(id); |
| 1373 results.list.push_back(result); | 1470 component->SetParseResult(result); |
| 1374 | 1471 |
| 1375 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1472 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1376 FROM_HERE, base::Bind(update_check_callback, 0, results, 0)); | 1473 FROM_HERE, base::Bind(update_check_callback, 0, 0)); |
| 1377 return true; | 1474 return true; |
| 1378 } | 1475 } |
| 1379 }; | 1476 }; |
| 1380 | 1477 |
| 1381 class FakeCrxDownloader : public CrxDownloader { | 1478 class FakeCrxDownloader : public CrxDownloader { |
| 1382 public: | 1479 public: |
| 1383 static std::unique_ptr<CrxDownloader> Create( | 1480 static std::unique_ptr<CrxDownloader> Create( |
| 1384 bool is_background_download, | 1481 bool is_background_download, |
| 1385 net::URLRequestContextGetter* context_getter, | 1482 net::URLRequestContextGetter* context_getter, |
| 1386 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 1483 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| 1387 return std::unique_ptr<CrxDownloader>(new FakeCrxDownloader()); | 1484 return base::MakeUnique<FakeCrxDownloader>(); |
| 1388 } | 1485 } |
| 1389 | 1486 |
| 1390 private: | |
| 1391 FakeCrxDownloader() | 1487 FakeCrxDownloader() |
| 1392 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} | 1488 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} |
| 1393 ~FakeCrxDownloader() override {} | |
| 1394 | 1489 |
| 1490 private: |
| 1395 void DoStartDownload(const GURL& url) override { | 1491 void DoStartDownload(const GURL& url) override { |
| 1396 DownloadMetrics download_metrics; | 1492 DownloadMetrics download_metrics; |
| 1397 download_metrics.url = url; | 1493 download_metrics.url = url; |
| 1398 download_metrics.downloader = DownloadMetrics::kNone; | 1494 download_metrics.downloader = DownloadMetrics::kNone; |
| 1399 download_metrics.error = 0; | 1495 download_metrics.error = 0; |
| 1400 download_metrics.downloaded_bytes = 1843; | 1496 download_metrics.downloaded_bytes = 1843; |
| 1401 download_metrics.total_bytes = 1843; | 1497 download_metrics.total_bytes = 1843; |
| 1402 download_metrics.download_time_ms = 1000; | 1498 download_metrics.download_time_ms = 1000; |
| 1403 | 1499 |
| 1404 FilePath path; | 1500 FilePath path; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1420 base::Bind(&FakeCrxDownloader::OnDownloadComplete, | 1516 base::Bind(&FakeCrxDownloader::OnDownloadComplete, |
| 1421 base::Unretained(this), true, result, download_metrics)); | 1517 base::Unretained(this), true, result, download_metrics)); |
| 1422 } | 1518 } |
| 1423 }; | 1519 }; |
| 1424 | 1520 |
| 1425 class FakePingManager : public FakePingManagerImpl { | 1521 class FakePingManager : public FakePingManagerImpl { |
| 1426 public: | 1522 public: |
| 1427 explicit FakePingManager(const scoped_refptr<Configurator>& config) | 1523 explicit FakePingManager(const scoped_refptr<Configurator>& config) |
| 1428 : FakePingManagerImpl(config) {} | 1524 : FakePingManagerImpl(config) {} |
| 1429 ~FakePingManager() override { | 1525 ~FakePingManager() override { |
| 1430 const auto& ping_items = items(); | 1526 const auto ping_data = FakePingManagerImpl::ping_data(); |
| 1431 EXPECT_EQ(1U, ping_items.size()); | 1527 EXPECT_EQ(1u, ping_data.size()); |
| 1432 EXPECT_EQ("jebgalgnebhfojomionfpkfelancnnkf", ping_items[0].id); | 1528 EXPECT_EQ("jebgalgnebhfojomionfpkfelancnnkf", ping_data[0].id); |
| 1433 EXPECT_EQ(base::Version("0.9"), ping_items[0].previous_version); | 1529 EXPECT_EQ(base::Version("0.9"), ping_data[0].previous_version); |
| 1434 EXPECT_EQ(base::Version("1.0"), ping_items[0].next_version); | 1530 EXPECT_EQ(base::Version("1.0"), ping_data[0].next_version); |
| 1435 EXPECT_EQ(3, ping_items[0].error_category); // kInstallError. | 1531 EXPECT_EQ(3, ping_data[0].error_category); // kInstallError. |
| 1436 EXPECT_EQ(9, ping_items[0].error_code); // kInstallerError. | 1532 EXPECT_EQ(9, ping_data[0].error_code); // kInstallerError. |
| 1437 } | 1533 } |
| 1438 }; | 1534 }; |
| 1439 | 1535 |
| 1440 std::unique_ptr<PingManager> ping_manager(new FakePingManager(config())); | 1536 scoped_refptr<UpdateClient> update_client = |
| 1441 scoped_refptr<UpdateClient> update_client(new UpdateClientImpl( | 1537 base::MakeShared<UpdateClientImpl>( |
| 1442 config(), std::move(ping_manager), &FakeUpdateChecker::Create, | 1538 config(), base::MakeUnique<FakePingManager>(config()), |
| 1443 &FakeCrxDownloader::Create)); | 1539 &FakeUpdateChecker::Create, &FakeCrxDownloader::Create); |
| 1444 | 1540 |
| 1445 MockObserver observer; | 1541 MockObserver observer; |
| 1446 { | 1542 { |
| 1447 InSequence seq; | 1543 InSequence seq; |
| 1448 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, | 1544 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, |
| 1449 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 1545 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); |
| 1450 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, | 1546 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, |
| 1451 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 1547 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); |
| 1452 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, | 1548 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, |
| 1453 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 1549 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 1550 .Times(AtLeast(1)); |
| 1454 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_READY, | 1551 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_READY, |
| 1455 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 1552 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); |
| 1456 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, | 1553 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, |
| 1457 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 1554 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); |
| 1458 } | 1555 } |
| 1459 | 1556 |
| 1460 update_client->AddObserver(&observer); | 1557 update_client->AddObserver(&observer); |
| 1461 | 1558 |
| 1462 std::vector<std::string> ids; | 1559 std::vector<std::string> ids = {"jebgalgnebhfojomionfpkfelancnnkf"}; |
| 1463 ids.push_back(std::string("jebgalgnebhfojomionfpkfelancnnkf")); | |
| 1464 | |
| 1465 update_client->Update( | 1560 update_client->Update( |
| 1466 ids, base::Bind(&DataCallbackFake::Callback), | 1561 ids, base::Bind(&DataCallbackFake::Callback), |
| 1467 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); | 1562 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
| 1468 | 1563 |
| 1469 RunThreads(); | 1564 RunThreads(); |
| 1470 | 1565 |
| 1471 update_client->RemoveObserver(&observer); | 1566 update_client->RemoveObserver(&observer); |
| 1472 } | 1567 } |
| 1473 | 1568 |
| 1474 // Tests the fallback from differential to full update scenario for one CRX. | 1569 // Tests the fallback from differential to full update scenario for one CRX. |
| 1475 TEST_F(UpdateClientTest, OneCrxDiffUpdateFailsFullUpdateSucceeds) { | 1570 TEST_F(UpdateClientTest, OneCrxDiffUpdateFailsFullUpdateSucceeds) { |
| 1476 class DataCallbackFake { | 1571 class DataCallbackFake { |
| 1477 public: | 1572 public: |
| 1478 static void Callback(const std::vector<std::string>& ids, | 1573 static void Callback(const std::vector<std::string>& ids, |
| 1479 std::vector<CrxComponent>* components) { | 1574 std::vector<CrxComponent>* components) { |
| 1480 static int num_calls = 0; | 1575 static int num_calls = 0; |
| 1481 | 1576 |
| 1482 // Must use the same stateful installer object. | 1577 // Must use the same stateful installer object. |
| 1483 static scoped_refptr<CrxInstaller> installer( | 1578 static scoped_refptr<CrxInstaller> installer = |
| 1484 new VersionedTestInstaller()); | 1579 base::MakeShared<VersionedTestInstaller>(); |
| 1485 | 1580 |
| 1486 ++num_calls; | 1581 ++num_calls; |
| 1487 | 1582 |
| 1488 CrxComponent crx; | 1583 CrxComponent crx; |
| 1489 crx.name = "test_ihfo"; | 1584 crx.name = "test_ihfo"; |
| 1490 crx.pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash)); | 1585 crx.pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash)); |
| 1491 crx.installer = installer; | 1586 crx.installer = installer; |
| 1492 if (num_calls == 1) { | 1587 if (num_calls == 1) { |
| 1493 crx.version = base::Version("0.8"); | 1588 crx.version = base::Version("0.8"); |
| 1494 } else if (num_calls == 2) { | 1589 } else if (num_calls == 2) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1507 EXPECT_EQ(Error::NONE, error); | 1602 EXPECT_EQ(Error::NONE, error); |
| 1508 quit_closure.Run(); | 1603 quit_closure.Run(); |
| 1509 } | 1604 } |
| 1510 }; | 1605 }; |
| 1511 | 1606 |
| 1512 class FakeUpdateChecker : public UpdateChecker { | 1607 class FakeUpdateChecker : public UpdateChecker { |
| 1513 public: | 1608 public: |
| 1514 static std::unique_ptr<UpdateChecker> Create( | 1609 static std::unique_ptr<UpdateChecker> Create( |
| 1515 const scoped_refptr<Configurator>& config, | 1610 const scoped_refptr<Configurator>& config, |
| 1516 PersistedData* metadata) { | 1611 PersistedData* metadata) { |
| 1517 return std::unique_ptr<UpdateChecker>(new FakeUpdateChecker()); | 1612 return base::MakeUnique<FakeUpdateChecker>(); |
| 1518 } | 1613 } |
| 1519 | 1614 |
| 1520 bool CheckForUpdates( | 1615 bool CheckForUpdates( |
| 1521 const IdToCrxUpdateItemMap& items_to_check, | 1616 const std::vector<std::string>& ids_to_check, |
| 1617 const IdToComponentPtrMap& components, |
| 1522 const std::string& additional_attributes, | 1618 const std::string& additional_attributes, |
| 1523 bool enabled_component_updates, | 1619 bool enabled_component_updates, |
| 1524 const UpdateCheckCallback& update_check_callback) override { | 1620 const UpdateCheckCallback& update_check_callback) override { |
| 1525 static int num_call = 0; | 1621 static int num_call = 0; |
| 1526 ++num_call; | 1622 ++num_call; |
| 1527 | 1623 |
| 1528 UpdateResponse::Results results; | 1624 UpdateResponse::Results results; |
| 1529 | 1625 |
| 1530 if (num_call == 1) { | 1626 if (num_call == 1) { |
| 1531 /* | 1627 /* |
| 1532 Fake the following response: | 1628 Fake the following response: |
| 1533 <?xml version='1.0' encoding='UTF-8'?> | 1629 <?xml version='1.0' encoding='UTF-8'?> |
| 1534 <response protocol='3.0'> | 1630 <response protocol='3.0'> |
| 1535 <app appid='ihfokbkgjpifnbbojhneepfflplebdkc'> | 1631 <app appid='ihfokbkgjpifnbbojhneepfflplebdkc'> |
| 1536 <updatecheck status='ok'> | 1632 <updatecheck status='ok'> |
| 1537 <urls> | 1633 <urls> |
| 1538 <url codebase='http://localhost/download/'/> | 1634 <url codebase='http://localhost/download/'/> |
| 1539 </urls> | 1635 </urls> |
| 1540 <manifest version='1.0' prodversionmin='11.0.1.0'> | 1636 <manifest version='1.0' prodversionmin='11.0.1.0'> |
| 1541 <packages> | 1637 <packages> |
| 1542 <package name='ihfokbkgjpifnbbojhneepfflplebdkc_1.crx' | 1638 <package name='ihfokbkgjpifnbbojhneepfflplebdkc_1.crx' |
| 1543 hash_sha256='813c59747e139a608b3b5fc49633affc6db57437 | 1639 hash_sha256='813c59747e139a608b3b5fc49633affc6db57437 |
| 1544 3f309f156ea6d27229c0b3f9'/> | 1640 3f309f156ea6d27229c0b3f9' |
| 1641 fp='1'/> |
| 1545 </packages> | 1642 </packages> |
| 1546 </manifest> | 1643 </manifest> |
| 1547 </updatecheck> | 1644 </updatecheck> |
| 1548 </app> | 1645 </app> |
| 1549 </response> | 1646 </response> |
| 1550 */ | 1647 */ |
| 1648 const std::string id = "ihfokbkgjpifnbbojhneepfflplebdkc"; |
| 1649 EXPECT_EQ(id, ids_to_check[0]); |
| 1650 EXPECT_EQ(1u, components.count(id)); |
| 1651 |
| 1551 UpdateResponse::Result::Manifest::Package package; | 1652 UpdateResponse::Result::Manifest::Package package; |
| 1552 package.name = "ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"; | 1653 package.name = "ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"; |
| 1553 package.hash_sha256 = | 1654 package.hash_sha256 = |
| 1554 "813c59747e139a608b3b5fc49633affc6db574373f309f156ea6d27229c0b3f9"; | 1655 "813c59747e139a608b3b5fc49633affc6db574373f309f156ea6d27229c0b3f9"; |
| 1555 package.fingerprint = "1"; | 1656 package.fingerprint = "1"; |
| 1657 |
| 1556 UpdateResponse::Result result; | 1658 UpdateResponse::Result result; |
| 1557 result.extension_id = "ihfokbkgjpifnbbojhneepfflplebdkc"; | 1659 result.extension_id = id; |
| 1558 result.status = "ok"; | 1660 result.status = "ok"; |
| 1559 result.crx_urls.push_back(GURL("http://localhost/download/")); | 1661 result.crx_urls.push_back(GURL("http://localhost/download/")); |
| 1560 result.manifest.version = "1.0"; | 1662 result.manifest.version = "1.0"; |
| 1561 result.manifest.browser_min_version = "11.0.1.0"; | 1663 result.manifest.browser_min_version = "11.0.1.0"; |
| 1562 result.manifest.packages.push_back(package); | 1664 result.manifest.packages.push_back(package); |
| 1563 results.list.push_back(result); | 1665 |
| 1666 auto& component = components.at(id); |
| 1667 component->SetParseResult(result); |
| 1564 } else if (num_call == 2) { | 1668 } else if (num_call == 2) { |
| 1565 /* | 1669 /* |
| 1566 Fake the following response: | 1670 Fake the following response: |
| 1567 <?xml version='1.0' encoding='UTF-8'?> | 1671 <?xml version='1.0' encoding='UTF-8'?> |
| 1568 <response protocol='3.0'> | 1672 <response protocol='3.0'> |
| 1569 <app appid='ihfokbkgjpifnbbojhneepfflplebdkc'> | 1673 <app appid='ihfokbkgjpifnbbojhneepfflplebdkc'> |
| 1570 <updatecheck status='ok'> | 1674 <updatecheck status='ok'> |
| 1571 <urls> | 1675 <urls> |
| 1572 <url codebase='http://localhost/download/'/> | 1676 <url codebase='http://localhost/download/'/> |
| 1573 <url codebasediff='http://localhost/download/'/> | 1677 <url codebasediff='http://localhost/download/'/> |
| 1574 </urls> | 1678 </urls> |
| 1575 <manifest version='2.0' prodversionmin='11.0.1.0'> | 1679 <manifest version='2.0' prodversionmin='11.0.1.0'> |
| 1576 <packages> | 1680 <packages> |
| 1577 <package name='ihfokbkgjpifnbbojhneepfflplebdkc_2.crx' | 1681 <package name='ihfokbkgjpifnbbojhneepfflplebdkc_2.crx' |
| 1578 namediff='ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx' | 1682 namediff='ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx' |
| 1579 hash_sha256='1af337fbd19c72db0f870753bcd7711c3ae9dcaa | 1683 hash_sha256='1af337fbd19c72db0f870753bcd7711c3ae9dcaa |
| 1580 0ecde26c262bad942b112990' | 1684 0ecde26c262bad942b112990' |
| 1581 fp='22' | 1685 fp='22' |
| 1582 hashdiff_sha256='73c6e2d4f783fc4ca5481e89e0b8bfce7aec | 1686 hashdiff_sha256='73c6e2d4f783fc4ca5481e89e0b8bfce7aec |
| 1583 8ead3686290c94792658ec06f2f2'/> | 1687 8ead3686290c94792658ec06f2f2'/> |
| 1584 </packages> | 1688 </packages> |
| 1585 </manifest> | 1689 </manifest> |
| 1586 </updatecheck> | 1690 </updatecheck> |
| 1587 </app> | 1691 </app> |
| 1588 </response> | 1692 </response> |
| 1589 */ | 1693 */ |
| 1694 const std::string id = "ihfokbkgjpifnbbojhneepfflplebdkc"; |
| 1695 EXPECT_EQ(id, ids_to_check[0]); |
| 1696 EXPECT_EQ(1u, components.count(id)); |
| 1697 |
| 1590 UpdateResponse::Result::Manifest::Package package; | 1698 UpdateResponse::Result::Manifest::Package package; |
| 1591 package.name = "ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"; | 1699 package.name = "ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"; |
| 1592 package.namediff = "ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"; | 1700 package.namediff = "ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"; |
| 1593 package.hash_sha256 = | 1701 package.hash_sha256 = |
| 1594 "1af337fbd19c72db0f870753bcd7711c3ae9dcaa0ecde26c262bad942b112990"; | 1702 "1af337fbd19c72db0f870753bcd7711c3ae9dcaa0ecde26c262bad942b112990"; |
| 1595 package.hashdiff_sha256 = | 1703 package.hashdiff_sha256 = |
| 1596 "73c6e2d4f783fc4ca5481e89e0b8bfce7aec8ead3686290c94792658ec06f2f2"; | 1704 "73c6e2d4f783fc4ca5481e89e0b8bfce7aec8ead3686290c94792658ec06f2f2"; |
| 1597 package.fingerprint = "22"; | 1705 package.fingerprint = "22"; |
| 1706 |
| 1598 UpdateResponse::Result result; | 1707 UpdateResponse::Result result; |
| 1599 result.extension_id = "ihfokbkgjpifnbbojhneepfflplebdkc"; | 1708 result.extension_id = id; |
| 1600 result.status = "ok"; | 1709 result.status = "ok"; |
| 1601 result.crx_urls.push_back(GURL("http://localhost/download/")); | 1710 result.crx_urls.push_back(GURL("http://localhost/download/")); |
| 1602 result.crx_diffurls.push_back(GURL("http://localhost/download/")); | 1711 result.crx_diffurls.push_back(GURL("http://localhost/download/")); |
| 1603 result.manifest.version = "2.0"; | 1712 result.manifest.version = "2.0"; |
| 1604 result.manifest.browser_min_version = "11.0.1.0"; | 1713 result.manifest.browser_min_version = "11.0.1.0"; |
| 1605 result.manifest.packages.push_back(package); | 1714 result.manifest.packages.push_back(package); |
| 1606 results.list.push_back(result); | 1715 |
| 1716 auto& component = components.at(id); |
| 1717 component->SetParseResult(result); |
| 1607 } else { | 1718 } else { |
| 1608 NOTREACHED(); | 1719 NOTREACHED(); |
| 1609 } | 1720 } |
| 1610 | 1721 |
| 1611 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1722 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1612 FROM_HERE, base::Bind(update_check_callback, 0, results, 0)); | 1723 FROM_HERE, base::Bind(update_check_callback, 0, 0)); |
| 1613 return true; | 1724 return true; |
| 1614 } | 1725 } |
| 1615 }; | 1726 }; |
| 1616 | 1727 |
| 1617 class FakeCrxDownloader : public CrxDownloader { | 1728 class FakeCrxDownloader : public CrxDownloader { |
| 1618 public: | 1729 public: |
| 1619 static std::unique_ptr<CrxDownloader> Create( | 1730 static std::unique_ptr<CrxDownloader> Create( |
| 1620 bool is_background_download, | 1731 bool is_background_download, |
| 1621 net::URLRequestContextGetter* context_getter, | 1732 net::URLRequestContextGetter* context_getter, |
| 1622 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 1733 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| 1623 return std::unique_ptr<CrxDownloader>(new FakeCrxDownloader()); | 1734 return base::MakeUnique<FakeCrxDownloader>(); |
| 1624 } | 1735 } |
| 1625 | 1736 |
| 1626 private: | |
| 1627 FakeCrxDownloader() | 1737 FakeCrxDownloader() |
| 1628 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} | 1738 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} |
| 1629 ~FakeCrxDownloader() override {} | |
| 1630 | 1739 |
| 1740 private: |
| 1631 void DoStartDownload(const GURL& url) override { | 1741 void DoStartDownload(const GURL& url) override { |
| 1632 DownloadMetrics download_metrics; | 1742 DownloadMetrics download_metrics; |
| 1633 FilePath path; | 1743 FilePath path; |
| 1634 Result result; | 1744 Result result; |
| 1635 if (url.path() == "/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx") { | 1745 if (url.path() == "/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx") { |
| 1636 download_metrics.url = url; | 1746 download_metrics.url = url; |
| 1637 download_metrics.downloader = DownloadMetrics::kNone; | 1747 download_metrics.downloader = DownloadMetrics::kNone; |
| 1638 download_metrics.error = 0; | 1748 download_metrics.error = 0; |
| 1639 download_metrics.downloaded_bytes = 53638; | 1749 download_metrics.downloaded_bytes = 53638; |
| 1640 download_metrics.total_bytes = 53638; | 1750 download_metrics.total_bytes = 53638; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1691 base::Bind(&FakeCrxDownloader::OnDownloadComplete, | 1801 base::Bind(&FakeCrxDownloader::OnDownloadComplete, |
| 1692 base::Unretained(this), true, result, download_metrics)); | 1802 base::Unretained(this), true, result, download_metrics)); |
| 1693 } | 1803 } |
| 1694 }; | 1804 }; |
| 1695 | 1805 |
| 1696 class FakePingManager : public FakePingManagerImpl { | 1806 class FakePingManager : public FakePingManagerImpl { |
| 1697 public: | 1807 public: |
| 1698 explicit FakePingManager(const scoped_refptr<Configurator>& config) | 1808 explicit FakePingManager(const scoped_refptr<Configurator>& config) |
| 1699 : FakePingManagerImpl(config) {} | 1809 : FakePingManagerImpl(config) {} |
| 1700 ~FakePingManager() override { | 1810 ~FakePingManager() override { |
| 1701 const auto& ping_items = items(); | 1811 const auto ping_data = FakePingManagerImpl::ping_data(); |
| 1702 EXPECT_EQ(2U, ping_items.size()); | 1812 EXPECT_EQ(2u, ping_data.size()); |
| 1703 EXPECT_EQ("ihfokbkgjpifnbbojhneepfflplebdkc", ping_items[0].id); | 1813 EXPECT_EQ("ihfokbkgjpifnbbojhneepfflplebdkc", ping_data[0].id); |
| 1704 EXPECT_EQ(base::Version("0.8"), ping_items[0].previous_version); | 1814 EXPECT_EQ(base::Version("0.8"), ping_data[0].previous_version); |
| 1705 EXPECT_EQ(base::Version("1.0"), ping_items[0].next_version); | 1815 EXPECT_EQ(base::Version("1.0"), ping_data[0].next_version); |
| 1706 EXPECT_EQ(0, ping_items[0].error_category); | 1816 EXPECT_EQ(0, ping_data[0].error_category); |
| 1707 EXPECT_EQ(0, ping_items[0].error_code); | 1817 EXPECT_EQ(0, ping_data[0].error_code); |
| 1708 EXPECT_EQ("ihfokbkgjpifnbbojhneepfflplebdkc", ping_items[1].id); | 1818 EXPECT_EQ("ihfokbkgjpifnbbojhneepfflplebdkc", ping_data[1].id); |
| 1709 EXPECT_EQ(base::Version("1.0"), ping_items[1].previous_version); | 1819 EXPECT_EQ(base::Version("1.0"), ping_data[1].previous_version); |
| 1710 EXPECT_EQ(base::Version("2.0"), ping_items[1].next_version); | 1820 EXPECT_EQ(base::Version("2.0"), ping_data[1].next_version); |
| 1711 EXPECT_TRUE(ping_items[1].diff_update_failed); | 1821 EXPECT_EQ(0, ping_data[1].error_category); |
| 1712 EXPECT_EQ(1, ping_items[1].diff_error_category); // kNetworkError. | 1822 EXPECT_EQ(0, ping_data[1].error_code); |
| 1713 EXPECT_EQ(-1, ping_items[1].diff_error_code); | 1823 EXPECT_TRUE(ping_data[1].diff_update_failed); |
| 1824 EXPECT_EQ(1, ping_data[1].diff_error_category); // kNetworkError. |
| 1825 EXPECT_EQ(-1, ping_data[1].diff_error_code); |
| 1714 } | 1826 } |
| 1715 }; | 1827 }; |
| 1716 | 1828 |
| 1717 std::unique_ptr<FakePingManager> ping_manager(new FakePingManager(config())); | 1829 scoped_refptr<UpdateClient> update_client = |
| 1718 scoped_refptr<UpdateClient> update_client(new UpdateClientImpl( | 1830 base::MakeShared<UpdateClientImpl>( |
| 1719 config(), std::move(ping_manager), &FakeUpdateChecker::Create, | 1831 config(), base::MakeUnique<FakePingManager>(config()), |
| 1720 &FakeCrxDownloader::Create)); | 1832 &FakeUpdateChecker::Create, &FakeCrxDownloader::Create); |
| 1721 | 1833 |
| 1722 MockObserver observer; | 1834 MockObserver observer; |
| 1723 { | 1835 { |
| 1724 InSequence seq; | 1836 InSequence seq; |
| 1725 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, | 1837 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, |
| 1726 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 1838 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); |
| 1727 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, | 1839 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, |
| 1728 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 1840 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); |
| 1729 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, | 1841 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, |
| 1730 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 1842 "ihfokbkgjpifnbbojhneepfflplebdkc")) |
| 1843 .Times(AtLeast(1)); |
| 1731 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_READY, | 1844 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_READY, |
| 1732 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 1845 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); |
| 1733 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATED, | 1846 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATED, |
| 1734 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 1847 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); |
| 1735 | 1848 |
| 1736 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, | 1849 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, |
| 1737 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 1850 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); |
| 1738 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, | 1851 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, |
| 1739 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 1852 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); |
| 1740 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, | 1853 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, |
| 1741 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 1854 "ihfokbkgjpifnbbojhneepfflplebdkc")) |
| 1742 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, | 1855 .Times(AtLeast(1)); |
| 1743 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | |
| 1744 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_READY, | 1856 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_READY, |
| 1745 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 1857 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); |
| 1746 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATED, | 1858 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATED, |
| 1747 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); | 1859 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); |
| 1748 } | 1860 } |
| 1749 | 1861 |
| 1750 update_client->AddObserver(&observer); | 1862 update_client->AddObserver(&observer); |
| 1751 | 1863 |
| 1752 std::vector<std::string> ids; | 1864 const std::vector<std::string> ids = {"ihfokbkgjpifnbbojhneepfflplebdkc"}; |
| 1753 ids.push_back(std::string("ihfokbkgjpifnbbojhneepfflplebdkc")); | |
| 1754 | 1865 |
| 1755 { | 1866 { |
| 1756 base::RunLoop runloop; | 1867 base::RunLoop runloop; |
| 1757 update_client->Update( | 1868 update_client->Update( |
| 1758 ids, base::Bind(&DataCallbackFake::Callback), | 1869 ids, base::Bind(&DataCallbackFake::Callback), |
| 1759 base::Bind(&CompletionCallbackFake::Callback, runloop.QuitClosure())); | 1870 base::Bind(&CompletionCallbackFake::Callback, runloop.QuitClosure())); |
| 1760 runloop.Run(); | 1871 runloop.Run(); |
| 1761 } | 1872 } |
| 1762 | 1873 |
| 1763 { | 1874 { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1776 // after the first check has completed. The CRX has no updates. | 1887 // after the first check has completed. The CRX has no updates. |
| 1777 TEST_F(UpdateClientTest, OneCrxNoUpdateQueuedCall) { | 1888 TEST_F(UpdateClientTest, OneCrxNoUpdateQueuedCall) { |
| 1778 class DataCallbackFake { | 1889 class DataCallbackFake { |
| 1779 public: | 1890 public: |
| 1780 static void Callback(const std::vector<std::string>& ids, | 1891 static void Callback(const std::vector<std::string>& ids, |
| 1781 std::vector<CrxComponent>* components) { | 1892 std::vector<CrxComponent>* components) { |
| 1782 CrxComponent crx; | 1893 CrxComponent crx; |
| 1783 crx.name = "test_jebg"; | 1894 crx.name = "test_jebg"; |
| 1784 crx.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); | 1895 crx.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
| 1785 crx.version = base::Version("0.9"); | 1896 crx.version = base::Version("0.9"); |
| 1786 crx.installer = new TestInstaller; | 1897 crx.installer = base::MakeShared<TestInstaller>(); |
| 1787 components->push_back(crx); | 1898 components->push_back(crx); |
| 1788 } | 1899 } |
| 1789 }; | 1900 }; |
| 1790 | 1901 |
| 1791 class CompletionCallbackFake { | 1902 class CompletionCallbackFake { |
| 1792 public: | 1903 public: |
| 1793 static void Callback(const base::Closure& quit_closure, Error error) { | 1904 static void Callback(const base::Closure& quit_closure, Error error) { |
| 1794 static int num_call = 0; | 1905 static int num_call = 0; |
| 1795 ++num_call; | 1906 ++num_call; |
| 1796 | 1907 |
| 1797 EXPECT_EQ(Error::NONE, error); | 1908 EXPECT_EQ(Error::NONE, error); |
| 1798 | 1909 |
| 1799 if (num_call == 2) | 1910 if (num_call == 2) |
| 1800 quit_closure.Run(); | 1911 quit_closure.Run(); |
| 1801 } | 1912 } |
| 1802 }; | 1913 }; |
| 1803 | 1914 |
| 1804 class FakeUpdateChecker : public UpdateChecker { | 1915 class FakeUpdateChecker : public UpdateChecker { |
| 1805 public: | 1916 public: |
| 1806 static std::unique_ptr<UpdateChecker> Create( | 1917 static std::unique_ptr<UpdateChecker> Create( |
| 1807 const scoped_refptr<Configurator>& config, | 1918 const scoped_refptr<Configurator>& config, |
| 1808 PersistedData* metadata) { | 1919 PersistedData* metadata) { |
| 1809 return std::unique_ptr<UpdateChecker>(new FakeUpdateChecker()); | 1920 return base::MakeUnique<FakeUpdateChecker>(); |
| 1810 } | 1921 } |
| 1811 | 1922 |
| 1812 bool CheckForUpdates( | 1923 bool CheckForUpdates( |
| 1813 const IdToCrxUpdateItemMap& items_to_check, | 1924 const std::vector<std::string>& ids_to_check, |
| 1925 const IdToComponentPtrMap& components, |
| 1814 const std::string& additional_attributes, | 1926 const std::string& additional_attributes, |
| 1815 bool enabled_component_updates, | 1927 bool enabled_component_updates, |
| 1816 const UpdateCheckCallback& update_check_callback) override { | 1928 const UpdateCheckCallback& update_check_callback) override { |
| 1929 EXPECT_TRUE(enabled_component_updates); |
| 1930 EXPECT_EQ(1u, ids_to_check.size()); |
| 1931 const std::string id = "jebgalgnebhfojomionfpkfelancnnkf"; |
| 1932 EXPECT_EQ(id, ids_to_check.front()); |
| 1933 EXPECT_EQ(1u, components.count(id)); |
| 1934 |
| 1935 auto& component = components.at(id); |
| 1936 |
| 1937 EXPECT_FALSE(component->on_demand()); |
| 1938 |
| 1939 UpdateResponse::Result result; |
| 1940 result.extension_id = id; |
| 1941 result.status = "noupdate"; |
| 1942 component->SetParseResult(result); |
| 1943 |
| 1817 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1944 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1818 FROM_HERE, | 1945 FROM_HERE, base::Bind(update_check_callback, 0, 0)); |
| 1819 base::Bind(update_check_callback, 0, UpdateResponse::Results(), 0)); | |
| 1820 return true; | 1946 return true; |
| 1821 } | 1947 } |
| 1822 }; | 1948 }; |
| 1823 | 1949 |
| 1824 class FakeCrxDownloader : public CrxDownloader { | 1950 class FakeCrxDownloader : public CrxDownloader { |
| 1825 public: | 1951 public: |
| 1826 static std::unique_ptr<CrxDownloader> Create( | 1952 static std::unique_ptr<CrxDownloader> Create( |
| 1827 bool is_background_download, | 1953 bool is_background_download, |
| 1828 net::URLRequestContextGetter* context_getter, | 1954 net::URLRequestContextGetter* context_getter, |
| 1829 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 1955 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| 1830 return std::unique_ptr<CrxDownloader>(new FakeCrxDownloader()); | 1956 return base::MakeUnique<FakeCrxDownloader>(); |
| 1831 } | 1957 } |
| 1832 | 1958 |
| 1833 private: | |
| 1834 FakeCrxDownloader() | 1959 FakeCrxDownloader() |
| 1835 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} | 1960 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} |
| 1836 ~FakeCrxDownloader() override {} | |
| 1837 | 1961 |
| 1962 private: |
| 1838 void DoStartDownload(const GURL& url) override { EXPECT_TRUE(false); } | 1963 void DoStartDownload(const GURL& url) override { EXPECT_TRUE(false); } |
| 1839 }; | 1964 }; |
| 1840 | 1965 |
| 1841 class FakePingManager : public FakePingManagerImpl { | 1966 class FakePingManager : public FakePingManagerImpl { |
| 1842 public: | 1967 public: |
| 1843 explicit FakePingManager(const scoped_refptr<Configurator>& config) | 1968 explicit FakePingManager(const scoped_refptr<Configurator>& config) |
| 1844 : FakePingManagerImpl(config) {} | 1969 : FakePingManagerImpl(config) {} |
| 1845 ~FakePingManager() override { EXPECT_TRUE(items().empty()); } | 1970 ~FakePingManager() override { EXPECT_TRUE(ping_data().empty()); } |
| 1846 }; | 1971 }; |
| 1847 | 1972 |
| 1848 std::unique_ptr<PingManager> ping_manager(new FakePingManager(config())); | 1973 std::unique_ptr<PingManager> ping_manager = |
| 1849 scoped_refptr<UpdateClient> update_client(new UpdateClientImpl( | 1974 base::MakeUnique<FakePingManager>(config()); |
| 1850 config(), std::move(ping_manager), &FakeUpdateChecker::Create, | 1975 scoped_refptr<UpdateClient> update_client = |
| 1851 &FakeCrxDownloader::Create)); | 1976 base::MakeShared<UpdateClientImpl>( |
| 1977 config(), base::MakeUnique<FakePingManager>(config()), |
| 1978 &FakeUpdateChecker::Create, &FakeCrxDownloader::Create); |
| 1852 | 1979 |
| 1853 MockObserver observer; | 1980 MockObserver observer; |
| 1854 InSequence seq; | 1981 InSequence seq; |
| 1855 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, | 1982 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, |
| 1856 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 1983 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); |
| 1857 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, | 1984 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, |
| 1858 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 1985 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); |
| 1859 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, | 1986 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, |
| 1860 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 1987 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); |
| 1861 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, | 1988 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, |
| 1862 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 1989 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); |
| 1863 | 1990 |
| 1864 update_client->AddObserver(&observer); | 1991 update_client->AddObserver(&observer); |
| 1865 | 1992 |
| 1866 std::vector<std::string> ids; | 1993 const std::vector<std::string> ids = {"jebgalgnebhfojomionfpkfelancnnkf"}; |
| 1867 ids.push_back(std::string("jebgalgnebhfojomionfpkfelancnnkf")); | |
| 1868 | |
| 1869 update_client->Update( | 1994 update_client->Update( |
| 1870 ids, base::Bind(&DataCallbackFake::Callback), | 1995 ids, base::Bind(&DataCallbackFake::Callback), |
| 1871 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); | 1996 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
| 1872 update_client->Update( | 1997 update_client->Update( |
| 1873 ids, base::Bind(&DataCallbackFake::Callback), | 1998 ids, base::Bind(&DataCallbackFake::Callback), |
| 1874 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); | 1999 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
| 1875 | 2000 |
| 1876 RunThreads(); | 2001 RunThreads(); |
| 1877 | 2002 |
| 1878 update_client->RemoveObserver(&observer); | 2003 update_client->RemoveObserver(&observer); |
| 1879 } | 2004 } |
| 1880 | 2005 |
| 1881 // Tests the install of one CRX. | 2006 // Tests the install of one CRX. |
| 1882 TEST_F(UpdateClientTest, OneCrxInstall) { | 2007 TEST_F(UpdateClientTest, OneCrxInstall) { |
| 1883 class DataCallbackFake { | 2008 class DataCallbackFake { |
| 1884 public: | 2009 public: |
| 1885 static void Callback(const std::vector<std::string>& ids, | 2010 static void Callback(const std::vector<std::string>& ids, |
| 1886 std::vector<CrxComponent>* components) { | 2011 std::vector<CrxComponent>* components) { |
| 1887 CrxComponent crx; | 2012 CrxComponent crx; |
| 1888 crx.name = "test_jebg"; | 2013 crx.name = "test_jebg"; |
| 1889 crx.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); | 2014 crx.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
| 1890 crx.version = base::Version("0.0"); | 2015 crx.version = base::Version("0.0"); |
| 1891 crx.installer = new TestInstaller; | 2016 crx.installer = base::MakeShared<TestInstaller>(); |
| 1892 | 2017 |
| 1893 components->push_back(crx); | 2018 components->push_back(crx); |
| 1894 } | 2019 } |
| 1895 }; | 2020 }; |
| 1896 | 2021 |
| 1897 class CompletionCallbackFake { | 2022 class CompletionCallbackFake { |
| 1898 public: | 2023 public: |
| 1899 static void Callback(const base::Closure& quit_closure, Error error) { | 2024 static void Callback(const base::Closure& quit_closure, Error error) { |
| 1900 EXPECT_EQ(Error::NONE, error); | 2025 EXPECT_EQ(Error::NONE, error); |
| 1901 quit_closure.Run(); | 2026 quit_closure.Run(); |
| 1902 } | 2027 } |
| 1903 }; | 2028 }; |
| 1904 | 2029 |
| 1905 class FakeUpdateChecker : public UpdateChecker { | 2030 class FakeUpdateChecker : public UpdateChecker { |
| 1906 public: | 2031 public: |
| 1907 static std::unique_ptr<UpdateChecker> Create( | 2032 static std::unique_ptr<UpdateChecker> Create( |
| 1908 const scoped_refptr<Configurator>& config, | 2033 const scoped_refptr<Configurator>& config, |
| 1909 PersistedData* metadata) { | 2034 PersistedData* metadata) { |
| 1910 return std::unique_ptr<UpdateChecker>(new FakeUpdateChecker()); | 2035 return base::MakeUnique<FakeUpdateChecker>(); |
| 1911 } | 2036 } |
| 1912 | 2037 |
| 1913 bool CheckForUpdates( | 2038 bool CheckForUpdates( |
| 1914 const IdToCrxUpdateItemMap& items_to_check, | 2039 const std::vector<std::string>& ids_to_check, |
| 2040 const IdToComponentPtrMap& components, |
| 1915 const std::string& additional_attributes, | 2041 const std::string& additional_attributes, |
| 1916 bool enabled_component_updates, | 2042 bool enabled_component_updates, |
| 1917 const UpdateCheckCallback& update_check_callback) override { | 2043 const UpdateCheckCallback& update_check_callback) override { |
| 1918 /* | 2044 /* |
| 1919 Fake the following response: | 2045 Fake the following response: |
| 1920 | 2046 |
| 1921 <?xml version='1.0' encoding='UTF-8'?> | 2047 <?xml version='1.0' encoding='UTF-8'?> |
| 1922 <response protocol='3.0'> | 2048 <response protocol='3.0'> |
| 1923 <app appid='jebgalgnebhfojomionfpkfelancnnkf'> | 2049 <app appid='jebgalgnebhfojomionfpkfelancnnkf'> |
| 1924 <updatecheck status='ok'> | 2050 <updatecheck status='ok'> |
| 1925 <urls> | 2051 <urls> |
| 1926 <url codebase='http://localhost/download/'/> | 2052 <url codebase='http://localhost/download/'/> |
| 1927 </urls> | 2053 </urls> |
| 1928 <manifest version='1.0' prodversionmin='11.0.1.0'> | 2054 <manifest version='1.0' prodversionmin='11.0.1.0'> |
| 1929 <packages> | 2055 <packages> |
| 1930 <package name='jebgalgnebhfojomionfpkfelancnnkf.crx' | 2056 <package name='jebgalgnebhfojomionfpkfelancnnkf.crx' |
| 1931 hash_sha256='6fc4b93fd11134de1300c2c0bb88c12b644a4ec0fd | 2057 hash_sha256='6fc4b93fd11134de1300c2c0bb88c12b644a4ec0fd |
| 1932 7c9b12cb7cc067667bde87'/> | 2058 7c9b12cb7cc067667bde87'/> |
| 1933 </packages> | 2059 </packages> |
| 1934 </manifest> | 2060 </manifest> |
| 1935 </updatecheck> | 2061 </updatecheck> |
| 1936 </app> | 2062 </app> |
| 1937 </response> | 2063 </response> |
| 1938 */ | 2064 */ |
| 2065 EXPECT_TRUE(enabled_component_updates); |
| 2066 EXPECT_EQ(1u, ids_to_check.size()); |
| 2067 |
| 2068 const std::string id = "jebgalgnebhfojomionfpkfelancnnkf"; |
| 2069 EXPECT_EQ(id, ids_to_check[0]); |
| 2070 EXPECT_EQ(1u, components.count(id)); |
| 2071 |
| 1939 UpdateResponse::Result::Manifest::Package package; | 2072 UpdateResponse::Result::Manifest::Package package; |
| 1940 package.name = "jebgalgnebhfojomionfpkfelancnnkf.crx"; | 2073 package.name = "jebgalgnebhfojomionfpkfelancnnkf.crx"; |
| 1941 package.hash_sha256 = | 2074 package.hash_sha256 = |
| 1942 "6fc4b93fd11134de1300c2c0bb88c12b644a4ec0fd7c9b12cb7cc067667bde87"; | 2075 "6fc4b93fd11134de1300c2c0bb88c12b644a4ec0fd7c9b12cb7cc067667bde87"; |
| 2076 |
| 1943 UpdateResponse::Result result; | 2077 UpdateResponse::Result result; |
| 1944 result.extension_id = "jebgalgnebhfojomionfpkfelancnnkf"; | 2078 result.extension_id = id; |
| 1945 result.status = "ok"; | 2079 result.status = "ok"; |
| 1946 result.crx_urls.push_back(GURL("http://localhost/download/")); | 2080 result.crx_urls.push_back(GURL("http://localhost/download/")); |
| 1947 result.manifest.version = "1.0"; | 2081 result.manifest.version = "1.0"; |
| 1948 result.manifest.browser_min_version = "11.0.1.0"; | 2082 result.manifest.browser_min_version = "11.0.1.0"; |
| 1949 result.manifest.packages.push_back(package); | 2083 result.manifest.packages.push_back(package); |
| 1950 | 2084 |
| 1951 UpdateResponse::Results results; | 2085 auto& component = components.at(id); |
| 1952 results.list.push_back(result); | 2086 component->SetParseResult(result); |
| 2087 |
| 2088 // Verify that calling Install sets ondemand. |
| 2089 EXPECT_TRUE(component->on_demand()); |
| 1953 | 2090 |
| 1954 base::ThreadTaskRunnerHandle::Get()->PostTask( | 2091 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1955 FROM_HERE, base::Bind(update_check_callback, 0, results, 0)); | 2092 FROM_HERE, base::Bind(update_check_callback, 0, 0)); |
| 1956 return true; | 2093 return true; |
| 1957 } | 2094 } |
| 1958 }; | 2095 }; |
| 1959 | 2096 |
| 1960 class FakeCrxDownloader : public CrxDownloader { | 2097 class FakeCrxDownloader : public CrxDownloader { |
| 1961 public: | 2098 public: |
| 1962 static std::unique_ptr<CrxDownloader> Create( | 2099 static std::unique_ptr<CrxDownloader> Create( |
| 1963 bool is_background_download, | 2100 bool is_background_download, |
| 1964 net::URLRequestContextGetter* context_getter, | 2101 net::URLRequestContextGetter* context_getter, |
| 1965 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 2102 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| 1966 return std::unique_ptr<CrxDownloader>(new FakeCrxDownloader()); | 2103 return base::MakeUnique<FakeCrxDownloader>(); |
| 1967 } | 2104 } |
| 1968 | 2105 |
| 1969 private: | |
| 1970 FakeCrxDownloader() | 2106 FakeCrxDownloader() |
| 1971 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} | 2107 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} |
| 1972 ~FakeCrxDownloader() override {} | |
| 1973 | 2108 |
| 2109 private: |
| 1974 void DoStartDownload(const GURL& url) override { | 2110 void DoStartDownload(const GURL& url) override { |
| 1975 DownloadMetrics download_metrics; | 2111 DownloadMetrics download_metrics; |
| 1976 FilePath path; | 2112 FilePath path; |
| 1977 Result result; | 2113 Result result; |
| 1978 if (url.path() == "/download/jebgalgnebhfojomionfpkfelancnnkf.crx") { | 2114 if (url.path() == "/download/jebgalgnebhfojomionfpkfelancnnkf.crx") { |
| 1979 download_metrics.url = url; | 2115 download_metrics.url = url; |
| 1980 download_metrics.downloader = DownloadMetrics::kNone; | 2116 download_metrics.downloader = DownloadMetrics::kNone; |
| 1981 download_metrics.error = 0; | 2117 download_metrics.error = 0; |
| 1982 download_metrics.downloaded_bytes = 1843; | 2118 download_metrics.downloaded_bytes = 1843; |
| 1983 download_metrics.total_bytes = 1843; | 2119 download_metrics.total_bytes = 1843; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2003 base::Bind(&FakeCrxDownloader::OnDownloadComplete, | 2139 base::Bind(&FakeCrxDownloader::OnDownloadComplete, |
| 2004 base::Unretained(this), true, result, download_metrics)); | 2140 base::Unretained(this), true, result, download_metrics)); |
| 2005 } | 2141 } |
| 2006 }; | 2142 }; |
| 2007 | 2143 |
| 2008 class FakePingManager : public FakePingManagerImpl { | 2144 class FakePingManager : public FakePingManagerImpl { |
| 2009 public: | 2145 public: |
| 2010 explicit FakePingManager(const scoped_refptr<Configurator>& config) | 2146 explicit FakePingManager(const scoped_refptr<Configurator>& config) |
| 2011 : FakePingManagerImpl(config) {} | 2147 : FakePingManagerImpl(config) {} |
| 2012 ~FakePingManager() override { | 2148 ~FakePingManager() override { |
| 2013 const auto& ping_items = items(); | 2149 const auto ping_data = FakePingManagerImpl::ping_data(); |
| 2014 EXPECT_EQ(1U, ping_items.size()); | 2150 EXPECT_EQ(1u, ping_data.size()); |
| 2015 EXPECT_EQ("jebgalgnebhfojomionfpkfelancnnkf", ping_items[0].id); | 2151 EXPECT_EQ("jebgalgnebhfojomionfpkfelancnnkf", ping_data[0].id); |
| 2016 EXPECT_EQ(base::Version("0.0"), ping_items[0].previous_version); | 2152 EXPECT_EQ(base::Version("0.0"), ping_data[0].previous_version); |
| 2017 EXPECT_EQ(base::Version("1.0"), ping_items[0].next_version); | 2153 EXPECT_EQ(base::Version("1.0"), ping_data[0].next_version); |
| 2018 EXPECT_EQ(0, ping_items[0].error_category); | 2154 EXPECT_EQ(0, ping_data[0].error_category); |
| 2019 EXPECT_EQ(0, ping_items[0].error_code); | 2155 EXPECT_EQ(0, ping_data[0].error_code); |
| 2020 } | 2156 } |
| 2021 }; | 2157 }; |
| 2022 | 2158 |
| 2023 std::unique_ptr<FakePingManager> ping_manager(new FakePingManager(config())); | 2159 scoped_refptr<UpdateClient> update_client = |
| 2024 scoped_refptr<UpdateClient> update_client(new UpdateClientImpl( | 2160 base::MakeShared<UpdateClientImpl>( |
| 2025 config(), std::move(ping_manager), &FakeUpdateChecker::Create, | 2161 config(), base::MakeUnique<FakePingManager>(config()), |
| 2026 &FakeCrxDownloader::Create)); | 2162 &FakeUpdateChecker::Create, &FakeCrxDownloader::Create); |
| 2027 | |
| 2028 // Verify that calling Install sets ondemand. | |
| 2029 OnDemandTester ondemand_tester(update_client, true); | |
| 2030 | 2163 |
| 2031 MockObserver observer; | 2164 MockObserver observer; |
| 2032 ON_CALL(observer, OnEvent(_, _)) | |
| 2033 .WillByDefault(Invoke(&ondemand_tester, &OnDemandTester::CheckOnDemand)); | |
| 2034 | |
| 2035 InSequence seq; | 2165 InSequence seq; |
| 2036 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, | 2166 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, |
| 2037 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 2167 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); |
| 2038 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, | 2168 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, |
| 2039 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 2169 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); |
| 2040 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, | 2170 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, |
| 2041 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 2171 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 2172 .Times(AtLeast(1)); |
| 2042 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_READY, | 2173 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_READY, |
| 2043 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 2174 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); |
| 2044 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATED, | 2175 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATED, |
| 2045 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); | 2176 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); |
| 2046 | 2177 |
| 2047 update_client->AddObserver(&observer); | 2178 update_client->AddObserver(&observer); |
| 2048 | 2179 |
| 2049 update_client->Install( | 2180 update_client->Install( |
| 2050 std::string("jebgalgnebhfojomionfpkfelancnnkf"), | 2181 std::string("jebgalgnebhfojomionfpkfelancnnkf"), |
| 2051 base::Bind(&DataCallbackFake::Callback), | 2182 base::Bind(&DataCallbackFake::Callback), |
| 2052 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); | 2183 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
| 2053 | 2184 |
| 2054 RunThreads(); | 2185 RunThreads(); |
| 2055 | 2186 |
| 2056 update_client->RemoveObserver(&observer); | 2187 update_client->RemoveObserver(&observer); |
| 2057 } | 2188 } |
| 2058 | 2189 |
| 2059 // Tests that overlapping installs of the same CRX result in an error. | 2190 // Tests that overlapping installs of the same CRX result in an error. |
| 2060 TEST_F(UpdateClientTest, ConcurrentInstallSameCRX) { | 2191 TEST_F(UpdateClientTest, ConcurrentInstallSameCRX) { |
| 2061 class DataCallbackFake { | 2192 class DataCallbackFake { |
| 2062 public: | 2193 public: |
| 2063 static void Callback(const std::vector<std::string>& ids, | 2194 static void Callback(const std::vector<std::string>& ids, |
| 2064 std::vector<CrxComponent>* components) { | 2195 std::vector<CrxComponent>* components) { |
| 2065 CrxComponent crx; | 2196 CrxComponent crx; |
| 2066 crx.name = "test_jebg"; | 2197 crx.name = "test_jebg"; |
| 2067 crx.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); | 2198 crx.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
| 2068 crx.version = base::Version("0.0"); | 2199 crx.version = base::Version("0.0"); |
| 2069 crx.installer = new TestInstaller; | 2200 crx.installer = base::MakeShared<TestInstaller>(); |
| 2070 | 2201 |
| 2071 components->push_back(crx); | 2202 components->push_back(crx); |
| 2072 } | 2203 } |
| 2073 }; | 2204 }; |
| 2074 | 2205 |
| 2075 class CompletionCallbackFake { | 2206 class CompletionCallbackFake { |
| 2076 public: | 2207 public: |
| 2077 static void Callback(const base::Closure& quit_closure, Error error) { | 2208 static void Callback(const base::Closure& quit_closure, Error error) { |
| 2078 static int num_call = 0; | 2209 static int num_call = 0; |
| 2079 ++num_call; | 2210 ++num_call; |
| 2080 | 2211 |
| 2081 EXPECT_LE(num_call, 2); | 2212 EXPECT_LE(num_call, 2); |
| 2082 | 2213 |
| 2083 if (num_call == 1) { | 2214 if (num_call == 1) { |
| 2084 EXPECT_EQ(Error::UPDATE_IN_PROGRESS, error); | 2215 EXPECT_EQ(Error::UPDATE_IN_PROGRESS, error); |
| 2085 return; | 2216 return; |
| 2086 } | 2217 } |
| 2087 if (num_call == 2) { | 2218 if (num_call == 2) { |
| 2088 EXPECT_EQ(Error::NONE, error); | 2219 EXPECT_EQ(Error::NONE, error); |
| 2089 quit_closure.Run(); | 2220 quit_closure.Run(); |
| 2090 } | 2221 } |
| 2091 } | 2222 } |
| 2092 }; | 2223 }; |
| 2093 | 2224 |
| 2094 class FakeUpdateChecker : public UpdateChecker { | 2225 class FakeUpdateChecker : public UpdateChecker { |
| 2095 public: | 2226 public: |
| 2096 static std::unique_ptr<UpdateChecker> Create( | 2227 static std::unique_ptr<UpdateChecker> Create( |
| 2097 const scoped_refptr<Configurator>& config, | 2228 const scoped_refptr<Configurator>& config, |
| 2098 PersistedData* metadata) { | 2229 PersistedData* metadata) { |
| 2099 return std::unique_ptr<UpdateChecker>(new FakeUpdateChecker()); | 2230 return base::MakeUnique<FakeUpdateChecker>(); |
| 2100 } | 2231 } |
| 2101 | 2232 |
| 2102 bool CheckForUpdates( | 2233 bool CheckForUpdates( |
| 2103 const IdToCrxUpdateItemMap& items_to_check, | 2234 const std::vector<std::string>& ids_to_check, |
| 2235 const IdToComponentPtrMap& components, |
| 2104 const std::string& additional_attributes, | 2236 const std::string& additional_attributes, |
| 2105 bool enabled_component_updates, | 2237 bool enabled_component_updates, |
| 2106 const UpdateCheckCallback& update_check_callback) override { | 2238 const UpdateCheckCallback& update_check_callback) override { |
| 2239 EXPECT_TRUE(enabled_component_updates); |
| 2240 EXPECT_EQ(1u, ids_to_check.size()); |
| 2241 const std::string id = "jebgalgnebhfojomionfpkfelancnnkf"; |
| 2242 EXPECT_EQ(id, ids_to_check.front()); |
| 2243 EXPECT_EQ(1u, components.count(id)); |
| 2244 |
| 2245 UpdateResponse::Result result; |
| 2246 result.extension_id = id; |
| 2247 result.status = "noupdate"; |
| 2248 |
| 2249 auto& component = components.at(id); |
| 2250 component->SetParseResult(result); |
| 2251 |
| 2252 // Verify that calling Install sets ondemand. |
| 2253 EXPECT_TRUE(component->on_demand()); |
| 2254 |
| 2107 base::ThreadTaskRunnerHandle::Get()->PostTask( | 2255 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 2108 FROM_HERE, | 2256 FROM_HERE, base::Bind(update_check_callback, 0, 0)); |
| 2109 base::Bind(update_check_callback, 0, UpdateResponse::Results(), 0)); | |
| 2110 return true; | 2257 return true; |
| 2111 } | 2258 } |
| 2112 }; | 2259 }; |
| 2113 | 2260 |
| 2114 class FakeCrxDownloader : public CrxDownloader { | 2261 class FakeCrxDownloader : public CrxDownloader { |
| 2115 public: | 2262 public: |
| 2116 static std::unique_ptr<CrxDownloader> Create( | 2263 static std::unique_ptr<CrxDownloader> Create( |
| 2117 bool is_background_download, | 2264 bool is_background_download, |
| 2118 net::URLRequestContextGetter* context_getter, | 2265 net::URLRequestContextGetter* context_getter, |
| 2119 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 2266 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| 2120 return std::unique_ptr<CrxDownloader>(new FakeCrxDownloader()); | 2267 return base::MakeUnique<FakeCrxDownloader>(); |
| 2121 } | 2268 } |
| 2122 | 2269 |
| 2123 private: | |
| 2124 FakeCrxDownloader() | 2270 FakeCrxDownloader() |
| 2125 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} | 2271 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} |
| 2126 ~FakeCrxDownloader() override {} | |
| 2127 | 2272 |
| 2273 private: |
| 2128 void DoStartDownload(const GURL& url) override { EXPECT_TRUE(false); } | 2274 void DoStartDownload(const GURL& url) override { EXPECT_TRUE(false); } |
| 2129 }; | 2275 }; |
| 2130 | 2276 |
| 2131 class FakePingManager : public FakePingManagerImpl { | 2277 class FakePingManager : public FakePingManagerImpl { |
| 2132 public: | 2278 public: |
| 2133 explicit FakePingManager(const scoped_refptr<Configurator>& config) | 2279 explicit FakePingManager(const scoped_refptr<Configurator>& config) |
| 2134 : FakePingManagerImpl(config) {} | 2280 : FakePingManagerImpl(config) {} |
| 2135 ~FakePingManager() override { EXPECT_TRUE(items().empty()); } | 2281 ~FakePingManager() override { EXPECT_TRUE(ping_data().empty()); } |
| 2136 }; | 2282 }; |
| 2137 | 2283 |
| 2138 std::unique_ptr<FakePingManager> ping_manager(new FakePingManager(config())); | 2284 std::unique_ptr<FakePingManager> ping_manager = |
| 2139 scoped_refptr<UpdateClient> update_client(new UpdateClientImpl( | 2285 base::MakeUnique<FakePingManager>(config()); |
| 2140 config(), std::move(ping_manager), &FakeUpdateChecker::Create, | 2286 scoped_refptr<UpdateClient> update_client = |
| 2141 &FakeCrxDownloader::Create)); | 2287 base::MakeShared<UpdateClientImpl>( |
| 2142 | 2288 config(), base::MakeUnique<FakePingManager>(config()), |
| 2143 // Verify that calling Install sets ondemand. | 2289 &FakeUpdateChecker::Create, &FakeCrxDownloader::Create); |
| 2144 OnDemandTester ondemand_tester(update_client, true); | |
| 2145 | 2290 |
| 2146 MockObserver observer; | 2291 MockObserver observer; |
| 2147 ON_CALL(observer, OnEvent(_, _)) | |
| 2148 .WillByDefault(Invoke(&ondemand_tester, &OnDemandTester::CheckOnDemand)); | |
| 2149 | |
| 2150 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, | 2292 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, |
| 2151 "jebgalgnebhfojomionfpkfelancnnkf")) | 2293 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 2152 .Times(1); | 2294 .Times(1); |
| 2153 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, | 2295 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, |
| 2154 "jebgalgnebhfojomionfpkfelancnnkf")) | 2296 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 2155 .Times(1); | 2297 .Times(1); |
| 2156 | 2298 |
| 2157 update_client->AddObserver(&observer); | 2299 update_client->AddObserver(&observer); |
| 2158 | 2300 |
| 2159 update_client->Install( | 2301 update_client->Install( |
| 2160 std::string("jebgalgnebhfojomionfpkfelancnnkf"), | 2302 std::string("jebgalgnebhfojomionfpkfelancnnkf"), |
| 2161 base::Bind(&DataCallbackFake::Callback), | 2303 base::Bind(&DataCallbackFake::Callback), |
| 2162 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); | 2304 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
| 2163 | 2305 |
| 2164 update_client->Install( | 2306 update_client->Install( |
| 2165 std::string("jebgalgnebhfojomionfpkfelancnnkf"), | 2307 std::string("jebgalgnebhfojomionfpkfelancnnkf"), |
| 2166 base::Bind(&DataCallbackFake::Callback), | 2308 base::Bind(&DataCallbackFake::Callback), |
| 2167 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); | 2309 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
| 2168 | 2310 |
| 2169 RunThreads(); | 2311 RunThreads(); |
| 2170 | 2312 |
| 2171 update_client->RemoveObserver(&observer); | 2313 update_client->RemoveObserver(&observer); |
| 2172 } | 2314 } |
| 2173 | 2315 |
| 2174 // Make sure that we don't get any crashes when trying to update an empty list | 2316 // Tests that UpdateClient::Update returns Error::INVALID_ARGUMENT when |
| 2175 // of ids. | 2317 // the |ids| parameter is empty. |
| 2176 TEST_F(UpdateClientTest, EmptyIdList) { | 2318 TEST_F(UpdateClientTest, EmptyIdList) { |
| 2177 class DataCallbackFake { | 2319 class DataCallbackFake { |
| 2178 public: | 2320 public: |
| 2179 static void Callback(const std::vector<std::string>& ids, | 2321 static void Callback(const std::vector<std::string>& ids, |
| 2180 std::vector<CrxComponent>* components) {} | 2322 std::vector<CrxComponent>* components) {} |
| 2181 }; | 2323 }; |
| 2182 | 2324 |
| 2183 class CompletionCallbackFake { | 2325 class CompletionCallbackFake { |
| 2184 public: | 2326 public: |
| 2185 static void Callback(const base::Closure& quit_closure, Error error) { | 2327 static void Callback(const base::Closure& quit_closure, Error error) { |
| 2328 DCHECK_EQ(Error::INVALID_ARGUMENT, error); |
| 2186 quit_closure.Run(); | 2329 quit_closure.Run(); |
| 2187 } | 2330 } |
| 2188 }; | 2331 }; |
| 2332 |
| 2189 class FakeUpdateChecker : public UpdateChecker { | 2333 class FakeUpdateChecker : public UpdateChecker { |
| 2190 public: | 2334 public: |
| 2191 static std::unique_ptr<UpdateChecker> Create( | 2335 static std::unique_ptr<UpdateChecker> Create( |
| 2192 const scoped_refptr<Configurator>& config, | 2336 const scoped_refptr<Configurator>& config, |
| 2193 PersistedData* metadata) { | 2337 PersistedData* metadata) { |
| 2194 return std::unique_ptr<UpdateChecker>(new FakeUpdateChecker()); | 2338 return base::MakeUnique<FakeUpdateChecker>(); |
| 2195 } | 2339 } |
| 2196 | 2340 |
| 2197 bool CheckForUpdates( | 2341 bool CheckForUpdates( |
| 2198 const IdToCrxUpdateItemMap& items_to_check, | 2342 const std::vector<std::string>& ids_to_check, |
| 2343 const IdToComponentPtrMap& components, |
| 2199 const std::string& additional_attributes, | 2344 const std::string& additional_attributes, |
| 2200 bool enabled_component_updates, | 2345 bool enabled_component_updates, |
| 2201 const UpdateCheckCallback& update_check_callback) override { | 2346 const UpdateCheckCallback& update_check_callback) override { |
| 2202 return false; | 2347 return false; |
| 2203 } | 2348 } |
| 2204 }; | 2349 }; |
| 2205 | 2350 |
| 2206 class FakeCrxDownloader : public CrxDownloader { | 2351 class FakeCrxDownloader : public CrxDownloader { |
| 2207 public: | 2352 public: |
| 2208 static std::unique_ptr<CrxDownloader> Create( | 2353 static std::unique_ptr<CrxDownloader> Create( |
| 2209 bool is_background_download, | 2354 bool is_background_download, |
| 2210 net::URLRequestContextGetter* context_getter, | 2355 net::URLRequestContextGetter* context_getter, |
| 2211 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 2356 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| 2212 return std::unique_ptr<CrxDownloader>(new FakeCrxDownloader()); | 2357 return base::MakeUnique<FakeCrxDownloader>(); |
| 2213 } | 2358 } |
| 2214 | 2359 |
| 2215 private: | |
| 2216 FakeCrxDownloader() | 2360 FakeCrxDownloader() |
| 2217 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} | 2361 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} |
| 2218 ~FakeCrxDownloader() override {} | |
| 2219 | 2362 |
| 2363 private: |
| 2220 void DoStartDownload(const GURL& url) override { EXPECT_TRUE(false); } | 2364 void DoStartDownload(const GURL& url) override { EXPECT_TRUE(false); } |
| 2221 }; | 2365 }; |
| 2222 | 2366 |
| 2223 scoped_refptr<UpdateClient> update_client(new UpdateClientImpl( | 2367 scoped_refptr<UpdateClient> update_client = |
| 2224 config(), base::WrapUnique(new FakePingManagerImpl(config())), | 2368 base::MakeShared<UpdateClientImpl>( |
| 2225 &FakeUpdateChecker::Create, &FakeCrxDownloader::Create)); | 2369 config(), base::MakeUnique<FakePingManagerImpl>(config()), |
| 2370 &FakeUpdateChecker::Create, &FakeCrxDownloader::Create); |
| 2226 | 2371 |
| 2227 std::vector<std::string> empty_id_list; | 2372 const std::vector<std::string> empty_id_list; |
| 2228 base::RunLoop runloop; | |
| 2229 update_client->Update( | 2373 update_client->Update( |
| 2230 empty_id_list, base::Bind(&DataCallbackFake::Callback), | 2374 empty_id_list, base::Bind(&DataCallbackFake::Callback), |
| 2231 base::Bind(&CompletionCallbackFake::Callback, runloop.QuitClosure())); | 2375 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
| 2232 runloop.Run(); | 2376 RunThreads(); |
| 2233 } | 2377 } |
| 2234 | 2378 |
| 2235 TEST_F(UpdateClientTest, SendUninstallPing) { | 2379 TEST_F(UpdateClientTest, SendUninstallPing) { |
| 2236 class CompletionCallbackFake { | 2380 class CompletionCallbackFake { |
| 2237 public: | 2381 public: |
| 2238 static void Callback(const base::Closure& quit_closure, Error error) { | 2382 static void Callback(const base::Closure& quit_closure, Error error) { |
| 2239 quit_closure.Run(); | 2383 quit_closure.Run(); |
| 2240 } | 2384 } |
| 2241 }; | 2385 }; |
| 2242 | 2386 |
| 2243 class FakeUpdateChecker : public UpdateChecker { | 2387 class FakeUpdateChecker : public UpdateChecker { |
| 2244 public: | 2388 public: |
| 2245 static std::unique_ptr<UpdateChecker> Create( | 2389 static std::unique_ptr<UpdateChecker> Create( |
| 2246 const scoped_refptr<Configurator>& config, | 2390 const scoped_refptr<Configurator>& config, |
| 2247 PersistedData* metadata) { | 2391 PersistedData* metadata) { |
| 2248 return nullptr; | 2392 return nullptr; |
| 2249 } | 2393 } |
| 2250 | 2394 |
| 2251 bool CheckForUpdates( | 2395 bool CheckForUpdates( |
| 2252 const IdToCrxUpdateItemMap& items_to_check, | 2396 const std::vector<std::string>& ids_to_check, |
| 2397 const IdToComponentPtrMap& components, |
| 2253 const std::string& additional_attributes, | 2398 const std::string& additional_attributes, |
| 2254 bool enabled_component_updates, | 2399 bool enabled_component_updates, |
| 2255 const UpdateCheckCallback& update_check_callback) override { | 2400 const UpdateCheckCallback& update_check_callback) override { |
| 2256 return false; | 2401 return false; |
| 2257 } | 2402 } |
| 2258 }; | 2403 }; |
| 2259 | 2404 |
| 2260 class FakeCrxDownloader : public CrxDownloader { | 2405 class FakeCrxDownloader : public CrxDownloader { |
| 2261 public: | 2406 public: |
| 2262 static std::unique_ptr<CrxDownloader> Create( | 2407 static std::unique_ptr<CrxDownloader> Create( |
| 2263 bool is_background_download, | 2408 bool is_background_download, |
| 2264 net::URLRequestContextGetter* context_getter, | 2409 net::URLRequestContextGetter* context_getter, |
| 2265 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 2410 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| 2266 return nullptr; | 2411 return nullptr; |
| 2267 } | 2412 } |
| 2268 | 2413 |
| 2269 private: | 2414 private: |
| 2270 FakeCrxDownloader() | 2415 FakeCrxDownloader() |
| 2271 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} | 2416 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} |
| 2272 ~FakeCrxDownloader() override {} | 2417 ~FakeCrxDownloader() override {} |
| 2273 | 2418 |
| 2274 void DoStartDownload(const GURL& url) override {} | 2419 void DoStartDownload(const GURL& url) override {} |
| 2275 }; | 2420 }; |
| 2276 | 2421 |
| 2277 class FakePingManager : public FakePingManagerImpl { | 2422 class FakePingManager : public FakePingManagerImpl { |
| 2278 public: | 2423 public: |
| 2279 explicit FakePingManager(const scoped_refptr<Configurator>& config) | 2424 explicit FakePingManager(const scoped_refptr<Configurator>& config) |
| 2280 : FakePingManagerImpl(config) {} | 2425 : FakePingManagerImpl(config) {} |
| 2281 ~FakePingManager() override { | 2426 ~FakePingManager() override { |
| 2282 const auto& ping_items = items(); | 2427 const auto ping_data = FakePingManagerImpl::ping_data(); |
| 2283 EXPECT_EQ(1U, ping_items.size()); | 2428 EXPECT_EQ(1u, ping_data.size()); |
| 2284 EXPECT_EQ("jebgalgnebhfojomionfpkfelancnnkf", ping_items[0].id); | 2429 EXPECT_EQ("jebgalgnebhfojomionfpkfelancnnkf", ping_data[0].id); |
| 2285 EXPECT_EQ(base::Version("1.0"), ping_items[0].previous_version); | 2430 EXPECT_EQ(base::Version("1.0"), ping_data[0].previous_version); |
| 2286 EXPECT_EQ(base::Version("0.0"), ping_items[0].next_version); | 2431 EXPECT_EQ(base::Version("0.0"), ping_data[0].next_version); |
| 2287 EXPECT_EQ(10, ping_items[0].extra_code1); | 2432 EXPECT_EQ(10, ping_data[0].extra_code1); |
| 2288 } | 2433 } |
| 2289 }; | 2434 }; |
| 2290 | 2435 |
| 2291 std::unique_ptr<PingManager> ping_manager(new FakePingManager(config())); | 2436 scoped_refptr<UpdateClient> update_client = |
| 2292 scoped_refptr<UpdateClient> update_client(new UpdateClientImpl( | 2437 base::MakeShared<UpdateClientImpl>( |
| 2293 config(), std::move(ping_manager), &FakeUpdateChecker::Create, | 2438 config(), base::MakeUnique<FakePingManager>(config()), |
| 2294 &FakeCrxDownloader::Create)); | 2439 &FakeUpdateChecker::Create, &FakeCrxDownloader::Create); |
| 2295 | 2440 |
| 2296 update_client->SendUninstallPing( | 2441 update_client->SendUninstallPing( |
| 2297 "jebgalgnebhfojomionfpkfelancnnkf", base::Version("1.0"), 10, | 2442 "jebgalgnebhfojomionfpkfelancnnkf", base::Version("1.0"), 10, |
| 2298 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); | 2443 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
| 2299 | 2444 |
| 2300 RunThreads(); | 2445 RunThreads(); |
| 2301 } | 2446 } |
| 2302 | 2447 |
| 2303 TEST_F(UpdateClientTest, RetryAfter) { | 2448 TEST_F(UpdateClientTest, RetryAfter) { |
| 2304 class DataCallbackFake { | 2449 class DataCallbackFake { |
| 2305 public: | 2450 public: |
| 2306 static void Callback(const std::vector<std::string>& ids, | 2451 static void Callback(const std::vector<std::string>& ids, |
| 2307 std::vector<CrxComponent>* components) { | 2452 std::vector<CrxComponent>* components) { |
| 2308 CrxComponent crx; | 2453 CrxComponent crx; |
| 2309 crx.name = "test_jebg"; | 2454 crx.name = "test_jebg"; |
| 2310 crx.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); | 2455 crx.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
| 2311 crx.version = base::Version("0.9"); | 2456 crx.version = base::Version("0.9"); |
| 2312 crx.installer = new TestInstaller; | 2457 crx.installer = base::MakeShared<TestInstaller>(); |
| 2313 components->push_back(crx); | 2458 components->push_back(crx); |
| 2314 } | 2459 } |
| 2315 }; | 2460 }; |
| 2316 | 2461 |
| 2317 class CompletionCallbackFake { | 2462 class CompletionCallbackFake { |
| 2318 public: | 2463 public: |
| 2319 static void Callback(const base::Closure& quit_closure, Error error) { | 2464 static void Callback(const base::Closure& quit_closure, Error error) { |
| 2320 static int num_call = 0; | 2465 static int num_call = 0; |
| 2321 ++num_call; | 2466 ++num_call; |
| 2322 | 2467 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2340 | 2485 |
| 2341 quit_closure.Run(); | 2486 quit_closure.Run(); |
| 2342 } | 2487 } |
| 2343 }; | 2488 }; |
| 2344 | 2489 |
| 2345 class FakeUpdateChecker : public UpdateChecker { | 2490 class FakeUpdateChecker : public UpdateChecker { |
| 2346 public: | 2491 public: |
| 2347 static std::unique_ptr<UpdateChecker> Create( | 2492 static std::unique_ptr<UpdateChecker> Create( |
| 2348 const scoped_refptr<Configurator>& config, | 2493 const scoped_refptr<Configurator>& config, |
| 2349 PersistedData* metadata) { | 2494 PersistedData* metadata) { |
| 2350 return std::unique_ptr<UpdateChecker>(new FakeUpdateChecker()); | 2495 return base::MakeUnique<FakeUpdateChecker>(); |
| 2351 } | 2496 } |
| 2352 | 2497 |
| 2353 bool CheckForUpdates( | 2498 bool CheckForUpdates( |
| 2354 const IdToCrxUpdateItemMap& items_to_check, | 2499 const std::vector<std::string>& ids_to_check, |
| 2500 const IdToComponentPtrMap& components, |
| 2355 const std::string& additional_attributes, | 2501 const std::string& additional_attributes, |
| 2356 bool enabled_component_updates, | 2502 bool enabled_component_updates, |
| 2357 const UpdateCheckCallback& update_check_callback) override { | 2503 const UpdateCheckCallback& update_check_callback) override { |
| 2358 static int num_call = 0; | 2504 static int num_call = 0; |
| 2359 ++num_call; | 2505 ++num_call; |
| 2360 | 2506 |
| 2361 EXPECT_LE(num_call, 3); | 2507 EXPECT_LE(num_call, 3); |
| 2362 | 2508 |
| 2363 int retry_after_sec(0); | 2509 int retry_after_sec(0); |
| 2364 if (num_call == 1) { | 2510 if (num_call == 1) { |
| 2365 // Throttle the next call. | 2511 // Throttle the next call. |
| 2366 retry_after_sec = 60 * 60; // 1 hour. | 2512 retry_after_sec = 60 * 60; // 1 hour. |
| 2367 } | 2513 } |
| 2368 | 2514 |
| 2515 EXPECT_EQ(1u, ids_to_check.size()); |
| 2516 const std::string id = "jebgalgnebhfojomionfpkfelancnnkf"; |
| 2517 EXPECT_EQ(id, ids_to_check.front()); |
| 2518 EXPECT_EQ(1u, components.count(id)); |
| 2519 |
| 2520 auto& component = components.at(id); |
| 2521 |
| 2522 UpdateResponse::Result result; |
| 2523 result.extension_id = id; |
| 2524 result.status = "noupdate"; |
| 2525 component->SetParseResult(result); |
| 2526 |
| 2369 base::ThreadTaskRunnerHandle::Get()->PostTask( | 2527 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 2370 FROM_HERE, base::Bind(update_check_callback, 0, | 2528 FROM_HERE, base::Bind(update_check_callback, 0, retry_after_sec)); |
| 2371 UpdateResponse::Results(), retry_after_sec)); | |
| 2372 return true; | 2529 return true; |
| 2373 } | 2530 } |
| 2374 }; | 2531 }; |
| 2375 | 2532 |
| 2376 class FakeCrxDownloader : public CrxDownloader { | 2533 class FakeCrxDownloader : public CrxDownloader { |
| 2377 public: | 2534 public: |
| 2378 static std::unique_ptr<CrxDownloader> Create( | 2535 static std::unique_ptr<CrxDownloader> Create( |
| 2379 bool is_background_download, | 2536 bool is_background_download, |
| 2380 net::URLRequestContextGetter* context_getter, | 2537 net::URLRequestContextGetter* context_getter, |
| 2381 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 2538 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| 2382 return std::unique_ptr<CrxDownloader>(new FakeCrxDownloader()); | 2539 return base::MakeUnique<FakeCrxDownloader>(); |
| 2383 } | 2540 } |
| 2384 | 2541 |
| 2385 private: | |
| 2386 FakeCrxDownloader() | 2542 FakeCrxDownloader() |
| 2387 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} | 2543 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} |
| 2388 ~FakeCrxDownloader() override {} | |
| 2389 | 2544 |
| 2545 private: |
| 2390 void DoStartDownload(const GURL& url) override { EXPECT_TRUE(false); } | 2546 void DoStartDownload(const GURL& url) override { EXPECT_TRUE(false); } |
| 2391 }; | 2547 }; |
| 2392 | 2548 |
| 2393 class FakePingManager : public FakePingManagerImpl { | 2549 class FakePingManager : public FakePingManagerImpl { |
| 2394 public: | 2550 public: |
| 2395 explicit FakePingManager(const scoped_refptr<Configurator>& config) | 2551 explicit FakePingManager(const scoped_refptr<Configurator>& config) |
| 2396 : FakePingManagerImpl(config) {} | 2552 : FakePingManagerImpl(config) {} |
| 2397 ~FakePingManager() override { EXPECT_TRUE(items().empty()); } | 2553 ~FakePingManager() override { EXPECT_TRUE(ping_data().empty()); } |
| 2398 }; | 2554 }; |
| 2399 | 2555 |
| 2400 std::unique_ptr<PingManager> ping_manager(new FakePingManager(config())); | 2556 scoped_refptr<UpdateClient> update_client = |
| 2401 scoped_refptr<UpdateClient> update_client(new UpdateClientImpl( | 2557 base::MakeShared<UpdateClientImpl>( |
| 2402 config(), std::move(ping_manager), &FakeUpdateChecker::Create, | 2558 config(), base::MakeUnique<FakePingManager>(config()), |
| 2403 &FakeCrxDownloader::Create)); | 2559 &FakeUpdateChecker::Create, &FakeCrxDownloader::Create); |
| 2404 | 2560 |
| 2405 MockObserver observer; | 2561 MockObserver observer; |
| 2406 | 2562 |
| 2407 InSequence seq; | 2563 InSequence seq; |
| 2408 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, | 2564 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, |
| 2409 "jebgalgnebhfojomionfpkfelancnnkf")) | 2565 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 2410 .Times(1); | 2566 .Times(1); |
| 2411 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, | 2567 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, |
| 2412 "jebgalgnebhfojomionfpkfelancnnkf")) | 2568 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 2413 .Times(1); | 2569 .Times(1); |
| 2414 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, | 2570 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, |
| 2415 "jebgalgnebhfojomionfpkfelancnnkf")) | 2571 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 2416 .Times(1); | 2572 .Times(1); |
| 2417 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, | 2573 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, |
| 2418 "jebgalgnebhfojomionfpkfelancnnkf")) | 2574 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 2419 .Times(1); | 2575 .Times(1); |
| 2420 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, | 2576 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, |
| 2421 "jebgalgnebhfojomionfpkfelancnnkf")) | 2577 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 2422 .Times(1); | 2578 .Times(1); |
| 2423 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, | 2579 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, |
| 2424 "jebgalgnebhfojomionfpkfelancnnkf")) | 2580 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 2425 .Times(1); | 2581 .Times(1); |
| 2426 | 2582 |
| 2427 update_client->AddObserver(&observer); | 2583 update_client->AddObserver(&observer); |
| 2428 | 2584 |
| 2429 std::vector<std::string> ids; | 2585 const std::vector<std::string> ids = {"jebgalgnebhfojomionfpkfelancnnkf"}; |
| 2430 ids.push_back(std::string("jebgalgnebhfojomionfpkfelancnnkf")); | |
| 2431 | |
| 2432 { | 2586 { |
| 2433 // The engine handles this Update call but responds with a valid | 2587 // The engine handles this Update call but responds with a valid |
| 2434 // |retry_after_sec|, which causes subsequent calls to fail. | 2588 // |retry_after_sec|, which causes subsequent calls to fail. |
| 2435 base::RunLoop runloop; | 2589 base::RunLoop runloop; |
| 2436 update_client->Update( | 2590 update_client->Update( |
| 2437 ids, base::Bind(&DataCallbackFake::Callback), | 2591 ids, base::Bind(&DataCallbackFake::Callback), |
| 2438 base::Bind(&CompletionCallbackFake::Callback, runloop.QuitClosure())); | 2592 base::Bind(&CompletionCallbackFake::Callback, runloop.QuitClosure())); |
| 2439 runloop.Run(); | 2593 runloop.Run(); |
| 2440 } | 2594 } |
| 2441 | 2595 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2468 base::Bind(&CompletionCallbackFake::Callback, runloop.QuitClosure())); | 2622 base::Bind(&CompletionCallbackFake::Callback, runloop.QuitClosure())); |
| 2469 runloop.Run(); | 2623 runloop.Run(); |
| 2470 } | 2624 } |
| 2471 | 2625 |
| 2472 update_client->RemoveObserver(&observer); | 2626 update_client->RemoveObserver(&observer); |
| 2473 } | 2627 } |
| 2474 | 2628 |
| 2475 // Tests the update check for two CRXs scenario. The first component supports | 2629 // Tests the update check for two CRXs scenario. The first component supports |
| 2476 // the group policy to enable updates, and has its updates disabled. The second | 2630 // the group policy to enable updates, and has its updates disabled. The second |
| 2477 // component has an update. The server does not honor the "updatedisabled" | 2631 // component has an update. The server does not honor the "updatedisabled" |
| 2478 // attribute and returns updates for both components. | 2632 // attribute and returns updates for both components. However, the update for |
| 2633 // the first component is not apply and the client responds with a |
| 2634 // (SERVICE_ERROR, UPDATE_DISABLED) |
| 2479 TEST_F(UpdateClientTest, TwoCrxUpdateOneUpdateDisabled) { | 2635 TEST_F(UpdateClientTest, TwoCrxUpdateOneUpdateDisabled) { |
| 2480 class DataCallbackFake { | 2636 class DataCallbackFake { |
| 2481 public: | 2637 public: |
| 2482 static void Callback(const std::vector<std::string>& ids, | 2638 static void Callback(const std::vector<std::string>& ids, |
| 2483 std::vector<CrxComponent>* components) { | 2639 std::vector<CrxComponent>* components) { |
| 2484 CrxComponent crx1; | 2640 CrxComponent crx1; |
| 2485 crx1.name = "test_jebg"; | 2641 crx1.name = "test_jebg"; |
| 2486 crx1.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); | 2642 crx1.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
| 2487 crx1.version = base::Version("0.9"); | 2643 crx1.version = base::Version("0.9"); |
| 2488 crx1.installer = new TestInstaller; | 2644 crx1.installer = base::MakeShared<TestInstaller>(); |
| 2489 crx1.supports_group_policy_enable_component_updates = true; | 2645 crx1.supports_group_policy_enable_component_updates = true; |
| 2490 | 2646 |
| 2491 CrxComponent crx2; | 2647 CrxComponent crx2; |
| 2492 crx2.name = "test_ihfo"; | 2648 crx2.name = "test_ihfo"; |
| 2493 crx2.pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash)); | 2649 crx2.pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash)); |
| 2494 crx2.version = base::Version("0.8"); | 2650 crx2.version = base::Version("0.8"); |
| 2495 crx2.installer = new TestInstaller; | 2651 crx2.installer = base::MakeShared<TestInstaller>(); |
| 2496 | 2652 |
| 2497 components->push_back(crx1); | 2653 components->push_back(crx1); |
| 2498 components->push_back(crx2); | 2654 components->push_back(crx2); |
| 2499 } | 2655 } |
| 2500 }; | 2656 }; |
| 2501 | 2657 |
| 2502 class CompletionCallbackFake { | 2658 class CompletionCallbackFake { |
| 2503 public: | 2659 public: |
| 2504 static void Callback(const base::Closure& quit_closure, Error error) { | 2660 static void Callback(const base::Closure& quit_closure, Error error) { |
| 2505 EXPECT_EQ(Error::NONE, error); | 2661 EXPECT_EQ(Error::NONE, error); |
| 2506 quit_closure.Run(); | 2662 quit_closure.Run(); |
| 2507 } | 2663 } |
| 2508 }; | 2664 }; |
| 2509 | 2665 |
| 2510 class FakeUpdateChecker : public UpdateChecker { | 2666 class FakeUpdateChecker : public UpdateChecker { |
| 2511 public: | 2667 public: |
| 2512 static std::unique_ptr<UpdateChecker> Create( | 2668 static std::unique_ptr<UpdateChecker> Create( |
| 2513 const scoped_refptr<Configurator>& config, | 2669 const scoped_refptr<Configurator>& config, |
| 2514 PersistedData* metadata) { | 2670 PersistedData* metadata) { |
| 2515 return std::unique_ptr<UpdateChecker>(new FakeUpdateChecker()); | 2671 return base::MakeUnique<FakeUpdateChecker>(); |
| 2516 } | 2672 } |
| 2517 | 2673 |
| 2518 bool CheckForUpdates( | 2674 bool CheckForUpdates( |
| 2519 const IdToCrxUpdateItemMap& items_to_check, | 2675 const std::vector<std::string>& ids_to_check, |
| 2676 const IdToComponentPtrMap& components, |
| 2520 const std::string& additional_attributes, | 2677 const std::string& additional_attributes, |
| 2521 bool enabled_component_updates, | 2678 bool enabled_component_updates, |
| 2522 const UpdateCheckCallback& update_check_callback) override { | 2679 const UpdateCheckCallback& update_check_callback) override { |
| 2523 /* | 2680 /* |
| 2524 Fake the following response: | 2681 Fake the following response: |
| 2525 | 2682 |
| 2526 <?xml version='1.0' encoding='UTF-8'?> | 2683 <?xml version='1.0' encoding='UTF-8'?> |
| 2527 <response protocol='3.0'> | 2684 <response protocol='3.0'> |
| 2528 <app appid='jebgalgnebhfojomionfpkfelancnnkf'> | 2685 <app appid='jebgalgnebhfojomionfpkfelancnnkf'> |
| 2529 <updatecheck status='ok'> | 2686 <updatecheck status='ok'> |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2555 </app> | 2712 </app> |
| 2556 </response> | 2713 </response> |
| 2557 */ | 2714 */ |
| 2558 | 2715 |
| 2559 // UpdateClient reads the state of |enabled_component_updates| from the | 2716 // UpdateClient reads the state of |enabled_component_updates| from the |
| 2560 // configurator instance, persists its value in the corresponding | 2717 // configurator instance, persists its value in the corresponding |
| 2561 // update context, and propagates it down to each of the update actions, | 2718 // update context, and propagates it down to each of the update actions, |
| 2562 // and further down to the UpdateChecker instance. | 2719 // and further down to the UpdateChecker instance. |
| 2563 EXPECT_FALSE(enabled_component_updates); | 2720 EXPECT_FALSE(enabled_component_updates); |
| 2564 | 2721 |
| 2565 UpdateResponse::Result::Manifest::Package package1; | 2722 EXPECT_EQ(2u, ids_to_check.size()); |
| 2566 package1.name = "jebgalgnebhfojomionfpkfelancnnkf.crx"; | |
| 2567 package1.hash_sha256 = | |
| 2568 "6fc4b93fd11134de1300c2c0bb88c12b644a4ec0fd7c9b12cb7cc067667bde87"; | |
| 2569 | 2723 |
| 2570 UpdateResponse::Result result1; | 2724 { |
| 2571 result1.extension_id = "jebgalgnebhfojomionfpkfelancnnkf"; | 2725 const std::string id = "jebgalgnebhfojomionfpkfelancnnkf"; |
| 2572 result1.status = "ok"; | 2726 EXPECT_EQ(id, ids_to_check[0]); |
| 2573 result1.crx_urls.push_back(GURL("http://localhost/download/")); | 2727 EXPECT_EQ(1u, components.count(id)); |
| 2574 result1.manifest.version = "1.0"; | |
| 2575 result1.manifest.browser_min_version = "11.0.1.0"; | |
| 2576 result1.manifest.packages.push_back(package1); | |
| 2577 | 2728 |
| 2578 UpdateResponse::Result::Manifest::Package package2; | 2729 UpdateResponse::Result::Manifest::Package package; |
| 2579 package2.name = "ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"; | 2730 package.name = "jebgalgnebhfojomionfpkfelancnnkf.crx"; |
| 2580 package2.hash_sha256 = | 2731 package.hash_sha256 = |
| 2581 "813c59747e139a608b3b5fc49633affc6db574373f309f156ea6d27229c0b3f9"; | 2732 "6fc4b93fd11134de1300c2c0bb88c12b644a4ec0fd7c9b12cb7cc067667bde87"; |
| 2582 | 2733 |
| 2583 UpdateResponse::Result result2; | 2734 UpdateResponse::Result result; |
| 2584 result2.extension_id = "ihfokbkgjpifnbbojhneepfflplebdkc"; | 2735 result.extension_id = id; |
| 2585 result2.status = "ok"; | 2736 result.status = "ok"; |
| 2586 result2.crx_urls.push_back(GURL("http://localhost/download/")); | 2737 result.crx_urls.push_back(GURL("http://localhost/download/")); |
| 2587 result2.manifest.version = "1.0"; | 2738 result.manifest.version = "1.0"; |
| 2588 result2.manifest.browser_min_version = "11.0.1.0"; | 2739 result.manifest.browser_min_version = "11.0.1.0"; |
| 2589 result2.manifest.packages.push_back(package2); | 2740 result.manifest.packages.push_back(package); |
| 2590 | 2741 |
| 2591 UpdateResponse::Results results; | 2742 auto& component = components.at(id); |
| 2592 results.list.push_back(result1); | 2743 component->SetParseResult(result); |
| 2593 results.list.push_back(result2); | 2744 } |
| 2745 |
| 2746 { |
| 2747 const std::string id = "ihfokbkgjpifnbbojhneepfflplebdkc"; |
| 2748 EXPECT_EQ(id, ids_to_check[1]); |
| 2749 EXPECT_EQ(1u, components.count(id)); |
| 2750 |
| 2751 UpdateResponse::Result::Manifest::Package package; |
| 2752 package.name = "ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"; |
| 2753 package.hash_sha256 = |
| 2754 "813c59747e139a608b3b5fc49633affc6db574373f309f156ea6d27229c0b3f9"; |
| 2755 |
| 2756 UpdateResponse::Result result; |
| 2757 result.extension_id = id; |
| 2758 result.status = "ok"; |
| 2759 result.crx_urls.push_back(GURL("http://localhost/download/")); |
| 2760 result.manifest.version = "1.0"; |
| 2761 result.manifest.browser_min_version = "11.0.1.0"; |
| 2762 result.manifest.packages.push_back(package); |
| 2763 |
| 2764 auto& component = components.at(id); |
| 2765 component->SetParseResult(result); |
| 2766 } |
| 2594 | 2767 |
| 2595 base::ThreadTaskRunnerHandle::Get()->PostTask( | 2768 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 2596 FROM_HERE, base::Bind(update_check_callback, 0, results, 0)); | 2769 FROM_HERE, base::Bind(update_check_callback, 0, 0)); |
| 2597 return true; | 2770 return true; |
| 2598 } | 2771 } |
| 2599 }; | 2772 }; |
| 2600 | 2773 |
| 2601 class FakeCrxDownloader : public CrxDownloader { | 2774 class FakeCrxDownloader : public CrxDownloader { |
| 2602 public: | 2775 public: |
| 2603 static std::unique_ptr<CrxDownloader> Create( | 2776 static std::unique_ptr<CrxDownloader> Create( |
| 2604 bool is_background_download, | 2777 bool is_background_download, |
| 2605 net::URLRequestContextGetter* context_getter, | 2778 net::URLRequestContextGetter* context_getter, |
| 2606 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 2779 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| 2607 return std::unique_ptr<CrxDownloader>(new FakeCrxDownloader()); | 2780 return base::MakeUnique<FakeCrxDownloader>(); |
| 2608 } | 2781 } |
| 2609 | 2782 |
| 2610 private: | |
| 2611 FakeCrxDownloader() | 2783 FakeCrxDownloader() |
| 2612 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} | 2784 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} |
| 2613 ~FakeCrxDownloader() override {} | |
| 2614 | 2785 |
| 2786 private: |
| 2615 void DoStartDownload(const GURL& url) override { | 2787 void DoStartDownload(const GURL& url) override { |
| 2616 DownloadMetrics download_metrics; | 2788 DownloadMetrics download_metrics; |
| 2617 FilePath path; | 2789 FilePath path; |
| 2618 Result result; | 2790 Result result; |
| 2619 if (url.path() == "/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx") { | 2791 if (url.path() == "/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx") { |
| 2620 download_metrics.url = url; | 2792 download_metrics.url = url; |
| 2621 download_metrics.downloader = DownloadMetrics::kNone; | 2793 download_metrics.downloader = DownloadMetrics::kNone; |
| 2622 download_metrics.error = 0; | 2794 download_metrics.error = 0; |
| 2623 download_metrics.downloaded_bytes = 53638; | 2795 download_metrics.downloaded_bytes = 53638; |
| 2624 download_metrics.total_bytes = 53638; | 2796 download_metrics.total_bytes = 53638; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2644 base::Bind(&FakeCrxDownloader::OnDownloadComplete, | 2816 base::Bind(&FakeCrxDownloader::OnDownloadComplete, |
| 2645 base::Unretained(this), true, result, download_metrics)); | 2817 base::Unretained(this), true, result, download_metrics)); |
| 2646 } | 2818 } |
| 2647 }; | 2819 }; |
| 2648 | 2820 |
| 2649 class FakePingManager : public FakePingManagerImpl { | 2821 class FakePingManager : public FakePingManagerImpl { |
| 2650 public: | 2822 public: |
| 2651 explicit FakePingManager(const scoped_refptr<Configurator>& config) | 2823 explicit FakePingManager(const scoped_refptr<Configurator>& config) |
| 2652 : FakePingManagerImpl(config) {} | 2824 : FakePingManagerImpl(config) {} |
| 2653 ~FakePingManager() override { | 2825 ~FakePingManager() override { |
| 2654 const auto& ping_items = items(); | 2826 const auto ping_data = FakePingManagerImpl::ping_data(); |
| 2655 EXPECT_EQ(2U, ping_items.size()); | 2827 EXPECT_EQ(2u, ping_data.size()); |
| 2656 EXPECT_EQ("jebgalgnebhfojomionfpkfelancnnkf", ping_items[0].id); | 2828 EXPECT_EQ("jebgalgnebhfojomionfpkfelancnnkf", ping_data[0].id); |
| 2657 EXPECT_EQ(base::Version("0.9"), ping_items[0].previous_version); | 2829 EXPECT_EQ(base::Version("0.9"), ping_data[0].previous_version); |
| 2658 EXPECT_EQ(base::Version("1.0"), ping_items[0].next_version); | 2830 EXPECT_EQ(base::Version("1.0"), ping_data[0].next_version); |
| 2659 EXPECT_EQ(4, ping_items[0].error_category); | 2831 EXPECT_EQ(4, ping_data[0].error_category); |
| 2660 EXPECT_EQ(2, ping_items[0].error_code); | 2832 EXPECT_EQ(2, ping_data[0].error_code); |
| 2661 EXPECT_EQ("ihfokbkgjpifnbbojhneepfflplebdkc", ping_items[1].id); | 2833 EXPECT_EQ("ihfokbkgjpifnbbojhneepfflplebdkc", ping_data[1].id); |
| 2662 EXPECT_EQ(base::Version("0.8"), ping_items[1].previous_version); | 2834 EXPECT_EQ(base::Version("0.8"), ping_data[1].previous_version); |
| 2663 EXPECT_EQ(base::Version("1.0"), ping_items[1].next_version); | 2835 EXPECT_EQ(base::Version("1.0"), ping_data[1].next_version); |
| 2664 EXPECT_EQ(0, ping_items[1].error_category); | 2836 EXPECT_EQ(0, ping_data[1].error_category); |
| 2665 EXPECT_EQ(0, ping_items[1].error_code); | 2837 EXPECT_EQ(0, ping_data[1].error_code); |
| 2666 } | 2838 } |
| 2667 }; | 2839 }; |
| 2668 | 2840 |
| 2669 // Disables updates for the components declaring support for the group policy. | 2841 // Disables updates for the components declaring support for the group policy. |
| 2670 config()->SetEnabledComponentUpdates(false); | 2842 config()->SetEnabledComponentUpdates(false); |
| 2671 std::unique_ptr<FakePingManager> ping_manager(new FakePingManager(config())); | 2843 scoped_refptr<UpdateClient> update_client = |
| 2672 scoped_refptr<UpdateClient> update_client(new UpdateClientImpl( | 2844 base::MakeShared<UpdateClientImpl>( |
| 2673 config(), std::move(ping_manager), &FakeUpdateChecker::Create, | 2845 config(), base::MakeUnique<FakePingManager>(config()), |
| 2674 &FakeCrxDownloader::Create)); | 2846 &FakeUpdateChecker::Create, &FakeCrxDownloader::Create); |
| 2675 | 2847 |
| 2676 MockObserver observer; | 2848 MockObserver observer; |
| 2677 { | 2849 { |
| 2678 InSequence seq; | 2850 InSequence seq; |
| 2679 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, | 2851 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, |
| 2680 "jebgalgnebhfojomionfpkfelancnnkf")) | 2852 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 2681 .Times(1); | 2853 .Times(1); |
| 2682 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, | 2854 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, |
| 2683 "jebgalgnebhfojomionfpkfelancnnkf")) | 2855 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 2684 .Times(1); | 2856 .Times(1); |
| 2685 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, | 2857 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, |
| 2686 "jebgalgnebhfojomionfpkfelancnnkf")) | 2858 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 2687 .Times(1); | 2859 .Times(1); |
| 2688 } | 2860 } |
| 2689 { | 2861 { |
| 2690 InSequence seq; | 2862 InSequence seq; |
| 2691 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, | 2863 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, |
| 2692 "ihfokbkgjpifnbbojhneepfflplebdkc")) | 2864 "ihfokbkgjpifnbbojhneepfflplebdkc")) |
| 2693 .Times(1); | 2865 .Times(1); |
| 2694 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, | 2866 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, |
| 2695 "ihfokbkgjpifnbbojhneepfflplebdkc")) | 2867 "ihfokbkgjpifnbbojhneepfflplebdkc")) |
| 2696 .Times(1); | 2868 .Times(1); |
| 2697 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_WAIT, | |
| 2698 "ihfokbkgjpifnbbojhneepfflplebdkc")) | |
| 2699 .Times(1); | |
| 2700 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, | 2869 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, |
| 2701 "ihfokbkgjpifnbbojhneepfflplebdkc")) | 2870 "ihfokbkgjpifnbbojhneepfflplebdkc")) |
| 2702 .Times(1); | 2871 .Times(AtLeast(1)); |
| 2703 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_READY, | 2872 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_READY, |
| 2704 "ihfokbkgjpifnbbojhneepfflplebdkc")) | 2873 "ihfokbkgjpifnbbojhneepfflplebdkc")) |
| 2705 .Times(1); | 2874 .Times(1); |
| 2706 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATED, | 2875 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATED, |
| 2707 "ihfokbkgjpifnbbojhneepfflplebdkc")) | 2876 "ihfokbkgjpifnbbojhneepfflplebdkc")) |
| 2708 .Times(1); | 2877 .Times(1); |
| 2709 } | 2878 } |
| 2710 | 2879 |
| 2711 update_client->AddObserver(&observer); | 2880 update_client->AddObserver(&observer); |
| 2712 | 2881 |
| 2713 std::vector<std::string> ids; | 2882 const std::vector<std::string> ids = {"jebgalgnebhfojomionfpkfelancnnkf", |
| 2714 ids.push_back(std::string("jebgalgnebhfojomionfpkfelancnnkf")); | 2883 "ihfokbkgjpifnbbojhneepfflplebdkc"}; |
| 2715 ids.push_back(std::string("ihfokbkgjpifnbbojhneepfflplebdkc")); | |
| 2716 | |
| 2717 update_client->Update( | 2884 update_client->Update( |
| 2718 ids, base::Bind(&DataCallbackFake::Callback), | 2885 ids, base::Bind(&DataCallbackFake::Callback), |
| 2719 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); | 2886 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
| 2720 | 2887 |
| 2721 RunThreads(); | 2888 RunThreads(); |
| 2722 | 2889 |
| 2723 update_client->RemoveObserver(&observer); | 2890 update_client->RemoveObserver(&observer); |
| 2724 } | 2891 } |
| 2725 | 2892 |
| 2726 } // namespace update_client | 2893 } // namespace update_client |
| OLD | NEW |