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

Side by Side Diff: chrome/browser/chromeos/login/kiosk_browsertest.cc

Issue 205713002: Add a basic demo mode browser test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix license Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "apps/app_window.h" 5 #include "apps/app_window.h"
6 #include "apps/app_window_registry.h" 6 #include "apps/app_window_registry.h"
7 #include "apps/ui/native_app_window.h" 7 #include "apps/ui/native_app_window.h"
8 #include "ash/desktop_background/desktop_background_controller.h" 8 #include "ash/desktop_background/desktop_background_controller.h"
9 #include "ash/desktop_background/desktop_background_controller_observer.h" 9 #include "ash/desktop_background/desktop_background_controller_observer.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/chrome_notification_types.h" 16 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h" 17 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h"
18 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" 18 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
19 #include "chrome/browser/chromeos/login/app_launch_controller.h" 19 #include "chrome/browser/chromeos/login/app_launch_controller.h"
20 #include "chrome/browser/chromeos/login/fake_user_manager.h" 20 #include "chrome/browser/chromeos/login/fake_user_manager.h"
21 #include "chrome/browser/chromeos/login/mock_user_manager.h" 21 #include "chrome/browser/chromeos/login/mock_user_manager.h"
22 #include "chrome/browser/chromeos/login/oobe_base_test.h" 22 #include "chrome/browser/chromeos/login/oobe_base_test.h"
23 #include "chrome/browser/chromeos/login/startup_utils.h" 23 #include "chrome/browser/chromeos/login/startup_utils.h"
24 #include "chrome/browser/chromeos/login/test/app_window_waiter.h"
24 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" 25 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h"
25 #include "chrome/browser/chromeos/login/wizard_controller.h" 26 #include "chrome/browser/chromeos/login/wizard_controller.h"
26 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" 27 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
27 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" 28 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
28 #include "chrome/browser/chromeos/profiles/profile_helper.h" 29 #include "chrome/browser/chromeos/profiles/profile_helper.h"
29 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" 30 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
30 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " 31 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h "
31 #include "chrome/browser/extensions/extension_service.h" 32 #include "chrome/browser/extensions/extension_service.h"
32 #include "chrome/browser/extensions/extension_test_message_listener.h" 33 #include "chrome/browser/extensions/extension_test_message_listener.h"
33 #include "chrome/common/chrome_constants.h" 34 #include "chrome/common/chrome_constants.h"
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 221
221 content::WebContents* web_contents_; 222 content::WebContents* web_contents_;
222 const std::string js_; 223 const std::string js_;
223 scoped_refptr<content::MessageLoopRunner> runner_; 224 scoped_refptr<content::MessageLoopRunner> runner_;
224 225
225 DISALLOW_COPY_AND_ASSIGN(JsConditionWaiter); 226 DISALLOW_COPY_AND_ASSIGN(JsConditionWaiter);
226 }; 227 };
227 228
228 } // namespace 229 } // namespace
229 230
230 // Helper class that monitors app windows to wait for a window to appear.
231 class AppWindowObserver : public apps::AppWindowRegistry::Observer {
232 public:
233 AppWindowObserver(apps::AppWindowRegistry* registry,
234 const std::string& app_id)
235 : registry_(registry), app_id_(app_id), window_(NULL), running_(false) {
236 registry_->AddObserver(this);
237 }
238 virtual ~AppWindowObserver() { registry_->RemoveObserver(this); }
239
240 apps::AppWindow* Wait() {
241 running_ = true;
242 message_loop_runner_ = new content::MessageLoopRunner;
243 message_loop_runner_->Run();
244 EXPECT_TRUE(window_);
245 return window_;
246 }
247
248 // AppWindowRegistry::Observer
249 virtual void OnAppWindowAdded(apps::AppWindow* app_window) OVERRIDE {
250 if (!running_)
251 return;
252
253 if (app_window->extension_id() == app_id_) {
254 window_ = app_window;
255 message_loop_runner_->Quit();
256 running_ = false;
257 }
258 }
259 virtual void OnAppWindowIconChanged(apps::AppWindow* app_window) OVERRIDE {}
260 virtual void OnAppWindowRemoved(apps::AppWindow* app_window) OVERRIDE {}
261
262 private:
263 apps::AppWindowRegistry* registry_;
264 std::string app_id_;
265 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
266 apps::AppWindow* window_;
267 bool running_;
268
269 DISALLOW_COPY_AND_ASSIGN(AppWindowObserver);
270 };
271
272 class KioskTest : public OobeBaseTest { 231 class KioskTest : public OobeBaseTest {
273 public: 232 public:
274 KioskTest() { 233 KioskTest() {
275 set_exit_when_last_browser_closes(false); 234 set_exit_when_last_browser_closes(false);
276 } 235 }
277 236
278 virtual ~KioskTest() {} 237 virtual ~KioskTest() {}
279 238
280 protected: 239 protected:
281 virtual void SetUp() OVERRIDE { 240 virtual void SetUp() OVERRIDE {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 // Check if the kiosk webapp is really installed for the default profile. 367 // Check if the kiosk webapp is really installed for the default profile.
409 const extensions::Extension* app = 368 const extensions::Extension* app =
410 extensions::ExtensionSystem::Get(app_profile)-> 369 extensions::ExtensionSystem::Get(app_profile)->
411 extension_service()->GetInstalledExtension(test_app_id_); 370 extension_service()->GetInstalledExtension(test_app_id_);
412 EXPECT_TRUE(app); 371 EXPECT_TRUE(app);
413 372
414 // App should appear with its window. 373 // App should appear with its window.
415 apps::AppWindowRegistry* app_window_registry = 374 apps::AppWindowRegistry* app_window_registry =
416 apps::AppWindowRegistry::Get(app_profile); 375 apps::AppWindowRegistry::Get(app_profile);
417 apps::AppWindow* window = 376 apps::AppWindow* window =
418 AppWindowObserver(app_window_registry, test_app_id_).Wait(); 377 AppWindowWaiter(app_window_registry, test_app_id_).Wait();
419 EXPECT_TRUE(window); 378 EXPECT_TRUE(window);
420 379
421 // Login screen should be gone or fading out. 380 // Login screen should be gone or fading out.
422 chromeos::LoginDisplayHost* login_display_host = 381 chromeos::LoginDisplayHost* login_display_host =
423 chromeos::LoginDisplayHostImpl::default_host(); 382 chromeos::LoginDisplayHostImpl::default_host();
424 EXPECT_TRUE( 383 EXPECT_TRUE(
425 login_display_host == NULL || 384 login_display_host == NULL ||
426 login_display_host->GetNativeWindow()->layer()->GetTargetOpacity() == 385 login_display_host->GetNativeWindow()->layer()->GetTargetOpacity() ==
427 0.0f); 386 0.0f);
428 387
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 content::WindowedNotificationObserver( 1143 content::WindowedNotificationObserver(
1185 chrome::NOTIFICATION_KIOSK_APP_LAUNCHED, 1144 chrome::NOTIFICATION_KIOSK_APP_LAUNCHED,
1186 content::NotificationService::AllSources()).Wait(); 1145 content::NotificationService::AllSources()).Wait();
1187 1146
1188 // Check installer status. 1147 // Check installer status.
1189 EXPECT_EQ(chromeos::KioskAppLaunchError::NONE, 1148 EXPECT_EQ(chromeos::KioskAppLaunchError::NONE,
1190 chromeos::KioskAppLaunchError::Get()); 1149 chromeos::KioskAppLaunchError::Get());
1191 1150
1192 // Wait for the window to appear. 1151 // Wait for the window to appear.
1193 apps::AppWindow* window = 1152 apps::AppWindow* window =
1194 AppWindowObserver( 1153 AppWindowWaiter(
1195 apps::AppWindowRegistry::Get(ProfileManager::GetPrimaryUserProfile()), 1154 apps::AppWindowRegistry::Get(ProfileManager::GetPrimaryUserProfile()),
1196 kTestEnterpriseKioskApp).Wait(); 1155 kTestEnterpriseKioskApp).Wait();
1197 ASSERT_TRUE(window); 1156 ASSERT_TRUE(window);
1198 1157
1199 // Check whether the app can retrieve an OAuth2 access token. 1158 // Check whether the app can retrieve an OAuth2 access token.
1200 std::string result; 1159 std::string result;
1201 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 1160 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
1202 window->web_contents(), 1161 window->web_contents(),
1203 "chrome.identity.getAuthToken({ 'interactive': false }, function(token) {" 1162 "chrome.identity.getAuthToken({ 'interactive': false }, function(token) {"
1204 " window.domAutomationController.setAutomationId(0);" 1163 " window.domAutomationController.setAutomationId(0);"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 content::WindowedNotificationObserver( 1241 content::WindowedNotificationObserver(
1283 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE, 1242 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE,
1284 content::NotificationService::AllSources()).Wait(); 1243 content::NotificationService::AllSources()).Wait();
1285 1244
1286 // Wait for the wallpaper to load. 1245 // Wait for the wallpaper to load.
1287 WaitForWallpaper(); 1246 WaitForWallpaper();
1288 EXPECT_TRUE(wallpaper_loaded()); 1247 EXPECT_TRUE(wallpaper_loaded());
1289 } 1248 }
1290 1249
1291 } // namespace chromeos 1250 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698