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

Side by Side Diff: device/geolocation/wifi_data_provider_common_unittest.cc

Issue 2849613002: Use ScopedTaskEnvironment instead of MessageLoopForUI in device tests. (Closed)
Patch Set: self-review 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "device/geolocation/wifi_data_provider_common.h" 5 #include "device/geolocation/wifi_data_provider_common.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/test/scoped_task_environment.h"
13 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 14 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
14 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
15 #include "device/geolocation/wifi_data_provider_manager.h" 16 #include "device/geolocation/wifi_data_provider_manager.h"
16 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 using testing::_; 20 using testing::_;
20 using testing::AnyNumber; 21 using testing::AnyNumber;
21 using testing::AtLeast; 22 using testing::AtLeast;
22 using testing::DoAll; 23 using testing::DoAll;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 private: 76 private:
76 ~WifiDataProviderCommonWithMock() override {} 77 ~WifiDataProviderCommonWithMock() override {}
77 78
78 DISALLOW_COPY_AND_ASSIGN(WifiDataProviderCommonWithMock); 79 DISALLOW_COPY_AND_ASSIGN(WifiDataProviderCommonWithMock);
79 }; 80 };
80 81
81 // Main test fixture 82 // Main test fixture
82 class GeolocationWifiDataProviderCommonTest : public testing::Test { 83 class GeolocationWifiDataProviderCommonTest : public testing::Test {
83 public: 84 public:
84 GeolocationWifiDataProviderCommonTest() 85 GeolocationWifiDataProviderCommonTest()
85 : wifi_data_callback_(base::Bind(&base::DoNothing)), 86 : scoped_task_environment_(
87 base::test::ScopedTaskEnvironment::MainThreadType::UI),
88 wifi_data_callback_(base::Bind(&base::DoNothing)),
86 provider_(new WifiDataProviderCommonWithMock), 89 provider_(new WifiDataProviderCommonWithMock),
87 wlan_api_(provider_->wlan_api_.get()), 90 wlan_api_(provider_->wlan_api_.get()),
88 polling_policy_(provider_->polling_policy_.get()) {} 91 polling_policy_(provider_->polling_policy_.get()) {}
89 92
90 void SetUp() override { 93 void SetUp() override {
91 provider_->AddCallback(&wifi_data_callback_); 94 provider_->AddCallback(&wifi_data_callback_);
92 } 95 }
93 96
94 void TearDown() override { 97 void TearDown() override {
95 provider_->RemoveCallback(&wifi_data_callback_); 98 provider_->RemoveCallback(&wifi_data_callback_);
96 provider_->StopDataProvider(); 99 provider_->StopDataProvider();
97 } 100 }
98 101
99 protected: 102 protected:
100 const base::MessageLoopForUI message_loop_; 103 const base::test::ScopedTaskEnvironment scoped_task_environment_;
101 WifiDataProviderManager::WifiDataUpdateCallback wifi_data_callback_; 104 WifiDataProviderManager::WifiDataUpdateCallback wifi_data_callback_;
102 const scoped_refptr<WifiDataProviderCommonWithMock> provider_; 105 const scoped_refptr<WifiDataProviderCommonWithMock> provider_;
103 106
104 MockWlanApi* const wlan_api_; 107 MockWlanApi* const wlan_api_;
105 MockPollingPolicy* const polling_policy_; 108 MockPollingPolicy* const polling_policy_;
106 }; 109 };
107 110
108 TEST_F(GeolocationWifiDataProviderCommonTest, CreateDestroy) { 111 TEST_F(GeolocationWifiDataProviderCommonTest, CreateDestroy) {
109 // Test fixture members were SetUp correctly. 112 // Test fixture members were SetUp correctly.
110 EXPECT_TRUE(provider_); 113 EXPECT_TRUE(provider_);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 provider_->StartDataProvider(); 189 provider_->StartDataProvider();
187 run_loop.Run(); 190 run_loop.Run();
188 191
189 WifiData data; 192 WifiData data;
190 EXPECT_TRUE(provider_->GetData(&data)); 193 EXPECT_TRUE(provider_->GetData(&data));
191 ASSERT_EQ(1u, data.access_point_data.size()); 194 ASSERT_EQ(1u, data.access_point_data.size());
192 EXPECT_EQ(single_access_point.ssid, data.access_point_data.begin()->ssid); 195 EXPECT_EQ(single_access_point.ssid, data.access_point_data.begin()->ssid);
193 } 196 }
194 197
195 } // namespace device 198 } // namespace device
OLDNEW
« no previous file with comments | « device/geolocation/wifi_data_provider_chromeos_unittest.cc ('k') | device/geolocation/wifi_data_provider_linux_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698