| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_TEST_COMPONENT_UPDATER_SERVICE_UNITTEST
_H_ | 5 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_TEST_COMPONENT_UPDATER_SERVICE_UNITTEST
_H_ |
| 6 #define CHROME_BROWSER_COMPONENT_UPDATER_TEST_COMPONENT_UPDATER_SERVICE_UNITTEST
_H_ | 6 #define CHROME_BROWSER_COMPONENT_UPDATER_TEST_COMPONENT_UPDATER_SERVICE_UNITTEST
_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <map> |
| 10 #include <string> |
| 9 #include <utility> | 11 #include <utility> |
| 10 | 12 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/files/file_path.h" |
| 15 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/message_loop.h" |
| 13 #include "chrome/browser/component_updater/component_updater_service.h" | 18 #include "chrome/browser/component_updater/component_updater_service.h" |
| 14 #include "chrome/browser/component_updater/test/component_patcher_mock.h" | 19 #include "chrome/browser/component_updater/test/component_patcher_mock.h" |
| 20 #include "chrome/browser/component_updater/test/url_request_post_interceptor.h" |
| 21 #include "content/public/test/test_browser_thread.h" |
| 15 #include "content/public/test/test_notification_tracker.h" | 22 #include "content/public/test/test_notification_tracker.h" |
| 23 #include "net/url_request/url_request_test_util.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 25 |
| 18 using content::TestNotificationTracker; | 26 namespace component_updater { |
| 27 class PingManager; |
| 28 } |
| 19 | 29 |
| 20 class GURL; | |
| 21 class TestInstaller; | 30 class TestInstaller; |
| 22 | 31 |
| 23 // component 1 has extension id "jebgalgnebhfojomionfpkfelancnnkf", and | 32 // component 1 has extension id "jebgalgnebhfojomionfpkfelancnnkf", and |
| 24 // the RSA public key the following hash: | 33 // the RSA public key the following hash: |
| 25 const uint8 jebg_hash[] = {0x94, 0x16, 0x0b, 0x6d, 0x41, 0x75, 0xe9, 0xec, | 34 const uint8 jebg_hash[] = {0x94, 0x16, 0x0b, 0x6d, 0x41, 0x75, 0xe9, 0xec, |
| 26 0x8e, 0xd5, 0xfa, 0x54, 0xb0, 0xd2, 0xdd, 0xa5, | 35 0x8e, 0xd5, 0xfa, 0x54, 0xb0, 0xd2, 0xdd, 0xa5, |
| 27 0x6e, 0x05, 0x6b, 0xe8, 0x73, 0x47, 0xf6, 0xc4, | 36 0x6e, 0x05, 0x6b, 0xe8, 0x73, 0x47, 0xf6, 0xc4, |
| 28 0x11, 0x9f, 0xbc, 0xb3, 0x09, 0xb3, 0x5b, 0x40}; | 37 0x11, 0x9f, 0xbc, 0xb3, 0x09, 0xb3, 0x5b, 0x40}; |
| 29 // component 2 has extension id "abagagagagagagagagagagagagagagag", and | 38 // component 2 has extension id "abagagagagagagagagagagagagagagag", and |
| 30 // the RSA public key the following hash: | 39 // the RSA public key the following hash: |
| 31 const uint8 abag_hash[] = {0x01, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, | 40 const uint8 abag_hash[] = {0x01, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, |
| 32 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, | 41 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, |
| 33 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, | 42 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, |
| 34 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x01}; | 43 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x01}; |
| 35 // component 3 has extension id "ihfokbkgjpifnbbojhneepfflplebdkc", and | 44 // component 3 has extension id "ihfokbkgjpifnbbojhneepfflplebdkc", and |
| 36 // the RSA public key the following hash: | 45 // the RSA public key the following hash: |
| 37 const uint8 ihfo_hash[] = {0x87, 0x5e, 0xa1, 0xa6, 0x9f, 0x85, 0xd1, 0x1e, | 46 const uint8 ihfo_hash[] = {0x87, 0x5e, 0xa1, 0xa6, 0x9f, 0x85, 0xd1, 0x1e, |
| 38 0x97, 0xd4, 0x4f, 0x55, 0xbf, 0xb4, 0x13, 0xa2, | 47 0x97, 0xd4, 0x4f, 0x55, 0xbf, 0xb4, 0x13, 0xa2, |
| 39 0xe7, 0xc5, 0xc8, 0xf5, 0x60, 0x19, 0x78, 0x1b, | 48 0xe7, 0xc5, 0xc8, 0xf5, 0x60, 0x19, 0x78, 0x1b, |
| 40 0x6d, 0xe9, 0x4c, 0xeb, 0x96, 0x05, 0x42, 0x17}; | 49 0x6d, 0xe9, 0x4c, 0xeb, 0x96, 0x05, 0x42, 0x17}; |
| 41 | 50 |
| 42 class TestConfigurator : public ComponentUpdateService::Configurator { | 51 class TestConfigurator : public ComponentUpdateService::Configurator { |
| 43 public: | 52 public: |
| 44 explicit TestConfigurator(); | 53 explicit TestConfigurator(); |
| 45 | 54 |
| 46 virtual ~TestConfigurator(); | 55 virtual ~TestConfigurator(); |
| 47 | 56 |
| 57 virtual void Init(ComponentUpdateService* cus) OVERRIDE; |
| 58 |
| 48 virtual int InitialDelay() OVERRIDE; | 59 virtual int InitialDelay() OVERRIDE; |
| 49 | 60 |
| 50 typedef std::pair<CrxComponent*, int> CheckAtLoopCount; | 61 typedef std::pair<CrxComponent*, int> CheckAtLoopCount; |
| 51 | 62 |
| 52 virtual int NextCheckDelay() OVERRIDE; | 63 virtual int NextCheckDelay() OVERRIDE; |
| 53 | 64 |
| 54 virtual int StepDelay() OVERRIDE; | 65 virtual int StepDelay() OVERRIDE; |
| 55 | 66 |
| 56 virtual int MinimumReCheckWait() OVERRIDE; | 67 virtual int MinimumReCheckWait() OVERRIDE; |
| 57 | 68 |
| 58 virtual int OnDemandDelay() OVERRIDE; | 69 virtual int OnDemandDelay() OVERRIDE; |
| 59 | 70 |
| 60 virtual GURL UpdateUrl() OVERRIDE; | 71 virtual GURL UpdateUrl() OVERRIDE; |
| 61 | 72 |
| 73 virtual GURL PingUrl() OVERRIDE; |
| 74 |
| 62 virtual const char* ExtraRequestParams() OVERRIDE; | 75 virtual const char* ExtraRequestParams() OVERRIDE; |
| 63 | 76 |
| 64 virtual size_t UrlSizeLimit() OVERRIDE; | 77 virtual size_t UrlSizeLimit() OVERRIDE; |
| 65 | 78 |
| 66 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE; | 79 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE; |
| 67 | 80 |
| 68 // Don't use the utility process to decode files. | 81 // Don't use the utility process to decode files. |
| 69 virtual bool InProcess() OVERRIDE; | 82 virtual bool InProcess() OVERRIDE; |
| 70 | 83 |
| 71 virtual void OnEvent(Events event, int extra) OVERRIDE; | |
| 72 | |
| 73 virtual ComponentPatcher* CreateComponentPatcher() OVERRIDE; | 84 virtual ComponentPatcher* CreateComponentPatcher() OVERRIDE; |
| 74 | 85 |
| 75 virtual bool DeltasEnabled() const OVERRIDE; | 86 virtual bool DeltasEnabled() const OVERRIDE; |
| 76 | 87 |
| 77 void SetLoopCount(int times); | 88 void SetLoopCount(int times); |
| 78 | 89 |
| 79 void SetRecheckTime(int seconds); | 90 void SetRecheckTime(int seconds); |
| 80 | 91 |
| 81 void SetOnDemandTime(int seconds); | 92 void SetOnDemandTime(int seconds); |
| 82 | 93 |
| 83 void AddComponentToCheck(CrxComponent* com, int at_loop_iter); | 94 void AddComponentToCheck(CrxComponent* com, int at_loop_iter); |
| 84 | 95 |
| 85 void SetComponentUpdateService(ComponentUpdateService* cus); | |
| 86 | |
| 87 private: | 96 private: |
| 88 int times_; | 97 int times_; |
| 89 int recheck_time_; | 98 int recheck_time_; |
| 90 int ondemand_time_; | 99 int ondemand_time_; |
| 91 | 100 |
| 92 std::list<CheckAtLoopCount> components_to_check_; | 101 std::list<CheckAtLoopCount> components_to_check_; |
| 93 ComponentUpdateService* cus_; | 102 ComponentUpdateService* cus_; |
| 103 scoped_refptr<net::TestURLRequestContextGetter> context_; |
| 104 scoped_ptr<component_updater::PingManager> ping_manager_; |
| 94 }; | 105 }; |
| 95 | 106 |
| 96 class ComponentUpdaterTest : public testing::Test { | 107 class ComponentUpdaterTest : public testing::Test { |
| 97 public: | 108 public: |
| 98 enum TestComponents { | 109 enum TestComponents { |
| 99 kTestComponent_abag, | 110 kTestComponent_abag, |
| 100 kTestComponent_jebg, | 111 kTestComponent_jebg, |
| 101 kTestComponent_ihfo, | 112 kTestComponent_ihfo, |
| 102 }; | 113 }; |
| 103 | 114 |
| 104 ComponentUpdaterTest(); | 115 ComponentUpdaterTest(); |
| 105 | 116 |
| 106 virtual ~ComponentUpdaterTest(); | 117 virtual ~ComponentUpdaterTest(); |
| 107 | 118 |
| 108 virtual void TearDown(); | 119 virtual void TearDown(); |
| 109 | 120 |
| 110 ComponentUpdateService* component_updater(); | 121 ComponentUpdateService* component_updater(); |
| 111 | 122 |
| 112 // Makes the full path to a component updater test file. | 123 // Makes the full path to a component updater test file. |
| 113 const base::FilePath test_file(const char* file); | 124 const base::FilePath test_file(const char* file); |
| 114 | 125 |
| 115 TestNotificationTracker& notification_tracker(); | 126 content::TestNotificationTracker& notification_tracker(); |
| 116 | 127 |
| 117 TestConfigurator* test_configurator(); | 128 TestConfigurator* test_configurator(); |
| 118 | 129 |
| 119 ComponentUpdateService::Status RegisterComponent(CrxComponent* com, | 130 ComponentUpdateService::Status RegisterComponent(CrxComponent* com, |
| 120 TestComponents component, | 131 TestComponents component, |
| 121 const Version& version, | 132 const Version& version, |
| 122 TestInstaller* installer); | 133 TestInstaller* installer); |
| 134 protected: |
| 135 base::MessageLoop message_loop_; |
| 123 | 136 |
| 124 private: | 137 private: |
| 138 TestConfigurator* test_config_; |
| 139 base::FilePath test_data_dir_; |
| 140 content::TestNotificationTracker notification_tracker_; |
| 141 content::TestBrowserThread ui_thread_; |
| 142 content::TestBrowserThread file_thread_; |
| 143 content::TestBrowserThread io_thread_; |
| 125 scoped_ptr<ComponentUpdateService> component_updater_; | 144 scoped_ptr<ComponentUpdateService> component_updater_; |
| 126 base::FilePath test_data_dir_; | |
| 127 TestNotificationTracker notification_tracker_; | |
| 128 TestConfigurator* test_config_; | |
| 129 }; | 145 }; |
| 130 | 146 |
| 131 const char expected_crx_url[] = | 147 const char expected_crx_url[] = |
| 132 "http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"; | 148 "http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"; |
| 133 | 149 |
| 150 class PingChecker : public RequestCounter { |
| 151 public: |
| 152 explicit PingChecker(const std::map<std::string, std::string>& attributes); |
| 153 |
| 154 virtual ~PingChecker(); |
| 155 |
| 156 virtual void Trial(net::URLRequest* request) OVERRIDE; |
| 157 |
| 158 int NumHits() const { |
| 159 return num_hits_; |
| 160 } |
| 161 int NumMisses() const { |
| 162 return num_misses_; |
| 163 } |
| 164 |
| 165 private: |
| 166 int num_hits_; |
| 167 int num_misses_; |
| 168 const std::map<std::string, std::string> attributes_; |
| 169 virtual bool Test(net::URLRequest* request); |
| 170 }; |
| 171 |
| 134 #endif // CHROME_BROWSER_COMPONENT_UPDATER_TEST_COMPONENT_UPDATER_SERVICE_UNITT
EST_H_ | 172 #endif // CHROME_BROWSER_COMPONENT_UPDATER_TEST_COMPONENT_UPDATER_SERVICE_UNITT
EST_H_ |
| OLD | NEW |