Skip to content

Commit

Permalink
Add browser test for new user CrOS login flow
Browse files Browse the repository at this point in the history
BUG=178009
TEST=this test

Review URL: https://codereview.chromium.org/13542003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194572 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
glotov@chromium.org committed Apr 17, 2013
1 parent 3e902a8 commit a99442b
Show file tree
Hide file tree
Showing 12 changed files with 347 additions and 31 deletions.
34 changes: 18 additions & 16 deletions chrome/browser/chromeos/login/login_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ using ::testing::_;
using ::testing::AnyNumber;
using ::testing::Return;

namespace chromeos {
namespace {

class LoginTestBase : public CrosInProcessBrowserTest {
class LoginTestBase : public chromeos::CrosInProcessBrowserTest {
public:
LoginTestBase()
: mock_cryptohome_library_(NULL),
Expand All @@ -59,8 +59,8 @@ class LoginTestBase : public CrosInProcessBrowserTest {
.WillRepeatedly(Return(true));
}

MockCryptohomeLibrary* mock_cryptohome_library_;
MockNetworkLibrary* mock_network_library_;
chromeos::MockCryptohomeLibrary* mock_cryptohome_library_;
chromeos::MockNetworkLibrary* mock_network_library_;

private:
DISALLOW_COPY_AND_ASSIGN(LoginTestBase);
Expand All @@ -73,26 +73,27 @@ class LoginUserTest : public LoginTestBase {
}

virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
command_line->AppendSwitchASCII(switches::kLoginUser, "TestUser@gmail.com");
command_line->AppendSwitchASCII(switches::kLoginProfile, "user");
command_line->AppendSwitchASCII(
chromeos::switches::kLoginUser, "TestUser@gmail.com");
command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
command_line->AppendSwitch(::switches::kNoFirstRun);
}
};

class LoginGuestTest : public LoginTestBase {
protected:
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
command_line->AppendSwitch(switches::kGuestSession);
command_line->AppendSwitch(chromeos::switches::kGuestSession);
command_line->AppendSwitch(::switches::kIncognito);
command_line->AppendSwitchASCII(switches::kLoginProfile, "user");
command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
command_line->AppendSwitch(::switches::kNoFirstRun);
}
};

class LoginCursorTest : public LoginTestBase {
protected:
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
command_line->AppendSwitch(switches::kLoginManager);
command_line->AppendSwitch(chromeos::switches::kLoginManager);
}
};

Expand Down Expand Up @@ -148,11 +149,11 @@ class TestContentBrowserClient : public chrome::ChromeContentBrowserClient {
};


class LoginSigninTest : public CrosInProcessBrowserTest {
class LoginSigninTest : public chromeos::CrosInProcessBrowserTest {
protected:
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
command_line->AppendSwitch(switches::kLoginManager);
command_line->AppendSwitch(switches::kForceLoginManagerInTests);
command_line->AppendSwitch(chromeos::switches::kLoginManager);
command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
}

virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
Expand Down Expand Up @@ -200,7 +201,8 @@ IN_PROC_BROWSER_TEST_F(LoginGuestTest, CursorShown) {
// Verifies the cursor is hidden at startup on login screen.
IN_PROC_BROWSER_TEST_F(LoginCursorTest, CursorHidden) {
// Login screen needs to be shown explicitly when running test.
ShowLoginWizard(WizardController::kLoginScreenName, gfx::Size());
chromeos::ShowLoginWizard(chromeos::WizardController::kLoginScreenName,
gfx::Size());

// Cursor should be hidden at startup
EXPECT_FALSE(ash::Shell::GetInstance()->cursor_manager()->IsCursorVisible());
Expand All @@ -209,8 +211,8 @@ IN_PROC_BROWSER_TEST_F(LoginCursorTest, CursorHidden) {
EXPECT_TRUE(ui_test_utils::SendMouseMoveSync(gfx::Point()));
EXPECT_TRUE(ash::Shell::GetInstance()->cursor_manager()->IsCursorVisible());

MessageLoop::current()->DeleteSoon(FROM_HERE,
BaseLoginDisplayHost::default_host());
MessageLoop::current()->DeleteSoon(
FROM_HERE, chromeos::BaseLoginDisplayHost::default_host());
}

// Verifies that the webui for login comes up successfully.
Expand All @@ -222,4 +224,4 @@ IN_PROC_BROWSER_TEST_F(LoginSigninTest, WebUIVisible) {
runner->Run();
}

} // namespace chromeos
}
204 changes: 204 additions & 0 deletions chrome/browser/chromeos/login/oobe_browsertest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/command_line.h"
#include "base/path_service.h"
#include "chrome/browser/chrome_browser_main.h"
#include "chrome/browser/chrome_browser_main_extra_parts.h"
#include "chrome/browser/chrome_content_browser_client.h"
#include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h"
#include "chrome/browser/chromeos/login/existing_user_controller.h"
#include "chrome/browser/chromeos/login/webui_login_display.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
#include "chrome/browser/google_apis/test_server/http_request.h"
#include "chrome/browser/google_apis/test_server/http_response.h"
#include "chrome/browser/google_apis/test_server/http_server.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "chromeos/chromeos_switches.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h"
#include "content/public/test/test_utils.h"
#include "google_apis/gaia/gaia_switches.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

using namespace google_apis;
using namespace google_apis::test_server;

namespace {

// Used to add an observer to NotificationService after it's created.
class TestBrowserMainExtraParts
: public ChromeBrowserMainExtraParts,
public content::NotificationObserver {
public:
TestBrowserMainExtraParts() {}
virtual ~TestBrowserMainExtraParts() {}

// ChromeBrowserMainExtraParts implementation.
virtual void PreEarlyInitialization() OVERRIDE {
registrar_.Add(this, chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE,
content::NotificationService::AllSources());
registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED,
content::NotificationService::AllSources());
}

void set_quit_task(const base::Closure& quit_task) { quit_task_ = quit_task; }
void set_gaia_url(const std::string& url) { gaia_url_ = url; }

private:
// Overridden from content::NotificationObserver:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE {
if (type == chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE) {
LOG(INFO) << "NOTIFICATION_LOGIN_WEBUI_VISIBLE";
chromeos::ExistingUserController* controller =
chromeos::ExistingUserController::current_controller();
CHECK(controller);
chromeos::WebUILoginDisplay* webui_login_display =
static_cast<chromeos::WebUILoginDisplay*>(
controller->login_display());
CHECK(webui_login_display);
webui_login_display->SetGaiaOriginForTesting(gaia_url_);
webui_login_display->ShowSigninScreenForCreds("username", "password");
// TODO(glotov): mock GAIA server (test_server_) should support
// username/password configuration.
} else if (type == chrome::NOTIFICATION_SESSION_STARTED) {
LOG(INFO) << "chrome::NOTIFICATION_SESSION_STARTED";
quit_task_.Run();
} else {
NOTREACHED();
}
}

content::NotificationRegistrar registrar_;
base::Closure quit_task_;
std::string gaia_url_;

DISALLOW_COPY_AND_ASSIGN(TestBrowserMainExtraParts);
};

