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. 4 5 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_TEST_COMPONENT_UPDATER_SERVICE_UNITTEST_H_ 6 #define CHROME_BROWSER_COMPONENT_UPDATER_TEST_COMPONENT_UPDATER_SERVICE_UNITTEST_H_ 7 8 #include <string> 9 10 #include "base/compiler_specific.h" 11 #include "base/files/file_path.h" 12 #include "base/macros.h" 13 #include "base/memory/scoped_ptr.h" 14 #include "components/component_updater/component_updater_service.h" 15 #include "content/public/test/test_browser_thread_bundle.h" 16 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gtest/include/gtest/gtest.h" 18 19 namespace net { 20 class LocalHostTestURLRequestInterceptor; 21 } 22 23 namespace component_updater { 24 25 class InterceptorFactory; 26 class TestConfigurator; 27 class TestInstaller; 28 class URLRequestPostInterceptor; 29 30 // Intercepts HTTP GET requests sent to "localhost". 31 typedef net::LocalHostTestURLRequestInterceptor GetInterceptor; 32 33 class ComponentUpdaterTest : public testing::Test { 34 public: 35 enum TestComponents { 36 kTestComponent_abag, 37 kTestComponent_jebg, 38 kTestComponent_ihfo, 39 }; 40 41 ComponentUpdaterTest(); 42 43 virtual ~ComponentUpdaterTest(); 44 45 virtual void SetUp(); 46 47 virtual void TearDown(); 48 49 ComponentUpdateService* component_updater(); 50 51 // Makes the full path to a component updater test file. 52 const base::FilePath test_file(const char* file); 53 54 TestConfigurator* test_configurator(); 55 56 ComponentUpdateService::Status RegisterComponent(CrxComponent* com, 57 TestComponents component, 58 const Version& version, 59 TestInstaller* installer); 60 61 protected: 62 void RunThreads(); 63 void RunThreadsUntilIdle(); 64 65 scoped_ptr<InterceptorFactory> interceptor_factory_; 66 URLRequestPostInterceptor* post_interceptor_; // Owned by the factory. 67 68 scoped_ptr<GetInterceptor> get_interceptor_; 69 70 private: 71 TestConfigurator* test_config_; 72 content::TestBrowserThreadBundle thread_bundle_; 73 scoped_ptr<ComponentUpdateService> component_updater_; 74 }; 75 76 const char expected_crx_url[] = 77 "http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"; 78 79 class MockServiceObserver : public ServiceObserver { 80 public: 81 MockServiceObserver(); 82 ~MockServiceObserver(); 83 MOCK_METHOD2(OnEvent, void(Events event, const std::string&)); 84 }; 85 86 class OnDemandTester { 87 public: 88 static ComponentUpdateService::Status OnDemand( 89 ComponentUpdateService* cus, 90 const std::string& component_id); 91 }; 92 93 } // namespace component_updater 94 95 #endif // CHROME_BROWSER_COMPONENT_UPDATER_TEST_COMPONENT_UPDATER_SERVICE_UNITTEST_H_ 96