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

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

Issue 99863007: Added CrOS-specific OAuth2 browser test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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/shell_window.h" 5 #include "apps/shell_window.h"
6 #include "apps/shell_window_registry.h" 6 #include "apps/shell_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/bind.h"
12 #include "base/bind_helpers.h"
13 #include "base/callback.h"
14 #include "base/command_line.h"
15 #include "base/location.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/message_loop/message_loop.h"
18 #include "base/path_service.h"
19 #include "base/prefs/scoped_user_pref_update.h"
20 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/chrome_browser_main.h"
22 #include "chrome/browser/chrome_browser_main_extra_parts.h"
23 #include "chrome/browser/chrome_content_browser_client.h"
24 #include "chrome/browser/chrome_notification_types.h" 12 #include "chrome/browser/chrome_notification_types.h"
25 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h" 13 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h"
26 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" 14 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
27 #include "chrome/browser/chromeos/login/app_launch_controller.h" 15 #include "chrome/browser/chromeos/login/app_launch_controller.h"
28 #include "chrome/browser/chromeos/login/app_launch_signin_screen.h"
29 #include "chrome/browser/chromeos/login/existing_user_controller.h"
30 #include "chrome/browser/chromeos/login/fake_user_manager.h" 16 #include "chrome/browser/chromeos/login/fake_user_manager.h"
31 #include "chrome/browser/chromeos/login/login_display_host_impl.h" 17 #include "chrome/browser/chromeos/login/oobe_base_test.h"
32 #include "chrome/browser/chromeos/login/mock_user_manager.h"
33 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" 18 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h"
34 #include "chrome/browser/chromeos/login/webui_login_display.h"
35 #include "chrome/browser/chromeos/login/wizard_controller.h" 19 #include "chrome/browser/chromeos/login/wizard_controller.h"
36 #include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h"
37 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" 20 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
38 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" 21 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
39 #include "chrome/browser/chromeos/settings/cros_settings.h"
40 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" 22 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
41 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " 23 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h "
42 #include "chrome/browser/extensions/extension_service.h" 24 #include "chrome/browser/extensions/extension_service.h"
43 #include "chrome/browser/extensions/extension_system.h" 25 #include "chrome/browser/extensions/extension_system.h"
44 #include "chrome/browser/extensions/extension_test_message_listener.h" 26 #include "chrome/browser/extensions/extension_test_message_listener.h"
45 #include "chrome/browser/lifetime/application_lifetime.h"
46 #include "chrome/browser/profiles/profile_manager.h"
47 #include "chrome/browser/ui/browser.h"
48 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
49 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
50 #include "chrome/common/chrome_paths.h"
51 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
52 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
53 #include "chrome/test/base/in_process_browser_test.h"
54 #include "chrome/test/base/interactive_test_utils.h"
55 #include "chrome/test/base/ui_test_utils.h"
56 #include "chromeos/chromeos_switches.h" 29 #include "chromeos/chromeos_switches.h"
57 #include "chromeos/settings/cros_settings_names.h"
58 #include "components/policy/core/common/cloud/policy_builder.h"
59 #include "content/public/browser/notification_observer.h" 30 #include "content/public/browser/notification_observer.h"
60 #include "content/public/browser/notification_registrar.h" 31 #include "content/public/browser/notification_registrar.h"
61 #include "content/public/browser/notification_service.h" 32 #include "content/public/browser/notification_service.h"
62 #include "content/public/test/browser_test_utils.h" 33 #include "content/public/test/browser_test_utils.h"
63 #include "content/public/test/test_utils.h"
64 #include "extensions/common/extension.h"
65 #include "google_apis/gaia/fake_gaia.h"
66 #include "google_apis/gaia/gaia_constants.h" 34 #include "google_apis/gaia/gaia_constants.h"
67 #include "google_apis/gaia/gaia_switches.h" 35 #include "google_apis/gaia/gaia_switches.h"
68 #include "google_apis/gaia/gaia_urls.h" 36 #include "google_apis/gaia/gaia_urls.h"
69 #include "net/base/network_change_notifier.h"
70 #include "net/dns/mock_host_resolver.h"
71 #include "net/test/embedded_test_server/embedded_test_server.h"
72 #include "net/test/embedded_test_server/http_request.h"
73 #include "net/test/embedded_test_server/http_response.h"
74 #include "testing/gmock/include/gmock/gmock.h"
75 #include "testing/gtest/include/gtest/gtest.h"
76 #include "ui/aura/window.h"
77 #include "ui/compositor/layer.h"
78 37
79 namespace em = enterprise_management; 38 namespace em = enterprise_management;
80 39
81 namespace chromeos { 40 namespace chromeos {
82 41
83 namespace { 42 namespace {
84 43
85 // This is a simple test app that creates an app window and immediately closes 44 // This is a simple test app that creates an app window and immediately closes
86 // it again. Webstore data json is in 45 // it again. Webstore data json is in
87 // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/ 46 // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 private: 183 private:
225 apps::ShellWindowRegistry* registry_; 184 apps::ShellWindowRegistry* registry_;
226 std::string app_id_; 185 std::string app_id_;
227 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 186 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
228 apps::ShellWindow* window_; 187 apps::ShellWindow* window_;
229 bool running_; 188 bool running_;
230 189
231 DISALLOW_COPY_AND_ASSIGN(ShellWindowObserver); 190 DISALLOW_COPY_AND_ASSIGN(ShellWindowObserver);
232 }; 191 };
233 192
234 class KioskTest : public InProcessBrowserTest { 193 class KioskTest : public OobeBaseTest {
235 public: 194 public:
236 KioskTest() { 195 KioskTest() {
237 set_exit_when_last_browser_closes(false); 196 set_exit_when_last_browser_closes(false);
238 } 197 }
239 198
240 virtual ~KioskTest() {} 199 virtual ~KioskTest() {}
241 200
242 protected: 201 protected:
243 virtual void SetUp() OVERRIDE {
244 base::FilePath test_data_dir;
245 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
246 embedded_test_server()->ServeFilesFromDirectory(test_data_dir);
247 embedded_test_server()->RegisterRequestHandler(
248 base::Bind(&FakeGaia::HandleRequest, base::Unretained(&fake_gaia_)));
249 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
250 // Stop IO thread here because no threads are allowed while
251 // spawning sandbox host process. See crbug.com/322732.
252 embedded_test_server()->StopThread();
253
254 mock_user_manager_.reset(new MockUserManager);
255 AppLaunchController::SkipSplashWaitForTesting();
256 AppLaunchController::SetNetworkWaitForTesting(kTestNetworkTimeoutSeconds);
257
258 InProcessBrowserTest::SetUp();
259 }
260
261 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
262 host_resolver()->AddRule("*", "127.0.0.1");
263
264 network_portal_detector_ = new NetworkPortalDetectorTestImpl();
265 NetworkPortalDetector::InitializeForTesting(network_portal_detector_);
266 network_portal_detector_->SetDefaultNetworkPathForTesting(
267 kStubEthernetServicePath);
268 }
269
270 virtual void SetUpOnMainThread() OVERRIDE {
271 // Restart the thread as the sandbox host process has already been spawned.
272 embedded_test_server()->RestartThreadAndListen();
273 }
274 202
275 virtual void CleanUpOnMainThread() OVERRIDE { 203 virtual void CleanUpOnMainThread() OVERRIDE {
276 AppLaunchController::SetNetworkTimeoutCallbackForTesting(NULL); 204 AppLaunchController::SetNetworkTimeoutCallbackForTesting(NULL);
277 AppLaunchSigninScreen::SetUserManagerForTesting(NULL); 205 AppLaunchSigninScreen::SetUserManagerForTesting(NULL);
278 206
279 // If the login display is still showing, exit gracefully. 207 OobeBaseTest::CleanUpOnMainThread();
280 if (LoginDisplayHostImpl::default_host()) {
281 base::MessageLoop::current()->PostTask(FROM_HERE,
282 base::Bind(&chrome::AttemptExit));
283 content::RunMessageLoop();
284 }
285 208
286 // Clean up while main thread still runs. 209 // Clean up while main thread still runs.
287 // See http://crbug.com/176659. 210 // See http://crbug.com/176659.
288 KioskAppManager::Get()->CleanUp(); 211 KioskAppManager::Get()->CleanUp();
289 } 212 }
290 213
291 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 214 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
292 command_line->AppendSwitch(chromeos::switches::kLoginManager); 215 OobeBaseTest::SetUpCommandLine(command_line);
293 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
294 command_line->AppendSwitch(::switches::kDisableBackgroundNetworking);
295 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
296 216
297 // Create gaia and webstore URL from test server url but using different 217 // Create gaia and webstore URL from test server url but using different
298 // host names. This is to avoid gaia response being tagged as from 218 // host names. This is to avoid gaia response being tagged as from
299 // webstore in chrome_resource_dispatcher_host_delegate.cc. 219 // webstore in chrome_resource_dispatcher_host_delegate.cc.
300 const GURL& server_url = embedded_test_server()->base_url(); 220 const GURL& server_url = embedded_test_server()->base_url();
301
302 std::string gaia_host("gaia");
303 GURL::Replacements replace_gaia_host;
304 replace_gaia_host.SetHostStr(gaia_host);
305 GURL gaia_url = server_url.ReplaceComponents(replace_gaia_host);
306 command_line->AppendSwitchASCII(::switches::kGaiaUrl, gaia_url.spec());
307 command_line->AppendSwitchASCII(::switches::kLsoUrl, gaia_url.spec());
308 command_line->AppendSwitchASCII(::switches::kGoogleApisUrl,
309 gaia_url.spec());
310
311 std::string webstore_host("webstore"); 221 std::string webstore_host("webstore");
312 GURL::Replacements replace_webstore_host; 222 GURL::Replacements replace_webstore_host;
313 replace_webstore_host.SetHostStr(webstore_host); 223 replace_webstore_host.SetHostStr(webstore_host);
314 GURL webstore_url = server_url.ReplaceComponents(replace_webstore_host); 224 GURL webstore_url = server_url.ReplaceComponents(replace_webstore_host);
315 command_line->AppendSwitchASCII( 225 command_line->AppendSwitchASCII(
316 ::switches::kAppsGalleryURL, 226 ::switches::kAppsGalleryURL,
317 webstore_url.Resolve("/chromeos/app_mode/webstore").spec()); 227 webstore_url.Resolve("/chromeos/app_mode/webstore").spec());
318 command_line->AppendSwitchASCII( 228 command_line->AppendSwitchASCII(
319 ::switches::kAppsGalleryDownloadURL, 229 ::switches::kAppsGalleryDownloadURL,
320 webstore_url.Resolve( 230 webstore_url.Resolve(
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 311
402 // Wait until the app terminates if it is still running. 312 // Wait until the app terminates if it is still running.
403 if (!shell_window_registry->GetShellWindowsForApp(kTestKioskApp).empty()) 313 if (!shell_window_registry->GetShellWindowsForApp(kTestKioskApp).empty())
404 content::RunMessageLoop(); 314 content::RunMessageLoop();
405 315
406 // Check that the app had been informed that it is running in a kiosk 316 // Check that the app had been informed that it is running in a kiosk
407 // session. 317 // session.
408 EXPECT_TRUE(launch_data_check_listener.was_satisfied()); 318 EXPECT_TRUE(launch_data_check_listener.was_satisfied());
409 } 319 }
410 320
411 void SimulateNetworkOffline() {
412 NetworkPortalDetector::CaptivePortalState offline_state;
413 offline_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE;
414 network_portal_detector_->SetDetectionResultsForTesting(
415 kStubEthernetServicePath, offline_state);
416 network_portal_detector_->NotifyObserversForTesting();
417 }
418
419 base::Closure SimulateNetworkOfflineClosure() {
420 return base::Bind(&KioskTest::SimulateNetworkOffline,
421 base::Unretained(this));
422 }
423
424 void SimulateNetworkOnline() {
425 NetworkPortalDetector::CaptivePortalState online_state;
426 online_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE;
427 online_state.response_code = 204;
428 network_portal_detector_->SetDetectionResultsForTesting(
429 kStubEthernetServicePath, online_state);
430 network_portal_detector_->NotifyObserversForTesting();
431 }
432
433 base::Closure SimulateNetworkOnlineClosure() {
434 return base::Bind(&KioskTest::SimulateNetworkOnline,
435 base::Unretained(this));
436 }
437
438 void SimulateNetworkPortal() {
439 NetworkPortalDetector::CaptivePortalState portal_state;
440 portal_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL;
441 network_portal_detector_->SetDetectionResultsForTesting(
442 kStubEthernetServicePath, portal_state);
443 network_portal_detector_->NotifyObserversForTesting();
444 }
445
446 base::Closure SimulateNetworkPortalClosure() {
447 return base::Bind(&KioskTest::SimulateNetworkPortal,
448 base::Unretained(this));
449 }
450
451 void WaitForAppLaunchNetworkTimeout() { 321 void WaitForAppLaunchNetworkTimeout() {
452 if (GetAppLaunchController()->network_wait_timedout()) 322 if (GetAppLaunchController()->network_wait_timedout())
453 return; 323 return;
454 324
455 scoped_refptr<content::MessageLoopRunner> runner = 325 scoped_refptr<content::MessageLoopRunner> runner =
456 new content::MessageLoopRunner; 326 new content::MessageLoopRunner;
457 327
458 base::Closure callback = base::Bind( 328 base::Closure callback = base::Bind(
459 &OnNetworkWaitTimedOut, runner->QuitClosure()); 329 &OnNetworkWaitTimedOut, runner->QuitClosure());
460 AppLaunchController::SetNetworkTimeoutCallbackForTesting(&callback); 330 AppLaunchController::SetNetworkTimeoutCallbackForTesting(&callback);
(...skipping 23 matching lines...) Expand all
484 new content::MessageLoopRunner; 354 new content::MessageLoopRunner;
485 KioskAppManager::Get()->GetConsumerKioskModeStatus( 355 KioskAppManager::Get()->GetConsumerKioskModeStatus(
486 base::Bind(&ConsumerKioskModeStatusCheck, 356 base::Bind(&ConsumerKioskModeStatusCheck,
487 &status, 357 &status,
488 runner->QuitClosure())); 358 runner->QuitClosure()));
489 runner->Run(); 359 runner->Run();
490 CHECK_NE(status, static_cast<KioskAppManager::ConsumerKioskModeStatus>(-1)); 360 CHECK_NE(status, static_cast<KioskAppManager::ConsumerKioskModeStatus>(-1));
491 return status; 361 return status;
492 } 362 }
493 363
494 void JsExpect(const std::string& expression) {
495 bool result;
496 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
497 GetLoginUI()->GetWebContents(),
498 "window.domAutomationController.send(!!(" + expression + "));",
499 &result));
500 ASSERT_TRUE(result) << expression;
501 }
502
503 content::WebUI* GetLoginUI() {
504 return static_cast<chromeos::LoginDisplayHostImpl*>(
505 chromeos::LoginDisplayHostImpl::default_host())->GetOobeUI()->web_ui();
506 }
507
508 SigninScreenHandler* GetSigninScreenHandler() {
509 return static_cast<chromeos::LoginDisplayHostImpl*>(
510 chromeos::LoginDisplayHostImpl::default_host())
511 ->GetOobeUI()
512 ->signin_screen_handler_for_test();
513 }
514
515 AppLaunchController* GetAppLaunchController() { 364 AppLaunchController* GetAppLaunchController() {
516 return chromeos::LoginDisplayHostImpl::default_host() 365 return chromeos::LoginDisplayHostImpl::default_host()
517 ->GetAppLaunchController(); 366 ->GetAppLaunchController();
518 } 367 }
519
520 FakeGaia fake_gaia_;
521 scoped_ptr<MockUserManager> mock_user_manager_;
522 NetworkPortalDetectorTestImpl* network_portal_detector_;
523 }; 368 };
524 369
525 IN_PROC_BROWSER_TEST_F(KioskTest, InstallAndLaunchApp) { 370 IN_PROC_BROWSER_TEST_F(KioskTest, InstallAndLaunchApp) {
526 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure()); 371 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure());
527 WaitForAppLaunchSuccess(); 372 WaitForAppLaunchSuccess();
528 } 373 }
529 374
530 IN_PROC_BROWSER_TEST_F(KioskTest, LaunchAppNetworkDown) { 375 IN_PROC_BROWSER_TEST_F(KioskTest, LaunchAppNetworkDown) {
531 // Mock network could be configured with owner's password. 376 // Mock network could be configured with owner's password.
532 ScopedCanConfigureNetwork can_configure_network(true, true); 377 ScopedCanConfigureNetwork can_configure_network(true, true);
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 content::WindowedNotificationObserver( 883 content::WindowedNotificationObserver(
1039 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE, 884 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE,
1040 content::NotificationService::AllSources()).Wait(); 885 content::NotificationService::AllSources()).Wait();
1041 886
1042 // Wait for the wallpaper to load. 887 // Wait for the wallpaper to load.
1043 WaitForWallpaper(); 888 WaitForWallpaper();
1044 EXPECT_TRUE(wallpaper_loaded()); 889 EXPECT_TRUE(wallpaper_loaded());
1045 } 890 }
1046 891
1047 } // namespace chromeos 892 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698