Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/message_loop/message_loop.h" | |
| 6 #include "content/browser/browser_thread_impl.h" | |
| 7 #include "content/public/browser/power_profiler_service.h" | |
| 8 #include "content/test/test_power_data_provider.h" | |
| 9 #include "content/test/test_power_profiler_observer.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 namespace content { | |
| 13 | |
| 14 class PowerProfilerServiceTest : public testing::Test { | |
|
qsr
2014/01/27 10:01:47
See off review patch for suggestion on this: mainl
Pan
2014/01/28 13:32:58
Done.
| |
| 15 public: | |
| 16 void ServiceStartTest() { | |
| 17 service_ = new PowerProfilerService(make_scoped_ptr<PowerDataProvider>( | |
| 18 new TestPowerDataProvider(kEvents))); | |
| 19 EXPECT_TRUE(service_->IsAvailable()); | |
| 20 } | |
| 21 | |
| 22 void AddObserverTest() { | |
| 23 for (int index = 0; index < kObservers; ++index) | |
| 24 service_->AddObserver(&observers_[index]); | |
| 25 | |
| 26 // No one received PowerEvent now. | |
| 27 for (int index = 0; index < kObservers; ++index) | |
| 28 EXPECT_EQ(observers_[0].valid_event_count(), 0); | |
| 29 } | |
| 30 | |
| 31 void RemoveObserverTest() { | |
| 32 for (int index = 0; index < kObservers; ++index) | |
| 33 service_->RemoveObserver(&observers_[index]); | |
| 34 | |
| 35 // Everyone received |kEvents| events. | |
| 36 for (int index = 0; index < kObservers; ++index) | |
| 37 EXPECT_EQ(observers_[index].valid_event_count(), kEvents); | |
| 38 } | |
| 39 | |
| 40 protected: | |
| 41 PowerProfilerServiceTest() {} | |
| 42 virtual ~PowerProfilerServiceTest() {} | |
| 43 | |
| 44 virtual void SetUp() { | |
| 45 ui_thread_.reset(new BrowserThreadImpl(BrowserThread::UI)); | |
| 46 ui_thread_->Start(); | |
| 47 } | |
| 48 | |
| 49 virtual void TearDown() { | |
| 50 ui_thread_->Stop(); | |
| 51 } | |
| 52 | |
| 53 private: | |
| 54 const static int kEvents = 5; | |
| 55 const static int kObservers = 3; | |
| 56 | |
| 57 PowerProfilerService* service_; | |
| 58 TestPowerProfilerObserver observers_[kObservers]; | |
| 59 | |
| 60 scoped_ptr<BrowserThreadImpl> ui_thread_; | |
| 61 base::MessageLoop message_loop_; | |
| 62 | |
| 63 DISALLOW_COPY_AND_ASSIGN(PowerProfilerServiceTest); | |
| 64 }; | |
| 65 | |
| 66 TEST_F(PowerProfilerServiceTest, AvailableService) { | |
| 67 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 68 base::Bind(&PowerProfilerServiceTest::ServiceStartTest, | |
| 69 base::Unretained(this))); | |
| 70 | |
| 71 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 72 base::Bind(&PowerProfilerServiceTest::AddObserverTest, | |
| 73 base::Unretained(this))); | |
| 74 | |
| 75 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(300)); | |
| 76 | |
| 77 BrowserThread::PostTaskAndReply(BrowserThread::UI, FROM_HERE, | |
| 78 base::Bind(&PowerProfilerServiceTest::RemoveObserverTest, | |
| 79 base::Unretained(this)), base::MessageLoop::QuitClosure()); | |
| 80 } | |
| 81 | |
| 82 } // namespace content | |
| OLD | NEW |