aw: Rendering test harness and end-to-end smoke test
[chromium-blink-merge.git] / content / browser / geolocation / wifi_data_provider_chromeos_unittest.cc
blobeb0442194cb85e5de95b80c5b77aadd60db22651
1 // Copyright (c) 2011 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.
5 #include "base/message_loop/message_loop.h"
6 #include "base/strings/stringprintf.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chromeos/dbus/dbus_thread_manager.h"
9 #include "chromeos/dbus/shill_manager_client.h"
10 #include "chromeos/network/geolocation_handler.h"
11 #include "content/browser/geolocation/wifi_data_provider_chromeos.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/cros_system_api/dbus/service_constants.h"
15 namespace content {
17 class GeolocationChromeOsWifiDataProviderTest : public testing::Test {
18 protected:
19 GeolocationChromeOsWifiDataProviderTest() {
22 virtual void SetUp() override {
23 chromeos::DBusThreadManager::Initialize();
24 chromeos::NetworkHandler::Initialize();
25 manager_client_ =
26 chromeos::DBusThreadManager::Get()->GetShillManagerClient();
27 manager_test_ = manager_client_->GetTestInterface();
28 provider_ = new WifiDataProviderChromeOs();
29 message_loop_.RunUntilIdle();
32 virtual void TearDown() override {
33 provider_ = NULL;
34 chromeos::NetworkHandler::Shutdown();
35 chromeos::DBusThreadManager::Shutdown();
38 bool GetAccessPointData() {
39 return provider_->GetAccessPointData(&ap_data_);
42 void AddAccessPoints(int ssids, int aps_per_ssid) {
43 for (int i = 0; i < ssids; ++i) {
44 for (int j = 0; j < aps_per_ssid; ++j) {
45 base::DictionaryValue properties;
46 std::string mac_address =
47 base::StringPrintf("%02X:%02X:%02X:%02X:%02X:%02X",
48 i, j, 3, 4, 5, 6);
49 std::string channel = base::StringPrintf("%d", i * 10 + j);
50 std::string strength = base::StringPrintf("%d", i * 100 + j);
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(shill::kTypeWifi, properties);
60 message_loop_.RunUntilIdle();
63 base::MessageLoopForUI message_loop_;
64 scoped_refptr<WifiDataProviderChromeOs> provider_;
65 chromeos::ShillManagerClient* manager_client_;
66 chromeos::ShillManagerClient::TestInterface* manager_test_;
67 WifiData::AccessPointDataSet ap_data_;
70 TEST_F(GeolocationChromeOsWifiDataProviderTest, NoAccessPoints) {
71 message_loop_.RunUntilIdle();
72 // Initial call to GetAccessPointData requests data and will return false.
73 EXPECT_FALSE(GetAccessPointData());
74 message_loop_.RunUntilIdle();
75 // Additional call to GetAccessPointData also returns false with no devices.
76 EXPECT_FALSE(GetAccessPointData());
77 EXPECT_EQ(0u, ap_data_.size());
80 TEST_F(GeolocationChromeOsWifiDataProviderTest, GetOneAccessPoint) {
81 message_loop_.RunUntilIdle();
82 EXPECT_FALSE(GetAccessPointData());
84 AddAccessPoints(1, 1);
85 EXPECT_TRUE(GetAccessPointData());
86 ASSERT_EQ(1u, ap_data_.size());
87 EXPECT_EQ("00:00:03:04:05:06",
88 base::UTF16ToUTF8(ap_data_.begin()->mac_address));
91 TEST_F(GeolocationChromeOsWifiDataProviderTest, GetManyAccessPoints) {
92 message_loop_.RunUntilIdle();
93 EXPECT_FALSE(GetAccessPointData());
95 AddAccessPoints(3, 4);
96 EXPECT_TRUE(GetAccessPointData());
97 ASSERT_EQ(12u, ap_data_.size());
100 } // namespace content