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

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: 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
(Empty)
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 "base/path_service.h"
7 #include "chrome/browser/chrome_browser_main.h"
8 #include "chrome/browser/chrome_browser_main_extra_parts.h"
9 #include "chrome/browser/chrome_content_browser_client.h"
10 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h"
11 #include "chrome/browser/chromeos/login/existing_user_controller.h"
12 #include "chrome/browser/chromeos/login/webui_login_display.h"
13 #include "chrome/browser/chromeos/login/wizard_controller.h"
14 #include "chrome/browser/google_apis/test_server/http_request.h"
15 #include "chrome/browser/google_apis/test_server/http_response.h"
16 #include "chrome/browser/google_apis/test_server/http_server.h"
17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/common/chrome_notification_types.h"
19 #include "chrome/common/chrome_paths.h"
20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/test/base/in_process_browser_test.h"
22 #include "chrome/test/base/interactive_test_utils.h"
23 #include "chrome/test/base/ui_test_utils.h"
24 #include "chromeos/chromeos_switches.h"
25 #include "content/public/browser/notification_observer.h"
26 #include "content/public/browser/notification_registrar.h"
27 #include "content/public/browser/notification_service.h"
28 #include "content/public/test/test_utils.h"
29 #include "google_apis/gaia/gaia_switches.h"
30 #include "testing/gmock/include/gmock/gmock.h"
31 #include "testing/gtest/include/gtest/gtest.h"
32
33 using namespace google_apis;
34 using namespace google_apis::test_server;
35
36 namespace {
37
38 // Used to add an observer to NotificationService after it's created.
39 class TestBrowserMainExtraParts
40 : public ChromeBrowserMainExtraParts,
41 public content::NotificationObserver {
42 public:
43 TestBrowserMainExtraParts() {}
44 virtual ~TestBrowserMainExtraParts() {}
45
46 // ChromeBrowserMainExtraParts implementation.
47 virtual void PreEarlyInitialization() OVERRIDE {
48 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE,
49 content::NotificationService::AllSources());
50 registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED,
51 content::NotificationService::AllSources());
52 }
53
54 void set_quit_task(const base::Closure& quit_task) { quit_task_ = quit_task; }
55
56 private:
57 // Overridden from content::NotificationObserver:
58 virtual void Observe(int type,
59 const content::NotificationSource& source,
60 const content::NotificationDetails& details) OVERRIDE {
61 if (type == chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE) {
62 LOG(INFO) << "NOTIFICATION_LOGIN_WEBUI_VISIBLE";
63 chromeos::ExistingUserController* controller =
64 chromeos::ExistingUserController::current_controller();
65 CHECK(controller);
66 chromeos::WebUILoginDisplay* webui_login_display =
67 static_cast<chromeos::WebUILoginDisplay*>(
68 controller->login_display());
69 CHECK(webui_login_display);
70 webui_login_display->ShowSigninScreenForCreds("username", "password");
Nikita (slow) 2013/04/08 17:43:44 nit: Please add TODO that mock GAIA server should
glotov 2013/04/08 19:30:24 Done.
71 } else if (type == chrome::NOTIFICATION_SESSION_STARTED) {
72 LOG(INFO) << "chrome::NOTIFICATION_SESSION_STARTED";
73 quit_task_.Run();
74 } else {
75 NOTREACHED();
76 }
77 }
78
79 content::NotificationRegistrar registrar_;
80 base::Closure quit_task_;
81
82 DISALLOW_COPY_AND_ASSIGN(TestBrowserMainExtraParts);
83 };
84
85 class TestContentBrowserClient : public chrome::ChromeContentBrowserClient {
86 public:
87 TestContentBrowserClient() {}
88 virtual ~TestContentBrowserClient() {}
89
90 virtual content::BrowserMainParts* CreateBrowserMainParts(
91 const content::MainFunctionParams& parameters) OVERRIDE {
92 ChromeBrowserMainParts* main_parts = static_cast<ChromeBrowserMainParts*>(
93 ChromeContentBrowserClient::CreateBrowserMainParts(parameters));
94
95 browser_main_extra_parts_ = new TestBrowserMainExtraParts();
96 main_parts->AddParts(browser_main_extra_parts_);
97 return main_parts;
98 }
99
100 TestBrowserMainExtraParts* browser_main_extra_parts_;
101
102 private:
103 DISALLOW_COPY_AND_ASSIGN(TestContentBrowserClient);
104 };
105
106 const base::FilePath kServiceLogin("chromeos/service_login.html");
107
108 class OobeTest : public chromeos::CrosInProcessBrowserTest {
109 protected:
110 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
111 command_line->AppendSwitch(chromeos::switches::kLoginManager);
112 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
113 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
114 command_line->AppendSwitchASCII(switches::kAuthExtensionPath, "gaia_auth");
115 command_line->AppendSwitchASCII(switches::kGaiaHost, "localhost:8040");
116 }
117
118 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
119 content_browser_client_.reset(new TestContentBrowserClient());
120 original_content_browser_client_ = content::SetBrowserClientForTesting(
121 content_browser_client_.get());
122 base::FilePath test_data_dir;
123 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
124 CHECK(file_util::ReadFileToString(test_data_dir.Append(kServiceLogin),
125 &service_login_response_));
126 }
127
128 scoped_ptr<TestContentBrowserClient> content_browser_client_;
129 content::ContentBrowserClient* original_content_browser_client_;
130
131 public:
132 scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request) {
133 GURL url = test_server_->GetURL(request.relative_url);
134 LOG(INFO) << "Http request: " << url.spec();
135
Nikita (slow) 2013/04/08 17:43:44 Please add TODO to support parsing request paramet
136 scoped_ptr<HttpResponse> http_response(new HttpResponse());
137 if (url.path() == "/ServiceLogin") {
138 http_response->set_code(test_server::SUCCESS);
139 http_response->set_content(service_login_response_);
140 http_response->set_content_type("text/html");
141 } else if (url.path() == "/ServiceLoginAuth") {
142 int continue_arg_begin = request.content.find("continue=") + 9;
143 int continue_arg_end = request.content.find("&", continue_arg_begin);
144 const std::string continue_url = request.content.substr(
Nikita (slow) 2013/04/08 17:43:44 You should add attemptToken parameter with some st
glotov 2013/04/10 13:03:24 Done.
145 continue_arg_begin, continue_arg_end - continue_arg_begin);
146 http_response->set_code(test_server::SUCCESS);
147 const std::string redirect_js =
148 "document.location.href = unescape('" + continue_url + "');";
149 http_response->set_content(
150 "<HTML><HEAD><SCRIPT>\n" + redirect_js + "\n</SCRIPT></HEAD></HTML>");
151 http_response->set_content_type("text/html");
152 } else {
153 NOTREACHED() << url.path();
154 }
155 return http_response.Pass();
156 }
157
158 HttpServer* test_server_;
159 std::string service_login_response_;
160 };
161
162 IN_PROC_BROWSER_TEST_F(OobeTest, NewUser) {
163 test_server_ = new HttpServer();
164 CHECK(test_server_->InitializeAndWaitUntilReady());
165 test_server_->RegisterRequestHandler(
166 base::Bind(&OobeTest::HandleRequest, base::Unretained(this)));
167 LOG(INFO) << "Set up http server at " << test_server_->base_url();
168
169 chromeos::SigninScreenHandler::UseHttpForGaiaForTesting();
170 chromeos::WizardController::SkipPostLoginScreensForTesting();
171 chromeos::WizardController* wizard_controller =
172 chromeos::WizardController::default_controller();
173 CHECK(wizard_controller);
174 wizard_controller->SkipToLoginForTesting();
175
176 scoped_refptr<content::MessageLoopRunner> runner =
177 new content::MessageLoopRunner;
178 content_browser_client_->browser_main_extra_parts_->set_quit_task(
179 runner->QuitClosure());
180 runner->Run();
181
182 LOG(INFO) << "Stopping the http server.";
183 test_server_->ShutdownAndWaitUntilComplete();
184 }
185
186 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698