OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/metrics/metrics_service.h" | 5 #include "components/metrics/metrics_service.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 } | 484 } |
485 | 485 |
486 TEST_F(MetricsServiceTest, SplitRotation) { | 486 TEST_F(MetricsServiceTest, SplitRotation) { |
487 TestMetricsServiceClient client; | 487 TestMetricsServiceClient client; |
488 TestMetricsService service(GetMetricsStateManager(), &client, | 488 TestMetricsService service(GetMetricsStateManager(), &client, |
489 GetLocalState()); | 489 GetLocalState()); |
490 service.InitializeMetricsRecordingState(); | 490 service.InitializeMetricsRecordingState(); |
491 service.Start(); | 491 service.Start(); |
492 // Rotation loop should create a log and mark state as idle. | 492 // Rotation loop should create a log and mark state as idle. |
493 // Upload loop should start upload or be restarted. | 493 // Upload loop should start upload or be restarted. |
| 494 // The independent-metrics upload job will be started and always be a task. |
494 task_runner_->RunPendingTasks(); | 495 task_runner_->RunPendingTasks(); |
495 // Rotation loop should terminated due to being idle. | 496 // Rotation loop should terminated due to being idle. |
496 // Upload loop should start uploading if it isn't already. | 497 // Upload loop should start uploading if it isn't already. |
497 task_runner_->RunPendingTasks(); | 498 task_runner_->RunPendingTasks(); |
498 EXPECT_TRUE(client.uploader()->is_uploading()); | 499 EXPECT_TRUE(client.uploader()->is_uploading()); |
499 EXPECT_EQ(0U, task_runner_->NumPendingTasks()); | 500 EXPECT_EQ(1U, task_runner_->NumPendingTasks()); |
500 service.OnApplicationNotIdle(); | 501 service.OnApplicationNotIdle(); |
501 EXPECT_TRUE(client.uploader()->is_uploading()); | 502 EXPECT_TRUE(client.uploader()->is_uploading()); |
502 EXPECT_EQ(1U, task_runner_->NumPendingTasks()); | 503 EXPECT_EQ(2U, task_runner_->NumPendingTasks()); |
503 // Log generation should be suppressed due to unsent log. | 504 // Log generation should be suppressed due to unsent log. |
504 // Idle state should not be reset. | 505 // Idle state should not be reset. |
505 task_runner_->RunPendingTasks(); | 506 task_runner_->RunPendingTasks(); |
506 EXPECT_TRUE(client.uploader()->is_uploading()); | 507 EXPECT_TRUE(client.uploader()->is_uploading()); |
507 EXPECT_EQ(1U, task_runner_->NumPendingTasks()); | 508 EXPECT_EQ(2U, task_runner_->NumPendingTasks()); |
508 // Make sure idle state was not reset. | 509 // Make sure idle state was not reset. |
509 task_runner_->RunPendingTasks(); | 510 task_runner_->RunPendingTasks(); |
510 EXPECT_TRUE(client.uploader()->is_uploading()); | 511 EXPECT_TRUE(client.uploader()->is_uploading()); |
511 EXPECT_EQ(1U, task_runner_->NumPendingTasks()); | 512 EXPECT_EQ(2U, task_runner_->NumPendingTasks()); |
512 // Upload should not be rescheduled, since there are no other logs. | 513 // Upload should not be rescheduled, since there are no other logs. |
513 client.uploader()->CompleteUpload(200); | 514 client.uploader()->CompleteUpload(200); |
514 EXPECT_FALSE(client.uploader()->is_uploading()); | 515 EXPECT_FALSE(client.uploader()->is_uploading()); |
515 EXPECT_EQ(1U, task_runner_->NumPendingTasks()); | 516 EXPECT_EQ(2U, task_runner_->NumPendingTasks()); |
516 // Running should generate a log, restart upload loop, and mark idle. | 517 // Running should generate a log, restart upload loop, and mark idle. |
517 task_runner_->RunPendingTasks(); | 518 task_runner_->RunPendingTasks(); |
518 EXPECT_FALSE(client.uploader()->is_uploading()); | 519 EXPECT_FALSE(client.uploader()->is_uploading()); |
519 EXPECT_EQ(2U, task_runner_->NumPendingTasks()); | 520 EXPECT_EQ(3U, task_runner_->NumPendingTasks()); |
520 // Upload should start, and rotation loop should idle out. | 521 // Upload should start, and rotation loop should idle out. |
521 task_runner_->RunPendingTasks(); | 522 task_runner_->RunPendingTasks(); |
522 EXPECT_TRUE(client.uploader()->is_uploading()); | 523 EXPECT_TRUE(client.uploader()->is_uploading()); |
523 EXPECT_EQ(0U, task_runner_->NumPendingTasks()); | 524 EXPECT_EQ(1U, task_runner_->NumPendingTasks()); |
524 // Uploader should reschedule when there is another log available. | 525 // Uploader should reschedule when there is another log available. |
525 service.PushExternalLog("Blah"); | 526 service.PushExternalLog("Blah"); |
526 client.uploader()->CompleteUpload(200); | 527 client.uploader()->CompleteUpload(200); |
527 EXPECT_FALSE(client.uploader()->is_uploading()); | 528 EXPECT_FALSE(client.uploader()->is_uploading()); |
528 EXPECT_EQ(1U, task_runner_->NumPendingTasks()); | 529 EXPECT_EQ(2U, task_runner_->NumPendingTasks()); |
529 // Upload should start. | 530 // Upload should start. |
530 task_runner_->RunPendingTasks(); | 531 task_runner_->RunPendingTasks(); |
531 EXPECT_TRUE(client.uploader()->is_uploading()); | 532 EXPECT_TRUE(client.uploader()->is_uploading()); |
532 EXPECT_EQ(0U, task_runner_->NumPendingTasks()); | 533 EXPECT_EQ(1U, task_runner_->NumPendingTasks()); |
533 } | 534 } |
534 | 535 |
535 TEST_F(MetricsServiceTest, GetSyntheticFieldTrialActiveGroups) { | 536 TEST_F(MetricsServiceTest, GetSyntheticFieldTrialActiveGroups) { |
536 TestMetricsServiceClient client; | 537 TestMetricsServiceClient client; |
537 MetricsService service(GetMetricsStateManager(), &client, GetLocalState()); | 538 MetricsService service(GetMetricsStateManager(), &client, GetLocalState()); |
538 | 539 |
539 // Instantiate and setup the corresponding singleton observer which tracks the | 540 // Instantiate and setup the corresponding singleton observer which tracks the |
540 // creation of all SyntheticTrialGroups. | 541 // creation of all SyntheticTrialGroups. |
541 service.AddSyntheticTrialObserver( | 542 service.AddSyntheticTrialObserver( |
542 variations::SyntheticTrialsActiveGroupIdProvider::GetInstance()); | 543 variations::SyntheticTrialsActiveGroupIdProvider::GetInstance()); |
(...skipping 18 matching lines...) Expand all Loading... |
561 std::string trial1_hash = | 562 std::string trial1_hash = |
562 base::StringPrintf("%x-%x", trial1.id.name, trial1.id.group); | 563 base::StringPrintf("%x-%x", trial1.id.name, trial1.id.group); |
563 EXPECT_TRUE(base::ContainsValue(output, trial1_hash)); | 564 EXPECT_TRUE(base::ContainsValue(output, trial1_hash)); |
564 | 565 |
565 std::string trial2_hash = | 566 std::string trial2_hash = |
566 base::StringPrintf("%x-%x", trial2.id.name, trial2.id.group); | 567 base::StringPrintf("%x-%x", trial2.id.name, trial2.id.group); |
567 EXPECT_TRUE(base::ContainsValue(output, trial2_hash)); | 568 EXPECT_TRUE(base::ContainsValue(output, trial2_hash)); |
568 } | 569 } |
569 | 570 |
570 } // namespace metrics | 571 } // namespace metrics |
OLD | NEW |