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

Side by Side Diff: chromeos/network/geolocation_handler_unittest.cc

Issue 11887008: Deprecate ShillNetworkClient and add GeolocationHandler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix initialization / shutdown Created 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/memory/scoped_ptr.h"
6 #include "base/message_loop.h"
7 #include "base/stringprintf.h"
8 #include "base/values.h"
9 #include "chromeos/dbus/dbus_thread_manager.h"
10 #include "chromeos/dbus/shill_manager_client.h"
11 #include "chromeos/network/geolocation_handler.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/cros_system_api/dbus/service_constants.h"
14
15 namespace chromeos {
16
17 class GeolocationHandlerTest : public testing::Test {
18 public:
19 GeolocationHandlerTest() : manager_test_(NULL) {
20 }
21
22 virtual ~GeolocationHandlerTest() {
23 }
24
25 virtual void SetUp() OVERRIDE {
26 // Initialize DBusThreadManager with a stub implementation.
27 DBusThreadManager::InitializeWithStub();
28 // Get the test interface for manager / device.
29 manager_test_ =
30 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface();
31 ASSERT_TRUE(manager_test_);
32 geolocation_handler_.reset(new GeolocationHandler());
33 message_loop_.RunUntilIdle();
34 }
35
36 virtual void TearDown() OVERRIDE {
37 geolocation_handler_.reset();
38 DBusThreadManager::Shutdown();
39 }
40
41 bool GetWifiAccessPoints() {
42 return geolocation_handler_->GetWifiAccessPoints(&wifi_access_points_);
43 }
44
45 void AddAccessPoint(int idx) {
46 base::DictionaryValue properties;
47 std::string mac_address =
48 base::StringPrintf("%02X:%02X:%02X:%02X:%02X:%02X",
49 idx, 0, 0, 0, 0, 0);
50 std::string channel = StringPrintf("%d", idx);
51 std::string strength = StringPrintf("%d", idx * 10);
52 properties.SetStringWithoutPathExpansion(
53 shill::kGeoMacAddressProperty, mac_address);
54 properties.SetStringWithoutPathExpansion(
55 shill::kGeoChannelProperty, channel);
56 properties.SetStringWithoutPathExpansion(
57 shill::kGeoSignalStrengthProperty, strength);
58 manager_test_->AddGeoNetwork(flimflam::kTypeWifi, properties);
59 message_loop_.RunUntilIdle();
60 }
61
62 protected:
63 MessageLoopForUI message_loop_;
64 scoped_ptr<GeolocationHandler> geolocation_handler_;
65 ShillManagerClient::TestInterface* manager_test_;
66 WifiAccessPointVector wifi_access_points_;
67
68 private:
69 DISALLOW_COPY_AND_ASSIGN(GeolocationHandlerTest);
70 };
71
72 TEST_F(GeolocationHandlerTest, NoAccessPoints) {
73 // Inititial call should return false.
74 EXPECT_FALSE(GetWifiAccessPoints());
75 message_loop_.RunUntilIdle();
76 // Second call should return false since there are no devices.
77 EXPECT_FALSE(GetWifiAccessPoints());
78 }
79
80 TEST_F(GeolocationHandlerTest, OneAccessPoint) {
81 // Add an acces point.
82 AddAccessPoint(1);
83 message_loop_.RunUntilIdle();
84 // Inititial call should return false and request access points.
85 EXPECT_FALSE(GetWifiAccessPoints());
86 message_loop_.RunUntilIdle();
87 // Second call should return true since we have an access point.
88 EXPECT_TRUE(GetWifiAccessPoints());
89 ASSERT_EQ(1u, wifi_access_points_.size());
90 EXPECT_EQ("01:00:00:00:00:00", wifi_access_points_[0].mac_address);
91 EXPECT_EQ(1, wifi_access_points_[0].channel);
92 }
93
94 TEST_F(GeolocationHandlerTest, MultipleAccessPoints) {
95 // Add several acces points.
96 AddAccessPoint(1);
97 AddAccessPoint(2);
98 AddAccessPoint(3);
99 message_loop_.RunUntilIdle();
100 // Inititial call should return false and request access points.
101 EXPECT_FALSE(GetWifiAccessPoints());
102 message_loop_.RunUntilIdle();
103 // Second call should return true since we have an access point.
104 EXPECT_TRUE(GetWifiAccessPoints());
105 EXPECT_EQ(3u, wifi_access_points_.size());
106 EXPECT_EQ("02:00:00:00:00:00", wifi_access_points_[1].mac_address);
107 EXPECT_EQ(3, wifi_access_points_[2].channel);
108 }
109
110 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698