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

Side by Side Diff: chrome/renderer/safe_browsing/phishing_dom_feature_extractor_browsertest.cc

Issue 7981027: Fix the clock values in PhishingDOMFeatureExtractorTest.Continuation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Note that although this is not a "browser" test, it runs as part of 5 // Note that although this is not a "browser" test, it runs as part of
6 // browser_tests. This is because WebKit does not work properly if it is 6 // browser_tests. This is because WebKit does not work properly if it is
7 // shutdown and re-initialized. Since browser_tests runs each test in a 7 // shutdown and re-initialized. Since browser_tests runs each test in a
8 // new process, this avoids the problem. 8 // new process, this avoids the problem.
9 9
10 #include "chrome/renderer/safe_browsing/phishing_dom_feature_extractor.h" 10 #include "chrome/renderer/safe_browsing/phishing_dom_feature_extractor.h"
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 // Note: the empty HEAD is important -- WebKit will synthesize a HEAD if 248 // Note: the empty HEAD is important -- WebKit will synthesize a HEAD if
249 // there isn't one present, which can be confusing for the element counts. 249 // there isn't one present, which can be confusing for the element counts.
250 std::string response = "<html><head></head><body>" 250 std::string response = "<html><head></head><body>"
251 "<form action=\"ondomain\"></form>"; 251 "<form action=\"ondomain\"></form>";
252 for (int i = 0; i < 45; ++i) { 252 for (int i = 0; i < 45; ++i) {
253 response.append("<p>"); 253 response.append("<p>");
254 } 254 }
255 response.append("<form action=\"http://host2.com/\"></form></body></html>"); 255 response.append("<form action=\"http://host2.com/\"></form></body></html>");
256 responses_["http://host.com/"] = response; 256 responses_["http://host.com/"] = response;
257 257
258 // Advance the clock 8 ms every 10 elements processed, 10 ms between chunks. 258 // Advance the clock 12 ms every 10 elements processed, 10 ms between chunks.
259 // Note that this assumes kClockCheckGranularity = 10 and 259 // Note that this assumes kClockCheckGranularity = 10 and
260 // kMaxTimePerChunkMs = 20. 260 // kMaxTimePerChunkMs = 20.
261 base::TimeTicks now = base::TimeTicks::Now(); 261 base::TimeTicks now = base::TimeTicks::Now();
262 EXPECT_CALL(clock_, Now()) 262 EXPECT_CALL(clock_, Now())
263 // Time check at the start of extraction. 263 // Time check at the start of extraction.
264 .WillOnce(Return(now)) 264 .WillOnce(Return(now))
265 // Time check at the start of the first chunk of work. 265 // Time check at the start of the first chunk of work.
266 .WillOnce(Return(now)) 266 .WillOnce(Return(now))
267 // Time check after the first 10 elements. 267 // Time check after the first 10 elements.
268 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(8))) 268 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(12)))
269 // Time check after the next 10 elements. This is over the chunk 269 // Time check after the next 10 elements. This is over the chunk
270 // time limit, so a continuation task will be posted. 270 // time limit, so a continuation task will be posted.
271 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(16))) 271 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(24)))
272 // Time check at the start of the second chunk of work. 272 // Time check at the start of the second chunk of work.
273 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(26))) 273 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(34)))
274 // Time check after resuming iteration for the second chunk. 274 // Time check after resuming iteration for the second chunk.
275 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(28))) 275 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(36)))
276 // Time check after the next 10 elements. 276 // Time check after the next 10 elements.
277 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(36))) 277 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(48)))
278 // Time check after the next 10 elements. This will trigger another 278 // Time check after the next 10 elements. This will trigger another
279 // continuation task. 279 // continuation task.
280 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(44))) 280 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(60)))
281 // Time check at the start of the third chunk of work. 281 // Time check at the start of the third chunk of work.
282 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(54))) 282 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(70)))
283 // Time check after resuming iteration for the third chunk. 283 // Time check after resuming iteration for the third chunk.
284 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(56))) 284 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(72)))
285 // Time check after the last 10 elements. 285 // Time check after the last 10 elements.
286 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(64))) 286 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(84)))
287 // A final time check for the histograms. 287 // A final time check for the histograms.
288 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(66))); 288 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(86)));
289 289
290 FeatureMap expected_features; 290 FeatureMap expected_features;
291 expected_features.AddBooleanFeature(features::kPageHasForms); 291 expected_features.AddBooleanFeature(features::kPageHasForms);
292 expected_features.AddRealFeature(features::kPageActionOtherDomainFreq, 0.5); 292 expected_features.AddRealFeature(features::kPageActionOtherDomainFreq, 0.5);
293 293
294 FeatureMap features; 294 FeatureMap features;
295 LoadURL("http://host.com/"); 295 LoadURL("http://host.com/");
296 ASSERT_TRUE(ExtractFeatures(&features)); 296 ASSERT_TRUE(ExtractFeatures(&features));
297 EXPECT_THAT(features.features(), ContainerEq(expected_features.features())); 297 EXPECT_THAT(features.features(), ContainerEq(expected_features.features()));
298 // Make sure none of the mock expectations carry over to the next test. 298 // Make sure none of the mock expectations carry over to the next test.
(...skipping 17 matching lines...) Expand all
316 // Time check after the next 10 elements. This is over the limit. 316 // Time check after the next 10 elements. This is over the limit.
317 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(600))) 317 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(600)))
318 // A final time check for the histograms. 318 // A final time check for the histograms.
319 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(620))); 319 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(620)));
320 320
321 features.Clear(); 321 features.Clear();
322 EXPECT_FALSE(ExtractFeatures(&features)); 322 EXPECT_FALSE(ExtractFeatures(&features));
323 } 323 }
324 324
325 } // namespace safe_browsing 325 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698