1 // Copyright (c) 2014 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.
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_MIXIN_BASED_BROWSER_TEST_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_MIXIN_BASED_BROWSER_TEST_H_
8 #include "base/memory/scoped_vector.h"
9 #include "chrome/test/base/in_process_browser_test.h"
13 class MixinBasedBrowserTest
: public InProcessBrowserTest
{
15 // A class that can be used to add some features not related directly to the
16 // testing process in order not to make the test class too complicated and to
17 // set up them in a proper time (at the same time when the corresponding set
18 // ups for the main test are run).
20 // To used this you need to derive a class from from
21 // MixinBasedBrowserTest::Mixin, e.g. MixinYouWantToUse, and declare all
22 // the methods you'd like in this new class. You also can reload setups and
23 // teardowns if you need so. Test which wants to use some mixin should call
24 // AddMixin(mixin_) from its constructor, where mixin_ should be an instance
25 // of MixinYouWantToUse.
27 // All methods in Mixin are complete analogs of those in InProcessBrowserTest,
28 // so if some usecases are unclear, take a look at in_process_browser_test.h
34 // Is called before creating the browser and running
35 // SetUpInProcessBrowserTestFixture.
36 // Should be used for setting up the command line.
37 virtual void SetUpCommandLine(base::CommandLine
* command_line
) {}
39 // Is called before creating the browser.
40 // Should be used to set up the environment for running the browser.
41 virtual void SetUpInProcessBrowserTestFixture() {}
43 // Is called after creating the browser and before executing test code.
44 // Should be used for setting up things related to the browser object.
45 virtual void SetUpOnMainThread() {}
47 // Is called after executing the test code and before the browser is torn
49 // Should be used to do the necessary cleanup on the working browser.
50 virtual void TearDownOnMainThread() {}
52 // Is called after the browser is torn down.
53 // Should be used to do the remaining cleanup.
54 virtual void TearDownInProcessBrowserTestFixture() {}
57 MixinBasedBrowserTest();
58 ~MixinBasedBrowserTest() override
;
60 // Override from InProcessBrowserTest.
61 void SetUpCommandLine(base::CommandLine
* command_line
) override
;
62 void SetUpInProcessBrowserTestFixture() override
;
63 void SetUpOnMainThread() override
;
64 void TearDownOnMainThread() override
;
65 void TearDownInProcessBrowserTestFixture() override
;
68 // Adds |mixin| as an mixin for this test, passing ownership
69 // for it to MixinBasedBrowserTest.
70 // Should be called in constructor of the test (should be already completed
71 // before running set ups).
72 void AddMixin(Mixin
* mixin
);
75 // Keeps all the mixins for this test,
76 ScopedVector
<Mixin
> mixins_
;
78 // Is false initially, becomes true when any of SetUp* methods is called.
79 // Required to check that AddMixin is always called before setting up.
80 bool setup_was_launched_
;
83 } // namespace chromeos
85 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_MIXIN_BASED_BROWSER_TEST_H_