9241cbdff58c6c5dfe9f8efd9b88d57f53c72539
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / login / oobe_browsertest.cc
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
3 // found in the LICENSE file.
4
5 #include "base/command_line.h"
6 #include "chrome/browser/chrome_notification_types.h"
7 #include "chrome/browser/chromeos/login/existing_user_controller.h"
8 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h"
9 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
10 #include "chrome/browser/chromeos/login/ui/webui_login_display.h"
11 #include "chrome/browser/chromeos/login/ui/webui_login_view.h"
12 #include "chrome/browser/chromeos/login/wizard_controller.h"
13 #include "chrome/browser/defaults.h"
14 #include "chrome/browser/lifetime/application_lifetime.h"
15 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/test/base/in_process_browser_test.h"
18 #include "chromeos/chromeos_switches.h"
19 #include "content/public/browser/web_contents.h"
20 #include "content/public/common/renderer_preferences.h"
21 #include "content/public/test/test_utils.h"
22 #include "google_apis/gaia/fake_gaia.h"
23 #include "google_apis/gaia/gaia_switches.h"
24 #include "net/test/embedded_test_server/embedded_test_server.h"
25 #include "net/test/embedded_test_server/http_response.h"
26 #include "testing/gtest/include/gtest/gtest.h"
27 #include "ui/base/test/ui_controls.h"
28 #include "ui/views/widget/widget.h"
29
30 using namespace net::test_server;
31
32 namespace chromeos {
33
34 class OobeTest : public InProcessBrowserTest {
35  public:
36   OobeTest() {}
37   virtual ~OobeTest() {}
38
39   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
40     command_line->AppendSwitch(chromeos::switches::kLoginManager);
41     command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
42     command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
43     command_line->AppendSwitchASCII(
44         ::switches::kAuthExtensionPath, "gaia_auth");
45     fake_gaia_.Initialize();
46   }
47
48   virtual void SetUpOnMainThread() OVERRIDE {
49     CHECK(embedded_test_server()->InitializeAndWaitUntilReady());
50     embedded_test_server()->RegisterRequestHandler(
51         base::Bind(&FakeGaia::HandleRequest, base::Unretained(&fake_gaia_)));
52     LOG(INFO) << "Set up http server at " << embedded_test_server()->base_url();
53
54     CommandLine::ForCurrentProcess()->AppendSwitchASCII(
55         ::switches::kGaiaUrl, embedded_test_server()->base_url().spec());
56   }
57
58   virtual void TearDownOnMainThread() OVERRIDE {
59     // If the login display is still showing, exit gracefully.
60     if (LoginDisplayHostImpl::default_host()) {
61       base::MessageLoop::current()->PostTask(FROM_HERE,
62                                              base::Bind(&chrome::AttemptExit));
63       content::RunMessageLoop();
64     }
65   }
66
67   chromeos::WebUILoginDisplay* GetLoginDisplay() {
68     chromeos::ExistingUserController* controller =
69         chromeos::ExistingUserController::current_controller();
70     CHECK(controller);
71     return static_cast<chromeos::WebUILoginDisplay*>(
72         controller->login_display());
73   }
74
75   views::Widget* GetLoginWindowWidget() {
76     return static_cast<chromeos::LoginDisplayHostImpl*>(
77         chromeos::LoginDisplayHostImpl::default_host())
78         ->login_window_for_test();
79   }
80
81  private:
82   FakeGaia fake_gaia_;
83   DISALLOW_COPY_AND_ASSIGN(OobeTest);
84 };
85
86 IN_PROC_BROWSER_TEST_F(OobeTest, NewUser) {
87   chromeos::WizardController::SkipPostLoginScreensForTesting();
88   chromeos::WizardController* wizard_controller =
89       chromeos::WizardController::default_controller();
90   CHECK(wizard_controller);
91   wizard_controller->SkipToLoginForTesting(LoginScreenContext());
92
93   content::WindowedNotificationObserver(
94     chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
95     content::NotificationService::AllSources()).Wait();
96
97   // TODO(glotov): mock GAIA server (test_server()) should support
98   // username/password configuration.
99   GetLoginDisplay()->ShowSigninScreenForCreds("username", "password");
100
101   content::WindowedNotificationObserver(
102     chrome::NOTIFICATION_SESSION_STARTED,
103     content::NotificationService::AllSources()).Wait();
104 }
105
106 IN_PROC_BROWSER_TEST_F(OobeTest, Accelerator) {
107   chromeos::WizardController::SkipPostLoginScreensForTesting();
108   chromeos::WizardController* wizard_controller =
109       chromeos::WizardController::default_controller();
110   CHECK(wizard_controller);
111   wizard_controller->SkipToLoginForTesting(LoginScreenContext());
112
113   content::WindowedNotificationObserver(
114     chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
115     content::NotificationService::AllSources()).Wait();
116
117   gfx::NativeWindow login_window = GetLoginWindowWidget()->GetNativeWindow();
118
119   ui_controls::SendKeyPress(login_window,
120                             ui::VKEY_E,
121                             true,    // control
122                             false,   // shift
123                             true,    // alt
124                             false);  // command
125   OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_ENROLLMENT).Wait();
126 }
127
128 IN_PROC_BROWSER_TEST_F(OobeTest, LinkDisambiguationDefaultRespected) {
129   chromeos::LoginDisplayHostImpl* display_host =
130       static_cast<chromeos::LoginDisplayHostImpl*>(
131           chromeos::LoginDisplayHostImpl::default_host());
132   ASSERT_TRUE(display_host);
133   chromeos::WebUILoginView* login_view = display_host->GetWebUILoginView();
134   ASSERT_TRUE(login_view);
135   content::WebContents* web_contents = login_view->GetWebContents();
136   ASSERT_TRUE(web_contents);
137   content::RendererPreferences* prefs = web_contents->GetMutableRendererPrefs();
138   ASSERT_TRUE(prefs);
139   // Per crbug/431163 the WiFi selection dropdown doesn't support the link
140   // disambiguation popup for gesture events, and this feature is disabled
141   // within ChromeOS. Ensure that the web preferences reflect the default.
142   if (browser_defaults::kShowLinkDisambiguationPopup) {
143     EXPECT_EQ(
144         content::TapMultipleTargetsStrategy::
145             TAP_MULTIPLE_TARGETS_STRATEGY_POPUP,
146         prefs->tap_multiple_targets_strategy);
147   } else {
148     EXPECT_EQ(
149         content::TapMultipleTargetsStrategy::TAP_MULTIPLE_TARGETS_STRATEGY_NONE,
150         prefs->tap_multiple_targets_strategy);
151   }
152 }
153
154 }  // namespace chromeos