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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/oobe_browsertest.cc
diff --git a/chrome/browser/chromeos/login/kiosk_browsertest.cc b/chrome/browser/chromeos/login/oobe_browsertest.cc
similarity index 52%
copy from chrome/browser/chromeos/login/kiosk_browsertest.cc
copy to chrome/browser/chromeos/login/oobe_browsertest.cc
index 36875d7d5b760fd0e1eccd3b29a0d7994bc11245..b0ffedf8d53ab342351e84a44a6673d009d56501 100644
--- a/chrome/browser/chromeos/login/kiosk_browsertest.cc
+++ b/chrome/browser/chromeos/login/oobe_browsertest.cc
@@ -4,32 +4,20 @@
#include "base/command_line.h"
#include "base/path_service.h"
-#include "base/stringprintf.h"
-#include "chrome/browser/browser_process.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/app_mode/kiosk_app_launch_error.h"
-#include "chrome/browser/chromeos/app_mode/kiosk_app_manager.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/webui_login_display_host.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
-#include "chrome/browser/extensions/extension_service.h"
-#include "chrome/browser/extensions/extension_system.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/lifetime/application_lifetime.h"
-#include "chrome/browser/prefs/scoped_user_pref_update.h"
-#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
-#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
-#include "chrome/common/extensions/extension.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"
@@ -39,45 +27,32 @@
#include "content/public/browser/notification_service.h"
#include "content/public/test/test_utils.h"
#include "google_apis/gaia/gaia_switches.h"
-#include "net/base/host_port_pair.h"
-#include "net/dns/mock_host_resolver.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 chromeos {
-
namespace {
-const char kWebstoreDomain[] = "cws.com";
-
-// Webstore data json is in
-// chrome/test/data/chromeos/app_mode/webstore/inlineinstall/
-// detail/ggbflgnkafappblpkiflbgpmkfdpnhhe
-const char kTestKioskApp[] = "ggbflgnkafappblpkiflbgpmkfdpnhhe";
-
// 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_KIOSK_APPS_LOADED,
- content::NotificationService::AllSources());
- registrar_.Add(this, chrome::NOTIFICATION_KIOSK_APP_LAUNCHED,
+ 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:
@@ -86,20 +61,19 @@ class TestBrowserMainExtraParts
const content::NotificationDetails& details) OVERRIDE {
if (type == chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE) {
LOG(INFO) << "NOTIFICATION_LOGIN_WEBUI_VISIBLE";
- } else if (type == chrome::NOTIFICATION_KIOSK_APPS_LOADED) {
- LOG(INFO) << "chrome::NOTIFICATION_KIOSK_APPS_LOADED";
- content::WebUI* web_ui = static_cast<chromeos::WebUILoginDisplayHost*>(
- chromeos::WebUILoginDisplayHost::default_host())->
- GetOobeUI()->web_ui();
- web_ui->CallJavascriptFunction("login.AppsMenuButton.runAppForTesting",
- base::StringValue(kTestKioskApp));
- } else if (type == chrome::NOTIFICATION_KIOSK_APP_LAUNCHED) {
- LOG(INFO) << "chrome::NOTIFICATION_KIOSK_APP_LAUNCHED";
- registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
- content::NotificationService::AllSources());
- quit_task_.Run();
- } else if (type == content::NOTIFICATION_RENDERER_PROCESS_CLOSED) {
- LOG(INFO) << "content::NOTIFICATION_RENDERER_PROCESS_CLOSED";
+ 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();
@@ -108,6 +82,7 @@ class TestBrowserMainExtraParts
content::NotificationRegistrar registrar_;
base::Closure quit_task_;
+ std::string gaia_url_;
DISALLOW_COPY_AND_ASSIGN(TestBrowserMainExtraParts);
};
@@ -133,95 +108,97 @@ class TestContentBrowserClient : public chrome::ChromeContentBrowserClient {
DISALLOW_COPY_AND_ASSIGN(TestContentBrowserClient);
};
-} // namespace
-
-class KioskTest : public chromeos::CrosInProcessBrowserTest {
- public:
- KioskTest() : chromeos::CrosInProcessBrowserTest() {
- SetExitWhenLastBrowserCloses(false);
- }
+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->AppendSwitch(::switches::kDisableBackgroundNetworking);
+ command_line->AppendSwitch(switches::kDisableChromeCaptivePortalDetector);
command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
-
- ASSERT_TRUE(test_server()->Start());
- net::HostPortPair host_port = test_server()->host_port_pair();
- std::string test_gallery_url = base::StringPrintf(
- "http://%s:%d/files/chromeos/app_mode/webstore",
- kWebstoreDomain, host_port.port());
- command_line->AppendSwitchASCII(
- ::switches::kAppsGalleryURL, test_gallery_url);
-
- std::string test_gallery_download_url = test_gallery_url;
- test_gallery_download_url.append("/downloads/%s.crx");
- command_line->AppendSwitchASCII(
- ::switches::kAppsGalleryDownloadURL, test_gallery_download_url);
+ 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());
- host_resolver()->AddRule(kWebstoreDomain, "127.0.0.1");
+ 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 {
- // Clean up while main thread still runs.
- // See http://crbug.com/176659.
- chromeos::KioskAppManager::Get()->CleanUp();
+ LOG(INFO) << "Stopping the http server.";
+ test_server_->ShutdownAndWaitUntilComplete();
+ delete test_server_; // Destructor wants UI thread.
}
- void ReloadKioskApps() {
- chromeos::KioskAppManager::Get()->AddApp(kTestKioskApp);
+ 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(KioskTest, InstallAndLaunchApp) {
- // Start UI, find menu entry for this app and launch it.
+IN_PROC_BROWSER_TEST_F(OobeTest, NewUser) {
chromeos::WizardController::SkipPostLoginScreensForTesting();
chromeos::WizardController* wizard_controller =
chromeos::WizardController::default_controller();
CHECK(wizard_controller);
wizard_controller->SkipToLoginForTesting();
- ReloadKioskApps();
-
- // The first loop exits after we receive NOTIFICATION_KIOSK_APP_LAUNCHED
- // notification - right at app launch.
scoped_refptr<content::MessageLoopRunner> runner =
new content::MessageLoopRunner;
content_browser_client_->browser_main_extra_parts_->set_quit_task(
runner->QuitClosure());
runner->Run();
-
- // Check installer status.
- EXPECT_EQ(chromeos::KioskAppLaunchError::NONE,
- chromeos::KioskAppLaunchError::Get());
-
- // Check if the kiosk webapp is really installed for the default profile.
- ASSERT_TRUE(ProfileManager::GetDefaultProfile());
- const extensions::Extension* app =
- extensions::ExtensionSystem::Get(ProfileManager::GetDefaultProfile())->
- extension_service()->GetInstalledExtension(kTestKioskApp);
- EXPECT_TRUE(app);
-
- // The second loop exits when kiosk app terminates and we receive
- // NOTIFICATION_RENDERER_PROCESS_CLOSED.
- scoped_refptr<content::MessageLoopRunner> runner2 =
- new content::MessageLoopRunner;
- content_browser_client_->browser_main_extra_parts_->set_quit_task(
- runner2->QuitClosure());
- runner2->Run();
}
-} // namespace chromeos
+}
« 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