1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_UNITTEST_H_
6 #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_UNITTEST_H_
10 #include "base/compiler_specific.h"
11 #include "base/files/file_path.h"
12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "components/component_updater/component_updater_service.h"
16 #include "content/public/test/test_browser_thread_bundle.h"
17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h"
21 class LocalHostTestURLRequestInterceptor
;
24 namespace update_client
{
26 class InterceptorFactory
;
27 class TestConfigurator
;
29 class URLRequestPostInterceptor
;
32 namespace component_updater
{
34 // Intercepts HTTP GET requests sent to "localhost".
35 typedef net::LocalHostTestURLRequestInterceptor GetInterceptor
;
37 class ComponentUpdaterTest
: public testing::Test
{
45 ComponentUpdaterTest();
47 ~ComponentUpdaterTest() override
;
49 void SetUp() override
;
51 void TearDown() override
;
53 ComponentUpdateService
* component_updater();
55 // Makes the full path to a component updater test file.
56 const base::FilePath
test_file(const char* file
);
58 scoped_refptr
<update_client::TestConfigurator
> test_configurator();
60 ComponentUpdateService::Status
RegisterComponent(
61 update_client::CrxComponent
* com
,
62 TestComponents component
,
63 const Version
& version
,
64 const scoped_refptr
<update_client::TestInstaller
>& installer
);
68 void RunThreadsUntilIdle();
70 scoped_ptr
<update_client::InterceptorFactory
> interceptor_factory_
;
72 // Owned by the factory.
73 update_client::URLRequestPostInterceptor
* post_interceptor_
;
75 scoped_ptr
<GetInterceptor
> get_interceptor_
;
78 content::TestBrowserThreadBundle thread_bundle_
;
79 scoped_refptr
<update_client::TestConfigurator
> test_config_
;
80 scoped_ptr
<ComponentUpdateService
> component_updater_
;
83 const char expected_crx_url
[] =
84 "http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx";
86 class MockServiceObserver
: public ServiceObserver
{
88 MockServiceObserver();
89 ~MockServiceObserver();
90 MOCK_METHOD2(OnEvent
, void(Events event
, const std::string
&));
93 class OnDemandTester
{
95 static ComponentUpdateService::Status
OnDemand(
96 ComponentUpdateService
* cus
,
97 const std::string
& component_id
);
100 } // namespace component_updater
102 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_UNITTEST_H_