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

Unified Diff: content/browser/power_profiler/power_profiler_service_unittest.cc

Issue 140583003: Chrome power profiler service (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/power_profiler/power_profiler_service_unittest.cc
diff --git a/content/browser/power_profiler/power_profiler_service_unittest.cc b/content/browser/power_profiler/power_profiler_service_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..92f64e81ec0ab7e56fb66b492b58a42afaf21c5e
--- /dev/null
+++ b/content/browser/power_profiler/power_profiler_service_unittest.cc
@@ -0,0 +1,82 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/message_loop/message_loop.h"
+#include "content/browser/browser_thread_impl.h"
+#include "content/public/browser/power_profiler_service.h"
+#include "content/test/test_power_data_provider.h"
+#include "content/test/test_power_profiler_observer.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace content {
+
+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.
+ public:
+ void ServiceStartTest() {
+ service_ = new PowerProfilerService(make_scoped_ptr<PowerDataProvider>(
+ new TestPowerDataProvider(kEvents)));
+ EXPECT_TRUE(service_->IsAvailable());
+ }
+
+ void AddObserverTest() {
+ for (int index = 0; index < kObservers; ++index)
+ service_->AddObserver(&observers_[index]);
+
+ // No one received PowerEvent now.
+ for (int index = 0; index < kObservers; ++index)
+ EXPECT_EQ(observers_[0].valid_event_count(), 0);
+ }
+
+ void RemoveObserverTest() {
+ for (int index = 0; index < kObservers; ++index)
+ service_->RemoveObserver(&observers_[index]);
+
+ // Everyone received |kEvents| events.
+ for (int index = 0; index < kObservers; ++index)
+ EXPECT_EQ(observers_[index].valid_event_count(), kEvents);
+ }
+
+ protected:
+ PowerProfilerServiceTest() {}
+ virtual ~PowerProfilerServiceTest() {}
+
+ virtual void SetUp() {
+ ui_thread_.reset(new BrowserThreadImpl(BrowserThread::UI));
+ ui_thread_->Start();
+ }
+
+ virtual void TearDown() {
+ ui_thread_->Stop();
+ }
+
+ private:
+ const static int kEvents = 5;
+ const static int kObservers = 3;
+
+ PowerProfilerService* service_;
+ TestPowerProfilerObserver observers_[kObservers];
+
+ scoped_ptr<BrowserThreadImpl> ui_thread_;
+ base::MessageLoop message_loop_;
+
+ DISALLOW_COPY_AND_ASSIGN(PowerProfilerServiceTest);
+};
+
+TEST_F(PowerProfilerServiceTest, AvailableService) {
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ base::Bind(&PowerProfilerServiceTest::ServiceStartTest,
+ base::Unretained(this)));
+
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ base::Bind(&PowerProfilerServiceTest::AddObserverTest,
+ base::Unretained(this)));
+
+ base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(300));
+
+ BrowserThread::PostTaskAndReply(BrowserThread::UI, FROM_HERE,
+ base::Bind(&PowerProfilerServiceTest::RemoveObserverTest,
+ base::Unretained(this)), base::MessageLoop::QuitClosure());
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698