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

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: Feedback + elim bogus shill errors 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"
James Cook 2016/11/02 01:57:33 Do you still need this include?
stevenjb 2016/11/02 18:03:41 Good catch. Removed.
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[] = "wifi1_guid"; // Matches FakeShillManagerClient
36 }
37
38 namespace chromeos {
39
40 class NetworkPrefStateObserverTest : public testing::Test {
41 public:
42 NetworkPrefStateObserverTest()
43 : fake_user_manager_(new chromeos::FakeChromeUserManager),
44 user_manager_enabler_(fake_user_manager_),
45 profile_manager_(TestingBrowserProcess::GetGlobal()) {}
46 ~NetworkPrefStateObserverTest() override {}
47
48 void SetUp() override {
49 testing::Test::SetUp();
50 DBusThreadManager::Initialize();
51 NetworkHandler::Initialize();
52 base::RunLoop().RunUntilIdle();
53 ASSERT_TRUE(profile_manager_.SetUp());
54 network_pref_state_observer_.reset(new NetworkPrefStateObserver);
55 }
56
57 void TearDown() override {
58 network_pref_state_observer_.reset();
59 NetworkHandler::Shutdown();
60 DBusThreadManager::Shutdown();
61 testing::Test::TearDown();
62 }
63
64 protected:
65 Profile* LoginAndReturnProfile() {
66 fake_user_manager_->AddUser(AccountId::FromUserEmail(kUserId));
67 Profile* profile = profile_manager_.CreateTestingProfile(kUserId);
68 content::NotificationService::current()->Notify(
69 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
70 content::NotificationService::AllSources(),
71 content::Details<Profile>(profile));
72 base::RunLoop().RunUntilIdle();
73 return profile;
74 }
75
76 content::TestBrowserThreadBundle thread_bundle_;
77 FakeChromeUserManager* fake_user_manager_;
78 chromeos::ScopedUserManagerEnabler user_manager_enabler_;
79 TestingProfileManager profile_manager_;
80 std::unique_ptr<NetworkPrefStateObserver> network_pref_state_observer_;
81
82 private:
83 DISALLOW_COPY_AND_ASSIGN(NetworkPrefStateObserverTest);
84 };
85
86 TEST_F(NetworkPrefStateObserverTest, LoginUser) {
87 UIProxyConfig ui_proxy_config;
88
89 // UIProxyConfigService should exist with device PrefService.
90 UIProxyConfigService* device_ui_proxy_config_service =
91 NetworkHandler::Get()->ui_proxy_config_service();
92 ASSERT_TRUE(device_ui_proxy_config_service);
93 // Default mode for device prefs should be MODE_DIRECT.
94 device_ui_proxy_config_service->GetProxyConfig(kNetworkId, &ui_proxy_config);
95 EXPECT_EQ(UIProxyConfig::MODE_DIRECT, ui_proxy_config.mode);
96
97 Profile* profile = LoginAndReturnProfile();
98
99 // New UIProxyConfigService should be created with a profile PrefService.
100 UIProxyConfigService* profile_ui_proxy_config_service =
101 NetworkHandler::Get()->ui_proxy_config_service();
102 ASSERT_TRUE(profile_ui_proxy_config_service);
103 ASSERT_NE(device_ui_proxy_config_service, profile_ui_proxy_config_service);
104 // Mode should still be MODE_DIRECT.
105 profile_ui_proxy_config_service->GetProxyConfig(kNetworkId, &ui_proxy_config);
106 EXPECT_EQ(UIProxyConfig::MODE_DIRECT, ui_proxy_config.mode);
107
108 // Set the profile pref to PAC script mode.
109 std::unique_ptr<base::DictionaryValue> proxy_config(
110 base::MakeUnique<base::DictionaryValue>());
111 proxy_config->SetString("mode", ProxyPrefs::kPacScriptProxyModeName);
112 proxy_config->SetString("pac_url", "http://proxy");
113 profile->GetPrefs()->Set(proxy_config::prefs::kProxy, *proxy_config.get());
114 base::RunLoop().RunUntilIdle();
115
116 // Mode should now be MODE_PAC_SCRIPT.
117 NetworkHandler::Get()->ui_proxy_config_service()->GetProxyConfig(
118 kNetworkId, &ui_proxy_config);
119 EXPECT_EQ(UIProxyConfig::MODE_PAC_SCRIPT, ui_proxy_config.mode);
120 }
121
122 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698