class TestContentBrowserClient : public chrome::ChromeContentBrowserClient {
public:
TestContentBrowserClient() {}
virtual ~TestContentBrowserClient() {}

virtual content::BrowserMainParts* CreateBrowserMainParts(
const content::MainFunctionParams& parameters) OVERRIDE {
ChromeBrowserMainParts* main_parts = static_cast<ChromeBrowserMainParts*>(
ChromeContentBrowserClient::CreateBrowserMainParts(parameters));

browser_main_extra_parts_ = new TestBrowserMainExtraParts();
main_parts->AddParts(browser_main_extra_parts_);
return main_parts;
}

TestBrowserMainExtraParts* browser_main_extra_parts_;

private:
DISALLOW_COPY_AND_ASSIGN(TestContentBrowserClient);
};

const base::FilePath kServiceLogin("chromeos/service_login.html");

class OobeTest : public chromeos::CrosInProcessBrowserTest {
protected:
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
command_line->AppendSwitch(chromeos::switches::kLoginManager);
command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
command_line->AppendSwitch(switches::kDisableChromeCaptivePortalDetector);
command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
command_line->AppendSwitchASCII(switches::kAuthExtensionPath, "gaia_auth");
}

virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
content_browser_client_.reset(new TestContentBrowserClient());
original_content_browser_client_ = content::SetBrowserClientForTesting(
content_browser_client_.get());
base::FilePath test_data_dir;
PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
CHECK(file_util::ReadFileToString(test_data_dir.Append(kServiceLogin),
&service_login_response_));
}

virtual void SetUpOnMainThread() OVERRIDE {
test_server_ = new HttpServer(); // Constructor wants UI thread.
CHECK(test_server_->InitializeAndWaitUntilReady());
test_server_->RegisterRequestHandler(
base::Bind(&OobeTest::HandleRequest, base::Unretained(this)));
LOG(INFO) << "Set up http server at " << test_server_->base_url();
CHECK(test_server_->port() >= 8040 && test_server_->port() < 8045)
<< "Current manifest_test.json for gaia_login restrictions "
<< "does not allow this port";

const std::string gaia_url =
"http://localhost:" + test_server_->base_url().port();
content_browser_client_->browser_main_extra_parts_->set_gaia_url(gaia_url);
}

virtual void CleanUpOnMainThread() OVERRIDE {
LOG(INFO) << "Stopping the http server.";
test_server_->ShutdownAndWaitUntilComplete();
delete test_server_; // Destructor wants UI thread.
}

scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request) {
GURL url = test_server_->GetURL(request.relative_url);
LOG(INFO) << "Http request: " << url.spec();

scoped_ptr<HttpResponse> http_response(new HttpResponse());
if (url.path() == "/ServiceLogin") {
http_response->set_code(test_server::SUCCESS);
http_response->set_content(service_login_response_);
http_response->set_content_type("text/html");
} else if (url.path() == "/ServiceLoginAuth") {
LOG(INFO) << "Params: " << request.content;
static const char kContinueParam[] = "continue=";
int continue_arg_begin = request.content.find(kContinueParam) +
arraysize(kContinueParam) - 1;
int continue_arg_end = request.content.find("&", continue_arg_begin);
const std::string continue_url = request.content.substr(
continue_arg_begin, continue_arg_end - continue_arg_begin);
http_response->set_code(test_server::SUCCESS);
const std::string redirect_js =
"document.location.href = unescape('" + continue_url + "');";
http_response->set_content(
"<HTML><HEAD><SCRIPT>\n" + redirect_js + "\n</SCRIPT></HEAD></HTML>");
http_response->set_content_type("text/html");
} else {
NOTREACHED() << url.path();
}
return http_response.Pass();
}

scoped_ptr<TestContentBrowserClient> content_browser_client_;
content::ContentBrowserClient* original_content_browser_client_;
std::string service_login_response_;
HttpServer* test_server_; // cant use scoped_ptr because destructor
// needs UI thread.
};

IN_PROC_BROWSER_TEST_F(OobeTest, NewUser) {
chromeos::WizardController::SkipPostLoginScreensForTesting();
chromeos::WizardController* wizard_controller =
chromeos::WizardController::default_controller();
CHECK(wizard_controller);
wizard_controller->SkipToLoginForTesting();

scoped_refptr<content::MessageLoopRunner> runner =
new content::MessageLoopRunner;
content_browser_client_->browser_main_extra_parts_->set_quit_task(
runner->QuitClosure());
runner->Run();
}

}
5 changes: 5 additions & 0 deletions chrome/browser/chromeos/login/webui_login_display.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ void WebUILoginDisplay::ShowSigninScreenForCreds(
webui_handler_->ShowSigninScreenForCreds(username, password);
}

void WebUILoginDisplay::SetGaiaOriginForTesting(const std::string& arg) {
if (webui_handler_)
webui_handler_->SetGaiaOriginForTesting(arg);
}

const UserList& WebUILoginDisplay::GetUsers() const {
return users_;
}
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/chromeos/login/webui_login_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class WebUILoginDisplay : public LoginDisplay,
LoginDisplayWebUIHandler* webui_handler) OVERRIDE;
virtual void ShowSigninScreenForCreds(const std::string& username,
const std::string& password);
virtual void SetGaiaOriginForTesting(const std::string& arg);
virtual const UserList& GetUsers() const OVERRIDE;
virtual bool IsShowGuest() const OVERRIDE;
virtual bool IsShowUsers() const OVERRIDE;
Expand Down
27 changes: 19 additions & 8 deletions chrome/browser/extensions/user_script_master.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "base/version.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/extensions/image_loader.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/extensions/api/i18n/default_locale_handler.h"
Expand All @@ -29,6 +30,7 @@
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_process_host.h"
#include "extensions/common/extension_resource.h"
#include "ui/base/resource/resource_bundle.h"

using content::BrowserThread;

Expand Down Expand Up @@ -188,14 +190,23 @@ static bool LoadScriptContent(UserScript::File* script_file,
script_file->extension_root(), script_file->relative_path(),
ExtensionResource::SYMLINKS_MUST_RESOLVE_WITHIN_ROOT);
if (path.empty()) {
LOG(WARNING) << "Failed to get file path to "
<< script_file->relative_path().value() << " from "
<< script_file->extension_root().value();
return false;
}
if (!file_util::ReadFileToString(path, &content)) {
LOG(WARNING) << "Failed to load user script file: " << path.value();
return false;
int resource_id;
if (extensions::ImageLoader::IsComponentExtensionResource(
script_file->extension_root(), script_file->relative_path(),
&resource_id)) {
const ResourceBundle& rb = ResourceBundle::GetSharedInstance();
content = rb.GetRawDataResource(resource_id).as_string();
} else {
LOG(WARNING) << "Failed to get file path to "
<< script_file->relative_path().value() << " from "
<< script_file->extension_root().value();
return false;
}
} else {
if (!file_util::ReadFileToString(path, &content)) {
LOG(WARNING) << "Failed to load user script file: " << path.value();
return false;
}
}

// Localize the content.
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/resources/chromeos/login/screen_gaia_signin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
cr.define('login', function() {
// Gaia loading time after which error message must be displayed and
// lazy portal check should be fired.
/** @const */ var GAIA_LOADING_PORTAL_SUSSPECT_TIME_SEC = 7;
/** @const */ var GAIA_LOADING_PORTAL_SUSSPECT_TIME_SEC = 15;

// Maximum Gaia loading time in seconds.
/** @const */ var MAX_GAIA_LOADING_TIME_SEC = 60;
Expand Down Expand Up @@ -231,7 +231,7 @@ cr.define('login', function() {
url += '?' + params.join('&');

if (data.forceReload || this.extensionUrl_ != url) {
console.log('Opening extension: ' + data.url +
console.log('Opening extension: ' + url +
', opt_email=' + data.email);

this.error_ = 0;
Expand Down
Loading

0 comments on commit a99442b

Please sign in to comment.