OLD | NEW |
| (Empty) |
1 // Copyright 2016 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 "ash/common/system/chromeos/network/vpn_list.h" | |
6 | |
7 #include <algorithm> | |
8 #include <vector> | |
9 | |
10 #include "ash/public/interfaces/vpn_list.mojom.h" | |
11 #include "base/macros.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 | |
14 using ash::mojom::ThirdPartyVpnProvider; | |
15 using ash::mojom::ThirdPartyVpnProviderPtr; | |
16 | |
17 namespace ash { | |
18 | |
19 namespace { | |
20 | |
21 class TestVpnListObserver : public VpnList::Observer { | |
22 public: | |
23 TestVpnListObserver() {} | |
24 ~TestVpnListObserver() override {} | |
25 | |
26 // VpnList::Observer: | |
27 void OnVPNProvidersChanged() override { change_count_++; } | |
28 | |
29 int change_count_ = 0; | |
30 }; | |
31 | |
32 } // namespace | |
33 | |
34 using VpnListTest = testing::Test; | |
35 | |
36 TEST_F(VpnListTest, BuiltInProvider) { | |
37 VpnList vpn_list; | |
38 | |
39 // The VPN list should only contain the built-in provider. | |
40 ASSERT_EQ(1u, vpn_list.vpn_providers().size()); | |
41 VPNProvider provider = vpn_list.vpn_providers()[0]; | |
42 EXPECT_FALSE(provider.third_party); | |
43 EXPECT_TRUE(provider.extension_id.empty()); | |
44 } | |
45 | |
46 TEST_F(VpnListTest, ThirdPartyProviders) { | |
47 VpnList vpn_list; | |
48 | |
49 // The VPN list should only contain the built-in provider. | |
50 EXPECT_EQ(1u, vpn_list.vpn_providers().size()); | |
51 | |
52 // Add some third party (extension-backed) providers. | |
53 std::vector<ThirdPartyVpnProviderPtr> third_party_providers; | |
54 ThirdPartyVpnProviderPtr third_party1 = ThirdPartyVpnProvider::New(); | |
55 third_party1->name = "name1"; | |
56 third_party1->extension_id = "extension_id1"; | |
57 third_party_providers.push_back(std::move(third_party1)); | |
58 | |
59 ThirdPartyVpnProviderPtr third_party2 = ThirdPartyVpnProvider::New(); | |
60 third_party2->name = "name2"; | |
61 third_party2->extension_id = "extension_id2"; | |
62 third_party_providers.push_back(std::move(third_party2)); | |
63 | |
64 vpn_list.SetThirdPartyVpnProviders(std::move(third_party_providers)); | |
65 | |
66 // Mojo types will be converted to internal ash types. | |
67 VPNProvider provider1("extension_id1", "name1"); | |
68 VPNProvider provider2("extension_id2", "name2"); | |
69 | |
70 // List contains the extension-backed providers. Order doesn't matter. | |
71 std::vector<VPNProvider> providers = vpn_list.vpn_providers(); | |
72 EXPECT_EQ(3u, providers.size()); | |
73 EXPECT_EQ(1u, std::count(providers.begin(), providers.end(), provider1)); | |
74 EXPECT_EQ(1u, std::count(providers.begin(), providers.end(), provider2)); | |
75 } | |
76 | |
77 TEST_F(VpnListTest, Observers) { | |
78 VpnList vpn_list; | |
79 | |
80 // Observers are not notified when they are added. | |
81 TestVpnListObserver observer; | |
82 vpn_list.AddObserver(&observer); | |
83 EXPECT_EQ(0, observer.change_count_); | |
84 | |
85 // Add a third party (extension-backed) provider. | |
86 std::vector<ThirdPartyVpnProviderPtr> third_party_providers; | |
87 ThirdPartyVpnProviderPtr third_party1 = ThirdPartyVpnProvider::New(); | |
88 third_party1->name = "name1"; | |
89 third_party1->extension_id = "extension_id1"; | |
90 third_party_providers.push_back(std::move(third_party1)); | |
91 vpn_list.SetThirdPartyVpnProviders(std::move(third_party_providers)); | |
92 | |
93 // Observer was notified. | |
94 EXPECT_EQ(1, observer.change_count_); | |
95 | |
96 vpn_list.RemoveObserver(&observer); | |
97 } | |
98 | |
99 } // namespace ash | |
OLD | NEW |