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

Side by Side Diff: ash/system/power/power_status_unittest.cc

Issue 2846723004: Use ScopedTaskEnvironment instead of MessageLoopForUI in ash tests. (Closed)
Patch Set: Created 3 years, 7 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 unified diff | Download patch
« no previous file with comments | « no previous file | ash/test/ash_test_environment_default.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "ash/system/power/power_status.h" 5 #include "ash/system/power/power_status.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "ash/resources/vector_icons/vector_icons.h" 9 #include "ash/resources/vector_icons/vector_icons.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/test/scoped_task_environment.h"
12 #include "chromeos/dbus/dbus_thread_manager.h" 12 #include "chromeos/dbus/dbus_thread_manager.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/cros_system_api/dbus/service_constants.h" 14 #include "third_party/cros_system_api/dbus/service_constants.h"
15 15
16 using power_manager::PowerSupplyProperties; 16 using power_manager::PowerSupplyProperties;
17 17
18 namespace ash { 18 namespace ash {
19 namespace { 19 namespace {
20 20
21 class TestObserver : public PowerStatus::Observer { 21 class TestObserver : public PowerStatus::Observer {
22 public: 22 public:
23 TestObserver() : power_changed_count_(0) {} 23 TestObserver() : power_changed_count_(0) {}
24 ~TestObserver() override {} 24 ~TestObserver() override {}
25 25
26 int power_changed_count() const { return power_changed_count_; } 26 int power_changed_count() const { return power_changed_count_; }
27 27
28 // PowerStatus::Observer overrides: 28 // PowerStatus::Observer overrides:
29 void OnPowerStatusChanged() override { ++power_changed_count_; } 29 void OnPowerStatusChanged() override { ++power_changed_count_; }
30 30
31 private: 31 private:
32 int power_changed_count_; 32 int power_changed_count_;
33 33
34 DISALLOW_COPY_AND_ASSIGN(TestObserver); 34 DISALLOW_COPY_AND_ASSIGN(TestObserver);
35 }; 35 };
36 36
37 } // namespace 37 } // namespace
38 38
39 class PowerStatusTest : public testing::Test { 39 class PowerStatusTest : public testing::Test {
40 public: 40 public:
41 PowerStatusTest() : power_status_(NULL) {} 41 PowerStatusTest()
42 : scoped_task_environment_(
43 base::test::ScopedTaskEnvironment::MainThreadType::UI),
44 power_status_(NULL) {}
42 ~PowerStatusTest() override {} 45 ~PowerStatusTest() override {}
43 46
44 void SetUp() override { 47 void SetUp() override {
45 chromeos::DBusThreadManager::Initialize(); 48 chromeos::DBusThreadManager::Initialize();
46 PowerStatus::Initialize(); 49 PowerStatus::Initialize();
47 power_status_ = PowerStatus::Get(); 50 power_status_ = PowerStatus::Get();
48 test_observer_.reset(new TestObserver); 51 test_observer_.reset(new TestObserver);
49 power_status_->AddObserver(test_observer_.get()); 52 power_status_->AddObserver(test_observer_.get());
50 } 53 }
51 54
52 void TearDown() override { 55 void TearDown() override {
53 power_status_->RemoveObserver(test_observer_.get()); 56 power_status_->RemoveObserver(test_observer_.get());
54 test_observer_.reset(); 57 test_observer_.reset();
55 PowerStatus::Shutdown(); 58 PowerStatus::Shutdown();
56 chromeos::DBusThreadManager::Shutdown(); 59 chromeos::DBusThreadManager::Shutdown();
57 } 60 }
58 61
59 protected: 62 protected:
60 base::MessageLoopForUI message_loop_; 63 base::test::ScopedTaskEnvironment scoped_task_environment_;
61 PowerStatus* power_status_; // Not owned. 64 PowerStatus* power_status_; // Not owned.
62 std::unique_ptr<TestObserver> test_observer_; 65 std::unique_ptr<TestObserver> test_observer_;
63 66
64 private: 67 private:
65 DISALLOW_COPY_AND_ASSIGN(PowerStatusTest); 68 DISALLOW_COPY_AND_ASSIGN(PowerStatusTest);
66 }; 69 };
67 70
68 TEST_F(PowerStatusTest, InitializeAndUpdate) { 71 TEST_F(PowerStatusTest, InitializeAndUpdate) {
69 // Test that the initial power supply state should be acquired after 72 // Test that the initial power supply state should be acquired after
70 // PowerStatus is instantiated. This depends on 73 // PowerStatus is instantiated. This depends on
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 // the battery is 100% full. 288 // the battery is 100% full.
286 prop.set_battery_percent(99.0); 289 prop.set_battery_percent(99.0);
287 power_status_->SetProtoForTesting(prop); 290 power_status_->SetProtoForTesting(prop);
288 EXPECT_EQ(11, power_status_->GetBatteryImageInfo().charge_level); 291 EXPECT_EQ(11, power_status_->GetBatteryImageInfo().charge_level);
289 prop.set_battery_percent(100.0); 292 prop.set_battery_percent(100.0);
290 power_status_->SetProtoForTesting(prop); 293 power_status_->SetProtoForTesting(prop);
291 EXPECT_EQ(12, power_status_->GetBatteryImageInfo().charge_level); 294 EXPECT_EQ(12, power_status_->GetBatteryImageInfo().charge_level);
292 } 295 }
293 296
294 } // namespace ash 297 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/test/ash_test_environment_default.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698