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

Side by Side Diff: net/base/address_tracker_linux_unittest.cc

Issue 899573002: Add WiFi SSID getter to NetworkChangeNotifier. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build Created 5 years, 10 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 | « net/base/address_tracker_linux.cc ('k') | net/base/network_change_notifier.h » ('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) 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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "net/base/address_tracker_linux.h" 6 #include "net/base/address_tracker_linux.h"
7 7
8 #include <linux/if.h> 8 #include <linux/if.h>
9 9
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 #ifndef IFA_F_HOMEADDRESS 15 #ifndef IFA_F_HOMEADDRESS
16 #define IFA_F_HOMEADDRESS 0x10 16 #define IFA_F_HOMEADDRESS 0x10
17 #endif 17 #endif
18 18
19 namespace net { 19 namespace net {
20 namespace internal { 20 namespace internal {
21 namespace { 21 namespace {
22 22
23 const int kTestInterfaceTun = 123; 23 const int kTestInterfaceTun = 123;
24 const char kWiFiSSID[] = "TestWiFi";
25 const char kInterfaceWithNoSSID[] = "wlan999";
24 26
25 char* TestGetInterfaceName(int interface_index, char* buf) { 27 char* TestGetInterfaceName(int interface_index, char* buf) {
26 if (interface_index == kTestInterfaceTun) 28 if (interface_index == kTestInterfaceTun)
27 return strncpy(buf, "tun0", IFNAMSIZ); 29 return strncpy(buf, "tun0", IFNAMSIZ);
28 return strncpy(buf, "eth0", IFNAMSIZ); 30 return strncpy(buf, "eth0", IFNAMSIZ);
29 } 31 }
30 32
33 std::string TestGetInterfaceSSID(const std::string& ifname) {
34 return (ifname == kInterfaceWithNoSSID) ? "" : kWiFiSSID;
35 }
36
31 } // namespace 37 } // namespace
32 38
33 typedef std::vector<char> Buffer; 39 typedef std::vector<char> Buffer;
34 40
35 class AddressTrackerLinuxTest : public testing::Test { 41 class AddressTrackerLinuxTest : public testing::Test {
36 protected: 42 protected:
37 AddressTrackerLinuxTest() {} 43 AddressTrackerLinuxTest() {}
38 44
39 void InitializeAddressTracker(bool tracking) { 45 void InitializeAddressTracker(bool tracking) {
40 if (tracking) { 46 if (tracking) {
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 EXPECT_TRUE(HandleLinkMessage(buffer)); 551 EXPECT_TRUE(HandleLinkMessage(buffer));
546 EXPECT_EQ(1u, GetOnlineLinks().count(0)); 552 EXPECT_EQ(1u, GetOnlineLinks().count(0));
547 EXPECT_EQ(1u, GetOnlineLinks().size()); 553 EXPECT_EQ(1u, GetOnlineLinks().size());
548 } 554 }
549 555
550 TEST_F(AddressTrackerLinuxTest, NonTrackingModeInit) { 556 TEST_F(AddressTrackerLinuxTest, NonTrackingModeInit) {
551 AddressTrackerLinux tracker; 557 AddressTrackerLinux tracker;
552 tracker.Init(); 558 tracker.Init();
553 } 559 }
554 560
561 TEST_F(AddressTrackerLinuxTest, ConnectionSSIDFromInterfaceList) {
562 NetworkInterfaceList list;
563 EXPECT_EQ(std::string(), AddressTrackerLinux::ConnectionSSIDFromInterfaceList(
564 list, TestGetInterfaceSSID));
565
566 NetworkInterface interface1;
567 interface1.name = "wlan0";
568 interface1.type = NetworkChangeNotifier::CONNECTION_WIFI;
569 list.push_back(interface1);
570 ASSERT_EQ(1u, list.size());
571 EXPECT_EQ(std::string(kWiFiSSID),
572 AddressTrackerLinux::ConnectionSSIDFromInterfaceList(
573 list, TestGetInterfaceSSID));
574
575 NetworkInterface interface2;
576 interface2.name = "wlan1";
577 interface2.type = NetworkChangeNotifier::CONNECTION_WIFI;
578 list.push_back(interface2);
579 ASSERT_EQ(2u, list.size());
580 EXPECT_EQ(std::string(kWiFiSSID),
581 AddressTrackerLinux::ConnectionSSIDFromInterfaceList(
582 list, TestGetInterfaceSSID));
583
584 NetworkInterface interface3;
585 interface3.name = kInterfaceWithNoSSID;
586 interface3.type = NetworkChangeNotifier::CONNECTION_WIFI;
587 list.push_back(interface3);
588 ASSERT_EQ(3u, list.size());
589 EXPECT_EQ(std::string(), AddressTrackerLinux::ConnectionSSIDFromInterfaceList(
590 list, TestGetInterfaceSSID));
591
592 list.pop_back();
593 NetworkInterface interface4;
594 interface4.name = "eth0";
595 interface4.type = NetworkChangeNotifier::CONNECTION_ETHERNET;
596 list.push_back(interface4);
597 ASSERT_EQ(3u, list.size());
598 EXPECT_EQ(std::string(), AddressTrackerLinux::ConnectionSSIDFromInterfaceList(
599 list, TestGetInterfaceSSID));
600 }
601
555 } // namespace 602 } // namespace
556 603
557 } // namespace internal 604 } // namespace internal
558 } // namespace net 605 } // namespace net
OLDNEW
« no previous file with comments | « net/base/address_tracker_linux.cc ('k') | net/base/network_change_notifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698