1eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Copyright 2013 The Chromium Authors. All rights reserved.
2eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Use of this source code is governed by a BSD-style license that can be
3eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// found in the LICENSE file.
4eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
5eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#ifndef CHROME_BROWSER_COMPONENT_UPDATER_TEST_COMPONENT_UPDATER_SERVICE_UNITTEST_H_
6eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#define CHROME_BROWSER_COMPONENT_UPDATER_TEST_COMPONENT_UPDATER_SERVICE_UNITTEST_H_
7eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
8ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include <string>
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
10eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/compiler_specific.h"
11ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "base/files/file_path.h"
121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/macros.h"
13eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/memory/scoped_ptr.h"
1403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "components/component_updater/component_updater_service.h"
154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "content/public/test/test_browser_thread_bundle.h"
16a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "testing/gmock/include/gmock/gmock.h"
17eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "testing/gtest/include/gtest/gtest.h"
18eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccinamespace net {
201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass LocalHostTestURLRequestInterceptor;
211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
23f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace component_updater {
24f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass InterceptorFactory;
261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass TestConfigurator;
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class TestInstaller;
281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass URLRequestPostInterceptor;
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
30f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Intercepts HTTP GET requests sent to "localhost".
311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccitypedef net::LocalHostTestURLRequestInterceptor GetInterceptor;
32eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
33eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochclass ComponentUpdaterTest : public testing::Test {
34eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch public:
35eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  enum TestComponents {
36eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    kTestComponent_abag,
37eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    kTestComponent_jebg,
38eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    kTestComponent_ihfo,
39eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  };
40eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
41eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  ComponentUpdaterTest();
42eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
43eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual ~ComponentUpdaterTest();
44eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
45f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void SetUp();
46f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
47eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual void TearDown();
48eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
49eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  ComponentUpdateService* component_updater();
50eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
51eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Makes the full path to a component updater test file.
52eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  const base::FilePath test_file(const char* file);
53eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
54eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  TestConfigurator* test_configurator();
55eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
56eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  ComponentUpdateService::Status RegisterComponent(CrxComponent* com,
57eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                                                   TestComponents component,
58eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                                                   const Version& version,
59eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                                                   TestInstaller* installer);
604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
61ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch protected:
624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void RunThreads();
634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void RunThreadsUntilIdle();
64eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
65a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  scoped_ptr<InterceptorFactory> interceptor_factory_;
66010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  URLRequestPostInterceptor* post_interceptor_;  // Owned by the factory.
67f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
68f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  scoped_ptr<GetInterceptor> get_interceptor_;
69010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
70eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch private:
71eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  TestConfigurator* test_config_;
724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  content::TestBrowserThreadBundle thread_bundle_;
73ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  scoped_ptr<ComponentUpdateService> component_updater_;
74eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch};
75eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
76eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochconst char expected_crx_url[] =
77eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    "http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx";
78eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
795c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liuclass MockServiceObserver : public ServiceObserver {
80a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) public:
815c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  MockServiceObserver();
825c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  ~MockServiceObserver();
835c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  MOCK_METHOD2(OnEvent, void(Events event, const std::string&));
84a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)};
85a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class OnDemandTester {
871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) public:
881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  static ComponentUpdateService::Status OnDemand(
89010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      ComponentUpdateService* cus,
90010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      const std::string& component_id);
911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)};
921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
93f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}  // namespace component_updater
94f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
95eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#endif  // CHROME_BROWSER_COMPONENT_UPDATER_TEST_COMPONENT_UPDATER_SERVICE_UNITTEST_H_
96