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

Side by Side Diff: chrome/common/extensions/extension_localization_peer_unittest.cc

Issue 7602023: Use a monotonic clock (TimeTicks) to report network times to WebCore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync & Merge Created 9 years 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include <map> 5 #include <map>
6 #include <string> 6 #include <string>
7 7
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "chrome/common/extensions/extension_message_bundle.h" 9 #include "chrome/common/extensions/extension_message_bundle.h"
10 #include "chrome/common/extensions/extension_localization_peer.h" 10 #include "chrome/common/extensions/extension_localization_peer.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 GURL* new_first_party_for_cookies)); 65 GURL* new_first_party_for_cookies));
66 MOCK_METHOD1(OnReceivedResponse, void( 66 MOCK_METHOD1(OnReceivedResponse, void(
67 const webkit_glue::ResourceResponseInfo& info)); 67 const webkit_glue::ResourceResponseInfo& info));
68 MOCK_METHOD1(OnDownloadedData, void(int len)); 68 MOCK_METHOD1(OnDownloadedData, void(int len));
69 MOCK_METHOD3(OnReceivedData, void(const char* data, 69 MOCK_METHOD3(OnReceivedData, void(const char* data,
70 int data_length, 70 int data_length,
71 int encoded_data_length)); 71 int encoded_data_length));
72 MOCK_METHOD3(OnCompletedRequest, void( 72 MOCK_METHOD3(OnCompletedRequest, void(
73 const net::URLRequestStatus& status, 73 const net::URLRequestStatus& status,
74 const std::string& security_info, 74 const std::string& security_info,
75 const base::Time& completion_time)); 75 const base::TimeTicks& completion_time));
76 76
77 private: 77 private:
78 DISALLOW_COPY_AND_ASSIGN(MockResourceLoaderBridgePeer); 78 DISALLOW_COPY_AND_ASSIGN(MockResourceLoaderBridgePeer);
79 }; 79 };
80 80
81 class ExtensionLocalizationPeerTest : public testing::Test { 81 class ExtensionLocalizationPeerTest : public testing::Test {
82 protected: 82 protected:
83 virtual void SetUp() { 83 virtual void SetUp() {
84 sender_.reset(new MockIpcMessageSender()); 84 sender_.reset(new MockIpcMessageSender());
85 original_peer_.reset(new MockResourceLoaderBridgePeer()); 85 original_peer_.reset(new MockResourceLoaderBridgePeer());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 } 135 }
136 136
137 MATCHER_P(IsURLRequestEqual, status, "") { return arg.status() == status; } 137 MATCHER_P(IsURLRequestEqual, status, "") { return arg.status() == status; }
138 138
139 TEST_F(ExtensionLocalizationPeerTest, OnCompletedRequestBadURLRequestStatus) { 139 TEST_F(ExtensionLocalizationPeerTest, OnCompletedRequestBadURLRequestStatus) {
140 // It will self-delete once it exits OnCompletedRequest. 140 // It will self-delete once it exits OnCompletedRequest.
141 ExtensionLocalizationPeer* filter_peer = filter_peer_.release(); 141 ExtensionLocalizationPeer* filter_peer = filter_peer_.release();
142 142
143 EXPECT_CALL(*original_peer_, OnReceivedResponse(_)); 143 EXPECT_CALL(*original_peer_, OnReceivedResponse(_));
144 EXPECT_CALL(*original_peer_, OnCompletedRequest( 144 EXPECT_CALL(*original_peer_, OnCompletedRequest(
145 IsURLRequestEqual(net::URLRequestStatus::CANCELED), "", base::Time())); 145 IsURLRequestEqual(net::URLRequestStatus::CANCELED), "", base::TimeTicks()));
146 146
147 net::URLRequestStatus status; 147 net::URLRequestStatus status;
148 status.set_status(net::URLRequestStatus::FAILED); 148 status.set_status(net::URLRequestStatus::FAILED);
149 filter_peer->OnCompletedRequest(status, "", base::Time()); 149 filter_peer->OnCompletedRequest(status, "", base::TimeTicks());
150 } 150 }
151 151
152 TEST_F(ExtensionLocalizationPeerTest, OnCompletedRequestEmptyData) { 152 TEST_F(ExtensionLocalizationPeerTest, OnCompletedRequestEmptyData) {
153 // It will self-delete once it exits OnCompletedRequest. 153 // It will self-delete once it exits OnCompletedRequest.
154 ExtensionLocalizationPeer* filter_peer = filter_peer_.release(); 154 ExtensionLocalizationPeer* filter_peer = filter_peer_.release();
155 155
156 EXPECT_CALL(*original_peer_, OnReceivedData(_, _, _)).Times(0); 156 EXPECT_CALL(*original_peer_, OnReceivedData(_, _, _)).Times(0);
157 EXPECT_CALL(*sender_, Send(_)).Times(0); 157 EXPECT_CALL(*sender_, Send(_)).Times(0);
158 158
159 EXPECT_CALL(*original_peer_, OnReceivedResponse(_)); 159 EXPECT_CALL(*original_peer_, OnReceivedResponse(_));
160 EXPECT_CALL(*original_peer_, OnCompletedRequest( 160 EXPECT_CALL(*original_peer_, OnCompletedRequest(
161 IsURLRequestEqual(net::URLRequestStatus::SUCCESS), "", base::Time())); 161 IsURLRequestEqual(net::URLRequestStatus::SUCCESS), "",
162 base::TimeTicks()));
162 163
163 net::URLRequestStatus status; 164 net::URLRequestStatus status;
164 status.set_status(net::URLRequestStatus::SUCCESS); 165 status.set_status(net::URLRequestStatus::SUCCESS);
165 filter_peer->OnCompletedRequest(status, "", base::Time()); 166 filter_peer->OnCompletedRequest(status, "", base::TimeTicks());
166 } 167 }
167 168
168 TEST_F(ExtensionLocalizationPeerTest, OnCompletedRequestNoCatalogs) { 169 TEST_F(ExtensionLocalizationPeerTest, OnCompletedRequestNoCatalogs) {
169 // It will self-delete once it exits OnCompletedRequest. 170 // It will self-delete once it exits OnCompletedRequest.
170 ExtensionLocalizationPeer* filter_peer = filter_peer_.release(); 171 ExtensionLocalizationPeer* filter_peer = filter_peer_.release();
171 172
172 SetData(filter_peer, "some text"); 173 SetData(filter_peer, "some text");
173 174
174 EXPECT_CALL(*sender_, Send(_)); 175 EXPECT_CALL(*sender_, Send(_));
175 176
176 std::string data = GetData(filter_peer); 177 std::string data = GetData(filter_peer);
177 EXPECT_CALL(*original_peer_, 178 EXPECT_CALL(*original_peer_,
178 OnReceivedData(StrEq(data.data()), data.length(), -1)).Times(2); 179 OnReceivedData(StrEq(data.data()), data.length(), -1)).Times(2);
179 180
180 EXPECT_CALL(*original_peer_, OnReceivedResponse(_)).Times(2); 181 EXPECT_CALL(*original_peer_, OnReceivedResponse(_)).Times(2);
181 EXPECT_CALL(*original_peer_, OnCompletedRequest( 182 EXPECT_CALL(*original_peer_, OnCompletedRequest(
182 IsURLRequestEqual( 183 IsURLRequestEqual(
183 net::URLRequestStatus::SUCCESS), "", base::Time())).Times(2); 184 net::URLRequestStatus::SUCCESS), "", base::TimeTicks())).Times(2);
184 185
185 net::URLRequestStatus status; 186 net::URLRequestStatus status;
186 status.set_status(net::URLRequestStatus::SUCCESS); 187 status.set_status(net::URLRequestStatus::SUCCESS);
187 filter_peer->OnCompletedRequest(status, "", base::Time()); 188 filter_peer->OnCompletedRequest(status, "", base::TimeTicks());
188 189
189 // Test if Send gets called again (it shouldn't be) when first call returned 190 // Test if Send gets called again (it shouldn't be) when first call returned
190 // an empty dictionary. 191 // an empty dictionary.
191 filter_peer = 192 filter_peer =
192 CreateExtensionLocalizationPeer("text/css", GURL(kExtensionUrl_1)); 193 CreateExtensionLocalizationPeer("text/css", GURL(kExtensionUrl_1));
193 SetData(filter_peer, "some text"); 194 SetData(filter_peer, "some text");
194 filter_peer->OnCompletedRequest(status, "", base::Time()); 195 filter_peer->OnCompletedRequest(status, "", base::TimeTicks());
195 } 196 }
196 197
197 TEST_F(ExtensionLocalizationPeerTest, OnCompletedRequestWithCatalogs) { 198 TEST_F(ExtensionLocalizationPeerTest, OnCompletedRequestWithCatalogs) {
198 // It will self-delete once it exits OnCompletedRequest. 199 // It will self-delete once it exits OnCompletedRequest.
199 ExtensionLocalizationPeer* filter_peer = 200 ExtensionLocalizationPeer* filter_peer =
200 CreateExtensionLocalizationPeer("text/css", GURL(kExtensionUrl_2)); 201 CreateExtensionLocalizationPeer("text/css", GURL(kExtensionUrl_2));
201 202
202 L10nMessagesMap messages; 203 L10nMessagesMap messages;
203 messages.insert(std::make_pair("text", "new text")); 204 messages.insert(std::make_pair("text", "new text"));
204 ExtensionToL10nMessagesMap& l10n_messages_map = 205 ExtensionToL10nMessagesMap& l10n_messages_map =
205 *GetExtensionToL10nMessagesMap(); 206 *GetExtensionToL10nMessagesMap();
206 l10n_messages_map["some_id2"] = messages; 207 l10n_messages_map["some_id2"] = messages;
207 208
208 SetData(filter_peer, "some __MSG_text__"); 209 SetData(filter_peer, "some __MSG_text__");
209 210
210 // We already have messages in memory, Send will be skipped. 211 // We already have messages in memory, Send will be skipped.
211 EXPECT_CALL(*sender_, Send(_)).Times(0); 212 EXPECT_CALL(*sender_, Send(_)).Times(0);
212 213
213 // __MSG_text__ gets replaced with "new text". 214 // __MSG_text__ gets replaced with "new text".
214 std::string data("some new text"); 215 std::string data("some new text");
215 EXPECT_CALL(*original_peer_, 216 EXPECT_CALL(*original_peer_,
216 OnReceivedData(StrEq(data.data()), data.length(), -1)); 217 OnReceivedData(StrEq(data.data()), data.length(), -1));
217 218
218 EXPECT_CALL(*original_peer_, OnReceivedResponse(_)); 219 EXPECT_CALL(*original_peer_, OnReceivedResponse(_));
219 EXPECT_CALL(*original_peer_, OnCompletedRequest( 220 EXPECT_CALL(*original_peer_, OnCompletedRequest(
220 IsURLRequestEqual(net::URLRequestStatus::SUCCESS), "", base::Time())); 221 IsURLRequestEqual(net::URLRequestStatus::SUCCESS), "",
222 base::TimeTicks()));
221 223
222 net::URLRequestStatus status; 224 net::URLRequestStatus status;
223 status.set_status(net::URLRequestStatus::SUCCESS); 225 status.set_status(net::URLRequestStatus::SUCCESS);
224 filter_peer->OnCompletedRequest(status, "", base::Time()); 226 filter_peer->OnCompletedRequest(status, "", base::TimeTicks());
225 } 227 }
226 228
227 TEST_F(ExtensionLocalizationPeerTest, OnCompletedRequestReplaceMessagesFails) { 229 TEST_F(ExtensionLocalizationPeerTest, OnCompletedRequestReplaceMessagesFails) {
228 // It will self-delete once it exits OnCompletedRequest. 230 // It will self-delete once it exits OnCompletedRequest.
229 ExtensionLocalizationPeer* filter_peer = 231 ExtensionLocalizationPeer* filter_peer =
230 CreateExtensionLocalizationPeer("text/css", GURL(kExtensionUrl_3)); 232 CreateExtensionLocalizationPeer("text/css", GURL(kExtensionUrl_3));
231 233
232 L10nMessagesMap messages; 234 L10nMessagesMap messages;
233 messages.insert(std::make_pair("text", "new text")); 235 messages.insert(std::make_pair("text", "new text"));
234 ExtensionToL10nMessagesMap& l10n_messages_map = 236 ExtensionToL10nMessagesMap& l10n_messages_map =
235 *GetExtensionToL10nMessagesMap(); 237 *GetExtensionToL10nMessagesMap();
236 l10n_messages_map["some_id3"] = messages; 238 l10n_messages_map["some_id3"] = messages;
237 239
238 std::string message("some __MSG_missing_message__"); 240 std::string message("some __MSG_missing_message__");
239 SetData(filter_peer, message); 241 SetData(filter_peer, message);
240 242
241 // We already have messages in memory, Send will be skipped. 243 // We already have messages in memory, Send will be skipped.
242 EXPECT_CALL(*sender_, Send(_)).Times(0); 244 EXPECT_CALL(*sender_, Send(_)).Times(0);
243 245
244 // __MSG_missing_message__ is missing, so message stays the same. 246 // __MSG_missing_message__ is missing, so message stays the same.
245 EXPECT_CALL(*original_peer_, 247 EXPECT_CALL(*original_peer_,
246 OnReceivedData(StrEq(message.data()), message.length(), -1)); 248 OnReceivedData(StrEq(message.data()), message.length(), -1));
247 249
248 EXPECT_CALL(*original_peer_, OnReceivedResponse(_)); 250 EXPECT_CALL(*original_peer_, OnReceivedResponse(_));
249 EXPECT_CALL(*original_peer_, OnCompletedRequest( 251 EXPECT_CALL(*original_peer_, OnCompletedRequest(
250 IsURLRequestEqual(net::URLRequestStatus::SUCCESS), "", base::Time())); 252 IsURLRequestEqual(net::URLRequestStatus::SUCCESS), "",
253 base::TimeTicks()));
251 254
252 net::URLRequestStatus status; 255 net::URLRequestStatus status;
253 status.set_status(net::URLRequestStatus::SUCCESS); 256 status.set_status(net::URLRequestStatus::SUCCESS);
254 filter_peer->OnCompletedRequest(status, "", base::Time()); 257 filter_peer->OnCompletedRequest(status, "", base::TimeTicks());
255 } 258 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_localization_peer.cc ('k') | chrome/renderer/security_filter_peer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698