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

Side by Side Diff: chrome/browser/chromeos/net/network_pref_state_observer_unittest.cc

Issue 2446893008: NetworkHandler: Add ui_proxy_config_service (Closed)
Patch Set: . 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/net/network_pref_state_observer.h"
6
7 #include <memory>
8
9 #include "base/macros.h"
10 #include "base/run_loop.h"
11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
13 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/test/base/testing_browser_process.h"
16 #include "chrome/test/base/testing_profile_manager.h"
17 #include "chromeos/dbus/dbus_thread_manager.h"
18 #include "chromeos/dbus/shill_device_client.h"
19 #include "chromeos/dbus/shill_service_client.h"
20 #include "chromeos/network/network_handler.h"
21 #include "chromeos/network/proxy/ui_proxy_config.h"
22 #include "chromeos/network/proxy/ui_proxy_config_service.h"
23 #include "components/prefs/pref_service.h"
24 #include "components/proxy_config/proxy_config_pref_names.h"
25 #include "components/proxy_config/proxy_prefs.h"
26 #include "content/public/browser/notification_details.h"
27 #include "content/public/browser/notification_service.h"
28 #include "content/public/browser/notification_source.h"
29 #include "content/public/test/test_browser_thread_bundle.h"
30 #include "testing/gtest/include/gtest/gtest.h"
31 #include "third_party/cros_system_api/dbus/service_constants.h"
32
33 namespace {
34 const char kUserId[] = "test@example.com";
35 const char kNetworkId[] = "test_wifi_guid";
36 }
37
38 namespace chromeos {
39 namespace test {
James Cook 2016/11/01 23:02:04 optional nit: I don't usually put the tests themse
stevenjb 2016/11/01 23:55:11 Done.
40
41 class NetworkPrefStateObserverTest : public testing::Test {
42 public:
43 NetworkPrefStateObserverTest()
44 : fake_user_manager_(new chromeos::FakeChromeUserManager),
45 user_manager_enabler_(fake_user_manager_),
46 profile_manager_(TestingBrowserProcess::GetGlobal()) {}
47 ~NetworkPrefStateObserverTest() override {}
48
49 void SetUp() override {
50 testing::Test::SetUp();
51 DBusThreadManager::Initialize();
52 SetupDefaultShillState();
53 NetworkHandler::Initialize();
54 base::RunLoop().RunUntilIdle();
55 ASSERT_TRUE(profile_manager_.SetUp());
56 network_pref_state_observer_.reset(new NetworkPrefStateObserver);
57 }
58
59 void TearDown() override {
60 network_pref_state_observer_.reset();
61 NetworkHandler::Shutdown();
62 DBusThreadManager::Shutdown();
63 testing::Test::TearDown();
64 }
65
66 protected:
67 void SetupDefaultShillState() {
68 base::RunLoop().RunUntilIdle();
James Cook 2016/11/01 23:02:04 It reads kinda weird to do this RunUntilIdle here.
stevenjb 2016/11/01 23:55:11 Removed.
69 ShillDeviceClient::TestInterface* device_test =
70 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface();
71 device_test->ClearDevices();
72 device_test->AddDevice("/device/stub_wifi_device1", shill::kTypeWifi,
73 "stub_wifi_device1");
74
75 ShillServiceClient::TestInterface* service_test =
76 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
77 service_test->ClearServices();
78 // Create a wifi network and set to online.
79 service_test->AddService("/service/wifi1", kNetworkId, "wifi1",
80 shill::kTypeWifi, shill::kStateOnline,
81 true /* add_to_visible */);
82 base::RunLoop().RunUntilIdle();
83 }
84
85 Profile* LoginAndReturnProfile() {
86 fake_user_manager_->AddUser(AccountId::FromUserEmail(kUserId));
87 Profile* profile = profile_manager_.CreateTestingProfile(kUserId);
88 content::NotificationService::current()->Notify(
89 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
90 content::NotificationService::AllSources(),
91 content::Details<Profile>(profile));
92 base::RunLoop().RunUntilIdle();
93 return profile;
94 }
95
96 protected:
James Cook 2016/11/01 23:02:04 not needed. or make the above helper methods publi
stevenjb 2016/11/01 23:55:11 Done.
97 content::TestBrowserThreadBundle thread_bundle_;
98 FakeChromeUserManager* fake_user_manager_;
99 chromeos::ScopedUserManagerEnabler user_manager_enabler_;
100 TestingProfileManager profile_manager_;
101 std::unique_ptr<NetworkPrefStateObserver> network_pref_state_observer_;
102
103 private:
104 DISALLOW_COPY_AND_ASSIGN(NetworkPrefStateObserverTest);
105 };
106
107 TEST_F(NetworkPrefStateObserverTest, LoginUser) {
108 UIProxyConfig ui_proxy_config;
109
110 // UIProxyConfigService should exist with device PrefService.
111 UIProxyConfigService* device_ui_proxy_config_service =
112 NetworkHandler::Get()->ui_proxy_config_service();
113 ASSERT_TRUE(device_ui_proxy_config_service);
114 // Default mode for device prefs should be MODE_DIRECT.
115 device_ui_proxy_config_service->GetProxyConfig(kNetworkId, &ui_proxy_config);
116 EXPECT_EQ(UIProxyConfig::MODE_DIRECT, ui_proxy_config.mode);
117
118 Profile* profile = LoginAndReturnProfile();
119
120 // New UIProxyConfigService should be created with a profile PrefService.
121 UIProxyConfigService* profile_ui_proxy_config_service =
122 NetworkHandler::Get()->ui_proxy_config_service();
123 ASSERT_TRUE(profile_ui_proxy_config_service);
124 ASSERT_NE(device_ui_proxy_config_service, profile_ui_proxy_config_service);
125 // Mode should still be MODE_DIRECT.
126 profile_ui_proxy_config_service->GetProxyConfig(kNetworkId, &ui_proxy_config);
127 EXPECT_EQ(UIProxyConfig::MODE_DIRECT, ui_proxy_config.mode);
128
129 // Set the profile pref to PAC script mode.
130 std::unique_ptr<base::DictionaryValue> proxy_config(
131 base::MakeUnique<base::DictionaryValue>());
132 proxy_config->SetString("mode", ProxyPrefs::kPacScriptProxyModeName);
133 proxy_config->SetString("pac_url", "http://proxy");
134 profile->GetPrefs()->Set(proxy_config::prefs::kProxy, *proxy_config.get());
135 base::RunLoop().RunUntilIdle();
136
137 // Mode should now be MODE_PAC_SCRIPT.
138 NetworkHandler::Get()->ui_proxy_config_service()->GetProxyConfig(
139 kNetworkId, &ui_proxy_config);
140 EXPECT_EQ(UIProxyConfig::MODE_PAC_SCRIPT, ui_proxy_config.mode);
141 }
James Cook 2016/11/01 23:02:04 Thanks for writing a nice test.
stevenjb 2016/11/01 23:55:11 Acknowledged.
142
143 } // namespace test
144 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698