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

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

Issue 13542003: Add browser test for new user CrOS login flow (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 7 years, 8 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/path_service.h" 6 #include "base/path_service.h"
7 #include "base/stringprintf.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/chrome_browser_main.h" 7 #include "chrome/browser/chrome_browser_main.h"
10 #include "chrome/browser/chrome_browser_main_extra_parts.h" 8 #include "chrome/browser/chrome_browser_main_extra_parts.h"
11 #include "chrome/browser/chrome_content_browser_client.h" 9 #include "chrome/browser/chrome_content_browser_client.h"
12 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h"
13 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
14 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" 10 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h"
15 #include "chrome/browser/chromeos/login/existing_user_controller.h" 11 #include "chrome/browser/chromeos/login/existing_user_controller.h"
16 #include "chrome/browser/chromeos/login/webui_login_display.h" 12 #include "chrome/browser/chromeos/login/webui_login_display.h"
17 #include "chrome/browser/chromeos/login/webui_login_display_host.h"
18 #include "chrome/browser/chromeos/login/wizard_controller.h" 13 #include "chrome/browser/chromeos/login/wizard_controller.h"
19 #include "chrome/browser/extensions/extension_service.h"
20 #include "chrome/browser/extensions/extension_system.h"
21 #include "chrome/browser/google_apis/test_server/http_request.h" 14 #include "chrome/browser/google_apis/test_server/http_request.h"
22 #include "chrome/browser/google_apis/test_server/http_response.h" 15 #include "chrome/browser/google_apis/test_server/http_response.h"
23 #include "chrome/browser/google_apis/test_server/http_server.h" 16 #include "chrome/browser/google_apis/test_server/http_server.h"
24 #include "chrome/browser/lifetime/application_lifetime.h"
25 #include "chrome/browser/prefs/scoped_user_pref_update.h"
26 #include "chrome/browser/profiles/profile_manager.h"
27 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
28 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
29 #include "chrome/common/chrome_notification_types.h" 18 #include "chrome/common/chrome_notification_types.h"
30 #include "chrome/common/chrome_paths.h" 19 #include "chrome/common/chrome_paths.h"
31 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
32 #include "chrome/common/extensions/extension.h"
33 #include "chrome/test/base/in_process_browser_test.h" 21 #include "chrome/test/base/in_process_browser_test.h"
34 #include "chrome/test/base/interactive_test_utils.h" 22 #include "chrome/test/base/interactive_test_utils.h"
35 #include "chrome/test/base/ui_test_utils.h" 23 #include "chrome/test/base/ui_test_utils.h"
36 #include "chromeos/chromeos_switches.h" 24 #include "chromeos/chromeos_switches.h"
37 #include "content/public/browser/notification_observer.h" 25 #include "content/public/browser/notification_observer.h"
38 #include "content/public/browser/notification_registrar.h" 26 #include "content/public/browser/notification_registrar.h"
39 #include "content/public/browser/notification_service.h" 27 #include "content/public/browser/notification_service.h"
40 #include "content/public/test/test_utils.h" 28 #include "content/public/test/test_utils.h"
41 #include "google_apis/gaia/gaia_switches.h" 29 #include "google_apis/gaia/gaia_switches.h"
42 #include "net/base/host_port_pair.h"
43 #include "net/dns/mock_host_resolver.h"
44 #include "testing/gmock/include/gmock/gmock.h" 30 #include "testing/gmock/include/gmock/gmock.h"
45 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
46 32
47 using namespace google_apis; 33 using namespace google_apis;
48 using namespace google_apis::test_server; 34 using namespace google_apis::test_server;
49 35
50 namespace chromeos {
51
52 namespace { 36 namespace {
53 37
54 const char kWebstoreDomain[] = "cws.com";
55
56 // Webstore data json is in
57 // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/
58 // detail/ggbflgnkafappblpkiflbgpmkfdpnhhe
59 const char kTestKioskApp[] = "ggbflgnkafappblpkiflbgpmkfdpnhhe";
60
61 // Used to add an observer to NotificationService after it's created. 38 // Used to add an observer to NotificationService after it's created.
62 class TestBrowserMainExtraParts 39 class TestBrowserMainExtraParts
63 : public ChromeBrowserMainExtraParts, 40 : public ChromeBrowserMainExtraParts,
64 public content::NotificationObserver { 41 public content::NotificationObserver {
65 public: 42 public:
66 TestBrowserMainExtraParts() {} 43 TestBrowserMainExtraParts() {}
67
68 virtual ~TestBrowserMainExtraParts() {} 44 virtual ~TestBrowserMainExtraParts() {}
69 45
70 // ChromeBrowserMainExtraParts implementation. 46 // ChromeBrowserMainExtraParts implementation.
71 virtual void PreEarlyInitialization() OVERRIDE { 47 virtual void PreEarlyInitialization() OVERRIDE {
72 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE, 48 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE,
73 content::NotificationService::AllSources()); 49 content::NotificationService::AllSources());
74 registrar_.Add(this, chrome::NOTIFICATION_KIOSK_APPS_LOADED, 50 registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED,
75 content::NotificationService::AllSources());
76 registrar_.Add(this, chrome::NOTIFICATION_KIOSK_APP_LAUNCHED,
77 content::NotificationService::AllSources()); 51 content::NotificationService::AllSources());
78 } 52 }
79 53
80 void set_quit_task(const base::Closure& quit_task) { quit_task_ = quit_task; } 54 void set_quit_task(const base::Closure& quit_task) { quit_task_ = quit_task; }
55 void set_gaia_url(const std::string& url) { gaia_url_ = url; }
81 56
82 private: 57 private:
83 // Overridden from content::NotificationObserver: 58 // Overridden from content::NotificationObserver:
84 virtual void Observe(int type, 59 virtual void Observe(int type,
85 const content::NotificationSource& source, 60 const content::NotificationSource& source,
86 const content::NotificationDetails& details) OVERRIDE { 61 const content::NotificationDetails& details) OVERRIDE {
87 if (type == chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE) { 62 if (type == chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE) {
88 LOG(INFO) << "NOTIFICATION_LOGIN_WEBUI_VISIBLE"; 63 LOG(INFO) << "NOTIFICATION_LOGIN_WEBUI_VISIBLE";
89 } else if (type == chrome::NOTIFICATION_KIOSK_APPS_LOADED) { 64 chromeos::ExistingUserController* controller =
90 LOG(INFO) << "chrome::NOTIFICATION_KIOSK_APPS_LOADED"; 65 chromeos::ExistingUserController::current_controller();
91 content::WebUI* web_ui = static_cast<chromeos::WebUILoginDisplayHost*>( 66 CHECK(controller);
92 chromeos::WebUILoginDisplayHost::default_host())-> 67 chromeos::WebUILoginDisplay* webui_login_display =
93 GetOobeUI()->web_ui(); 68 static_cast<chromeos::WebUILoginDisplay*>(
94 web_ui->CallJavascriptFunction("login.AppsMenuButton.runAppForTesting", 69 controller->login_display());
95 base::StringValue(kTestKioskApp)); 70 CHECK(webui_login_display);
96 } else if (type == chrome::NOTIFICATION_KIOSK_APP_LAUNCHED) { 71 webui_login_display->SetGaiaOriginForTesting(gaia_url_);
97 LOG(INFO) << "chrome::NOTIFICATION_KIOSK_APP_LAUNCHED"; 72 webui_login_display->ShowSigninScreenForCreds("username", "password");
98 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 73 // TODO(glotov): mock GAIA server (test_server_) should support
99 content::NotificationService::AllSources()); 74 // username/password configuration.
100 quit_task_.Run(); 75 } else if (type == chrome::NOTIFICATION_SESSION_STARTED) {
101 } else if (type == content::NOTIFICATION_RENDERER_PROCESS_CLOSED) { 76 LOG(INFO) << "chrome::NOTIFICATION_SESSION_STARTED";
102 LOG(INFO) << "content::NOTIFICATION_RENDERER_PROCESS_CLOSED";
103 quit_task_.Run(); 77 quit_task_.Run();
104 } else { 78 } else {
105 NOTREACHED(); 79 NOTREACHED();
106 } 80 }
107 } 81 }
108 82
109 content::NotificationRegistrar registrar_; 83 content::NotificationRegistrar registrar_;
110 base::Closure quit_task_; 84 base::Closure quit_task_;
85 std::string gaia_url_;
111 86
112 DISALLOW_COPY_AND_ASSIGN(TestBrowserMainExtraParts); 87 DISALLOW_COPY_AND_ASSIGN(TestBrowserMainExtraParts);
113 }; 88 };
114 89
115 class TestContentBrowserClient : public chrome::ChromeContentBrowserClient { 90 class TestContentBrowserClient : public chrome::ChromeContentBrowserClient {
116 public: 91 public:
117 TestContentBrowserClient() {} 92 TestContentBrowserClient() {}
118 virtual ~TestContentBrowserClient() {} 93 virtual ~TestContentBrowserClient() {}
119 94
120 virtual content::BrowserMainParts* CreateBrowserMainParts( 95 virtual content::BrowserMainParts* CreateBrowserMainParts(
121 const content::MainFunctionParams& parameters) OVERRIDE { 96 const content::MainFunctionParams& parameters) OVERRIDE {
122 ChromeBrowserMainParts* main_parts = static_cast<ChromeBrowserMainParts*>( 97 ChromeBrowserMainParts* main_parts = static_cast<ChromeBrowserMainParts*>(
123 ChromeContentBrowserClient::CreateBrowserMainParts(parameters)); 98 ChromeContentBrowserClient::CreateBrowserMainParts(parameters));
124 99
125 browser_main_extra_parts_ = new TestBrowserMainExtraParts(); 100 browser_main_extra_parts_ = new TestBrowserMainExtraParts();
126 main_parts->AddParts(browser_main_extra_parts_); 101 main_parts->AddParts(browser_main_extra_parts_);
127 return main_parts; 102 return main_parts;
128 } 103 }
129 104
130 TestBrowserMainExtraParts* browser_main_extra_parts_; 105 TestBrowserMainExtraParts* browser_main_extra_parts_;
131 106
132 private: 107 private:
133 DISALLOW_COPY_AND_ASSIGN(TestContentBrowserClient); 108 DISALLOW_COPY_AND_ASSIGN(TestContentBrowserClient);
134 }; 109 };
135 110
136 } // namespace 111 const base::FilePath kServiceLogin("chromeos/service_login.html");
137 112
138 class KioskTest : public chromeos::CrosInProcessBrowserTest { 113 class OobeTest : public chromeos::CrosInProcessBrowserTest {
139 public:
140 KioskTest() : chromeos::CrosInProcessBrowserTest() {
141 SetExitWhenLastBrowserCloses(false);
142 }
143
144 protected: 114 protected:
145
146 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 115 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
147 command_line->AppendSwitch(chromeos::switches::kLoginManager); 116 command_line->AppendSwitch(chromeos::switches::kLoginManager);
148 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests); 117 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
149 command_line->AppendSwitch(::switches::kDisableChromeCaptivePortalDetector); 118 command_line->AppendSwitch(switches::kDisableChromeCaptivePortalDetector);
150 command_line->AppendSwitch(::switches::kDisableBackgroundNetworking);
151 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user"); 119 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
152 120 command_line->AppendSwitchASCII(switches::kAuthExtensionPath, "gaia_auth");
153 ASSERT_TRUE(test_server()->Start());
154 net::HostPortPair host_port = test_server()->host_port_pair();
155 std::string test_gallery_url = base::StringPrintf(
156 "http://%s:%d/files/chromeos/app_mode/webstore",
157 kWebstoreDomain, host_port.port());
158 command_line->AppendSwitchASCII(
159 ::switches::kAppsGalleryURL, test_gallery_url);
160
161 std::string test_gallery_download_url = test_gallery_url;
162 test_gallery_download_url.append("/downloads/%s.crx");
163 command_line->AppendSwitchASCII(
164 ::switches::kAppsGalleryDownloadURL, test_gallery_download_url);
165 } 121 }
166 122
167 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 123 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
168 content_browser_client_.reset(new TestContentBrowserClient()); 124 content_browser_client_.reset(new TestContentBrowserClient());
169 original_content_browser_client_ = content::SetBrowserClientForTesting( 125 original_content_browser_client_ = content::SetBrowserClientForTesting(
170 content_browser_client_.get()); 126 content_browser_client_.get());
171 host_resolver()->AddRule(kWebstoreDomain, "127.0.0.1"); 127 base::FilePath test_data_dir;
128 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
129 CHECK(file_util::ReadFileToString(test_data_dir.Append(kServiceLogin),
130 &service_login_response_));
131 }
132
133 virtual void SetUpOnMainThread() OVERRIDE {
134 test_server_ = new HttpServer(); // Constructor wants UI thread.
135 CHECK(test_server_->InitializeAndWaitUntilReady());
136 test_server_->RegisterRequestHandler(
137 base::Bind(&OobeTest::HandleRequest, base::Unretained(this)));
138 LOG(INFO) << "Set up http server at " << test_server_->base_url();
139 CHECK(test_server_->port() >= 8040 && test_server_->port() < 8045)
140 << "Current manifest_test.json for gaia_login restrictions "
141 << "does not allow this port";
142
143 const std::string gaia_url =
144 "http://localhost:" + test_server_->base_url().port();
145 content_browser_client_->browser_main_extra_parts_->set_gaia_url(gaia_url);
172 } 146 }
173 147
174 virtual void CleanUpOnMainThread() OVERRIDE { 148 virtual void CleanUpOnMainThread() OVERRIDE {
175 // Clean up while main thread still runs. 149 LOG(INFO) << "Stopping the http server.";
176 // See http://crbug.com/176659. 150 test_server_->ShutdownAndWaitUntilComplete();
177 chromeos::KioskAppManager::Get()->CleanUp(); 151 delete test_server_; // Destructor wants UI thread.
178 } 152 }
179 153
180 void ReloadKioskApps() { 154 scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request) {
181 chromeos::KioskAppManager::Get()->AddApp(kTestKioskApp); 155 GURL url = test_server_->GetURL(request.relative_url);
156 LOG(INFO) << "Http request: " << url.spec();
157
158 scoped_ptr<HttpResponse> http_response(new HttpResponse());
159 if (url.path() == "/ServiceLogin") {
160 http_response->set_code(test_server::SUCCESS);
161 http_response->set_content(service_login_response_);
162 http_response->set_content_type("text/html");
163 } else if (url.path() == "/ServiceLoginAuth") {
164 LOG(INFO) << "Params: " << request.content;
165 static const char kContinueParam[] = "continue=";
166 int continue_arg_begin = request.content.find(kContinueParam) +
167 arraysize(kContinueParam) - 1;
168 int continue_arg_end = request.content.find("&", continue_arg_begin);
169 const std::string continue_url = request.content.substr(
170 continue_arg_begin, continue_arg_end - continue_arg_begin);
171 http_response->set_code(test_server::SUCCESS);
172 const std::string redirect_js =
173 "document.location.href = unescape('" + continue_url + "');";
174 http_response->set_content(
175 "<HTML><HEAD><SCRIPT>\n" + redirect_js + "\n</SCRIPT></HEAD></HTML>");
176 http_response->set_content_type("text/html");
177 } else {
178 NOTREACHED() << url.path();
179 }
180 return http_response.Pass();
182 } 181 }
183 182
184 scoped_ptr<TestContentBrowserClient> content_browser_client_; 183 scoped_ptr<TestContentBrowserClient> content_browser_client_;
185 content::ContentBrowserClient* original_content_browser_client_; 184 content::ContentBrowserClient* original_content_browser_client_;
186 std::string service_login_response_; 185 std::string service_login_response_;
186 HttpServer* test_server_; // cant use scoped_ptr because destructor
187 // needs UI thread.
187 }; 188 };
188 189
189 IN_PROC_BROWSER_TEST_F(KioskTest, InstallAndLaunchApp) { 190 IN_PROC_BROWSER_TEST_F(OobeTest, NewUser) {
190 // Start UI, find menu entry for this app and launch it.
191 chromeos::WizardController::SkipPostLoginScreensForTesting(); 191 chromeos::WizardController::SkipPostLoginScreensForTesting();
192 chromeos::WizardController* wizard_controller = 192 chromeos::WizardController* wizard_controller =
193 chromeos::WizardController::default_controller(); 193 chromeos::WizardController::default_controller();
194 CHECK(wizard_controller); 194 CHECK(wizard_controller);
195 wizard_controller->SkipToLoginForTesting(); 195 wizard_controller->SkipToLoginForTesting();
196 196
197 ReloadKioskApps();
198
199 // The first loop exits after we receive NOTIFICATION_KIOSK_APP_LAUNCHED
200 // notification - right at app launch.
201 scoped_refptr<content::MessageLoopRunner> runner = 197 scoped_refptr<content::MessageLoopRunner> runner =
202 new content::MessageLoopRunner; 198 new content::MessageLoopRunner;
203 content_browser_client_->browser_main_extra_parts_->set_quit_task( 199 content_browser_client_->browser_main_extra_parts_->set_quit_task(
204 runner->QuitClosure()); 200 runner->QuitClosure());
205 runner->Run(); 201 runner->Run();
206
207 // Check installer status.
208 EXPECT_EQ(chromeos::KioskAppLaunchError::NONE,
209 chromeos::KioskAppLaunchError::Get());
210
211 // Check if the kiosk webapp is really installed for the default profile.
212 ASSERT_TRUE(ProfileManager::GetDefaultProfile());
213 const extensions::Extension* app =
214 extensions::ExtensionSystem::Get(ProfileManager::GetDefaultProfile())->
215 extension_service()->GetInstalledExtension(kTestKioskApp);
216 EXPECT_TRUE(app);
217
218 // The second loop exits when kiosk app terminates and we receive
219 // NOTIFICATION_RENDERER_PROCESS_CLOSED.
220 scoped_refptr<content::MessageLoopRunner> runner2 =
221 new content::MessageLoopRunner;
222 content_browser_client_->browser_main_extra_parts_->set_quit_task(
223 runner2->QuitClosure());
224 runner2->Run();
225 } 202 }
226 203
227 } // namespace chromeos 204 }
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/login_browsertest.cc ('k') | chrome/browser/chromeos/login/webui_login_display.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698