OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "config.h" | 5 #include "config.h" |
6 #include "platform/Timer.h" | 6 #include "platform/Timer.h" |
7 | 7 |
8 #include "public/platform/Platform.h" | 8 #include "public/platform/Platform.h" |
9 #include "public/platform/WebScheduler.h" | 9 #include "public/platform/WebScheduler.h" |
10 #include "public/platform/WebThread.h" | 10 #include "public/platform/WebThread.h" |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 WTF::Vector<double> m_nextFireTimes; | 348 WTF::Vector<double> m_nextFireTimes; |
349 | 349 |
350 private: | 350 private: |
351 OwnPtr<TimerTestPlatform> m_platform; | 351 OwnPtr<TimerTestPlatform> m_platform; |
352 Platform* m_oldPlatform; | 352 Platform* m_oldPlatform; |
353 }; | 353 }; |
354 | 354 |
355 TEST_F(TimerTest, StartOneShot_Zero) | 355 TEST_F(TimerTest, StartOneShot_Zero) |
356 { | 356 { |
357 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 357 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
358 timer.startOneShot(0, FROM_HERE); | 358 timer.startOneShot(0, BLINK_FROM_HERE); |
359 | 359 |
360 ASSERT(hasOneTimerTask()); | 360 ASSERT(hasOneTimerTask()); |
361 EXPECT_FLOAT_EQ(0.0, nextTimerTaskDelaySecs()); | 361 EXPECT_FLOAT_EQ(0.0, nextTimerTaskDelaySecs()); |
362 | 362 |
363 runUntilIdle(); | 363 runUntilIdle(); |
364 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime)); | 364 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime)); |
365 } | 365 } |
366 | 366 |
367 TEST_F(TimerTest, StartOneShot_ZeroAndCancel) | 367 TEST_F(TimerTest, StartOneShot_ZeroAndCancel) |
368 { | 368 { |
369 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 369 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
370 timer.startOneShot(0, FROM_HERE); | 370 timer.startOneShot(0, BLINK_FROM_HERE); |
371 | 371 |
372 ASSERT(hasOneTimerTask()); | 372 ASSERT(hasOneTimerTask()); |
373 EXPECT_FLOAT_EQ(0.0, nextTimerTaskDelaySecs()); | 373 EXPECT_FLOAT_EQ(0.0, nextTimerTaskDelaySecs()); |
374 | 374 |
375 timer.stop(); | 375 timer.stop(); |
376 | 376 |
377 runUntilIdle(); | 377 runUntilIdle(); |
378 EXPECT_FALSE(m_runTimes.size()); | 378 EXPECT_FALSE(m_runTimes.size()); |
379 } | 379 } |
380 | 380 |
381 TEST_F(TimerTest, StartOneShot_ZeroAndCancelThenRepost) | 381 TEST_F(TimerTest, StartOneShot_ZeroAndCancelThenRepost) |
382 { | 382 { |
383 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 383 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
384 timer.startOneShot(0, FROM_HERE); | 384 timer.startOneShot(0, BLINK_FROM_HERE); |
385 | 385 |
386 ASSERT(hasOneTimerTask()); | 386 ASSERT(hasOneTimerTask()); |
387 EXPECT_FLOAT_EQ(0.0, nextTimerTaskDelaySecs()); | 387 EXPECT_FLOAT_EQ(0.0, nextTimerTaskDelaySecs()); |
388 | 388 |
389 timer.stop(); | 389 timer.stop(); |
390 | 390 |
391 runUntilIdle(); | 391 runUntilIdle(); |
392 EXPECT_FALSE(m_runTimes.size()); | 392 EXPECT_FALSE(m_runTimes.size()); |
393 | 393 |
394 timer.startOneShot(0, FROM_HERE); | 394 timer.startOneShot(0, BLINK_FROM_HERE); |
395 | 395 |
396 ASSERT(hasOneTimerTask()); | 396 ASSERT(hasOneTimerTask()); |
397 EXPECT_FLOAT_EQ(0.0, nextTimerTaskDelaySecs()); | 397 EXPECT_FLOAT_EQ(0.0, nextTimerTaskDelaySecs()); |
398 | 398 |
399 runUntilIdle(); | 399 runUntilIdle(); |
400 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime)); | 400 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime)); |
401 } | 401 } |
402 | 402 |
403 TEST_F(TimerTest, StartOneShot_Zero_RepostingAfterRunning) | 403 TEST_F(TimerTest, StartOneShot_Zero_RepostingAfterRunning) |
404 { | 404 { |
405 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 405 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
406 timer.startOneShot(0, FROM_HERE); | 406 timer.startOneShot(0, BLINK_FROM_HERE); |
407 | 407 |
408 ASSERT(hasOneTimerTask()); | 408 ASSERT(hasOneTimerTask()); |
409 EXPECT_FLOAT_EQ(0.0, nextTimerTaskDelaySecs()); | 409 EXPECT_FLOAT_EQ(0.0, nextTimerTaskDelaySecs()); |
410 | 410 |
411 runUntilIdle(); | 411 runUntilIdle(); |
412 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime)); | 412 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime)); |
413 | 413 |
414 timer.startOneShot(0, FROM_HERE); | 414 timer.startOneShot(0, BLINK_FROM_HERE); |
415 | 415 |
416 ASSERT(hasOneTimerTask()); | 416 ASSERT(hasOneTimerTask()); |
417 EXPECT_FLOAT_EQ(0.0, nextTimerTaskDelaySecs()); | 417 EXPECT_FLOAT_EQ(0.0, nextTimerTaskDelaySecs()); |
418 | 418 |
419 runUntilIdle(); | 419 runUntilIdle(); |
420 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime, m_startTime)); | 420 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime, m_startTime)); |
421 } | 421 } |
422 | 422 |
423 TEST_F(TimerTest, StartOneShot_NonZero) | 423 TEST_F(TimerTest, StartOneShot_NonZero) |
424 { | 424 { |
425 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 425 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
426 timer.startOneShot(10.0, FROM_HERE); | 426 timer.startOneShot(10.0, BLINK_FROM_HERE); |
427 | 427 |
428 ASSERT(hasOneTimerTask()); | 428 ASSERT(hasOneTimerTask()); |
429 EXPECT_FLOAT_EQ(10.0, nextTimerTaskDelaySecs()); | 429 EXPECT_FLOAT_EQ(10.0, nextTimerTaskDelaySecs()); |
430 | 430 |
431 runUntilIdle(); | 431 runUntilIdle(); |
432 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 10.0)); | 432 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 10.0)); |
433 } | 433 } |
434 | 434 |
435 TEST_F(TimerTest, StartOneShot_NonZeroAndCancel) | 435 TEST_F(TimerTest, StartOneShot_NonZeroAndCancel) |
436 { | 436 { |
437 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 437 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
438 timer.startOneShot(10, FROM_HERE); | 438 timer.startOneShot(10, BLINK_FROM_HERE); |
439 | 439 |
440 ASSERT(hasOneTimerTask()); | 440 ASSERT(hasOneTimerTask()); |
441 EXPECT_FLOAT_EQ(10.0, nextTimerTaskDelaySecs()); | 441 EXPECT_FLOAT_EQ(10.0, nextTimerTaskDelaySecs()); |
442 | 442 |
443 timer.stop(); | 443 timer.stop(); |
444 | 444 |
445 runUntilIdle(); | 445 runUntilIdle(); |
446 EXPECT_FALSE(m_runTimes.size()); | 446 EXPECT_FALSE(m_runTimes.size()); |
447 } | 447 } |
448 | 448 |
449 TEST_F(TimerTest, StartOneShot_NonZeroAndCancelThenRepost) | 449 TEST_F(TimerTest, StartOneShot_NonZeroAndCancelThenRepost) |
450 { | 450 { |
451 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 451 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
452 timer.startOneShot(10, FROM_HERE); | 452 timer.startOneShot(10, BLINK_FROM_HERE); |
453 | 453 |
454 ASSERT(hasOneTimerTask()); | 454 ASSERT(hasOneTimerTask()); |
455 EXPECT_FLOAT_EQ(10.0, nextTimerTaskDelaySecs()); | 455 EXPECT_FLOAT_EQ(10.0, nextTimerTaskDelaySecs()); |
456 | 456 |
457 timer.stop(); | 457 timer.stop(); |
458 | 458 |
459 runUntilIdle(); | 459 runUntilIdle(); |
460 EXPECT_FALSE(m_runTimes.size()); | 460 EXPECT_FALSE(m_runTimes.size()); |
461 | 461 |
462 double secondPostTime = monotonicallyIncreasingTime(); | 462 double secondPostTime = monotonicallyIncreasingTime(); |
463 timer.startOneShot(10, FROM_HERE); | 463 timer.startOneShot(10, BLINK_FROM_HERE); |
464 | 464 |
465 ASSERT(hasOneTimerTask()); | 465 ASSERT(hasOneTimerTask()); |
466 EXPECT_FLOAT_EQ(10.0, nextTimerTaskDelaySecs()); | 466 EXPECT_FLOAT_EQ(10.0, nextTimerTaskDelaySecs()); |
467 | 467 |
468 runUntilIdle(); | 468 runUntilIdle(); |
469 EXPECT_THAT(m_runTimes, ElementsAre(secondPostTime + 10.0)); | 469 EXPECT_THAT(m_runTimes, ElementsAre(secondPostTime + 10.0)); |
470 } | 470 } |
471 | 471 |
472 TEST_F(TimerTest, StartOneShot_NonZero_RepostingAfterRunning) | 472 TEST_F(TimerTest, StartOneShot_NonZero_RepostingAfterRunning) |
473 { | 473 { |
474 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 474 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
475 timer.startOneShot(10, FROM_HERE); | 475 timer.startOneShot(10, BLINK_FROM_HERE); |
476 | 476 |
477 ASSERT(hasOneTimerTask()); | 477 ASSERT(hasOneTimerTask()); |
478 EXPECT_FLOAT_EQ(10.0, nextTimerTaskDelaySecs()); | 478 EXPECT_FLOAT_EQ(10.0, nextTimerTaskDelaySecs()); |
479 | 479 |
480 runUntilIdle(); | 480 runUntilIdle(); |
481 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 10.0)); | 481 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 10.0)); |
482 | 482 |
483 timer.startOneShot(20, FROM_HERE); | 483 timer.startOneShot(20, BLINK_FROM_HERE); |
484 | 484 |
485 ASSERT(hasOneTimerTask()); | 485 ASSERT(hasOneTimerTask()); |
486 EXPECT_FLOAT_EQ(20.0, nextTimerTaskDelaySecs()); | 486 EXPECT_FLOAT_EQ(20.0, nextTimerTaskDelaySecs()); |
487 | 487 |
488 runUntilIdle(); | 488 runUntilIdle(); |
489 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 10.0, m_startTime + 30.0))
; | 489 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 10.0, m_startTime + 30.0))
; |
490 } | 490 } |
491 | 491 |
492 TEST_F(TimerTest, PostingTimerTwiceWithSameRunTimeDoesNothing) | 492 TEST_F(TimerTest, PostingTimerTwiceWithSameRunTimeDoesNothing) |
493 { | 493 { |
494 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 494 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
495 timer.startOneShot(10, FROM_HERE); | 495 timer.startOneShot(10, BLINK_FROM_HERE); |
496 timer.startOneShot(10, FROM_HERE); | 496 timer.startOneShot(10, BLINK_FROM_HERE); |
497 | 497 |
498 ASSERT(hasOneTimerTask()); | 498 ASSERT(hasOneTimerTask()); |
499 EXPECT_FLOAT_EQ(10.0, nextTimerTaskDelaySecs()); | 499 EXPECT_FLOAT_EQ(10.0, nextTimerTaskDelaySecs()); |
500 | 500 |
501 runUntilIdle(); | 501 runUntilIdle(); |
502 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 10.0)); | 502 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 10.0)); |
503 } | 503 } |
504 | 504 |
505 TEST_F(TimerTest, PostingTimerTwiceWithNewerRunTimeCancelsOriginalTask) | 505 TEST_F(TimerTest, PostingTimerTwiceWithNewerRunTimeCancelsOriginalTask) |
506 { | 506 { |
507 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 507 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
508 timer.startOneShot(10, FROM_HERE); | 508 timer.startOneShot(10, BLINK_FROM_HERE); |
509 timer.startOneShot(0, FROM_HERE); | 509 timer.startOneShot(0, BLINK_FROM_HERE); |
510 | 510 |
511 runUntilIdle(); | 511 runUntilIdle(); |
512 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 0.0)); | 512 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 0.0)); |
513 } | 513 } |
514 | 514 |
515 TEST_F(TimerTest, PostingTimerTwiceWithLaterRunTimeCancelsOriginalTask) | 515 TEST_F(TimerTest, PostingTimerTwiceWithLaterRunTimeCancelsOriginalTask) |
516 { | 516 { |
517 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 517 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
518 timer.startOneShot(0, FROM_HERE); | 518 timer.startOneShot(0, BLINK_FROM_HERE); |
519 timer.startOneShot(10, FROM_HERE); | 519 timer.startOneShot(10, BLINK_FROM_HERE); |
520 | 520 |
521 runUntilIdle(); | 521 runUntilIdle(); |
522 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 10.0)); | 522 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 10.0)); |
523 } | 523 } |
524 | 524 |
525 TEST_F(TimerTest, StartRepeatingTask) | 525 TEST_F(TimerTest, StartRepeatingTask) |
526 { | 526 { |
527 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 527 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
528 timer.startRepeating(1.0, FROM_HERE); | 528 timer.startRepeating(1.0, BLINK_FROM_HERE); |
529 | 529 |
530 ASSERT(hasOneTimerTask()); | 530 ASSERT(hasOneTimerTask()); |
531 EXPECT_FLOAT_EQ(1.0, nextTimerTaskDelaySecs()); | 531 EXPECT_FLOAT_EQ(1.0, nextTimerTaskDelaySecs()); |
532 | 532 |
533 runUntilIdleOrDeadlinePassed(m_startTime + 5.5); | 533 runUntilIdleOrDeadlinePassed(m_startTime + 5.5); |
534 EXPECT_THAT(m_runTimes, ElementsAre( | 534 EXPECT_THAT(m_runTimes, ElementsAre( |
535 m_startTime + 1.0, m_startTime + 2.0, m_startTime + 3.0, m_startTime + 4
.0, m_startTime + 5.0)); | 535 m_startTime + 1.0, m_startTime + 2.0, m_startTime + 3.0, m_startTime + 4
.0, m_startTime + 5.0)); |
536 } | 536 } |
537 | 537 |
538 TEST_F(TimerTest, StartRepeatingTask_ThenCancel) | 538 TEST_F(TimerTest, StartRepeatingTask_ThenCancel) |
539 { | 539 { |
540 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 540 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
541 timer.startRepeating(1.0, FROM_HERE); | 541 timer.startRepeating(1.0, BLINK_FROM_HERE); |
542 | 542 |
543 ASSERT(hasOneTimerTask()); | 543 ASSERT(hasOneTimerTask()); |
544 EXPECT_FLOAT_EQ(1.0, nextTimerTaskDelaySecs()); | 544 EXPECT_FLOAT_EQ(1.0, nextTimerTaskDelaySecs()); |
545 | 545 |
546 runUntilIdleOrDeadlinePassed(m_startTime + 2.5); | 546 runUntilIdleOrDeadlinePassed(m_startTime + 2.5); |
547 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 1.0, m_startTime + 2.0)); | 547 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 1.0, m_startTime + 2.0)); |
548 | 548 |
549 timer.stop(); | 549 timer.stop(); |
550 runUntilIdle(); | 550 runUntilIdle(); |
551 | 551 |
552 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 1.0, m_startTime + 2.0)); | 552 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 1.0, m_startTime + 2.0)); |
553 } | 553 } |
554 | 554 |
555 TEST_F(TimerTest, StartRepeatingTask_ThenPostOneShot) | 555 TEST_F(TimerTest, StartRepeatingTask_ThenPostOneShot) |
556 { | 556 { |
557 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 557 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
558 timer.startRepeating(1.0, FROM_HERE); | 558 timer.startRepeating(1.0, BLINK_FROM_HERE); |
559 | 559 |
560 ASSERT(hasOneTimerTask()); | 560 ASSERT(hasOneTimerTask()); |
561 EXPECT_FLOAT_EQ(1.0, nextTimerTaskDelaySecs()); | 561 EXPECT_FLOAT_EQ(1.0, nextTimerTaskDelaySecs()); |
562 | 562 |
563 runUntilIdleOrDeadlinePassed(m_startTime + 2.5); | 563 runUntilIdleOrDeadlinePassed(m_startTime + 2.5); |
564 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 1.0, m_startTime + 2.0)); | 564 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 1.0, m_startTime + 2.0)); |
565 | 565 |
566 timer.startOneShot(0, FROM_HERE); | 566 timer.startOneShot(0, BLINK_FROM_HERE); |
567 runUntilIdle(); | 567 runUntilIdle(); |
568 | 568 |
569 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 1.0, m_startTime + 2.0, m_
startTime + 2.5)); | 569 EXPECT_THAT(m_runTimes, ElementsAre(m_startTime + 1.0, m_startTime + 2.0, m_
startTime + 2.5)); |
570 } | 570 } |
571 | 571 |
572 TEST_F(TimerTest, IsActive_NeverPosted) | 572 TEST_F(TimerTest, IsActive_NeverPosted) |
573 { | 573 { |
574 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 574 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
575 | 575 |
576 EXPECT_FALSE(timer.isActive()); | 576 EXPECT_FALSE(timer.isActive()); |
577 } | 577 } |
578 | 578 |
579 TEST_F(TimerTest, IsActive_AfterPosting_OneShotZero) | 579 TEST_F(TimerTest, IsActive_AfterPosting_OneShotZero) |
580 { | 580 { |
581 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 581 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
582 timer.startOneShot(0, FROM_HERE); | 582 timer.startOneShot(0, BLINK_FROM_HERE); |
583 | 583 |
584 EXPECT_TRUE(timer.isActive()); | 584 EXPECT_TRUE(timer.isActive()); |
585 } | 585 } |
586 | 586 |
587 TEST_F(TimerTest, IsActive_AfterPosting_OneShotNonZero) | 587 TEST_F(TimerTest, IsActive_AfterPosting_OneShotNonZero) |
588 { | 588 { |
589 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 589 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
590 timer.startOneShot(10, FROM_HERE); | 590 timer.startOneShot(10, BLINK_FROM_HERE); |
591 | 591 |
592 EXPECT_TRUE(timer.isActive()); | 592 EXPECT_TRUE(timer.isActive()); |
593 } | 593 } |
594 | 594 |
595 TEST_F(TimerTest, IsActive_AfterPosting_Repeating) | 595 TEST_F(TimerTest, IsActive_AfterPosting_Repeating) |
596 { | 596 { |
597 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 597 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
598 timer.startRepeating(1.0, FROM_HERE); | 598 timer.startRepeating(1.0, BLINK_FROM_HERE); |
599 | 599 |
600 EXPECT_TRUE(timer.isActive()); | 600 EXPECT_TRUE(timer.isActive()); |
601 } | 601 } |
602 | 602 |
603 TEST_F(TimerTest, IsActive_AfterRunning_OneShotZero) | 603 TEST_F(TimerTest, IsActive_AfterRunning_OneShotZero) |
604 { | 604 { |
605 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 605 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
606 timer.startOneShot(0, FROM_HERE); | 606 timer.startOneShot(0, BLINK_FROM_HERE); |
607 | 607 |
608 runUntilIdle(); | 608 runUntilIdle(); |
609 EXPECT_FALSE(timer.isActive()); | 609 EXPECT_FALSE(timer.isActive()); |
610 } | 610 } |
611 | 611 |
612 TEST_F(TimerTest, IsActive_AfterRunning_OneShotNonZero) | 612 TEST_F(TimerTest, IsActive_AfterRunning_OneShotNonZero) |
613 { | 613 { |
614 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 614 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
615 timer.startOneShot(10, FROM_HERE); | 615 timer.startOneShot(10, BLINK_FROM_HERE); |
616 | 616 |
617 runUntilIdle(); | 617 runUntilIdle(); |
618 EXPECT_FALSE(timer.isActive()); | 618 EXPECT_FALSE(timer.isActive()); |
619 } | 619 } |
620 | 620 |
621 TEST_F(TimerTest, IsActive_AfterRunning_Repeating) | 621 TEST_F(TimerTest, IsActive_AfterRunning_Repeating) |
622 { | 622 { |
623 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 623 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
624 timer.startRepeating(1.0, FROM_HERE); | 624 timer.startRepeating(1.0, BLINK_FROM_HERE); |
625 | 625 |
626 runUntilIdleOrDeadlinePassed(m_startTime + 10); | 626 runUntilIdleOrDeadlinePassed(m_startTime + 10); |
627 EXPECT_TRUE(timer.isActive()); // It should run until cancelled. | 627 EXPECT_TRUE(timer.isActive()); // It should run until cancelled. |
628 } | 628 } |
629 | 629 |
630 TEST_F(TimerTest, NextFireInterval_OneShotZero) | 630 TEST_F(TimerTest, NextFireInterval_OneShotZero) |
631 { | 631 { |
632 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 632 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
633 timer.startOneShot(0, FROM_HERE); | 633 timer.startOneShot(0, BLINK_FROM_HERE); |
634 | 634 |
635 EXPECT_FLOAT_EQ(0.0, timer.nextFireInterval()); | 635 EXPECT_FLOAT_EQ(0.0, timer.nextFireInterval()); |
636 } | 636 } |
637 | 637 |
638 TEST_F(TimerTest, NextFireInterval_OneShotNonZero) | 638 TEST_F(TimerTest, NextFireInterval_OneShotNonZero) |
639 { | 639 { |
640 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 640 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
641 timer.startOneShot(10, FROM_HERE); | 641 timer.startOneShot(10, BLINK_FROM_HERE); |
642 | 642 |
643 EXPECT_FLOAT_EQ(10.0, timer.nextFireInterval()); | 643 EXPECT_FLOAT_EQ(10.0, timer.nextFireInterval()); |
644 } | 644 } |
645 | 645 |
646 TEST_F(TimerTest, NextFireInterval_OneShotNonZero_AfterAFewSeconds) | 646 TEST_F(TimerTest, NextFireInterval_OneShotNonZero_AfterAFewSeconds) |
647 { | 647 { |
648 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 648 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
649 timer.startOneShot(10, FROM_HERE); | 649 timer.startOneShot(10, BLINK_FROM_HERE); |
650 | 650 |
651 advanceTimeBy(2.0); | 651 advanceTimeBy(2.0); |
652 EXPECT_FLOAT_EQ(8.0, timer.nextFireInterval()); | 652 EXPECT_FLOAT_EQ(8.0, timer.nextFireInterval()); |
653 } | 653 } |
654 | 654 |
655 TEST_F(TimerTest, NextFireInterval_Repeating) | 655 TEST_F(TimerTest, NextFireInterval_Repeating) |
656 { | 656 { |
657 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 657 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
658 timer.startRepeating(20, FROM_HERE); | 658 timer.startRepeating(20, BLINK_FROM_HERE); |
659 | 659 |
660 EXPECT_FLOAT_EQ(20.0, timer.nextFireInterval()); | 660 EXPECT_FLOAT_EQ(20.0, timer.nextFireInterval()); |
661 } | 661 } |
662 | 662 |
663 TEST_F(TimerTest, RepeatInterval_NeverStarted) | 663 TEST_F(TimerTest, RepeatInterval_NeverStarted) |
664 { | 664 { |
665 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 665 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
666 | 666 |
667 EXPECT_FLOAT_EQ(0.0, timer.repeatInterval()); | 667 EXPECT_FLOAT_EQ(0.0, timer.repeatInterval()); |
668 } | 668 } |
669 | 669 |
670 TEST_F(TimerTest, RepeatInterval_OneShotZero) | 670 TEST_F(TimerTest, RepeatInterval_OneShotZero) |
671 { | 671 { |
672 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 672 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
673 timer.startOneShot(0, FROM_HERE); | 673 timer.startOneShot(0, BLINK_FROM_HERE); |
674 | 674 |
675 EXPECT_FLOAT_EQ(0.0, timer.repeatInterval()); | 675 EXPECT_FLOAT_EQ(0.0, timer.repeatInterval()); |
676 } | 676 } |
677 | 677 |
678 TEST_F(TimerTest, RepeatInterval_OneShotNonZero) | 678 TEST_F(TimerTest, RepeatInterval_OneShotNonZero) |
679 { | 679 { |
680 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 680 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
681 timer.startOneShot(10, FROM_HERE); | 681 timer.startOneShot(10, BLINK_FROM_HERE); |
682 | 682 |
683 EXPECT_FLOAT_EQ(0.0, timer.repeatInterval()); | 683 EXPECT_FLOAT_EQ(0.0, timer.repeatInterval()); |
684 } | 684 } |
685 | 685 |
686 TEST_F(TimerTest, RepeatInterval_Repeating) | 686 TEST_F(TimerTest, RepeatInterval_Repeating) |
687 { | 687 { |
688 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 688 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
689 timer.startRepeating(20, FROM_HERE); | 689 timer.startRepeating(20, BLINK_FROM_HERE); |
690 | 690 |
691 EXPECT_FLOAT_EQ(20.0, timer.repeatInterval()); | 691 EXPECT_FLOAT_EQ(20.0, timer.repeatInterval()); |
692 } | 692 } |
693 | 693 |
694 TEST_F(TimerTest, AugmentRepeatInterval) | 694 TEST_F(TimerTest, AugmentRepeatInterval) |
695 { | 695 { |
696 Timer<TimerTest> timer(this, &TimerTest::countingTask); | 696 Timer<TimerTest> timer(this, &TimerTest::countingTask); |
697 timer.startRepeating(10, FROM_HERE); | 697 timer.startRepeating(10, BLINK_FROM_HERE); |
698 EXPECT_FLOAT_EQ(10.0, timer.repeatInterval()); | 698 EXPECT_FLOAT_EQ(10.0, timer.repeatInterval()); |
699 EXPECT_FLOAT_EQ(10.0, timer.nextFireInterval()); | 699 EXPECT_FLOAT_EQ(10.0, timer.nextFireInterval()); |
700 | 700 |
701 advanceTimeBy(2.0); | 701 advanceTimeBy(2.0); |
702 timer.augmentRepeatInterval(10); | 702 timer.augmentRepeatInterval(10); |
703 | 703 |
704 EXPECT_FLOAT_EQ(20.0, timer.repeatInterval()); | 704 EXPECT_FLOAT_EQ(20.0, timer.repeatInterval()); |
705 EXPECT_FLOAT_EQ(18.0, timer.nextFireInterval()); | 705 EXPECT_FLOAT_EQ(18.0, timer.nextFireInterval()); |
706 | 706 |
707 runUntilIdleOrDeadlinePassed(m_startTime + 50.0); | 707 runUntilIdleOrDeadlinePassed(m_startTime + 50.0); |
(...skipping 27 matching lines...) Expand all Loading... |
735 private: | 735 private: |
736 mutable double m_lastFireTime; | 736 mutable double m_lastFireTime; |
737 double m_alignedFireTime; | 737 double m_alignedFireTime; |
738 }; | 738 }; |
739 | 739 |
740 TEST_F(TimerTest, TimerAlignment_OneShotZero) | 740 TEST_F(TimerTest, TimerAlignment_OneShotZero) |
741 { | 741 { |
742 MockTimerWithAlignment timer; | 742 MockTimerWithAlignment timer; |
743 timer.setAlignedFireTime(m_startTime + 1.0); | 743 timer.setAlignedFireTime(m_startTime + 1.0); |
744 | 744 |
745 timer.start(0.0, 0.0, FROM_HERE); | 745 timer.start(0.0, 0.0, BLINK_FROM_HERE); |
746 | 746 |
747 // The nextFireInterval gets overrriden. | 747 // The nextFireInterval gets overrriden. |
748 EXPECT_FLOAT_EQ(1.0, timer.nextFireInterval()); | 748 EXPECT_FLOAT_EQ(1.0, timer.nextFireInterval()); |
749 EXPECT_FLOAT_EQ(0.0, timer.nextUnalignedFireInterval()); | 749 EXPECT_FLOAT_EQ(0.0, timer.nextUnalignedFireInterval()); |
750 EXPECT_FLOAT_EQ(m_startTime, timer.lastFireTime()); | 750 EXPECT_FLOAT_EQ(m_startTime, timer.lastFireTime()); |
751 } | 751 } |
752 | 752 |
753 TEST_F(TimerTest, TimerAlignment_OneShotNonZero) | 753 TEST_F(TimerTest, TimerAlignment_OneShotNonZero) |
754 { | 754 { |
755 MockTimerWithAlignment timer; | 755 MockTimerWithAlignment timer; |
756 timer.setAlignedFireTime(m_startTime + 1.0); | 756 timer.setAlignedFireTime(m_startTime + 1.0); |
757 | 757 |
758 timer.start(0.5, 0.0, FROM_HERE); | 758 timer.start(0.5, 0.0, BLINK_FROM_HERE); |
759 | 759 |
760 // The nextFireInterval gets overrriden. | 760 // The nextFireInterval gets overrriden. |
761 EXPECT_FLOAT_EQ(1.0, timer.nextFireInterval()); | 761 EXPECT_FLOAT_EQ(1.0, timer.nextFireInterval()); |
762 EXPECT_FLOAT_EQ(0.5, timer.nextUnalignedFireInterval()); | 762 EXPECT_FLOAT_EQ(0.5, timer.nextUnalignedFireInterval()); |
763 EXPECT_FLOAT_EQ(m_startTime + 0.5, timer.lastFireTime()); | 763 EXPECT_FLOAT_EQ(m_startTime + 0.5, timer.lastFireTime()); |
764 } | 764 } |
765 | 765 |
766 TEST_F(TimerTest, DidChangeAlignmentInterval) | 766 TEST_F(TimerTest, DidChangeAlignmentInterval) |
767 { | 767 { |
768 MockTimerWithAlignment timer; | 768 MockTimerWithAlignment timer; |
769 timer.setAlignedFireTime(m_startTime + 1.0); | 769 timer.setAlignedFireTime(m_startTime + 1.0); |
770 | 770 |
771 timer.start(0.0, 0.0, FROM_HERE); | 771 timer.start(0.0, 0.0, BLINK_FROM_HERE); |
772 | 772 |
773 EXPECT_FLOAT_EQ(1.0, timer.nextFireInterval()); | 773 EXPECT_FLOAT_EQ(1.0, timer.nextFireInterval()); |
774 EXPECT_FLOAT_EQ(0.0, timer.nextUnalignedFireInterval()); | 774 EXPECT_FLOAT_EQ(0.0, timer.nextUnalignedFireInterval()); |
775 EXPECT_FLOAT_EQ(m_startTime, timer.lastFireTime()); | 775 EXPECT_FLOAT_EQ(m_startTime, timer.lastFireTime()); |
776 | 776 |
777 timer.setAlignedFireTime(m_startTime); | 777 timer.setAlignedFireTime(m_startTime); |
778 timer.didChangeAlignmentInterval(monotonicallyIncreasingTime()); | 778 timer.didChangeAlignmentInterval(monotonicallyIncreasingTime()); |
779 | 779 |
780 EXPECT_FLOAT_EQ(0.0, timer.nextFireInterval()); | 780 EXPECT_FLOAT_EQ(0.0, timer.nextFireInterval()); |
781 EXPECT_FLOAT_EQ(0.0, timer.nextUnalignedFireInterval()); | 781 EXPECT_FLOAT_EQ(0.0, timer.nextUnalignedFireInterval()); |
782 EXPECT_FLOAT_EQ(m_startTime, timer.lastFireTime()); | 782 EXPECT_FLOAT_EQ(m_startTime, timer.lastFireTime()); |
783 } | 783 } |
784 | 784 |
785 TEST_F(TimerTest, RepeatingTimerDoesNotDrift) | 785 TEST_F(TimerTest, RepeatingTimerDoesNotDrift) |
786 { | 786 { |
787 Timer<TimerTest> timer(this, &TimerTest::recordNextFireTimeTask); | 787 Timer<TimerTest> timer(this, &TimerTest::recordNextFireTimeTask); |
788 timer.startRepeating(2.0, FROM_HERE); | 788 timer.startRepeating(2.0, BLINK_FROM_HERE); |
789 | 789 |
790 ASSERT(hasOneTimerTask()); | 790 ASSERT(hasOneTimerTask()); |
791 recordNextFireTimeTask(&timer); // Next scheduled task to run at m_startTime
+ 2.0 | 791 recordNextFireTimeTask(&timer); // Next scheduled task to run at m_startTime
+ 2.0 |
792 | 792 |
793 // Simulate timer firing early. Next scheduled task to run at m_startTime +
4.0 | 793 // Simulate timer firing early. Next scheduled task to run at m_startTime +
4.0 |
794 advanceTimeBy(1.9); | 794 advanceTimeBy(1.9); |
795 runUntilIdleOrDeadlinePassed(gCurrentTimeSecs + 0.2); | 795 runUntilIdleOrDeadlinePassed(gCurrentTimeSecs + 0.2); |
796 | 796 |
797 advanceTimeBy(2.0); | 797 advanceTimeBy(2.0); |
798 runPendingTasks(); // Next scheduled task to run at m_startTime + 6.0 | 798 runPendingTasks(); // Next scheduled task to run at m_startTime + 6.0 |
(...skipping 20 matching lines...) Expand all Loading... |
819 m_startTime + 6.0, | 819 m_startTime + 6.0, |
820 m_startTime + 8.0, | 820 m_startTime + 8.0, |
821 m_startTime + 10.0, | 821 m_startTime + 10.0, |
822 m_startTime + 14.0, | 822 m_startTime + 14.0, |
823 m_startTime + 18.0, | 823 m_startTime + 18.0, |
824 m_startTime + 28.0)); | 824 m_startTime + 28.0)); |
825 } | 825 } |
826 | 826 |
827 } // namespace | 827 } // namespace |
828 } // namespace blink | 828 } // namespace blink |
OLD | NEW |