| OLD | NEW |
| 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 "chrome/browser/chrome_browser_main.h" | 7 #include "chrome/browser/chrome_browser_main.h" |
| 8 #include "chrome/browser/chrome_browser_main_extra_parts.h" | 8 #include "chrome/browser/chrome_browser_main_extra_parts.h" |
| 9 #include "chrome/browser/chrome_content_browser_client.h" | 9 #include "chrome/browser/chrome_content_browser_client.h" |
| 10 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" | 10 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" |
| 11 #include "chrome/browser/chromeos/login/existing_user_controller.h" | 11 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
| 12 #include "chrome/browser/chromeos/login/webui_login_display.h" | 12 #include "chrome/browser/chromeos/login/webui_login_display.h" |
| 13 #include "chrome/browser/chromeos/login/wizard_controller.h" | 13 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
| 17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
| 19 #include "chrome/test/base/interactive_test_utils.h" | 19 #include "chrome/test/base/interactive_test_utils.h" |
| 20 #include "chrome/test/base/ui_test_utils.h" | 20 #include "chrome/test/base/ui_test_utils.h" |
| 21 #include "chromeos/chromeos_switches.h" | 21 #include "chromeos/chromeos_switches.h" |
| 22 #include "content/public/browser/notification_observer.h" | 22 #include "content/public/browser/notification_observer.h" |
| 23 #include "content/public/browser/notification_registrar.h" | 23 #include "content/public/browser/notification_registrar.h" |
| 24 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
| 25 #include "content/public/test/test_utils.h" | 25 #include "content/public/test/test_utils.h" |
| 26 #include "google_apis/gaia/gaia_switches.h" | 26 #include "google_apis/gaia/gaia_switches.h" |
| 27 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 27 #include "net/test/embedded_test_server/http_request.h" | 28 #include "net/test/embedded_test_server/http_request.h" |
| 28 #include "net/test/embedded_test_server/http_response.h" | 29 #include "net/test/embedded_test_server/http_response.h" |
| 29 #include "net/test/embedded_test_server/http_server.h" | |
| 30 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 32 | 32 |
| 33 using namespace google_apis; | 33 using namespace net::test_server; |
| 34 using namespace google_apis::test_server; | |
| 35 | 34 |
| 36 namespace { | 35 namespace { |
| 37 | 36 |
| 38 // Used to add an observer to NotificationService after it's created. | 37 // Used to add an observer to NotificationService after it's created. |
| 39 class TestBrowserMainExtraParts | 38 class TestBrowserMainExtraParts |
| 40 : public ChromeBrowserMainExtraParts, | 39 : public ChromeBrowserMainExtraParts, |
| 41 public content::NotificationObserver { | 40 public content::NotificationObserver { |
| 42 public: | 41 public: |
| 43 TestBrowserMainExtraParts() | 42 TestBrowserMainExtraParts() |
| 44 : webui_visible_(false), | 43 : webui_visible_(false), |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 content_browser_client_.reset(new TestContentBrowserClient()); | 144 content_browser_client_.reset(new TestContentBrowserClient()); |
| 146 original_content_browser_client_ = content::SetBrowserClientForTesting( | 145 original_content_browser_client_ = content::SetBrowserClientForTesting( |
| 147 content_browser_client_.get()); | 146 content_browser_client_.get()); |
| 148 base::FilePath test_data_dir; | 147 base::FilePath test_data_dir; |
| 149 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); | 148 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); |
| 150 CHECK(file_util::ReadFileToString(test_data_dir.Append(kServiceLogin), | 149 CHECK(file_util::ReadFileToString(test_data_dir.Append(kServiceLogin), |
| 151 &service_login_response_)); | 150 &service_login_response_)); |
| 152 } | 151 } |
| 153 | 152 |
| 154 virtual void SetUpOnMainThread() OVERRIDE { | 153 virtual void SetUpOnMainThread() OVERRIDE { |
| 155 test_server_ = new HttpServer( | 154 test_server_ = new EmbeddedTestServer( |
| 156 content::BrowserThread::GetMessageLoopProxyForThread( | 155 content::BrowserThread::GetMessageLoopProxyForThread( |
| 157 content::BrowserThread::IO)); | 156 content::BrowserThread::IO)); |
| 158 CHECK(test_server_->InitializeAndWaitUntilReady()); | 157 CHECK(test_server_->InitializeAndWaitUntilReady()); |
| 159 test_server_->RegisterRequestHandler( | 158 test_server_->RegisterRequestHandler( |
| 160 base::Bind(&OobeTest::HandleRequest, base::Unretained(this))); | 159 base::Bind(&OobeTest::HandleRequest, base::Unretained(this))); |
| 161 LOG(INFO) << "Set up http server at " << test_server_->base_url(); | 160 LOG(INFO) << "Set up http server at " << test_server_->base_url(); |
| 162 CHECK(test_server_->port() >= 8040 && test_server_->port() < 8045) | 161 CHECK(test_server_->port() >= 8040 && test_server_->port() < 8045) |
| 163 << "Current manifest_test.json for gaia_login restrictions " | 162 << "Current manifest_test.json for gaia_login restrictions " |
| 164 << "does not allow this port"; | 163 << "does not allow this port"; |
| 165 | 164 |
| 166 const std::string gaia_url = | 165 const std::string gaia_url = |
| 167 "http://localhost:" + test_server_->base_url().port(); | 166 "http://localhost:" + test_server_->base_url().port(); |
| 168 content_browser_client_->browser_main_extra_parts_->set_gaia_url(gaia_url); | 167 content_browser_client_->browser_main_extra_parts_->set_gaia_url(gaia_url); |
| 169 } | 168 } |
| 170 | 169 |
| 171 virtual void CleanUpOnMainThread() OVERRIDE { | 170 virtual void CleanUpOnMainThread() OVERRIDE { |
| 172 LOG(INFO) << "Stopping the http server."; | 171 LOG(INFO) << "Stopping the http server."; |
| 173 EXPECT_TRUE(test_server_->ShutdownAndWaitUntilComplete()); | 172 EXPECT_TRUE(test_server_->ShutdownAndWaitUntilComplete()); |
| 174 delete test_server_; // Destructor wants UI thread. | 173 delete test_server_; // Destructor wants UI thread. |
| 175 } | 174 } |
| 176 | 175 |
| 177 scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request) { | 176 scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request) { |
| 178 GURL url = test_server_->GetURL(request.relative_url); | 177 GURL url = test_server_->GetURL(request.relative_url); |
| 179 LOG(INFO) << "Http request: " << url.spec(); | 178 LOG(INFO) << "Http request: " << url.spec(); |
| 180 | 179 |
| 181 scoped_ptr<HttpResponse> http_response(new HttpResponse()); | 180 scoped_ptr<HttpResponse> http_response(new HttpResponse()); |
| 182 if (url.path() == "/ServiceLogin") { | 181 if (url.path() == "/ServiceLogin") { |
| 183 http_response->set_code(test_server::SUCCESS); | 182 http_response->set_code(net::test_server::SUCCESS); |
| 184 http_response->set_content(service_login_response_); | 183 http_response->set_content(service_login_response_); |
| 185 http_response->set_content_type("text/html"); | 184 http_response->set_content_type("text/html"); |
| 186 } else if (url.path() == "/ServiceLoginAuth") { | 185 } else if (url.path() == "/ServiceLoginAuth") { |
| 187 LOG(INFO) << "Params: " << request.content; | 186 LOG(INFO) << "Params: " << request.content; |
| 188 static const char kContinueParam[] = "continue="; | 187 static const char kContinueParam[] = "continue="; |
| 189 int continue_arg_begin = request.content.find(kContinueParam) + | 188 int continue_arg_begin = request.content.find(kContinueParam) + |
| 190 arraysize(kContinueParam) - 1; | 189 arraysize(kContinueParam) - 1; |
| 191 int continue_arg_end = request.content.find("&", continue_arg_begin); | 190 int continue_arg_end = request.content.find("&", continue_arg_begin); |
| 192 const std::string continue_url = request.content.substr( | 191 const std::string continue_url = request.content.substr( |
| 193 continue_arg_begin, continue_arg_end - continue_arg_begin); | 192 continue_arg_begin, continue_arg_end - continue_arg_begin); |
| 194 http_response->set_code(test_server::SUCCESS); | 193 http_response->set_code(net::test_server::SUCCESS); |
| 195 const std::string redirect_js = | 194 const std::string redirect_js = |
| 196 "document.location.href = unescape('" + continue_url + "');"; | 195 "document.location.href = unescape('" + continue_url + "');"; |
| 197 http_response->set_content( | 196 http_response->set_content( |
| 198 "<HTML><HEAD><SCRIPT>\n" + redirect_js + "\n</SCRIPT></HEAD></HTML>"); | 197 "<HTML><HEAD><SCRIPT>\n" + redirect_js + "\n</SCRIPT></HEAD></HTML>"); |
| 199 http_response->set_content_type("text/html"); | 198 http_response->set_content_type("text/html"); |
| 200 } else { | 199 } else { |
| 201 NOTREACHED() << url.path(); | 200 NOTREACHED() << url.path(); |
| 202 } | 201 } |
| 203 return http_response.Pass(); | 202 return http_response.Pass(); |
| 204 } | 203 } |
| 205 | 204 |
| 206 scoped_ptr<TestContentBrowserClient> content_browser_client_; | 205 scoped_ptr<TestContentBrowserClient> content_browser_client_; |
| 207 content::ContentBrowserClient* original_content_browser_client_; | 206 content::ContentBrowserClient* original_content_browser_client_; |
| 208 std::string service_login_response_; | 207 std::string service_login_response_; |
| 209 HttpServer* test_server_; // cant use scoped_ptr because destructor | 208 EmbeddedTestServer* test_server_; // cant use scoped_ptr because destructor |
| 210 // needs UI thread. | 209 // needs UI thread. |
| 211 }; | 210 }; |
| 212 | 211 |
| 213 IN_PROC_BROWSER_TEST_F(OobeTest, NewUser) { | 212 IN_PROC_BROWSER_TEST_F(OobeTest, NewUser) { |
| 214 chromeos::WizardController::SkipPostLoginScreensForTesting(); | 213 chromeos::WizardController::SkipPostLoginScreensForTesting(); |
| 215 chromeos::WizardController* wizard_controller = | 214 chromeos::WizardController* wizard_controller = |
| 216 chromeos::WizardController::default_controller(); | 215 chromeos::WizardController::default_controller(); |
| 217 CHECK(wizard_controller); | 216 CHECK(wizard_controller); |
| 218 wizard_controller->SkipToLoginForTesting(); | 217 wizard_controller->SkipToLoginForTesting(); |
| 219 | 218 |
| 220 scoped_refptr<content::MessageLoopRunner> runner = | 219 scoped_refptr<content::MessageLoopRunner> runner = |
| 221 new content::MessageLoopRunner; | 220 new content::MessageLoopRunner; |
| 222 content_browser_client_->browser_main_extra_parts_->set_quit_task( | 221 content_browser_client_->browser_main_extra_parts_->set_quit_task( |
| 223 runner->QuitClosure()); | 222 runner->QuitClosure()); |
| 224 runner->Run(); | 223 runner->Run(); |
| 225 } | 224 } |
| 226 | 225 |
| 227 } | 226 } |
| OLD | NEW |