OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2015 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/status/data_promo_notification.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/run_loop.h" | |
9 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | |
10 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | |
11 #include "chrome/test/base/testing_browser_process.h" | |
12 #include "chrome/test/base/testing_profile_manager.h" | |
13 #include "chromeos/chromeos_switches.h" | |
14 #include "chromeos/dbus/dbus_thread_manager.h" | |
15 #include "chromeos/dbus/shill_device_client.h" | |
16 #include "chromeos/dbus/shill_service_client.h" | |
17 #include "chromeos/login/login_state.h" | |
18 #include "chromeos/network/network_state_handler.h" | |
19 #include "testing/platform_test.h" | |
20 #include "third_party/cros_system_api/dbus/service_constants.h" | |
21 #include "ui/chromeos/network/network_connect.h" | |
22 #include "ui/message_center/message_center.h" | |
23 | |
24 namespace { | |
25 | |
26 const char kCellularServicePath[] = "/service/cellular1"; | |
27 | |
28 class NetworkConnectTestDelegate : public ui::NetworkConnect::Delegate { | |
29 public: | |
30 NetworkConnectTestDelegate() {} | |
31 ~NetworkConnectTestDelegate() override {} | |
32 | |
33 void ShowNetworkConfigure(const std::string& network_id) override {} | |
34 void ShowNetworkSettingsForGuid(const std::string& network_id) override {} | |
35 bool ShowEnrollNetwork(const std::string& network_id) override { | |
36 return false; | |
37 } | |
38 void ShowMobileSimDialog() override {} | |
39 void ShowMobileSetupDialog(const std::string& service_path) override {} | |
40 | |
41 private: | |
42 DISALLOW_COPY_AND_ASSIGN(NetworkConnectTestDelegate); | |
43 }; | |
44 | |
45 } // namespace | |
46 | |
47 namespace chromeos { | |
48 namespace test { | |
49 | |
50 class DataPromoNotificationTest : public testing::Test { | |
51 public: | |
52 DataPromoNotificationTest() {} | |
53 ~DataPromoNotificationTest() override {} | |
54 | |
55 void SetUp() override { | |
56 testing::Test::SetUp(); | |
57 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
58 switches::kEnableDataSaverPrompt); | |
59 DBusThreadManager::Initialize(); | |
60 NetworkHandler::Initialize(); | |
61 data_promo_notification_.reset(new DataPromoNotification); | |
62 SetupUser(); | |
63 SetupNetworkShillState(); | |
64 message_center::MessageCenter::Initialize(); | |
65 base::RunLoop().RunUntilIdle(); | |
66 network_connect_delegate_.reset(new NetworkConnectTestDelegate); | |
67 ui::NetworkConnect::Initialize(network_connect_delegate_.get()); | |
68 } | |
69 | |
70 void TearDown() override { | |
71 ui::NetworkConnect::Shutdown(); | |
72 network_connect_delegate_.reset(); | |
73 message_center::MessageCenter::Shutdown(); | |
74 LoginState::Shutdown(); | |
75 profile_manager_.reset(); | |
76 user_manager_enabler_.reset(); | |
77 data_promo_notification_.reset(); | |
78 NetworkHandler::Shutdown(); | |
79 DBusThreadManager::Shutdown(); | |
80 testing::Test::TearDown(); | |
81 } | |
82 | |
83 protected: | |
84 void SetupUser() { | |
85 FakeChromeUserManager* user_manager = new FakeChromeUserManager(); | |
Greg Levin
2015/04/27 23:03:08
Does this need a matching delete somewhere? I cop
stevenjb
2015/04/28 22:32:59
No, because we are passing ownership to user_manag
Greg Levin
2015/04/29 14:46:09
Ok, got it, thanks! I rearranged a couple lines t
| |
86 user_manager_enabler_.reset(new ScopedUserManagerEnabler(user_manager)); | |
87 | |
88 const char kTestUserName[] = "test-user@example.com"; | |
89 user_manager->AddUser(kTestUserName); | |
90 user_manager->LoginUser(kTestUserName); | |
91 | |
92 profile_manager_.reset( | |
93 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); | |
94 ASSERT_TRUE(profile_manager_->SetUp()); | |
95 profile_manager_->SetLoggedIn(true); | |
96 ASSERT_TRUE(user_manager::UserManager::Get()->GetPrimaryUser()); | |
97 | |
98 LoginState::Initialize(); | |
99 LoginState::Get()->SetLoggedInState(LoginState::LOGGED_IN_ACTIVE, | |
100 LoginState::LOGGED_IN_USER_REGULAR); | |
101 } | |
102 | |
103 void SetupNetworkShillState() { | |
104 base::RunLoop().RunUntilIdle(); | |
105 | |
106 // Create a cellular device with provider. | |
107 ShillDeviceClient::TestInterface* device_test = | |
108 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); | |
109 device_test->ClearDevices(); | |
110 const char kCellularDevicePath[] = "/device/stub_cellular_device1"; | |
Greg Levin
2015/04/27 23:03:08
1) Do we prefer "const char" or "const std::string
stevenjb
2015/04/28 22:32:59
1) Outside of the scope of a function or class we
Greg Levin
2015/04/29 14:46:09
Done.
| |
111 device_test->AddDevice(kCellularDevicePath, shill::kTypeCellular, | |
112 "stub_cellular_device1"); | |
113 base::DictionaryValue home_provider; | |
114 home_provider.SetString("name", "Cellular1_Provider"); | |
115 home_provider.SetString("country", "us"); | |
116 device_test->SetDeviceProperty(kCellularDevicePath, | |
117 shill::kHomeProviderProperty, home_provider); | |
118 | |
119 // Create a cellular network and activate it. | |
120 ShillServiceClient::TestInterface* service_test = | |
121 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | |
122 service_test->ClearServices(); | |
123 service_test->AddService(kCellularServicePath, "cellular1_guid", | |
124 "cellular1" /* name */, shill::kTypeCellular, | |
125 "activated", true /* visible */); | |
126 service_test->SetServiceProperty( | |
127 kCellularServicePath, shill::kActivationStateProperty, | |
128 base::StringValue(shill::kActivationStateActivated)); | |
129 service_test->SetServiceProperty(kCellularServicePath, | |
130 shill::kConnectableProperty, | |
131 base::FundamentalValue(true)); | |
132 } | |
133 | |
134 scoped_ptr<DataPromoNotification> data_promo_notification_; | |
135 scoped_ptr<NetworkConnectTestDelegate> network_connect_delegate_; | |
136 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_; | |
137 scoped_ptr<TestingProfileManager> profile_manager_; | |
138 base::MessageLoop message_loop_; | |
139 | |
140 private: | |
141 DISALLOW_COPY_AND_ASSIGN(DataPromoNotificationTest); | |
142 }; | |
143 | |
144 TEST_F(DataPromoNotificationTest, DataSaverNotification) { | |
145 message_center::MessageCenter* message_center = | |
146 message_center::MessageCenter::Get(); | |
147 | |
148 // Network setup shouldn't be enough to activate notification. | |
149 const char kNotificationId[] = "chrome://settings/internet/data_saver"; | |
150 EXPECT_FALSE(message_center->FindVisibleNotificationById(kNotificationId)); | |
151 | |
152 ui::NetworkConnect::Get()->ConnectToNetwork(kCellularServicePath); | |
153 base::RunLoop().RunUntilIdle(); | |
154 // Connecting to cellular network (which here makes it the default network) | |
155 // should trigger the Data Saver notification. | |
156 EXPECT_TRUE(message_center->FindVisibleNotificationById(kNotificationId)); | |
157 } | |
158 | |
159 } // namespace test | |
160 } // namespace chromeos | |
OLD | NEW |