15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 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)
503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "chrome/browser/component_updater/test/component_updater_service_unittest.h"
603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
7116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include <vector>
8116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
91320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/files/file_util.h"
101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/memory/scoped_ptr.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/path_service.h"
124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "base/run_loop.h"
13eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/strings/string_number_conversions.h"
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/strings/string_util.h"
15eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/strings/stringprintf.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/values.h"
176e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chrome/browser/component_updater/component_updater_resource_throttle.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_paths.h"
1903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "components/component_updater/component_updater_utils.h"
201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "components/component_updater/test/test_configurator.h"
211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "components/component_updater/test/test_installer.h"
221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "components/component_updater/test/url_request_post_interceptor.h"
234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "content/public/browser/browser_thread.h"
24f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "content/public/browser/resource_controller.h"
25f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "content/public/browser/resource_request_info.h"
26f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "content/public/browser/resource_throttle.h"
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "libxml/globals.h"
28eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "net/base/upload_bytes_element_reader.h"
291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "net/url_request/test_url_request_interceptor.h"
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/url_request/url_fetcher.h"
311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "net/url_request/url_request.h"
32f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "net/url_request/url_request_test_util.h"
33eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "url/gurl.h"
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::BrowserThread;
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
37a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)using ::testing::_;
38010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)using ::testing::AnyNumber;
39a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)using ::testing::InSequence;
40a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)using ::testing::Mock;
41a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
42f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace component_updater {
43f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
445c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo LiuMockServiceObserver::MockServiceObserver() {
45a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)}
46a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
475c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo LiuMockServiceObserver::~MockServiceObserver() {
48a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)}
49a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
50ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben MurdochComponentUpdaterTest::ComponentUpdaterTest()
511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    : post_interceptor_(NULL),
521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      test_config_(NULL),
534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {
54eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // The component updater instance under test.
551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  test_config_ = new TestConfigurator(
561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      BrowserThread::GetBlockingPool()
571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci          ->GetSequencedTaskRunnerWithShutdownBehavior(
581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci              BrowserThread::GetBlockingPool()->GetSequenceToken(),
591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci              base::SequencedWorkerPool::SKIP_ON_SHUTDOWN),
601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
61eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  component_updater_.reset(ComponentUpdateServiceFactory(test_config_));
62ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
63eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  net::URLFetcher::SetEnableInterceptionForTests(true);
64eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
66eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochComponentUpdaterTest::~ComponentUpdaterTest() {
67eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  net::URLFetcher::SetEnableInterceptionForTests(false);
68eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
70f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void ComponentUpdaterTest::SetUp() {
711320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  get_interceptor_.reset(new GetInterceptor(
721320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
731320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
741320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci          base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)));
751320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  interceptor_factory_.reset(new InterceptorFactory(
761320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
77f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  post_interceptor_ = interceptor_factory_->CreateInterceptor();
78f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_TRUE(post_interceptor_);
79f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
80f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
81eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid ComponentUpdaterTest::TearDown() {
82f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  interceptor_factory_.reset();
83f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  get_interceptor_.reset();
84eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  xmlCleanupGlobals();
85eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
87eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochComponentUpdateService* ComponentUpdaterTest::component_updater() {
88eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return component_updater_.get();
89eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
91010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Makes the full path to a component updater test file.
92eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochconst base::FilePath ComponentUpdaterTest::test_file(const char* file) {
931320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  base::FilePath path;
941320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  PathService::Get(base::DIR_SOURCE_ROOT, &path);
951320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return path.AppendASCII("components").AppendASCII("test").AppendASCII("data")
961320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      .AppendASCII("component_updater").AppendASCII(file);
97eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
99eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTestConfigurator* ComponentUpdaterTest::test_configurator() {
100eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return test_config_;
101eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
103eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochComponentUpdateService::Status ComponentUpdaterTest::RegisterComponent(
104eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    CrxComponent* com,
105eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    TestComponents component,
106eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    const Version& version,
107eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    TestInstaller* installer) {
108eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (component == kTestComponent_abag) {
109eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    com->name = "test_abag";
110eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    com->pk_hash.assign(abag_hash, abag_hash + arraysize(abag_hash));
111eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  } else if (component == kTestComponent_jebg) {
112eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    com->name = "test_jebg";
113eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    com->pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash));
114eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  } else {
115eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    com->name = "test_ihfo";
116eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    com->pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash));
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
118eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  com->version = version;
119eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  com->installer = installer;
120eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return component_updater_->RegisterComponent(*com);
121eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)void ComponentUpdaterTest::RunThreads() {
1244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  base::RunLoop runloop;
1254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  test_configurator()->SetQuitClosure(runloop.QuitClosure());
1264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  runloop.Run();
127f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
128f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Since some tests need to drain currently enqueued tasks such as network
129f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // intercepts on the IO thread, run the threads until they are
130f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // idle. The component updater service won't loop again until the loop count
131f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // is set and the service is started.
132f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  RunThreadsUntilIdle();
1334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
1344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)void ComponentUpdaterTest::RunThreadsUntilIdle() {
1364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  base::RunLoop().RunUntilIdle();
1374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
1384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)ComponentUpdateService::Status OnDemandTester::OnDemand(
140010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    ComponentUpdateService* cus,
141010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    const std::string& component_id) {
142cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  return cus->GetOnDemandUpdater().OnDemandUpdate(component_id);
1431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
1441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Verify that our test fixture work and the component updater can
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// be created and destroyed with no side effects.
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ComponentUpdaterTest, VerifyFixture) {
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(component_updater() != NULL);
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Verify that the component updater can be caught in a quick
152ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch// start-shutdown situation. Failure of this test will be a crash.
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ComponentUpdaterTest, StartStop) {
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  component_updater()->Start();
1554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  RunThreadsUntilIdle();
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  component_updater()->Stop();
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Verify that when the server has no updates, we go back to sleep and
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the COMPONENT_UPDATER_STARTED and COMPONENT_UPDATER_SLEEPING notifications
161f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// are generated. No pings are sent.
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ComponentUpdaterTest, CheckCrxSleep) {
1635c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  MockServiceObserver observer;
164a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
165f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_CALL(observer,
1665c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu              OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, ""))
167010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      .Times(1);
168f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_CALL(observer,
1695c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu              OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, ""))
170010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      .Times(2);
171f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_CALL(observer,
1725c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu              OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED,
1735c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                      "abagagagagagagagagagagagagagagag"))
174010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      .Times(2);
175f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
176010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_TRUE(post_interceptor_->ExpectRequest(
177010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
178010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_TRUE(post_interceptor_->ExpectRequest(
179010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
180f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
181eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  TestInstaller installer;
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CrxComponent com;
1835c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  component_updater()->AddObserver(&observer);
184010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(
185010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      ComponentUpdateService::kOk,
186010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      RegisterComponent(&com, kTestComponent_abag, Version("1.1"), &installer));
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // We loop twice, but there are no updates so we expect two sleep messages.
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  test_configurator()->SetLoopCount(2);
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  component_updater()->Start();
1914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  RunThreads();
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count());
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
196f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Expect to see the two update check requests and no other requests,
197f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // including pings.
198f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(2, post_interceptor_->GetHitCount())
199f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
200f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(2, post_interceptor_->GetCount())
201f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
202010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_NE(
203010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      string::npos,
204010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      post_interceptor_->GetRequests()[0].find(
205010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"1.1\">"
206010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<updatecheck /></app>"))
207f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
208010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_NE(
209010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      string::npos,
210010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      post_interceptor_->GetRequests()[1].find(
211010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"1.1\">"
212010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<updatecheck /></app>"))
213f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
214f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  component_updater()->Stop();
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Loop twice again but this case we simulate a server error by returning
218f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // an empty file. Expect the behavior of the service to be the same as before.
219010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_CALL(observer, OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, ""))
220010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      .Times(1);
221a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  EXPECT_CALL(observer,
2225c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu              OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, ""))
223010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      .Times(2);
2241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_CALL(observer,
2255c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu              OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED,
2265c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                      "abagagagagagagagagagagagagagagag"))
227010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      .Times(2);
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
229f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  post_interceptor_->Reset();
230010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_TRUE(post_interceptor_->ExpectRequest(
231010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      new PartialMatch("updatecheck"), test_file("updatecheck_reply_empty")));
232010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_TRUE(post_interceptor_->ExpectRequest(
233010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      new PartialMatch("updatecheck"), test_file("updatecheck_reply_empty")));
234f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
235f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  test_configurator()->SetLoopCount(2);
236f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  component_updater()->Start();
237f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  RunThreads();
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count());
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
242f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(2, post_interceptor_->GetHitCount())
243f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
244f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(2, post_interceptor_->GetCount())
245f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
246010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_NE(
247010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      string::npos,
248010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      post_interceptor_->GetRequests()[0].find(
249010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"1.1\">"
250010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<updatecheck /></app>"))
251f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
252010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_NE(
253010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      string::npos,
254010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      post_interceptor_->GetRequests()[1].find(
255010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"1.1\">"
256010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<updatecheck /></app>"))
257f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
258f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  component_updater()->Stop();
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Verify that we can check for updates and install one component. Besides
263ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch// the notifications above COMPONENT_UPDATE_FOUND and COMPONENT_UPDATE_READY
264ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch// should have been fired. We do two loops so the second time around there
265ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch// should be nothing left to do.
266f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// We also check that the following network requests are issued:
267f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// 1- update check
2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 2- download crx
269f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// 3- ping
270f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// 4- second update check.
2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ComponentUpdaterTest, InstallCrx) {
2725c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  MockServiceObserver observer;
273a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  {
274a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    InSequence seq;
2755c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
2765c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, ""))
277010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
2785c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
2795c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_UPDATE_FOUND,
2805c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                        "jebgalgnebhfojomionfpkfelancnnkf"))
281010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
2825c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
2835c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED,
2845c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                        "abagagagagagagagagagagagagagagag"))
285010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
286010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    EXPECT_CALL(observer,
287010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                OnEvent(ServiceObserver::COMPONENT_UPDATE_DOWNLOADING,
288010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                        "jebgalgnebhfojomionfpkfelancnnkf"))
289010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                .Times(AnyNumber());
2905c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
2915c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_UPDATE_READY,
2925c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                        "jebgalgnebhfojomionfpkfelancnnkf"))
293010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
2945c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
2955c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_UPDATED,
2965c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                        "jebgalgnebhfojomionfpkfelancnnkf"))
297010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
2985c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
2995c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, ""))
300010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
3015c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
3025c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED,
3035c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                        "jebgalgnebhfojomionfpkfelancnnkf"))
304010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
3055c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
3065c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED,
3075c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                        "abagagagagagagagagagagagagagagag"))
308010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
3095c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
3105c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, ""))
311010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
312a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  }
313a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
314010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_TRUE(post_interceptor_->ExpectRequest(
315010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
316f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event")));
317010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_TRUE(post_interceptor_->ExpectRequest(
318010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
319f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
320f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  get_interceptor_->SetResponse(
321f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      GURL(expected_crx_url),
322f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
323f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
3245c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  component_updater()->AddObserver(&observer);
3255c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
326eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  TestInstaller installer1;
3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CrxComponent com1;
328eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1);
329eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  TestInstaller installer2;
3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CrxComponent com2;
331eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2);
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  test_configurator()->SetLoopCount(2);
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  component_updater()->Start();
3354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  RunThreads();
3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count());
3392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
3402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count());
3412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
342f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Expect three request in total: two update checks and one ping.
343f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(3, post_interceptor_->GetHitCount())
344f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
345f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(3, post_interceptor_->GetCount())
346f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
347f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
348f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Expect one component download.
349f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(1, get_interceptor_->GetHitCount());
350f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
351010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_NE(
352010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      string::npos,
353010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      post_interceptor_->GetRequests()[0].find(
354010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">"
355010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<updatecheck /></app>"))
356f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
357010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_NE(
358010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      string::npos,
359010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      post_interceptor_->GetRequests()[0].find(
360010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"2.2\">"
361010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<updatecheck /></app>"))
362f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
363f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
364010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_NE(
365010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      string::npos,
366010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      post_interceptor_->GetRequests()[1].find(
367010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" "
368010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "version=\"0.9\" nextversion=\"1.0\">"
369010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<event eventtype=\"3\" eventresult=\"1\"/>"))
370f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
371f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
372010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_NE(
373010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      string::npos,
374010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      post_interceptor_->GetRequests()[2].find(
375010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">"
376010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<updatecheck /></app>"));
377010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_NE(
378010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      string::npos,
379010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      post_interceptor_->GetRequests()[2].find(
380010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"2.2\">"
381010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<updatecheck /></app>"))
382f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Test the protocol version is correct and the extra request attributes
3855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // are included in the request.
386010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_NE(
387010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      string::npos,
388010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      post_interceptor_->GetRequests()[0].find(
389010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "request protocol=\"3.0\" extra=\"foo\""))
3905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
3915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Tokenize the request string to look for specific attributes, which
3935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // are important for backward compatibility with the version v2 of the update
3945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // protocol. In this case, inspect the <request>, which is the first element
3955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // after the xml declaration of the update request body.
3965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Expect to find the |os|, |arch|, |prodchannel|, and |prodversion|
3975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // attributes:
3985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // <?xml version="1.0" encoding="UTF-8"?>
3995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // <request... os=... arch=... prodchannel=... prodversion=...>
4005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // ...
4015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // </request>
4025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const std::string update_request(post_interceptor_->GetRequests()[0]);
4035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::vector<base::StringPiece> elements;
4045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Tokenize(update_request, "<>", &elements);
4055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_NE(string::npos, elements[1].find(" os="));
4065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_NE(string::npos, elements[1].find(" arch="));
4075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_NE(string::npos, elements[1].find(" prodchannel="));
4085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_NE(string::npos, elements[1].find(" prodversion="));
4095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
4105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Look for additional attributes of the request, such as |version|,
4115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // |requestid|, |lang|, and |nacl_arch|.
4125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_NE(string::npos, elements[1].find(" version="));
4135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_NE(string::npos, elements[1].find(" requestid="));
4145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_NE(string::npos, elements[1].find(" lang="));
4155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_NE(string::npos, elements[1].find(" nacl_arch="));
4165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
4172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  component_updater()->Stop();
4182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
4192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This test checks that the "prodversionmin" value is handled correctly. In
4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// particular there should not be an install because the minimum product
4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// version is much higher than of chrome.
4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ComponentUpdaterTest, ProdVersionCheck) {
424010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_TRUE(post_interceptor_->ExpectRequest(
425010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      new PartialMatch("updatecheck"), test_file("updatecheck_reply_2.xml")));
426f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
427f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  get_interceptor_->SetResponse(
428f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      GURL(expected_crx_url),
429f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
431eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  TestInstaller installer;
4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CrxComponent com;
433eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer);
4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  test_configurator()->SetLoopCount(1);
4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  component_updater()->Start();
4374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  RunThreads();
4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
439f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Expect one update check and no ping.
440f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(1, post_interceptor_->GetHitCount())
441f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
442f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(1, post_interceptor_->GetCount())
443f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
444f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
445f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Expect no download to occur.
446f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(0, get_interceptor_->GetHitCount());
447f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count());
4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  component_updater()->Stop();
4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
454f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Test that a update check due to an on demand call can cause installs.
4552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Here is the timeline:
4562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//  - First loop: we return a reply that indicates no update, so
4572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//    nothing happens.
458f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)//  - We make an on demand call.
4592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//  - This triggers a second loop, which has a reply that triggers an install.
4606e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#if defined(OS_LINUX)
4616e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// http://crbug.com/396488
4626e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#define MAYBE_OnDemandUpdate DISABLED_OnDemandUpdate
4636e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#else
4646e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#define MAYBE_OnDemandUpdate OnDemandUpdate
4656e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#endif
4666e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)TEST_F(ComponentUpdaterTest, MAYBE_OnDemandUpdate) {
4675c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  MockServiceObserver observer;
468a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  {
469a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    InSequence seq;
4705c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
4715c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, ""))
472010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
4735c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
4745c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED,
4755c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                        "abagagagagagagagagagagagagagagag"))
476010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
4775c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
4785c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED,
4795c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                        "jebgalgnebhfojomionfpkfelancnnkf"))
480010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
4815c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
4825c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, ""))
483010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
4845c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
4855c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, ""))
486010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
4875c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
4885c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_UPDATE_FOUND,
4895c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                        "jebgalgnebhfojomionfpkfelancnnkf"))
490010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
4915c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
4925c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED,
4935c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                        "abagagagagagagagagagagagagagagag"))
494010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
495010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    EXPECT_CALL(observer,
496010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                OnEvent(ServiceObserver::COMPONENT_UPDATE_DOWNLOADING,
497010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                        "jebgalgnebhfojomionfpkfelancnnkf"))
498010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                .Times(AnyNumber());
4995c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
5005c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_UPDATE_READY,
5015c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                        "jebgalgnebhfojomionfpkfelancnnkf"))
502010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
5035c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
5045c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_UPDATED,
5055c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                        "jebgalgnebhfojomionfpkfelancnnkf"))
506010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
5075c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
5085c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, ""))
509010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
510a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  }
511a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
512010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_TRUE(post_interceptor_->ExpectRequest(
513010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      new PartialMatch("updatecheck"), test_file("updatecheck_reply_empty")));
514f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
515f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  get_interceptor_->SetResponse(
516f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      GURL(expected_crx_url),
517f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
518f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
5195c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  component_updater()->AddObserver(&observer);
5205c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
521eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  TestInstaller installer1;
5222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  CrxComponent com1;
523eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), &installer1);
524eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  TestInstaller installer2;
5252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  CrxComponent com2;
526eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"), &installer2);
5272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // No update normally.
5291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  test_configurator()->SetLoopCount(1);
5301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  component_updater()->Start();
5311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  RunThreads();
5321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  component_updater()->Stop();
5331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
534f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(1, post_interceptor_->GetHitCount())
535f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
536f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(1, post_interceptor_->GetCount())
537f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
538f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
539f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(0, get_interceptor_->GetHitCount());
540f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
5411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Update after an on-demand check is issued.
542f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  post_interceptor_->Reset();
543010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_TRUE(post_interceptor_->ExpectRequest(
544010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
545f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event")));
546f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
547010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(
548010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      ComponentUpdateService::kOk,
549010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      OnDemandTester::OnDemand(component_updater(), GetCrxComponentID(com2)));
5501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  test_configurator()->SetLoopCount(1);
5512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  component_updater()->Start();
5524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  RunThreads();
5532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
5552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count());
5562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
5572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(1, static_cast<TestInstaller*>(com2.installer)->install_count());
5582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
559f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(2, post_interceptor_->GetHitCount())
560f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
561f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(2, post_interceptor_->GetCount())
562f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
563f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
564f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(1, get_interceptor_->GetHitCount());
565f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
566f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Expect the update check to contain an "ondemand" request for the
567f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // second component (com2) and a normal request for the other component.
568010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_NE(
569010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      string::npos,
570010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      post_interceptor_->GetRequests()[0].find(
571010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<app appid=\"abagagagagagagagagagagagagagagag\" "
572010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "version=\"2.2\"><updatecheck /></app>"))
573f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
574010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_NE(
575010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      string::npos,
576010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      post_interceptor_->GetRequests()[0].find(
577010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" "
578010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "version=\"0.9\" installsource=\"ondemand\"><updatecheck /></app>"))
579f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
580010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_NE(
581010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      string::npos,
582010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      post_interceptor_->GetRequests()[1].find(
583010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" "
584010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "version=\"0.9\" nextversion=\"1.0\">"
585010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<event eventtype=\"3\" eventresult=\"1\"/>"))
586f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
5872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
58846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // Also check what happens if previous check too soon. It works, since this
58946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // direct OnDemand call does not implement a cooldown.
5902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  test_configurator()->SetOnDemandTime(60 * 60);
591010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(
59246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      ComponentUpdateService::kOk,
593010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      OnDemandTester::OnDemand(component_updater(), GetCrxComponentID(com2)));
5942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Okay, now reset to 0 for the other tests.
5952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  test_configurator()->SetOnDemandTime(0);
5962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  component_updater()->Stop();
5972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Test a few error cases. NOTE: We don't have callbacks for
5992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // when the updates failed yet.
6005c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer));
601a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  {
602a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    InSequence seq;
6035c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
6045c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, ""))
605010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
6065c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
6075c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED,
6085c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                        "abagagagagagagagagagagagagagagag"))
609010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
6105c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
6115c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED,
6125c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                        "jebgalgnebhfojomionfpkfelancnnkf"))
613010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
6145c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
6155c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, ""))
616010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
617a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  }
618a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
6192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // No update: error from no server response
620f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  post_interceptor_->Reset();
621010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_TRUE(post_interceptor_->ExpectRequest(
622010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      new PartialMatch("updatecheck"), test_file("updatecheck_reply_empty")));
623f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
6242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  test_configurator()->SetLoopCount(1);
6252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  component_updater()->Start();
626010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(
627010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      ComponentUpdateService::kOk,
628010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      OnDemandTester::OnDemand(component_updater(), GetCrxComponentID(com2)));
6294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  RunThreads();
6302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  component_updater()->Stop();
6312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
632f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(1, post_interceptor_->GetHitCount())
633f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
634f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(1, post_interceptor_->GetCount())
635f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
636f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
6372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // No update: already updated to 1.0 so nothing new
6385c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer));
639a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  {
640a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    InSequence seq;
6415c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
6425c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, ""))
643010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
6445c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
6455c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED,
6465c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                        "jebgalgnebhfojomionfpkfelancnnkf"))
647010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
6485c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
6495c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED,
6505c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                        "abagagagagagagagagagagagagagagag"))
651010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
6525c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
6535c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, ""))
654010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
655a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  }
656a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
657f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  post_interceptor_->Reset();
658010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_TRUE(post_interceptor_->ExpectRequest(
659010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
660f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
6612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  test_configurator()->SetLoopCount(1);
6622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  component_updater()->Start();
663010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(
664010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      ComponentUpdateService::kOk,
665010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      OnDemandTester::OnDemand(component_updater(), GetCrxComponentID(com2)));
6664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  RunThreads();
6672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
668f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(1, post_interceptor_->GetHitCount())
669f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
670f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(1, post_interceptor_->GetCount())
671f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
672ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
6732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  component_updater()->Stop();
6742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
675c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
676c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Verify that a previously registered component can get re-registered
677c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// with a different version.
678c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(ComponentUpdaterTest, CheckReRegistration) {
6795c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  MockServiceObserver observer;
680a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  {
681a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    InSequence seq;
6825c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
6835c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, ""))
684010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
6855c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
6865c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_UPDATE_FOUND,
6875c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                        "jebgalgnebhfojomionfpkfelancnnkf"))
688010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
6895c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
6905c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED,
6915c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                        "abagagagagagagagagagagagagagagag"))
692010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
693010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    EXPECT_CALL(observer,
694010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                OnEvent(ServiceObserver::COMPONENT_UPDATE_DOWNLOADING,
695010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                        "jebgalgnebhfojomionfpkfelancnnkf"))
696010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                .Times(AnyNumber());
6975c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
6985c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_UPDATE_READY,
6995c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                        "jebgalgnebhfojomionfpkfelancnnkf"))
700010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
7015c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
7025c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_UPDATED,
7035c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                        "jebgalgnebhfojomionfpkfelancnnkf"))
704010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
7055c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
7065c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, ""))
707010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
7085c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
7095c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED,
7105c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                        "jebgalgnebhfojomionfpkfelancnnkf"))
711010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
7125c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
7135c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED,
7145c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                        "abagagagagagagagagagagagagagagag"))
715010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
7165c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
7175c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, ""))
718010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
719a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  }
720a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
721010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_TRUE(post_interceptor_->ExpectRequest(
722010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
723f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event")));
724010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_TRUE(post_interceptor_->ExpectRequest(
725010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
726f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
727f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  get_interceptor_->SetResponse(
728f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      GURL(expected_crx_url),
729f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
730f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
7315c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  component_updater()->AddObserver(&observer);
7325c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
733eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  TestInstaller installer1;
734c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  CrxComponent com1;
735eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1);
736eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  TestInstaller installer2;
737c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  CrxComponent com2;
738eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2);
739c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
740f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Loop twice to issue two checks: (1) with original 0.9 version, update to
741f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // 1.0, and do the second check (2) with the updated 1.0 version.
742c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  test_configurator()->SetLoopCount(2);
743c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  component_updater()->Start();
7444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  RunThreads();
745c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
746c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
747c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count());
748c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
749c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count());
750c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
751f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(3, post_interceptor_->GetHitCount())
752010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
753f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(1, get_interceptor_->GetHitCount());
754f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
755010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_NE(
756010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      string::npos,
757010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      post_interceptor_->GetRequests()[0].find(
758010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">"
759010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<updatecheck /></app>"))
760f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
761010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_NE(
762010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      string::npos,
763010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      post_interceptor_->GetRequests()[1].find(
764010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" "
765010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "version=\"0.9\" nextversion=\"1.0\">"
766010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<event eventtype=\"3\" eventresult=\"1\"/>"))
767f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
768010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_NE(
769010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      string::npos,
770010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      post_interceptor_->GetRequests()[2].find(
771010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">"
772010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<updatecheck /></app>"))
773f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
774c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
775a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  component_updater()->Stop();
776a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
777c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Now re-register, pretending to be an even newer version (2.2)
7785c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer));
779a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  {
780a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    InSequence seq;
7815c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
7825c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_UPDATER_STARTED, ""))
783010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
7845c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
7855c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED,
7865c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                        "jebgalgnebhfojomionfpkfelancnnkf"))
787010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
7885c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
7895c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_NOT_UPDATED,
7905c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                        "abagagagagagagagagagagagagagagag"))
791010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
7925c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(observer,
7935c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                OnEvent(ServiceObserver::COMPONENT_UPDATER_SLEEPING, ""))
794010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        .Times(1);
795a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  }
796a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
797f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  post_interceptor_->Reset();
798010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_TRUE(post_interceptor_->ExpectRequest(
799010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
800f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
801eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  TestInstaller installer3;
802c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(ComponentUpdateService::kReplaced,
803010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)            RegisterComponent(
804010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                &com1, kTestComponent_jebg, Version("2.2"), &installer3));
805c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
806c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Loop once just to notice the check happening with the re-register version.
807c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  test_configurator()->SetLoopCount(1);
808c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  component_updater()->Start();
8094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  RunThreads();
810c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
811eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // We created a new installer, so the counts go back to 0.
812c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
813c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count());
814c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
815c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count());
816c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
817f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // One update check and no additional pings are expected.
818f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(1, post_interceptor_->GetHitCount())
819010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
820f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(1, post_interceptor_->GetCount())
821010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
822f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
823010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_NE(
824010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      string::npos,
825010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      post_interceptor_->GetRequests()[0].find(
826010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"2.2\">"
827010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<updatecheck /></app>"));
828f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
829c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  component_updater()->Stop();
830c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
831eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
832ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// Verify that we can download and install a component and a differential
833ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// update to that component. We do three loops; the final loop should do
834ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// nothing.
835ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// We also check that exactly 5 non-ping network requests are issued:
836ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// 1- update check (response: v1 available)
837ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// 2- download crx (v1)
838ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// 3- update check (response: v2 available)
839ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// 4- download differential crx (v1 to v2)
840ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// 5- update check (response: no further update available)
841ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// There should be two pings, one for each update. The second will bear a
842ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// diffresult=1, while the first will not.
843ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben MurdochTEST_F(ComponentUpdaterTest, DifferentialUpdate) {
844010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_TRUE(post_interceptor_->ExpectRequest(
845010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      new PartialMatch("updatecheck"),
846010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      test_file("updatecheck_diff_reply_1.xml")));
847f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event")));
848010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_TRUE(post_interceptor_->ExpectRequest(
849010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      new PartialMatch("updatecheck"),
850010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      test_file("updatecheck_diff_reply_2.xml")));
851f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event")));
852010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_TRUE(post_interceptor_->ExpectRequest(
853010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      new PartialMatch("updatecheck"),
854010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      test_file("updatecheck_diff_reply_3.xml")));
855f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
856f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  get_interceptor_->SetResponse(
857f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"),
858f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"));
859f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  get_interceptor_->SetResponse(
860f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      GURL("http://localhost/download/"
861f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)           "ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"),
862f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"));
863ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
864ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  VersionedTestInstaller installer;
865ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  CrxComponent com;
866ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer);
867ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
868ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  test_configurator()->SetLoopCount(3);
869ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  component_updater()->Start();
8704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  RunThreads();
871ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
872ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
873ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count());
874ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
875f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(5, post_interceptor_->GetHitCount())
876f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
877f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(5, post_interceptor_->GetCount())
878f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
879f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(2, get_interceptor_->GetHitCount());
880f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
881010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_NE(
882010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      string::npos,
883010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      post_interceptor_->GetRequests()[0].find(
884010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"0.0\">"
885010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<updatecheck /></app>"))
886f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
887010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_NE(
888010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      string::npos,
889010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      post_interceptor_->GetRequests()[1].find(
890010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" "
891010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "version=\"0.0\" nextversion=\"1.0\">"
892010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<event eventtype=\"3\" eventresult=\"1\" nextfp=\"1\"/>"))
893f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
894010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_NE(
895010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      string::npos,
896010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      post_interceptor_->GetRequests()[2].find(
897010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"1.0\">"
898010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<updatecheck /><packages><package fp=\"1\"/></packages></app>"))
899f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
900010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_NE(
901010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      string::npos,
902010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      post_interceptor_->GetRequests()[3].find(
903010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" "
904010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "version=\"1.0\" nextversion=\"2.0\">"
905010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<event eventtype=\"3\" eventresult=\"1\" diffresult=\"1\" "
906010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "previousfp=\"1\" nextfp=\"22\"/>"))
907f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
908010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_NE(
909010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      string::npos,
910010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      post_interceptor_->GetRequests()[4].find(
911010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">"
912010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "<updatecheck /><packages><package fp=\"22\"/></packages></app>"))
913f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      << post_interceptor_->GetRequestsAsString();
914ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  component_updater()->Stop();
915ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch}
916ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
917eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Verify that component installation falls back to downloading and installing
918eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// a full update if the differential update fails (in this case, because the
919eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// installer does not know about the existing files). We do two loops; the final
920eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// loop should do nothing.
921ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// We also check that exactly 4 non-ping network requests are issued:
922eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// 1- update check (loop 1)
923eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// 2- download differential crx
924eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// 3- download full crx
925eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// 4- update check (loop 2 - no update available)
926ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// There should be one ping for the first attempted update.
9270529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// This test is flaky on Android. crbug.com/329883
9280529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#if defined(OS_ANDROID)
9290529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#define MAYBE_DifferentialUpdateFails DISABLED_DifferentialUpdateFails
9300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#else
9310529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#define MAYBE_DifferentialUpdateFails DifferentialUpdateFails
9320529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#endif
9330529e5d033099cbfc42635f6f6183833b09dff6eBen MurdochTEST_F(ComponentUpdaterTest, MAYBE_DifferentialUpdateFails) {
934010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_TRUE(post_interceptor_->ExpectRequest(
935010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      new PartialMatch("updatecheck"),
936010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      test_file("updatecheck_diff_reply_2.xml")));
937f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event")));
938010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_TRUE(post_interceptor_->ExpectRequest(
939010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      new PartialMatch("updatecheck"),
940010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      test_file("updatecheck_diff_reply_3.xml")));
941f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
942f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  get_interceptor_->SetResponse(
943f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"),
944f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"));
945f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  get_interceptor_->SetResponse(
946f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      GURL("http://localhost/download/"
947010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)          "ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"),
948f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"));
949f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  get_interceptor_->SetResponse(
950f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"),
951f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"));
952eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
953eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  TestInstaller installer;
954eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  CrxComponent com;
955eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), &installer);
956eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
957eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  test_configurator()->SetLoopCount(2);
958eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  component_updater()->Start();
9594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  RunThreads();
960eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
961eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // A failed differential update does not count as a failed install.
962