| 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 "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "content/browser/browser_thread_impl.h" | 7 #include "content/browser/browser_thread_impl.h" |
| 8 #include "content/browser/power_profiler/power_profiler_service.h" | 8 #include "content/browser/power_profiler/power_profiler_service.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace content { | 11 namespace content { |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 const int kNumEvents = 3; | 15 const int kNumEvents = 3; |
| 16 const int kDefaultSamplePeriodMs = 50; | 16 const int kDefaultSamplePeriodMs = 50; |
| 17 | 17 |
| 18 // Provide a set number of power events. | 18 // Provide a set number of power events. |
| 19 class TestPowerDataProvider : public PowerDataProvider { | 19 class TestPowerDataProvider : public PowerDataProvider { |
| 20 public: | 20 public: |
| 21 TestPowerDataProvider(int count) : num_events_to_send_(count) {} | 21 TestPowerDataProvider(int count) : num_events_to_send_(count) {} |
| 22 virtual ~TestPowerDataProvider() {} | 22 virtual ~TestPowerDataProvider() {} |
| 23 | 23 |
| 24 virtual PowerEventVector GetData() OVERRIDE { | 24 virtual PowerEventVector GetData() override { |
| 25 PowerEventVector events; | 25 PowerEventVector events; |
| 26 if (num_events_to_send_ == 0) | 26 if (num_events_to_send_ == 0) |
| 27 return events; | 27 return events; |
| 28 | 28 |
| 29 PowerEvent event; | 29 PowerEvent event; |
| 30 event.type = PowerEvent::SOC_PACKAGE; | 30 event.type = PowerEvent::SOC_PACKAGE; |
| 31 event.time = base::TimeTicks::Now(); | 31 event.time = base::TimeTicks::Now(); |
| 32 event.value = 1.0; | 32 event.value = 1.0; |
| 33 events.push_back(event); | 33 events.push_back(event); |
| 34 | 34 |
| 35 num_events_to_send_--; | 35 num_events_to_send_--; |
| 36 return events; | 36 return events; |
| 37 } | 37 } |
| 38 | 38 |
| 39 virtual base::TimeDelta GetSamplingRate() OVERRIDE { | 39 virtual base::TimeDelta GetSamplingRate() override { |
| 40 return base::TimeDelta::FromMilliseconds(kDefaultSamplePeriodMs); | 40 return base::TimeDelta::FromMilliseconds(kDefaultSamplePeriodMs); |
| 41 } | 41 } |
| 42 | 42 |
| 43 virtual AccuracyLevel GetAccuracyLevel() OVERRIDE { return High; } | 43 virtual AccuracyLevel GetAccuracyLevel() override { return High; } |
| 44 | 44 |
| 45 private: | 45 private: |
| 46 int num_events_to_send_; | 46 int num_events_to_send_; |
| 47 DISALLOW_COPY_AND_ASSIGN(TestPowerDataProvider); | 47 DISALLOW_COPY_AND_ASSIGN(TestPowerDataProvider); |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 class TestPowerProfilerObserver : public PowerProfilerObserver { | 50 class TestPowerProfilerObserver : public PowerProfilerObserver { |
| 51 public: | 51 public: |
| 52 TestPowerProfilerObserver() | 52 TestPowerProfilerObserver() |
| 53 : valid_event_count_(0), | 53 : valid_event_count_(0), |
| 54 total_num_events_received_(0) {} | 54 total_num_events_received_(0) {} |
| 55 virtual ~TestPowerProfilerObserver() {} | 55 virtual ~TestPowerProfilerObserver() {} |
| 56 | 56 |
| 57 virtual void OnPowerEvent(const PowerEventVector& events) OVERRIDE { | 57 virtual void OnPowerEvent(const PowerEventVector& events) override { |
| 58 if (IsValidEvent(events[0])) | 58 if (IsValidEvent(events[0])) |
| 59 ++valid_event_count_; | 59 ++valid_event_count_; |
| 60 | 60 |
| 61 total_num_events_received_++; | 61 total_num_events_received_++; |
| 62 if (total_num_events_received_ >= kNumEvents) { | 62 if (total_num_events_received_ >= kNumEvents) { |
| 63 // All expected events received, exiting. | 63 // All expected events received, exiting. |
| 64 quit_closure_.Run(); | 64 quit_closure_.Run(); |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 136 |
| 137 ServiceStartTest(); | 137 ServiceStartTest(); |
| 138 AddObserverTest(); | 138 AddObserverTest(); |
| 139 | 139 |
| 140 run_loop.Run(); | 140 run_loop.Run(); |
| 141 | 141 |
| 142 RemoveObserverTest(); | 142 RemoveObserverTest(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 } // namespace content | 145 } // namespace content |
| OLD | NEW |