Commit dbd9c9b2 authored by elizavetai's avatar elizavetai Committed by Commit bot

Class MixinBasedBrowserTest was added. This class expands its base class,...

Class MixinBasedBrowserTest was added. This class expands its base class, InProcessBrowserTest, by supporting adding mixins. Mixins can be used to add some features not related directly to the testing process in order not to make the test class too complicated and to set up them in a proper time (at the same time when the corresponding set ups for the main test are run).

A mixin should be a class inherited from MixinBasedBrowserTest::Mixin. Test which wants to use some mixin should call AddMixin(mixin_) from its constructor, where mixin_ should be an instance of e.g. MixinYouWantToUse.

Also, now LoginManagerTest is inherited from MixinBasedBrowserTest.

BUG=395653

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

Cr-Commit-Position: refs/heads/master@{#295954}
parent 252e18d2
......@@ -30,6 +30,7 @@ LoginManagerTest::LoginManagerTest(bool should_launch_browser)
}
void LoginManagerTest::TearDownOnMainThread() {
MixinBasedBrowserTest::TearDownOnMainThread();
if (LoginDisplayHostImpl::default_host())
LoginDisplayHostImpl::default_host()->Finalize();
base::MessageLoop::current()->RunUntilIdle();
......@@ -38,6 +39,7 @@ void LoginManagerTest::TearDownOnMainThread() {
void LoginManagerTest::SetUpCommandLine(CommandLine* command_line) {
command_line->AppendSwitch(chromeos::switches::kLoginManager);
command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
MixinBasedBrowserTest::SetUpCommandLine(command_line);
}
void LoginManagerTest::SetUpInProcessBrowserTestFixture() {
......@@ -46,6 +48,7 @@ void LoginManagerTest::SetUpInProcessBrowserTestFixture() {
mock_login_utils_->GetFakeLoginUtils()->set_should_launch_browser(
should_launch_browser_);
LoginUtils::Set(mock_login_utils_);
MixinBasedBrowserTest::SetUpInProcessBrowserTestFixture();
}
void LoginManagerTest::SetUpOnMainThread() {
......@@ -53,6 +56,7 @@ void LoginManagerTest::SetUpOnMainThread() {
chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
content::NotificationService::AllSources()).Wait();
InitializeWebContents();
MixinBasedBrowserTest::SetUpOnMainThread();
}
void LoginManagerTest::RegisterUser(const std::string& user_id) {
......
......@@ -7,9 +7,9 @@
#include <string>
#include "chrome/browser/chromeos/login/mixin_based_browser_test.h"
#include "chrome/browser/chromeos/login/mock_login_utils.h"
#include "chrome/browser/chromeos/login/test/js_checker.h"
#include "chrome/test/base/in_process_browser_test.h"
namespace content {
class WebContents;
......@@ -25,7 +25,7 @@ class UserContext;
// out-of-box as completed.
// Guarantees that WebUI has been initialized by waiting for
// NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE notification.
class LoginManagerTest : public InProcessBrowserTest {
class LoginManagerTest : public MixinBasedBrowserTest {
public:
explicit LoginManagerTest(bool should_launch_browser);
......
// Copyright (c) 2014 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 "chrome/browser/chromeos/login/mixin_based_browser_test.h"
namespace chromeos {
MixinBasedBrowserTest::MixinBasedBrowserTest() : setup_was_launched_(false) {
}
MixinBasedBrowserTest::~MixinBasedBrowserTest() {
}
void MixinBasedBrowserTest::SetUpCommandLine(base::CommandLine* command_line) {
setup_was_launched_ = true;
for (ScopedVector<Mixin>::iterator it = mixins_.begin(); it != mixins_.end();
++it) {
(*it)->SetUpCommandLine(command_line);
}
InProcessBrowserTest::SetUpCommandLine(command_line);
}
void MixinBasedBrowserTest::SetUpInProcessBrowserTestFixture() {
setup_was_launched_ = true;
for (ScopedVector<Mixin>::iterator it = mixins_.begin(); it != mixins_.end();
++it) {
(*it)->SetUpInProcessBrowserTestFixture();
}
InProcessBrowserTest::SetUpInProcessBrowserTestFixture();
}
void MixinBasedBrowserTest::SetUpOnMainThread() {
setup_was_launched_ = true;
for (ScopedVector<Mixin>::iterator it = mixins_.begin(); it != mixins_.end();
++it) {
(*it)->SetUpOnMainThread();
}
InProcessBrowserTest::SetUpOnMainThread();
}
void MixinBasedBrowserTest::TearDownOnMainThread() {
InProcessBrowserTest::TearDownOnMainThread();
for (ScopedVector<Mixin>::reverse_iterator it = mixins_.rbegin();
it != mixins_.rend();
++it) {
(*it)->TearDownInProcessBrowserTestFixture();
}
}
void MixinBasedBrowserTest::TearDownInProcessBrowserTestFixture() {
InProcessBrowserTest::TearDownInProcessBrowserTestFixture();
for (ScopedVector<Mixin>::reverse_iterator it = mixins_.rbegin();
it != mixins_.rend();
++it) {
(*it)->TearDownInProcessBrowserTestFixture();
}
}
void MixinBasedBrowserTest::AddMixin(MixinBasedBrowserTest::Mixin* mixin) {
CHECK(!setup_was_launched_)
<< "You are trying to add a mixin after setting up has already started.";
mixins_.push_back(mixin);
}
} // namespace chromeos
// Copyright (c) 2014 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.
#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_MIXIN_BASED_BROWSER_TEST_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_MIXIN_BASED_BROWSER_TEST_H_
#include "base/memory/scoped_vector.h"
#include "chrome/test/base/in_process_browser_test.h"
namespace chromeos {
class MixinBasedBrowserTest : public InProcessBrowserTest {
public:
// A class that can be used to add some features not related directly to the
// testing process in order not to make the test class too complicated and to
// set up them in a proper time (at the same time when the corresponding set
// ups for the main test are run).
//
// To used this you need to derive a class from from
// MixinBasedBrowserTest::Mixin, e.g. MixinYouWantToUse, and declare all
// the methods you'd like in this new class. You also can reload setups and
// teardowns if you need so. Test which wants to use some mixin should call
// AddMixin(mixin_) from its constructor, where mixin_ should be an instance
// of MixinYouWantToUse.
//
// All methods in Mixin are complete analogs of those in InProcessBrowserTest,
// so if some usecases are unclear, take a look at in_process_browser_test.h
class Mixin {
public:
Mixin() {}
virtual ~Mixin() {}
// Is called before creating the browser and running
// SetUpInProcessBrowserTestFixture.
// Should be used for setting up the command line.
virtual void SetUpCommandLine(base::CommandLine* command_line) {}
// Is called before creating the browser.
// Should be used to set up the environment for running the browser.
virtual void SetUpInProcessBrowserTestFixture() {}
// Is called after creating the browser and before executing test code.
// Should be used for setting up things related to the browser object.
virtual void SetUpOnMainThread() {}
// Is called after executing the test code and before the browser is torn
// down.
// Should be used to do the necessary cleanup on the working browser.
virtual void TearDownOnMainThread() {}
// Is called after the browser is torn down.
// Should be used to do the remaining cleanup.
virtual void TearDownInProcessBrowserTestFixture() {}
};
MixinBasedBrowserTest();
virtual ~MixinBasedBrowserTest();
// Override from InProcessBrowserTest.
virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE;
virtual void SetUpInProcessBrowserTestFixture() OVERRIDE;
virtual void SetUpOnMainThread() OVERRIDE;
virtual void TearDownOnMainThread() OVERRIDE;
virtual void TearDownInProcessBrowserTestFixture() OVERRIDE;
protected:
// Adds |mixin| as an mixin for this test, passing ownership
// for it to MixinBasedBrowserTest.
// Should be called in constructor of the test (should be already completed
// before running set ups).
void AddMixin(Mixin* mixin);
private:
// Keeps all the mixins for this test,
ScopedVector<Mixin> mixins_;
// Is false initially, becomes true when any of SetUp* methods is called.
// Required to check that AddMixin is always called before setting up.
bool setup_was_launched_;
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_LOGIN_MIXIN_BASED_BROWSER_TEST_H_
......@@ -307,6 +307,8 @@
'browser/chromeos/login/oobe_browsertest.cc',
'browser/chromeos/login/screenshot_tester.h',
'browser/chromeos/login/screenshot_tester.cc',
'browser/chromeos/login/mixin_based_browser_test.h',
'browser/chromeos/login/mixin_based_browser_test.cc',
'browser/chromeos/login/users/wallpaper/wallpaper_manager_browsertest.cc',
'browser/chromeos/login/users/wallpaper/wallpaper_manager_test_utils.cc',
'browser/chromeos/login/users/wallpaper/wallpaper_manager_test_utils.h',
......@@ -983,10 +985,12 @@
'browser/chromeos/login/kiosk_browsertest.cc',
'browser/chromeos/login/lock/screen_locker_tester.cc',
'browser/chromeos/login/lock/screen_locker_tester.h',
'browser/chromeos/login/login_screen_policy_browsertest.cc',
'browser/chromeos/login/login_utils_browsertest.cc',
'browser/chromeos/login/login_manager_test.cc',
'browser/chromeos/login/login_manager_test.h',
'browser/chromeos/login/login_screen_policy_browsertest.cc',
'browser/chromeos/login/login_utils_browsertest.cc',
'browser/chromeos/login/mixin_based_browser_test.cc',
'browser/chromeos/login/mixin_based_browser_test.h',
'browser/chromeos/login/oobe_localization_browsertest.cc',
'browser/chromeos/login/reset_browsertest.cc',
# TODO(nkostylev) Re-enable ResourceLoaderBrowserTest.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment