Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(516)

Side by Side Diff: extensions/browser/api/runtime/runtime_apitest.cc

Issue 1970613003: Add a new app API to enable watchdog behavior restarts in kiosk apps (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase + Nits Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 runtime_api->AllowNonKiostAppsInRestartOnWatchdogForTesting();
199
200 ExtensionApiTest::SetUpOnMainThread();
201 }
202
203 private:
204 DISALLOW_COPY_AND_ASSIGN(RestartOnWatchdogApiTest);
205 };
206
207 IN_PROC_BROWSER_TEST_F(RestartOnWatchdogApiTest, RestartOnWatchdogTest) {
208 ASSERT_TRUE(RunExtensionTest("runtime/restartOnWatchdog")) << message_;
209 }
210
131 } // namespace extensions 211 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698