OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/prefs/testing_pref_service.h" | 5 #include "base/prefs/testing_pref_service.h" |
6 #include "chrome/browser/web_resource/eula_accepted_notifier.h" | 6 #include "chrome/browser/web_resource/eula_accepted_notifier.h" |
7 #include "chrome/browser/web_resource/resource_request_allowed_notifier_test_uti l.h" | 7 #include "chrome/browser/web_resource/resource_request_allowed_notifier_test_uti l.h" |
8 #include "chrome/common/chrome_notification_types.h" | 8 #include "chrome/common/chrome_notification_types.h" |
9 #include "chrome/test/base/testing_browser_process.h" | 9 #include "chrome/test/base/testing_browser_process.h" |
10 #include "content/public/browser/notification_service.h" | 10 #include "content/public/browser/notification_service.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 // Network manipulation methods: | 96 // Network manipulation methods: |
97 void SetWaitingForNetwork(bool waiting) { | 97 void SetWaitingForNetwork(bool waiting) { |
98 resource_request_allowed_notifier_.SetWaitingForNetworkForTesting(waiting); | 98 resource_request_allowed_notifier_.SetWaitingForNetworkForTesting(waiting); |
99 } | 99 } |
100 | 100 |
101 void SimulateNetworkConnectionChange( | 101 void SimulateNetworkConnectionChange( |
102 net::NetworkChangeNotifier::ConnectionType type) { | 102 net::NetworkChangeNotifier::ConnectionType type) { |
103 network_notifier.SimulateNetworkConnectionChange(type); | 103 network_notifier.SimulateNetworkConnectionChange(type); |
104 } | 104 } |
105 | 105 |
106 // Simulate a resource request from the test service. | 106 // Simulate a resource request from the test service. |
Alexei Svitkine (slow)
2013/06/14 16:47:59
Nit: Update comment to explain return value.
Takashi Toyoshima
2013/06/17 07:04:40
Done.
| |
107 void SimulateResourceRequest() { | 107 bool SimulateResourceRequest() { |
108 resource_request_allowed_notifier_.ResourceRequestsAllowed(); | 108 return resource_request_allowed_notifier_.ResourceRequestsAllowed(); |
109 } | 109 } |
110 | 110 |
111 void SimulateEulaAccepted() { | 111 void SimulateEulaAccepted() { |
112 eula_notifier_->SimulateEulaAccepted(); | 112 eula_notifier_->SimulateEulaAccepted(); |
113 } | 113 } |
114 | 114 |
115 // Eula manipulation methods: | 115 // Eula manipulation methods: |
116 void SetNeedsEulaAcceptance(bool needs_acceptance) { | 116 void SetNeedsEulaAcceptance(bool needs_acceptance) { |
117 eula_notifier_->SetEulaAcceptedForTesting(!needs_acceptance); | 117 eula_notifier_->SetEulaAcceptedForTesting(!needs_acceptance); |
118 } | 118 } |
(...skipping 26 matching lines...) Expand all Loading... | |
145 content::TestBrowserThread ui_thread; | 145 content::TestBrowserThread ui_thread; |
146 TestNetworkChangeNotifier network_notifier; | 146 TestNetworkChangeNotifier network_notifier; |
147 TestRequestAllowedNotifier resource_request_allowed_notifier_; | 147 TestRequestAllowedNotifier resource_request_allowed_notifier_; |
148 TestEulaAcceptedNotifier* eula_notifier_; // Weak, owned by RRAN. | 148 TestEulaAcceptedNotifier* eula_notifier_; // Weak, owned by RRAN. |
149 bool was_notified_; | 149 bool was_notified_; |
150 | 150 |
151 DISALLOW_COPY_AND_ASSIGN(ResourceRequestAllowedNotifierTest); | 151 DISALLOW_COPY_AND_ASSIGN(ResourceRequestAllowedNotifierTest); |
152 }; | 152 }; |
153 | 153 |
154 TEST_F(ResourceRequestAllowedNotifierTest, DoNotNotifyIfOffline) { | 154 TEST_F(ResourceRequestAllowedNotifierTest, DoNotNotifyIfOffline) { |
155 SimulateResourceRequest(); | |
Takashi Toyoshima
2013/06/14 08:27:29
In this order, ResourceRequest always return true
| |
156 SetWaitingForNetwork(true); | 155 SetWaitingForNetwork(true); |
156 EXPECT_FALSE(SimulateResourceRequest()); | |
157 SimulateNetworkConnectionChange(net::NetworkChangeNotifier::CONNECTION_NONE); | 157 SimulateNetworkConnectionChange(net::NetworkChangeNotifier::CONNECTION_NONE); |
158 EXPECT_FALSE(was_notified()); | 158 EXPECT_FALSE(was_notified()); |
159 } | 159 } |
160 | 160 |
161 TEST_F(ResourceRequestAllowedNotifierTest, DoNotNotifyIfOnlineToOnline) { | 161 TEST_F(ResourceRequestAllowedNotifierTest, DoNotNotifyIfOnlineToOnline) { |
162 SimulateResourceRequest(); | |
163 SetWaitingForNetwork(false); | 162 SetWaitingForNetwork(false); |
163 EXPECT_TRUE(SimulateResourceRequest()); | |
164 SimulateNetworkConnectionChange( | 164 SimulateNetworkConnectionChange( |
165 net::NetworkChangeNotifier::CONNECTION_ETHERNET); | 165 net::NetworkChangeNotifier::CONNECTION_ETHERNET); |
166 EXPECT_FALSE(was_notified()); | 166 EXPECT_FALSE(was_notified()); |
167 } | 167 } |
168 | 168 |
169 TEST_F(ResourceRequestAllowedNotifierTest, NotifyOnReconnect) { | 169 TEST_F(ResourceRequestAllowedNotifierTest, NotifyOnReconnect) { |
Takashi Toyoshima
2013/06/14 08:27:29
This test is problem 2) of crbug.
But doesn't work
| |
170 SimulateResourceRequest(); | |
171 SetWaitingForNetwork(true); | 170 SetWaitingForNetwork(true); |
171 EXPECT_FALSE(SimulateResourceRequest()); | |
172 SimulateNetworkConnectionChange( | 172 SimulateNetworkConnectionChange( |
173 net::NetworkChangeNotifier::CONNECTION_ETHERNET); | 173 net::NetworkChangeNotifier::CONNECTION_ETHERNET); |
174 EXPECT_TRUE(was_notified()); | 174 EXPECT_TRUE(was_notified()); |
175 } | 175 } |
176 | 176 |
177 TEST_F(ResourceRequestAllowedNotifierTest, NoNotifyOnWardriving) { | 177 TEST_F(ResourceRequestAllowedNotifierTest, NoNotifyOnWardriving) { |
178 SimulateResourceRequest(); | |
179 SetWaitingForNetwork(false); | 178 SetWaitingForNetwork(false); |
179 EXPECT_TRUE(SimulateResourceRequest()); | |
180 SimulateNetworkConnectionChange( | 180 SimulateNetworkConnectionChange( |
181 net::NetworkChangeNotifier::CONNECTION_WIFI); | 181 net::NetworkChangeNotifier::CONNECTION_WIFI); |
182 EXPECT_FALSE(was_notified()); | 182 EXPECT_FALSE(was_notified()); |
183 SimulateNetworkConnectionChange( | 183 SimulateNetworkConnectionChange( |
184 net::NetworkChangeNotifier::CONNECTION_3G); | 184 net::NetworkChangeNotifier::CONNECTION_3G); |
185 EXPECT_FALSE(was_notified()); | 185 EXPECT_FALSE(was_notified()); |
186 SimulateNetworkConnectionChange( | 186 SimulateNetworkConnectionChange( |
187 net::NetworkChangeNotifier::CONNECTION_4G); | 187 net::NetworkChangeNotifier::CONNECTION_4G); |
188 EXPECT_FALSE(was_notified()); | 188 EXPECT_FALSE(was_notified()); |
189 SimulateNetworkConnectionChange( | 189 SimulateNetworkConnectionChange( |
190 net::NetworkChangeNotifier::CONNECTION_WIFI); | 190 net::NetworkChangeNotifier::CONNECTION_WIFI); |
191 EXPECT_FALSE(was_notified()); | 191 EXPECT_FALSE(was_notified()); |
192 } | 192 } |
193 | 193 |
194 TEST_F(ResourceRequestAllowedNotifierTest, NoNotifyOnFlakyConnection) { | 194 TEST_F(ResourceRequestAllowedNotifierTest, NotifyOnFlakyConnection) { |
Alexei Svitkine (slow)
2013/06/14 16:47:59
This test makes sense.
I think it's different fro
Takashi Toyoshima
2013/06/17 07:04:40
Oh, I see.
I'll leave original one separately.
| |
195 SimulateResourceRequest(); | |
196 SetWaitingForNetwork(false); | 195 SetWaitingForNetwork(false); |
196 EXPECT_TRUE(SimulateResourceRequest()); | |
197 SimulateNetworkConnectionChange( | |
198 net::NetworkChangeNotifier::CONNECTION_WIFI); | |
199 EXPECT_FALSE(was_notified()); | |
Takashi Toyoshima
2013/06/14 08:27:29
Network goes online, but not notified because Simu
Alexei Svitkine (slow)
2013/06/14 16:47:59
Add it as a comment in the test.
Takashi Toyoshima
2013/06/17 07:04:40
Done.
| |
200 SimulateNetworkConnectionChange( | |
201 net::NetworkChangeNotifier::CONNECTION_NONE); | |
202 EXPECT_FALSE(SimulateResourceRequest()); | |
Takashi Toyoshima
2013/06/14 08:27:29
Now, SimulateResourceRequest() returns false and w
Alexei Svitkine (slow)
2013/06/14 16:47:59
Add it as a comment in the test.
Takashi Toyoshima
2013/06/17 07:04:40
Done.
| |
203 EXPECT_FALSE(was_notified()); | |
204 SimulateNetworkConnectionChange( | |
205 net::NetworkChangeNotifier::CONNECTION_WIFI); | |
206 EXPECT_TRUE(was_notified()); | |
Takashi Toyoshima
2013/06/14 08:27:29
Yep, this time, it must be notified.
| |
207 } | |
208 | |
209 TEST_F(ResourceRequestAllowedNotifierTest, NoNotifyOnEulaAfterGoOffline) { | |
Takashi Toyoshima
2013/06/14 08:27:29
This test is problem 1) of crbug.
| |
210 DisableEulaAndNetwork(); | |
211 EXPECT_FALSE(SimulateResourceRequest()); | |
212 | |
197 SimulateNetworkConnectionChange( | 213 SimulateNetworkConnectionChange( |
198 net::NetworkChangeNotifier::CONNECTION_WIFI); | 214 net::NetworkChangeNotifier::CONNECTION_WIFI); |
199 EXPECT_FALSE(was_notified()); | 215 EXPECT_FALSE(was_notified()); |
200 SimulateNetworkConnectionChange( | 216 SimulateNetworkConnectionChange( |
201 net::NetworkChangeNotifier::CONNECTION_NONE); | 217 net::NetworkChangeNotifier::CONNECTION_NONE); |
202 EXPECT_FALSE(was_notified()); | 218 EXPECT_FALSE(was_notified()); |
203 SimulateNetworkConnectionChange( | 219 SimulateEulaAccepted(); |
204 net::NetworkChangeNotifier::CONNECTION_WIFI); | |
205 EXPECT_FALSE(was_notified()); | 220 EXPECT_FALSE(was_notified()); |
206 } | 221 } |
207 | 222 |
208 TEST_F(ResourceRequestAllowedNotifierTest, NoRequestNoNotify) { | 223 TEST_F(ResourceRequestAllowedNotifierTest, NoRequestNoNotify) { |
209 // Ensure that if the observing service does not request access, it does not | 224 // Ensure that if the observing service does not request access, it does not |
210 // get notified, even if the criteria is met. Note that this is done by not | 225 // get notified, even if the criteria is met. Note that this is done by not |
211 // calling SimulateResourceRequest here. | 226 // calling SimulateResourceRequest here. |
212 SetWaitingForNetwork(true); | 227 SetWaitingForNetwork(true); |
213 SimulateNetworkConnectionChange( | 228 SimulateNetworkConnectionChange( |
214 net::NetworkChangeNotifier::CONNECTION_ETHERNET); | 229 net::NetworkChangeNotifier::CONNECTION_ETHERNET); |
215 EXPECT_FALSE(was_notified()); | 230 EXPECT_FALSE(was_notified()); |
216 } | 231 } |
217 | 232 |
218 TEST_F(ResourceRequestAllowedNotifierTest, EulaOnlyNetworkOffline) { | 233 TEST_F(ResourceRequestAllowedNotifierTest, EulaOnlyNetworkOffline) { |
219 SimulateResourceRequest(); | |
220 DisableEulaAndNetwork(); | 234 DisableEulaAndNetwork(); |
235 EXPECT_FALSE(SimulateResourceRequest()); | |
221 | 236 |
222 SimulateEulaAccepted(); | 237 SimulateEulaAccepted(); |
223 EXPECT_FALSE(was_notified()); | 238 EXPECT_FALSE(was_notified()); |
224 } | 239 } |
225 | 240 |
226 TEST_F(ResourceRequestAllowedNotifierTest, EulaFirst) { | 241 TEST_F(ResourceRequestAllowedNotifierTest, EulaFirst) { |
Takashi Toyoshima
2013/06/14 08:27:29
This test is problem 3) of crbug.
Also doesn't wor
| |
227 SimulateResourceRequest(); | |
228 DisableEulaAndNetwork(); | 242 DisableEulaAndNetwork(); |
243 EXPECT_FALSE(SimulateResourceRequest()); | |
229 | 244 |
230 SimulateEulaAccepted(); | 245 SimulateEulaAccepted(); |
231 EXPECT_FALSE(was_notified()); | 246 EXPECT_FALSE(was_notified()); |
232 | 247 |
233 SimulateNetworkConnectionChange( | 248 SimulateNetworkConnectionChange( |
234 net::NetworkChangeNotifier::CONNECTION_WIFI); | 249 net::NetworkChangeNotifier::CONNECTION_WIFI); |
235 EXPECT_TRUE(was_notified()); | 250 EXPECT_TRUE(was_notified()); |
236 } | 251 } |
237 | 252 |
238 TEST_F(ResourceRequestAllowedNotifierTest, NetworkFirst) { | 253 TEST_F(ResourceRequestAllowedNotifierTest, NetworkFirst) { |
239 SimulateResourceRequest(); | |
240 DisableEulaAndNetwork(); | 254 DisableEulaAndNetwork(); |
255 EXPECT_FALSE(SimulateResourceRequest()); | |
241 | 256 |
242 SimulateNetworkConnectionChange( | 257 SimulateNetworkConnectionChange( |
243 net::NetworkChangeNotifier::CONNECTION_WIFI); | 258 net::NetworkChangeNotifier::CONNECTION_WIFI); |
244 EXPECT_FALSE(was_notified()); | 259 EXPECT_FALSE(was_notified()); |
245 | 260 |
246 SimulateEulaAccepted(); | 261 SimulateEulaAccepted(); |
247 EXPECT_TRUE(was_notified()); | 262 EXPECT_TRUE(was_notified()); |
248 } | 263 } |
249 | 264 |
250 TEST_F(ResourceRequestAllowedNotifierTest, NoRequestNoNotifyEula) { | 265 TEST_F(ResourceRequestAllowedNotifierTest, NoRequestNoNotifyEula) { |
251 // Ensure that if the observing service does not request access, it does not | 266 // Ensure that if the observing service does not request access, it does not |
252 // get notified, even if the criteria is met. Note that this is done by not | 267 // get notified, even if the criteria is met. Note that this is done by not |
253 // calling SimulateResourceRequest here. | 268 // calling SimulateResourceRequest here. |
254 DisableEulaAndNetwork(); | 269 DisableEulaAndNetwork(); |
255 | 270 |
256 SimulateNetworkConnectionChange( | 271 SimulateNetworkConnectionChange( |
257 net::NetworkChangeNotifier::CONNECTION_WIFI); | 272 net::NetworkChangeNotifier::CONNECTION_WIFI); |
258 EXPECT_FALSE(was_notified()); | 273 EXPECT_FALSE(was_notified()); |
259 | 274 |
260 SimulateEulaAccepted(); | 275 SimulateEulaAccepted(); |
261 EXPECT_FALSE(was_notified()); | 276 EXPECT_FALSE(was_notified()); |
262 } | 277 } |
OLD | NEW |