OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/chromeos/power/extension_event_observer.h" | 5 #include "chrome/browser/chromeos/power/extension_event_observer.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
7 #include <string> | 9 #include <string> |
8 | 10 |
9 #include "base/macros.h" | 11 #include "base/macros.h" |
10 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
12 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
13 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 15 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
14 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 16 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
15 #include "chrome/browser/chromeos/settings/cros_settings.h" | 17 #include "chrome/browser/chromeos/settings/cros_settings.h" |
16 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 18 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 // Tests that network requests started by an app while it is processing a push | 239 // Tests that network requests started by an app while it is processing a push |
238 // message delay any suspend attempt. | 240 // message delay any suspend attempt. |
239 TEST_F(ExtensionEventObserverTest, NetworkRequestsMayDelaySuspend) { | 241 TEST_F(ExtensionEventObserverTest, NetworkRequestsMayDelaySuspend) { |
240 scoped_refptr<extensions::Extension> app = CreateApp("NetworkRequests", true); | 242 scoped_refptr<extensions::Extension> app = CreateApp("NetworkRequests", true); |
241 extensions::ExtensionHost* host = CreateHostForApp(profile_, app.get()); | 243 extensions::ExtensionHost* host = CreateHostForApp(profile_, app.get()); |
242 ASSERT_TRUE(host); | 244 ASSERT_TRUE(host); |
243 EXPECT_TRUE(test_api_->WillDelaySuspendForExtensionHost(host)); | 245 EXPECT_TRUE(test_api_->WillDelaySuspendForExtensionHost(host)); |
244 | 246 |
245 // Test that network requests started while there is no pending push message | 247 // Test that network requests started while there is no pending push message |
246 // are ignored. | 248 // are ignored. |
247 const uint64 kNonPushRequestId = 5170725; | 249 const uint64_t kNonPushRequestId = 5170725; |
248 extension_event_observer_->OnNetworkRequestStarted(host, kNonPushRequestId); | 250 extension_event_observer_->OnNetworkRequestStarted(host, kNonPushRequestId); |
249 power_manager_client_->SendSuspendImminent(); | 251 power_manager_client_->SendSuspendImminent(); |
250 | 252 |
251 EXPECT_TRUE(test_api_->MaybeRunSuspendReadinessCallback()); | 253 EXPECT_TRUE(test_api_->MaybeRunSuspendReadinessCallback()); |
252 EXPECT_EQ(0, power_manager_client_->GetNumPendingSuspendReadinessCallbacks()); | 254 EXPECT_EQ(0, power_manager_client_->GetNumPendingSuspendReadinessCallbacks()); |
253 | 255 |
254 // Test that network requests started while a push message is pending delay | 256 // Test that network requests started while a push message is pending delay |
255 // the suspend even after the push message has been acked. | 257 // the suspend even after the push message has been acked. |
256 const int kPushMessageId = 178674; | 258 const int kPushMessageId = 178674; |
257 const uint64 kNetworkRequestId = 78917089; | 259 const uint64_t kNetworkRequestId = 78917089; |
258 power_manager_client_->SendDarkSuspendImminent(); | 260 power_manager_client_->SendDarkSuspendImminent(); |
259 extension_event_observer_->OnBackgroundEventDispatched( | 261 extension_event_observer_->OnBackgroundEventDispatched( |
260 host, extensions::api::gcm::OnMessage::kEventName, kPushMessageId); | 262 host, extensions::api::gcm::OnMessage::kEventName, kPushMessageId); |
261 | 263 |
262 EXPECT_TRUE(test_api_->MaybeRunSuspendReadinessCallback()); | 264 EXPECT_TRUE(test_api_->MaybeRunSuspendReadinessCallback()); |
263 EXPECT_EQ(1, power_manager_client_->GetNumPendingSuspendReadinessCallbacks()); | 265 EXPECT_EQ(1, power_manager_client_->GetNumPendingSuspendReadinessCallbacks()); |
264 | 266 |
265 extension_event_observer_->OnNetworkRequestStarted(host, kNetworkRequestId); | 267 extension_event_observer_->OnNetworkRequestStarted(host, kNetworkRequestId); |
266 extension_event_observer_->OnBackgroundEventAcked(host, kPushMessageId); | 268 extension_event_observer_->OnBackgroundEventAcked(host, kPushMessageId); |
267 EXPECT_EQ(1, power_manager_client_->GetNumPendingSuspendReadinessCallbacks()); | 269 EXPECT_EQ(1, power_manager_client_->GetNumPendingSuspendReadinessCallbacks()); |
(...skipping 11 matching lines...) Expand all Loading... |
279 // The easiest way to delete an extension host is to delete the Profile it is | 281 // The easiest way to delete an extension host is to delete the Profile it is |
280 // associated with so we create a new Profile here. | 282 // associated with so we create a new Profile here. |
281 const char kProfileName[] = "DeletedExtensionHostProfile"; | 283 const char kProfileName[] = "DeletedExtensionHostProfile"; |
282 Profile* new_profile = profile_manager_->CreateTestingProfile(kProfileName); | 284 Profile* new_profile = profile_manager_->CreateTestingProfile(kProfileName); |
283 | 285 |
284 extensions::ExtensionHost* host = CreateHostForApp(new_profile, app.get()); | 286 extensions::ExtensionHost* host = CreateHostForApp(new_profile, app.get()); |
285 ASSERT_TRUE(host); | 287 ASSERT_TRUE(host); |
286 EXPECT_TRUE(test_api_->WillDelaySuspendForExtensionHost(host)); | 288 EXPECT_TRUE(test_api_->WillDelaySuspendForExtensionHost(host)); |
287 | 289 |
288 const int kPushId = 156178; | 290 const int kPushId = 156178; |
289 const uint64 kNetworkId = 791605; | 291 const uint64_t kNetworkId = 791605; |
290 extension_event_observer_->OnBackgroundEventDispatched( | 292 extension_event_observer_->OnBackgroundEventDispatched( |
291 host, extensions::api::gcm::OnMessage::kEventName, kPushId); | 293 host, extensions::api::gcm::OnMessage::kEventName, kPushId); |
292 extension_event_observer_->OnNetworkRequestStarted(host, kNetworkId); | 294 extension_event_observer_->OnNetworkRequestStarted(host, kNetworkId); |
293 | 295 |
294 // Now delete the Profile. This has the side-effect of also deleting all the | 296 // Now delete the Profile. This has the side-effect of also deleting all the |
295 // ExtensionHosts. | 297 // ExtensionHosts. |
296 profile_manager_->DeleteTestingProfile(kProfileName); | 298 profile_manager_->DeleteTestingProfile(kProfileName); |
297 | 299 |
298 power_manager_client_->SendSuspendImminent(); | 300 power_manager_client_->SendSuspendImminent(); |
299 EXPECT_TRUE(test_api_->MaybeRunSuspendReadinessCallback()); | 301 EXPECT_TRUE(test_api_->MaybeRunSuspendReadinessCallback()); |
(...skipping 21 matching lines...) Expand all Loading... |
321 EXPECT_FALSE(test_api_->MaybeRunSuspendReadinessCallback()); | 323 EXPECT_FALSE(test_api_->MaybeRunSuspendReadinessCallback()); |
322 EXPECT_EQ(0, power_manager_client_->GetNumPendingSuspendReadinessCallbacks()); | 324 EXPECT_EQ(0, power_manager_client_->GetNumPendingSuspendReadinessCallbacks()); |
323 | 325 |
324 // Test that the ExtensionEventObserver does not delay suspend attempts when | 326 // Test that the ExtensionEventObserver does not delay suspend attempts when |
325 // it is disabled. | 327 // it is disabled. |
326 power_manager_client_->SendDarkSuspendImminent(); | 328 power_manager_client_->SendDarkSuspendImminent(); |
327 EXPECT_EQ(0, power_manager_client_->GetNumPendingSuspendReadinessCallbacks()); | 329 EXPECT_EQ(0, power_manager_client_->GetNumPendingSuspendReadinessCallbacks()); |
328 } | 330 } |
329 | 331 |
330 } // namespace chromeos | 332 } // namespace chromeos |
OLD | NEW |