Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Side by Side Diff: chrome/browser/component_updater/test/component_updater_service_unittest.h

Issue 18516010: Implemented completion pings for component updates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/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;
19
20 class GURL;
21 class TestInstaller; 26 class TestInstaller;
22 27
23 // component 1 has extension id "jebgalgnebhfojomionfpkfelancnnkf", and 28 // component 1 has extension id "jebgalgnebhfojomionfpkfelancnnkf", and
24 // the RSA public key the following hash: 29 // the RSA public key the following hash:
25 const uint8 jebg_hash[] = {0x94, 0x16, 0x0b, 0x6d, 0x41, 0x75, 0xe9, 0xec, 30 const uint8 jebg_hash[] = {0x94, 0x16, 0x0b, 0x6d, 0x41, 0x75, 0xe9, 0xec,
26 0x8e, 0xd5, 0xfa, 0x54, 0xb0, 0xd2, 0xdd, 0xa5, 31 0x8e, 0xd5, 0xfa, 0x54, 0xb0, 0xd2, 0xdd, 0xa5,
27 0x6e, 0x05, 0x6b, 0xe8, 0x73, 0x47, 0xf6, 0xc4, 32 0x6e, 0x05, 0x6b, 0xe8, 0x73, 0x47, 0xf6, 0xc4,
28 0x11, 0x9f, 0xbc, 0xb3, 0x09, 0xb3, 0x5b, 0x40}; 33 0x11, 0x9f, 0xbc, 0xb3, 0x09, 0xb3, 0x5b, 0x40};
29 // component 2 has extension id "abagagagagagagagagagagagagagagag", and 34 // component 2 has extension id "abagagagagagagagagagagagagagagag", and
30 // the RSA public key the following hash: 35 // the RSA public key the following hash:
(...skipping 21 matching lines...) Expand all
52 virtual int NextCheckDelay() OVERRIDE; 57 virtual int NextCheckDelay() OVERRIDE;
53 58
54 virtual int StepDelay() OVERRIDE; 59 virtual int StepDelay() OVERRIDE;
55 60
56 virtual int MinimumReCheckWait() OVERRIDE; 61 virtual int MinimumReCheckWait() OVERRIDE;
57 62
58 virtual int OnDemandDelay() OVERRIDE; 63 virtual int OnDemandDelay() OVERRIDE;
59 64
60 virtual GURL UpdateUrl() OVERRIDE; 65 virtual GURL UpdateUrl() OVERRIDE;
61 66
67 virtual GURL PingUrl() OVERRIDE;
68
62 virtual const char* ExtraRequestParams() OVERRIDE; 69 virtual const char* ExtraRequestParams() OVERRIDE;
63 70
64 virtual size_t UrlSizeLimit() OVERRIDE; 71 virtual size_t UrlSizeLimit() OVERRIDE;
65 72
66 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE; 73 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE;
67 74
68 // Don't use the utility process to decode files. 75 // Don't use the utility process to decode files.
69 virtual bool InProcess() OVERRIDE; 76 virtual bool InProcess() OVERRIDE;
70 77
71 virtual void OnEvent(Events event, int extra) OVERRIDE;
72
73 virtual ComponentPatcher* CreateComponentPatcher() OVERRIDE; 78 virtual ComponentPatcher* CreateComponentPatcher() OVERRIDE;
74 79
75 virtual bool DeltasEnabled() const OVERRIDE; 80 virtual bool DeltasEnabled() const OVERRIDE;
76 81
77 void SetLoopCount(int times); 82 void SetLoopCount(int times);
78 83
79 void SetRecheckTime(int seconds); 84 void SetRecheckTime(int seconds);
80 85
81 void SetOnDemandTime(int seconds); 86 void SetOnDemandTime(int seconds);
82 87
83 void AddComponentToCheck(CrxComponent* com, int at_loop_iter); 88 void AddComponentToCheck(CrxComponent* com, int at_loop_iter);
84 89
85 void SetComponentUpdateService(ComponentUpdateService* cus); 90 void SetComponentUpdateService(ComponentUpdateService* cus);
86 91
87 private: 92 private:
88 int times_; 93 int times_;
89 int recheck_time_; 94 int recheck_time_;
90 int ondemand_time_; 95 int ondemand_time_;
91 96
92 std::list<CheckAtLoopCount> components_to_check_; 97 std::list<CheckAtLoopCount> components_to_check_;
93 ComponentUpdateService* cus_; 98 ComponentUpdateService* cus_;
99 scoped_refptr<net::TestURLRequestContextGetter> context_;
94 }; 100 };
95 101
96 class ComponentUpdaterTest : public testing::Test { 102 class ComponentUpdaterTest : public testing::Test {
97 public: 103 public:
98 enum TestComponents { 104 enum TestComponents {
99 kTestComponent_abag, 105 kTestComponent_abag,
100 kTestComponent_jebg, 106 kTestComponent_jebg,
101 kTestComponent_ihfo, 107 kTestComponent_ihfo,
102 }; 108 };
103 109
104 ComponentUpdaterTest(); 110 ComponentUpdaterTest();
105 111
106 virtual ~ComponentUpdaterTest(); 112 virtual ~ComponentUpdaterTest();
107 113
108 virtual void TearDown(); 114 virtual void TearDown();
109 115
110 ComponentUpdateService* component_updater(); 116 ComponentUpdateService* component_updater();
111 117
112 // Makes the full path to a component updater test file. 118 // Makes the full path to a component updater test file.
113 const base::FilePath test_file(const char* file); 119 const base::FilePath test_file(const char* file);
114 120
115 TestNotificationTracker& notification_tracker(); 121 content::TestNotificationTracker& notification_tracker();
116 122
117 TestConfigurator* test_configurator(); 123 TestConfigurator* test_configurator();
118 124
119 ComponentUpdateService::Status RegisterComponent(CrxComponent* com, 125 ComponentUpdateService::Status RegisterComponent(CrxComponent* com,
120 TestComponents component, 126 TestComponents component,
121 const Version& version, 127 const Version& version,
122 TestInstaller* installer); 128 TestInstaller* installer);
129 protected:
130 base::MessageLoop message_loop_;
123 131
124 private: 132 private:
133 TestConfigurator* test_config_;
134 base::FilePath test_data_dir_;
135 content::TestNotificationTracker notification_tracker_;
136 content::TestBrowserThread ui_thread_;
137 content::TestBrowserThread file_thread_;
138 content::TestBrowserThread io_thread_;
125 scoped_ptr<ComponentUpdateService> component_updater_; 139 scoped_ptr<ComponentUpdateService> component_updater_;
126 base::FilePath test_data_dir_;
127 TestNotificationTracker notification_tracker_;
128 TestConfigurator* test_config_;
129 }; 140 };
130 141
131 const char expected_crx_url[] = 142 const char expected_crx_url[] =
132 "http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"; 143 "http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx";
133 144
145 class PingChecker : public RequestCounter {
146 public:
147 explicit PingChecker(const std::map<std::string, std::string>& attributes);
148
149 virtual ~PingChecker();
150
151 virtual void Trial(net::URLRequest* request) OVERRIDE;
152
153 int NumHits() const {
154 return num_hits_;
155 }
156 int NumMisses() const {
157 return num_misses_;
158 }
159
160 private:
161 int num_hits_;
162 int num_misses_;
163 const std::map<std::string, std::string> attributes_;
164 virtual bool Test(net::URLRequest* request);
165 };
166
134 #endif // CHROME_BROWSER_COMPONENT_UPDATER_TEST_COMPONENT_UPDATER_SERVICE_UNITT EST_H_ 167 #endif // CHROME_BROWSER_COMPONENT_UPDATER_TEST_COMPONENT_UPDATER_SERVICE_UNITT EST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698