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

Side by Side Diff: ash/common/system/chromeos/network/vpn_list_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698