component_updater_service_unittest.cc revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <list>
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <utility>
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h"
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/file_util.h"
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/files/file_path.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_vector.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/message_loop.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/path_service.h"
13eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/strings/string_number_conversions.h"
14eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/strings/stringprintf.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/values.h"
16eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "chrome/browser/component_updater/component_updater_service.h"
17eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "chrome/browser/component_updater/test/component_patcher_mock.h"
18eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "chrome/browser/component_updater/test/component_updater_service_unittest.h"
19eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "chrome/browser/component_updater/test/test_installer.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_notification_types.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_paths.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_observer.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_service.h"
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/test/test_browser_thread.h"
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/test/test_notification_tracker.h"
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/test/net/url_request_prepackaged_interceptor.h"
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "libxml/globals.h"
28eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "net/base/upload_bytes_element_reader.h"
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/url_request/url_fetcher.h"
30eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "net/url_request/url_request.h"
31eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "net/url_request/url_request_filter.h"
32eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "net/url_request/url_request_simple_job.h"
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/url_request/url_request_test_util.h"
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
35eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "url/gurl.h"
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::BrowserThread;
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::TestNotificationTracker;
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
40eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTestConfigurator::TestConfigurator()
41eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    : times_(1), recheck_time_(0), ondemand_time_(0), cus_(NULL) {
42eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
44eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTestConfigurator::~TestConfigurator() {
45eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
47eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochint TestConfigurator::InitialDelay() { return 0; }
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
49eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochint TestConfigurator::NextCheckDelay() {
50eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // This is called when a new full cycle of checking for updates is going
51eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // to happen. In test we normally only test one cycle so it is a good
52eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // time to break from the test messageloop Run() method so the test can
53eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // finish.
54eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (--times_ <= 0) {
55eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    base::MessageLoop::current()->Quit();
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return 0;
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
59eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Look for checks to issue in the middle of the loop.
60eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  for (std::list<CheckAtLoopCount>::iterator
61eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch           i = components_to_check_.begin();
62eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch       i != components_to_check_.end(); ) {
63eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    if (i->second == times_) {
64eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      cus_->CheckForUpdateSoon(*i->first);
65eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      i = components_to_check_.erase(i);
66eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    } else {
67eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      ++i;
68eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    }
692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
70eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return 1;
71eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
73eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochint TestConfigurator::StepDelay() {
74eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return 0;
75eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
77eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochint TestConfigurator::MinimumReCheckWait() {
78eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return recheck_time_;
79eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
81eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochint TestConfigurator::OnDemandDelay() {
82eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return ondemand_time_;
83eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochGURL TestConfigurator::UpdateUrl() {
86eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return GURL("http://localhost/upd");
87eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
89eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochconst char* TestConfigurator::ExtraRequestParams() { return "extra=foo"; }
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
91eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochsize_t TestConfigurator::UrlSizeLimit() { return 256; }
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
93eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochnet::URLRequestContextGetter* TestConfigurator::RequestContext() {
94eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return new net::TestURLRequestContextGetter(
95eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
96eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
98eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Don't use the utility process to decode files.
99eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochbool TestConfigurator::InProcess() { return true; }
1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
101eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid TestConfigurator::OnEvent(Events event, int extra) { }
1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
103eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochComponentPatcher* TestConfigurator::CreateComponentPatcher() {
104eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return new MockComponentPatcher();
105eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
107eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochbool TestConfigurator::DeltasEnabled() const {
108eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return true;
109eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
111eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Set how many update checks are called, the default value is just once.
112eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid TestConfigurator::SetLoopCount(int times) { times_ = times; }
1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
114eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid TestConfigurator::SetRecheckTime(int seconds) {
115eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  recheck_time_ = seconds;
116eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
118eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid TestConfigurator::SetOnDemandTime(int seconds) {
119eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  ondemand_time_ = seconds;
120eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
122eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid TestConfigurator::AddComponentToCheck(CrxComponent* com,
123eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                                           int at_loop_iter) {
124eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  components_to_check_.push_back(std::make_pair(com, at_loop_iter));
125eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
127eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid TestConfigurator::SetComponentUpdateService(ComponentUpdateService* cus) {
128eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  cus_ = cus;
129eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
131eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochComponentUpdaterTest::ComponentUpdaterTest() : test_config_(NULL) {
132eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // The component updater instance under test.
133eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  test_config_ = new TestConfigurator;
134eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  component_updater_.reset(ComponentUpdateServiceFactory(test_config_));
135eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  test_config_->SetComponentUpdateService(component_updater_.get());
136eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // The test directory is chrome/test/data/components.
137eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_);
138eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  test_data_dir_ = test_data_dir_.AppendASCII("components");
139eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
140eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Subscribe to all component updater notifications.
141eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  const int notifications[] = {
142eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED,
143eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING,
144eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND,
145eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    chrome::NOTIFICATION_COMPONENT_UPDATE_READY
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
148eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  for (int ix = 0; ix != arraysize(notifications); ++ix) {
149eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    notification_tracker_.ListenFor(
150eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch        notifications[ix], content::NotificationService::AllSources());
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
152eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  net::URLFetcher::SetEnableInterceptionForTests(true);
153eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
155eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochComponentUpdaterTest::~ComponentUpdaterTest() {
156eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  net::URLFetcher::SetEnableInterceptionForTests(false);
157eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
159eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid ComponentUpdaterTest::TearDown() {
160eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  xmlCleanupGlobals();
161eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
163eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochComponentUpdateService* ComponentUpdaterTest::component_updater() {
164eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return component_updater_.get();
165eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Makes the full path to a component updater test file.
168eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochconst base::FilePath ComponentUpdaterTest::test_file(const char* file) {
169eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return test_data_dir_.AppendASCII(file);
170eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
172eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTestNotificationTracker& ComponentUpdaterTest::notification_tracker() {
173eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return notification_tracker_;
174eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
176eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTestConfigurator* ComponentUpdaterTest::test_configurator() {
177eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return test_config_;
178eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
180eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochComponentUpdateService::Status ComponentUpdaterTest::RegisterComponent(
181eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    CrxComponent* com,
182eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    TestComponents component,
183eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    const Version& version,
184eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    TestInstaller* installer) {
185eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (component == kTestComponent_abag) {
186eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    com->name = "test_abag";
187eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    com->pk_hash.assign(abag_hash, abag_hash + arraysize(abag_hash));
188eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  } else if (component == kTestComponent_jebg) {
189eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    com->name = "test_jebg";
190eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    com->pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash));
191eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  } else {
192eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    com->name = "test_ihfo";
193eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    com->pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash));
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
195eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  com->version = version;
196eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  com->installer = installer;
197eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return component_updater_->RegisterComponent(*com);
198eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Verify that our test fixture work and the component updater can
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// be created and destroyed with no side effects.
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ComponentUpdaterTest, VerifyFixture) {
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(component_updater() != NULL);
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(0ul, notification_tracker().size());
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Verify that the component updater can be caught in a quick
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// start-shutdown situation. Failure of this test will be a crash. Also
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// if there is no work to do, there are no notifications generated.
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ComponentUpdaterTest, StartStop) {
21190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  base::MessageLoop message_loop;
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  component_updater()->Start();
2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  message_loop.RunUntilIdle();
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  component_updater()->Stop();
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(0ul, notification_tracker().size());
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Verify that when the server has no updates, we go back to sleep and
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the COMPONENT_UPDATER_STARTED and COMPONENT_UPDATER_SLEEPING notifications
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// are generated.
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ComponentUpdaterTest, CheckCrxSleep) {
22590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  base::MessageLoop message_loop;
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::TestBrowserThread file_thread(BrowserThread::FILE);
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::TestBrowserThread io_thread(BrowserThread::IO);
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  io_thread.StartIOThread();
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  file_thread.Start();
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
233c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  content::URLLocalHostRequestPrepackagedInterceptor interceptor;
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
235eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  TestInstaller installer;
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CrxComponent com;
237c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(ComponentUpdateService::kOk,
238eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            RegisterComponent(&com,
239eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                              kTestComponent_abag,
240eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                              Version("1.1"),
241eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                              &installer));
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const GURL expected_update_url(
244eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "http://localhost/upd?extra=foo"
245eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D1.1%26fp%3D%26uc");
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  interceptor.SetResponse(expected_update_url,
2482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                          test_file("updatecheck_reply_1.xml"));
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // We loop twice, but there are no updates so we expect two sleep messages.
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  test_configurator()->SetLoopCount(2);
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  component_updater()->Start();
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_EQ(1ul, notification_tracker().size());
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TestNotificationTracker::Event ev1 = notification_tracker().at(0);
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev1.type);
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  message_loop.Run();
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_EQ(3ul, notification_tracker().size());
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TestNotificationTracker::Event ev2 = notification_tracker().at(1);
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type);
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TestNotificationTracker::Event ev3 = notification_tracker().at(2);
2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type);
2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(2, interceptor.GetHitCount());
2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count());
2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  component_updater()->Stop();
2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Loop twice again but this case we simulate a server error by returning
2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // an empty file.
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  interceptor.SetResponse(expected_update_url,
2762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                          test_file("updatecheck_reply_empty"));
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  notification_tracker().Reset();
2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  test_configurator()->SetLoopCount(2);
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  component_updater()->Start();
2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  message_loop.Run();
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_EQ(3ul, notification_tracker().size());
2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ev1 = notification_tracker().at(0);
2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev1.type);
2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ev2 = notification_tracker().at(1);
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type);
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ev3 = notification_tracker().at(2);
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type);
2912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(4, interceptor.GetHitCount());
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count());
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  component_updater()->Stop();
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Verify that we can check for updates and install one component. Besides
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the notifications above NOTIFICATION_COMPONENT_UPDATE_FOUND and
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NOTIFICATION_COMPONENT_UPDATE_READY should have been fired. We do two loops
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// so the second time around there should be nothing left to do.
3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// We also check that only 3 network requests are issued:
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 1- manifest check
3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 2- download crx
3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 3- second manifest check.
3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ComponentUpdaterTest, InstallCrx) {
30890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  base::MessageLoop message_loop;
3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::TestBrowserThread file_thread(BrowserThread::FILE);
3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::TestBrowserThread io_thread(BrowserThread::IO);
3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  io_thread.StartIOThread();
3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  file_thread.Start();
3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
316c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  content::URLLocalHostRequestPrepackagedInterceptor interceptor;
3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
318eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  TestInstaller installer1;
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CrxComponent com1;
320eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1);
321eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  TestInstaller installer2;
3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CrxComponent com2;
323eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2);
3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const GURL expected_update_url_1(
326eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "http://localhost/upd?extra=foo"
327eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"
328eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc");
3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const GURL expected_update_url_2(
331eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "http://localhost/upd?extra=foo"
332eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"
333eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc");
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  interceptor.SetResponse(expected_update_url_1,
3362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                          test_file("updatecheck_reply_1.xml"));
3372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  interceptor.SetResponse(expected_update_url_2,
3382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                          test_file("updatecheck_reply_1.xml"));
3392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  interceptor.SetResponse(GURL(expected_crx_url),
3402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                          test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  test_configurator()->SetLoopCount(2);
3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  component_updater()->Start();
3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  message_loop.Run();
3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count());
3492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
3502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count());
3512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(3, interceptor.GetHitCount());
3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_EQ(5ul, notification_tracker().size());
3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TestNotificationTracker::Event ev1 = notification_tracker().at(1);
3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type);
3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TestNotificationTracker::Event ev2 = notification_tracker().at(2);
3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type);
3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TestNotificationTracker::Event ev3 = notification_tracker().at(3);
3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type);
3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TestNotificationTracker::Event ev4 = notification_tracker().at(4);
3662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type);
3672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  component_updater()->Stop();
3692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
3702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This test checks that the "prodversionmin" value is handled correctly. In
3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// particular there should not be an install because the minimum product
3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// version is much higher than of chrome.
3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ComponentUpdaterTest, ProdVersionCheck) {
37590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  base::MessageLoop message_loop;
3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::TestBrowserThread file_thread(BrowserThread::FILE);
3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::TestBrowserThread io_thread(BrowserThread::IO);
3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  io_thread.StartIOThread();
3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  file_thread.Start();
3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
383c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  content::URLLocalHostRequestPrepackagedInterceptor interceptor;
3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
385eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  TestInstaller installer;
3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CrxComponent com;
387eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer);
3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const GURL expected_update_url(
3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      "http://localhost/upd?extra=foo&x=id%3D"
391eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc");
3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  interceptor.SetResponse(expected_update_url,
3942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                          test_file("updatecheck_reply_2.xml"));
3952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  interceptor.SetResponse(GURL(expected_crx_url),
3962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                          test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  test_configurator()->SetLoopCount(1);
3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  component_updater()->Start();
4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  message_loop.Run();
4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(1, interceptor.GetHitCount());
4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count());
4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  component_updater()->Stop();
4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Test that a ping for an update check can cause installs.
4102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Here is the timeline:
4112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//  - First loop: we return a reply that indicates no update, so
4122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//    nothing happens.
4132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//  - We ping.
4142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//  - This triggers a second loop, which has a reply that triggers an install.
4152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ComponentUpdaterTest, CheckForUpdateSoon) {
41690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  base::MessageLoop message_loop;
4172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
4182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  content::TestBrowserThread file_thread(BrowserThread::FILE);
4192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  content::TestBrowserThread io_thread(BrowserThread::IO);
4202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  io_thread.StartIOThread();
4222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  file_thread.Start();
4232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
424c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  content::URLLocalHostRequestPrepackagedInterceptor interceptor;
4252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
426eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  TestInstaller installer1;
4272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  CrxComponent com1;
428eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), &installer1);
429eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  TestInstaller installer2;
4302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  CrxComponent com2;
431eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"), &installer2);
4322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const GURL expected_update_url_1(
434eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "http://localhost/upd?extra=foo"
435eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"
436eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc");
4372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const GURL expected_update_url_2(
439eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "http://localhost/upd?extra=foo"
440eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"
441eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "%26installsource%3Dondemand"
442eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc");
4432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  interceptor.SetResponse(expected_update_url_1,
4452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                          test_file("updatecheck_reply_empty"));
4462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  interceptor.SetResponse(expected_update_url_2,
4472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                          test_file("updatecheck_reply_1.xml"));
4482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  interceptor.SetResponse(GURL(expected_crx_url),
4492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                          test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
4502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Test success.
4512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  test_configurator()->SetLoopCount(2);
4522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  test_configurator()->AddComponentToCheck(&com2, 1);
4532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  component_updater()->Start();
4542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  message_loop.Run();
4552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
4572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count());
4582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
4592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(1, static_cast<TestInstaller*>(com2.installer)->install_count());
4602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(3, interceptor.GetHitCount());
4622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_EQ(5ul, notification_tracker().size());
4642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TestNotificationTracker::Event ev0= notification_tracker().at(0);
4662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type);
4672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TestNotificationTracker::Event ev1 = notification_tracker().at(1);
4692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type);
4702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TestNotificationTracker::Event ev2 = notification_tracker().at(2);
4722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev2.type);
4732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TestNotificationTracker::Event ev3 = notification_tracker().at(3);
4752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev3.type);
4762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TestNotificationTracker::Event ev4 = notification_tracker().at(4);
4782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type);
4792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Also check what happens if previous check too soon.
4812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  test_configurator()->SetOnDemandTime(60 * 60);
4822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(ComponentUpdateService::kError,
4832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)            component_updater()->CheckForUpdateSoon(com2));
4842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Okay, now reset to 0 for the other tests.
4852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  test_configurator()->SetOnDemandTime(0);
4862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  component_updater()->Stop();
4872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Test a few error cases. NOTE: We don't have callbacks for
4892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // when the updates failed yet.
4902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const GURL expected_update_url_3(
491eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "http://localhost/upd?extra=foo"
492eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc"
493eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc");
4942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // No update: error from no server response
4962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  interceptor.SetResponse(expected_update_url_3,
4972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                          test_file("updatecheck_reply_empty"));
4982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  notification_tracker().Reset();
4992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  test_configurator()->SetLoopCount(1);
5002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  component_updater()->Start();
5012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(ComponentUpdateService::kOk,
5022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)            component_updater()->CheckForUpdateSoon(com2));
5032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  message_loop.Run();
5052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_EQ(2ul, notification_tracker().size());
5072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ev0 = notification_tracker().at(0);
5082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type);
5092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ev1 = notification_tracker().at(1);
5102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type);
5112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  component_updater()->Stop();
5122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // No update: already updated to 1.0 so nothing new
5142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  interceptor.SetResponse(expected_update_url_3,
5152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                          test_file("updatecheck_reply_1.xml"));
5162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  notification_tracker().Reset();
5172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  test_configurator()->SetLoopCount(1);
5182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  component_updater()->Start();
5192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(ComponentUpdateService::kOk,
5202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)            component_updater()->CheckForUpdateSoon(com2));
5212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  message_loop.Run();
5232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_EQ(2ul, notification_tracker().size());
5252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ev0 = notification_tracker().at(0);
5262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type);
5272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ev1 = notification_tracker().at(1);
5282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type);
5292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  component_updater()->Stop();
5302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
531c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
532c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Verify that a previously registered component can get re-registered
533c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// with a different version.
534c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(ComponentUpdaterTest, CheckReRegistration) {
53590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  base::MessageLoop message_loop;
536c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
537c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  content::TestBrowserThread file_thread(BrowserThread::FILE);
538c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  content::TestBrowserThread io_thread(BrowserThread::IO);
539c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
540c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  io_thread.StartIOThread();
541c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  file_thread.Start();
542c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
543c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  content::URLLocalHostRequestPrepackagedInterceptor interceptor;
544c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
545eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  TestInstaller installer1;
546c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  CrxComponent com1;
547eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1);
548eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  TestInstaller installer2;
549c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  CrxComponent com2;
550eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2);
551c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
552c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Start with 0.9, and update to 1.0
553c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const GURL expected_update_url_1(
554eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "http://localhost/upd?extra=foo"
555eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"
556eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc");
557c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
558c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const GURL expected_update_url_2(
559eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "http://localhost/upd?extra=foo"
560eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"
561eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc");
562c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
563c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  interceptor.SetResponse(expected_update_url_1,
564c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                          test_file("updatecheck_reply_1.xml"));
565c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  interceptor.SetResponse(expected_update_url_2,
566c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                          test_file("updatecheck_reply_1.xml"));
567c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  interceptor.SetResponse(GURL(expected_crx_url),
568c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                          test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
569c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
570c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Loop twice to issue two checks: (1) with original 0.9 version
571c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // and (2) with the updated 1.0 version.
572c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  test_configurator()->SetLoopCount(2);
573c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
574c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  component_updater()->Start();
575c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  message_loop.Run();
576c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
577c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
578c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count());
579c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
580c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count());
581c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
582c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(3, interceptor.GetHitCount());
583c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
584c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_EQ(5ul, notification_tracker().size());
585c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
586c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  TestNotificationTracker::Event ev0 = notification_tracker().at(0);
587c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type);
588c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
589c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  TestNotificationTracker::Event ev1 = notification_tracker().at(1);
590c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type);
591c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
592c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  TestNotificationTracker::Event ev2 = notification_tracker().at(2);
593c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type);
594c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
595c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  TestNotificationTracker::Event ev3 = notification_tracker().at(3);
596c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type);
597c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
598c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  TestNotificationTracker::Event ev4 = notification_tracker().at(4);
599c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type);
600c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
601c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Now re-register, pretending to be an even newer version (2.2)
602eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  TestInstaller installer3;
603c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  component_updater()->Stop();
604c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(ComponentUpdateService::kReplaced,
605eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            RegisterComponent(&com1,
606eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                              kTestComponent_jebg,
607eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                              Version("2.2"),
608eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                              &installer3));
609c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
610c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Check that we send out 2.2 as our version.
611c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Interceptor's hit count should go up by 1.
612c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const GURL expected_update_url_3(
613eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "http://localhost/upd?extra=foo"
614eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D2.2%26fp%3D%26uc"
615eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc");
616c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
617c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  interceptor.SetResponse(expected_update_url_3,
618c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                          test_file("updatecheck_reply_1.xml"));
619c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
620c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  notification_tracker().Reset();
621c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
622c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Loop once just to notice the check happening with the re-register version.
623c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  test_configurator()->SetLoopCount(1);
624c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  component_updater()->Start();
625c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  message_loop.Run();
626c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
627c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_EQ(2ul, notification_tracker().size());
628c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
629c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ev0 = notification_tracker().at(0);
630c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type);
631c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
632c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ev1 = notification_tracker().at(1);
633c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type);
634c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
635c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(4, interceptor.GetHitCount());
636c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
637eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // We created a new installer, so the counts go back to 0.
638c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
639c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count());
640c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
641c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count());
642c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
643c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  component_updater()->Stop();
644c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
645eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
646eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Verify that component installation falls back to downloading and installing
647eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// a full update if the differential update fails (in this case, because the
648eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// installer does not know about the existing files). We do two loops; the final
649eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// loop should do nothing.
650eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// We also check that exactly 4 network requests are issued:
651eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// 1- update check (loop 1)
652eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// 2- download differential crx
653eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// 3- download full crx
654eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// 4- update check (loop 2 - no update available)
655eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(ComponentUpdaterTest, DifferentialUpdateFails) {
656eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  base::MessageLoop message_loop;
657eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
658eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  content::TestBrowserThread file_thread(BrowserThread::FILE);
659eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  content::TestBrowserThread io_thread(BrowserThread::IO);
660eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
661eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  io_thread.StartIOThread();
662eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  file_thread.Start();
663eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
664eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  content::URLLocalHostRequestPrepackagedInterceptor interceptor;
665eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
666eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  TestInstaller installer;
667eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  CrxComponent com;
668eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), &installer);
669eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
670eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  const GURL expected_update_url_1(
671eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "http://localhost/upd?extra=foo"
672eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D%26uc");
673eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  const GURL expected_update_url_2(
674eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "http://localhost/upd?extra=foo"
675eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D2.0%26fp%3Df22%26uc");
676eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  const GURL expected_crx_url_1(
677eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx");
678eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  const GURL expected_crx_url_1_diff_2(
679eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx");
680eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  const GURL expected_crx_url_2(
681eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx");
682eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
683eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  interceptor.SetResponse(expected_update_url_1,
684eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                          test_file("updatecheck_diff_reply_2.xml"));
685eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  interceptor.SetResponse(expected_update_url_2,
686eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                          test_file("updatecheck_diff_reply_3.xml"));
687eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  interceptor.SetResponse(expected_crx_url_1,
688eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                          test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"));
689eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  interceptor.SetResponse(
690eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      expected_crx_url_1_diff_2,
691eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"));
692eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  interceptor.SetResponse(expected_crx_url_2,
693eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                          test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"));
694eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
695eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  test_configurator()->SetLoopCount(2);
696eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
697eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  component_updater()->Start();
698eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  message_loop.Run();
699eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
700eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // A failed differential update does not count as a failed install.
701eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
702eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(1, static_cast<TestInstaller*>(com.installer)->install_count());
703eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
704eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(4, interceptor.GetHitCount());
705eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
706eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  component_updater()->Stop();
707eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
708eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
709eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Verify that we successfully propagate a patcher error.
710eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx contains an incorrect
711eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// patching instruction that should fail.
712eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(ComponentUpdaterTest, DifferentialUpdateFailErrorcode) {
713eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  base::MessageLoop message_loop;
714eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
715eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  content::TestBrowserThread file_thread(BrowserThread::FILE);
716eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  content::TestBrowserThread io_thread(BrowserThread::IO);
717eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
718eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  io_thread.StartIOThread();
719eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  file_thread.Start();
720eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
721eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  content::URLLocalHostRequestPrepackagedInterceptor interceptor;
722eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
723eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  VersionedTestInstaller installer;
724eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  CrxComponent com;
725eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer);
726eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
727eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  const GURL expected_update_url_0(
728eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "http://localhost/upd?extra=foo"
729eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc");
730eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  const GURL expected_update_url_1(
731eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "http://localhost/upd?extra=foo"
732eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D1%26uc");
733eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  const GURL expected_update_url_2(
734eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "http://localhost/upd?extra=foo"
735eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D2.0%26fp%3Df22%26uc");
736eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  const GURL expected_crx_url_1(
737eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx");
738eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  const GURL expected_crx_url_1_diff_2(
739eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx");
740eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  const GURL expected_crx_url_2(
741eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx");
742eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
743eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  interceptor.SetResponse(expected_update_url_0,
744eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                          test_file("updatecheck_diff_reply_1.xml"));
745eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  interceptor.SetResponse(expected_update_url_1,
746eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                          test_file("updatecheck_diff_reply_2.xml"));
747eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  interceptor.SetResponse(expected_update_url_2,
748eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                          test_file("updatecheck_diff_reply_3.xml"));
749eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  interceptor.SetResponse(expected_crx_url_1,
750eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                          test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"));
751eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  interceptor.SetResponse(
752eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      expected_crx_url_1_diff_2,
753eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx"));
754eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  interceptor.SetResponse(expected_crx_url_2,
755eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                          test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"));
756eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
757eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  test_configurator()->SetLoopCount(3);
758eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
759eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  component_updater()->Start();
760eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  message_loop.Run();
761eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
762eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
763eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count());
764eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
765eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ(6, interceptor.GetHitCount());
766eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
767eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  component_updater()->Stop();
768eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
769