| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/apps/app_browsertest_util.h" | 5 #include "chrome/browser/apps/app_browsertest_util.h" |
| 6 #include "chrome/browser/extensions/extension_apitest.h" | 6 #include "chrome/browser/extensions/extension_apitest.h" |
| 7 #include "chrome/browser/extensions/extension_function_test_utils.h" | 7 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 8 #include "chrome/browser/extensions/test_extension_dir.h" | 8 #include "chrome/browser/extensions/test_extension_dir.h" |
| 9 #include "chrome/test/base/ui_test_utils.h" | 9 #include "chrome/test/base/ui_test_utils.h" |
| 10 #include "content/public/browser/notification_service.h" | 10 #include "content/public/browser/notification_service.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 break; | 121 break; |
| 122 } else { | 122 } else { |
| 123 load_observer.Wait(); | 123 load_observer.Wait(); |
| 124 WaitForExtensionViewsToLoad(); | 124 WaitForExtensionViewsToLoad(); |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 ASSERT_TRUE( | 127 ASSERT_TRUE( |
| 128 registry->GetExtensionById(extension_id, ExtensionRegistry::TERMINATED)); | 128 registry->GetExtensionById(extension_id, ExtensionRegistry::TERMINATED)); |
| 129 } | 129 } |
| 130 | 130 |
| 131 namespace { |
| 132 |
| 133 // An intercepter of the real RuntimeAPIDelegate that simulates a successful |
| 134 // restart request every time. |
| 135 class RestartOnWatchdogApiDelegate : public RuntimeAPIDelegate { |
| 136 public: |
| 137 // Takes ownership of the |real_api_delegate|. |
| 138 RestartOnWatchdogApiDelegate( |
| 139 std::unique_ptr<RuntimeAPIDelegate> real_api_delegate) |
| 140 : real_api_delegate_(std::move(real_api_delegate)) {} |
| 141 ~RestartOnWatchdogApiDelegate() override {} |
| 142 |
| 143 // RuntimeAPIDelegate: |
| 144 void AddUpdateObserver(UpdateObserver* observer) override { |
| 145 real_api_delegate_->AddUpdateObserver(observer); |
| 146 } |
| 147 |
| 148 void RemoveUpdateObserver(UpdateObserver* observer) override { |
| 149 real_api_delegate_->RemoveUpdateObserver(observer); |
| 150 } |
| 151 |
| 152 base::Version GetPreviousExtensionVersion( |
| 153 const Extension* extension) override { |
| 154 return real_api_delegate_->GetPreviousExtensionVersion(extension); |
| 155 } |
| 156 |
| 157 void ReloadExtension(const std::string& extension_id) override { |
| 158 real_api_delegate_->ReloadExtension(extension_id); |
| 159 } |
| 160 |
| 161 bool CheckForUpdates(const std::string& extension_id, |
| 162 const UpdateCheckCallback& callback) override { |
| 163 return real_api_delegate_->CheckForUpdates(extension_id, callback); |
| 164 } |
| 165 |
| 166 void OpenURL(const GURL& uninstall_url) override { |
| 167 real_api_delegate_->OpenURL(uninstall_url); |
| 168 } |
| 169 |
| 170 bool GetPlatformInfo(api::runtime::PlatformInfo* info) override { |
| 171 return real_api_delegate_->GetPlatformInfo(info); |
| 172 } |
| 173 |
| 174 bool RestartDevice(std::string* error_message) override { |
| 175 *error_message = "success"; |
| 176 return true; |
| 177 } |
| 178 |
| 179 private: |
| 180 std::unique_ptr<RuntimeAPIDelegate> real_api_delegate_; |
| 181 |
| 182 DISALLOW_COPY_AND_ASSIGN(RestartOnWatchdogApiDelegate); |
| 183 }; |
| 184 |
| 185 } // namespace |
| 186 |
| 187 class RestartOnWatchdogApiTest : public ExtensionApiTest { |
| 188 public: |
| 189 RestartOnWatchdogApiTest() {} |
| 190 ~RestartOnWatchdogApiTest() override {} |
| 191 |
| 192 void SetUpOnMainThread() override { |
| 193 RuntimeAPI* runtime_api = RuntimeAPI::GetFactoryInstance()->Get(profile()); |
| 194 runtime_api->delegate_.reset( |
| 195 new RestartOnWatchdogApiDelegate(std::move(runtime_api->delegate_))); |
| 196 runtime_api->SetMinDurationBetweenRestartsForTesting( |
| 197 base::TimeDelta::FromSeconds(3)); |
| 198 |
| 199 ExtensionApiTest::SetUpOnMainThread(); |
| 200 } |
| 201 |
| 202 private: |
| 203 DISALLOW_COPY_AND_ASSIGN(RestartOnWatchdogApiTest); |
| 204 }; |
| 205 |
| 206 IN_PROC_BROWSER_TEST_F(RestartOnWatchdogApiTest, RestartOnWatchdogTest) { |
| 207 ASSERT_TRUE(RunExtensionTest("runtime/restartOnWatchdog")) << message_; |
| 208 } |
| 209 |
| 131 } // namespace extensions | 210 } // namespace extensions |
| OLD | NEW |