| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/callback_helpers.h" | 5 #include "base/callback_helpers.h" |
| 6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "components/pref_registry/pref_registry_syncable.h" | 7 #include "components/pref_registry/pref_registry_syncable.h" |
| 8 #include "components/pref_registry/testing_pref_service_syncable.h" | 8 #include "components/sync_preferences/testing_pref_service_syncable.h" |
| 9 #include "extensions/browser/api/runtime/runtime_api.h" | 9 #include "extensions/browser/api/runtime/runtime_api.h" |
| 10 #include "extensions/browser/api_test_utils.h" | 10 #include "extensions/browser/api_test_utils.h" |
| 11 #include "extensions/browser/api_unittest.h" | 11 #include "extensions/browser/api_unittest.h" |
| 12 #include "extensions/browser/test_extensions_browser_client.h" | 12 #include "extensions/browser/test_extensions_browser_client.h" |
| 13 #include "extensions/browser/test_runtime_api_delegate.h" | 13 #include "extensions/browser/test_runtime_api_delegate.h" |
| 14 #include "extensions/common/manifest.h" | 14 #include "extensions/common/manifest.h" |
| 15 | 15 |
| 16 namespace extensions { | 16 namespace extensions { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 return &testing_pref_service_; | 65 return &testing_pref_service_; |
| 66 } | 66 } |
| 67 | 67 |
| 68 std::unique_ptr<RuntimeAPIDelegate> CreateRuntimeAPIDelegate( | 68 std::unique_ptr<RuntimeAPIDelegate> CreateRuntimeAPIDelegate( |
| 69 content::BrowserContext* context) const override { | 69 content::BrowserContext* context) const override { |
| 70 const_cast<DelayedRestartExtensionsBrowserClient*>(this)->api_delegate_ = | 70 const_cast<DelayedRestartExtensionsBrowserClient*>(this)->api_delegate_ = |
| 71 new DelayedRestartTestApiDelegate(); | 71 new DelayedRestartTestApiDelegate(); |
| 72 return base::WrapUnique(api_delegate_); | 72 return base::WrapUnique(api_delegate_); |
| 73 } | 73 } |
| 74 | 74 |
| 75 user_prefs::TestingPrefServiceSyncable* testing_pref_service() { | 75 sync_preferences::TestingPrefServiceSyncable* testing_pref_service() { |
| 76 return &testing_pref_service_; | 76 return &testing_pref_service_; |
| 77 } | 77 } |
| 78 | 78 |
| 79 DelayedRestartTestApiDelegate* api_delegate() const { | 79 DelayedRestartTestApiDelegate* api_delegate() const { |
| 80 CHECK(api_delegate_); | 80 CHECK(api_delegate_); |
| 81 return api_delegate_; | 81 return api_delegate_; |
| 82 } | 82 } |
| 83 | 83 |
| 84 private: | 84 private: |
| 85 DelayedRestartTestApiDelegate* api_delegate_ = nullptr; // Not owned. | 85 DelayedRestartTestApiDelegate* api_delegate_ = nullptr; // Not owned. |
| 86 | 86 |
| 87 user_prefs::TestingPrefServiceSyncable testing_pref_service_; | 87 sync_preferences::TestingPrefServiceSyncable testing_pref_service_; |
| 88 | 88 |
| 89 DISALLOW_COPY_AND_ASSIGN(DelayedRestartExtensionsBrowserClient); | 89 DISALLOW_COPY_AND_ASSIGN(DelayedRestartExtensionsBrowserClient); |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 } // namespace | 92 } // namespace |
| 93 | 93 |
| 94 class RestartAfterDelayApiTest : public ApiUnitTest { | 94 class RestartAfterDelayApiTest : public ApiUnitTest { |
| 95 public: | 95 public: |
| 96 RestartAfterDelayApiTest() {} | 96 RestartAfterDelayApiTest() {} |
| 97 ~RestartAfterDelayApiTest() override {} | 97 ~RestartAfterDelayApiTest() override {} |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 RunRestartAfterDelayFunction( | 238 RunRestartAfterDelayFunction( |
| 239 "[1]", "Restart was requested too soon. It was throttled instead."); | 239 "[1]", "Restart was requested too soon. It was throttled instead."); |
| 240 ASSERT_TRUE(IsDelayedRestartTimerRunning()); | 240 ASSERT_TRUE(IsDelayedRestartTimerRunning()); |
| 241 // Restart will happen 2 seconds later, even though the request was just one | 241 // Restart will happen 2 seconds later, even though the request was just one |
| 242 // second. | 242 // second. |
| 243 ASSERT_NEAR((desired_restart_time() - last_restart_time).InSecondsF(), | 243 ASSERT_NEAR((desired_restart_time() - last_restart_time).InSecondsF(), |
| 244 base::TimeDelta::FromSeconds(2).InSecondsF(), 0.5); | 244 base::TimeDelta::FromSeconds(2).InSecondsF(), 0.5); |
| 245 } | 245 } |
| 246 | 246 |
| 247 } // namespace extensions | 247 } // namespace extensions |
| OLD | NEW |