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

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: 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) 2012 The Chromium Authors. All rights reserved.
Greg Spencer (Chromium) 2013/01/12 00:52:37 2013
stevenjb 2013/01/12 01:55:59 Done.
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 virtual ~GeolocationHandlerTest() {
22 }
23
24 virtual void SetUp() OVERRIDE {
25 // Initialize DBusThreadManager with a stub implementation.
26 DBusThreadManager::InitializeWithStub();
27 // Get the test interface for manager / device.
28 manager_test_ =
29 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface();
30 ASSERT_TRUE(manager_test_);
31 geolocation_handler_.reset(new GeolocationHandler());
32 message_loop_.RunUntilIdle();
33 }
34
35 virtual void TearDown() OVERRIDE {
36 geolocation_handler_.reset();
37 DBusThreadManager::Shutdown();
38 }
39
40 bool GetWifiAccessPoints() {
41 return geolocation_handler_->GetWifiAccessPoints(&wifi_access_points_);
42 }
43
44 void AddAccessPoint(int idx) {
45 base::DictionaryValue properties;
46 std::string mac_address =
47 base::StringPrintf("%02X:%02X:%02X:%02X:%02X:%02X",
48 idx, 0, 0, 0, 0, 0);
49 std::string channel = StringPrintf("%d", idx);
50 std::string strength = StringPrintf("%d", idx * 10);
51 properties.SetStringWithoutPathExpansion(
52 shill::kGeoMacAddressProperty, mac_address);
53 properties.SetStringWithoutPathExpansion(
54 shill::kGeoChannelProperty, channel);
55 properties.SetStringWithoutPathExpansion(
56 shill::kGeoSignalStrengthProperty, strength);
57 manager_test_->AddGeoNetwork(flimflam::kTypeWifi, properties);
58 message_loop_.RunUntilIdle();
59 }
60
61 protected:
62 MessageLoopForUI message_loop_;
63 scoped_ptr<GeolocationHandler> geolocation_handler_;
64 ShillManagerClient::TestInterface* manager_test_;
65 WifiAccessPointVector wifi_access_points_;
66
67 private:
68 DISALLOW_COPY_AND_ASSIGN(GeolocationHandlerTest);
69 };
70
71 TEST_F(GeolocationHandlerTest, NoAccessPoints) {
72 // Inititial call should return false.
73 EXPECT_FALSE(GetWifiAccessPoints());
74 message_loop_.RunUntilIdle();
75 // Second call should return false since there are no devices.
76 EXPECT_FALSE(GetWifiAccessPoints());
77 }
78
79 TEST_F(GeolocationHandlerTest, OneAccessPoint) {
80 // Add an acces point.
81 AddAccessPoint(1);
82 message_loop_.RunUntilIdle();
83 // Inititial call should return false and request access points.
84 EXPECT_FALSE(GetWifiAccessPoints());
85 message_loop_.RunUntilIdle();
86 // Second call should return true since we have an access point.
87 EXPECT_TRUE(GetWifiAccessPoints());
88 ASSERT_EQ(1u, wifi_access_points_.size());
89 EXPECT_EQ("01:00:00:00:00:00", wifi_access_points_[0].mac_address);
90 EXPECT_EQ(1, wifi_access_points_[0].channel);
91 }
92
93 TEST_F(GeolocationHandlerTest, MultipleAccessPoints) {
94 // Add several acces points.
95 AddAccessPoint(1);
96 AddAccessPoint(2);
97 AddAccessPoint(3);
98 message_loop_.RunUntilIdle();
99 // Inititial call should return false and request access points.
100 EXPECT_FALSE(GetWifiAccessPoints());
101 message_loop_.RunUntilIdle();
102 // Second call should return true since we have an access point.
103 EXPECT_TRUE(GetWifiAccessPoints());
104 EXPECT_EQ(3u, wifi_access_points_.size());
105 EXPECT_EQ("02:00:00:00:00:00", wifi_access_points_[1].mac_address);
106 EXPECT_EQ(3, wifi_access_points_[2].channel);
107 }
108
109 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698