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

Side by Side Diff: chrome/browser/ui/test/test_browser_dialog.h

Issue 2532793002: Add a TestBrowserDialog helper class for testing browser dialogs in a consistent way. (Closed)
Patch Set: Comment example. Use TestNameWithoutDisabledPrefix Created 4 years 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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.
4
5 #ifndef CHROME_BROWSER_UI_TEST_TEST_BROWSER_DIALOG_H_
6 #define CHROME_BROWSER_UI_TEST_TEST_BROWSER_DIALOG_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/macros.h"
12 #include "chrome/browser/ui/browser_window.h"
13 #include "chrome/test/base/in_process_browser_test.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/gfx/native_widget_types.h"
16
17 // TestBrowserDialog provides a way to register an InProcessBrowserTest testing
18 // harness with a framework that invokes Chrome browser dialogs in a consistent
19 // way. It optionally provides a way to invoke dialogs "interactively". This
20 // allows screenshots to be generated easily, with the same test data, to assist
21 // with UI review. It also provides a registry of dialogs so they can be
22 // systematically checked for subtle changes and regressions.
23 //
24 // To use TestBrowserDialog, a test harness should inherit from
25 // DialogBrowserTest rather than InProcessBrowserTest. If the dialog under test
26 // has only a single mode of operation, the only other requirement on the test
27 // harness is an override:
28 //
29 // class FooDialogTest : public DialogBrowserTest {
30 // public:
31 // ..
32 // // DialogBrowserTest:
33 // void ShowDialog(const std::string& name) override {
34 // /* Show dialog attached to browser() and leave it open. */
35 // }
36 // ..
37 // };
38 //
39 // then in the foo_dialog_browsertest.cc, define any number of
40 //
41 // IN_PROC_BROWSER_TEST_F(FooDialogTest, InvokeDialog_name) {
42 // RunDialog();
43 // }
44 //
45 // The string after "InvokeDialog_" (here, "name") is the argument given to
46 // ShowDialog(). In a regular test suite run, RunDialog() shows the dialog and
47 // immediately closes it (after ensuring it was actually created).
48 //
49 // To get a list of all available dialogs, run the `BrowserDialogTest.Invoke`
50 // test case without other arguments. I.e.
51 //
52 // browser_tests --gtest_filter=BrowserDialogTest.Invoke
53 //
54 // Dialogs listed can be shown interactively using the --dialog argument. E.g.
55 //
56 // browser_tests --gtest_filter=BrowserDialogTest.Invoke --interactive \
57 // --dialog=FooDialogTest.InvokeDialog_name
58 class TestBrowserDialog {
59 protected:
60 TestBrowserDialog();
61
62 // Runs the dialog whose name corresponds to the current test case.
63 void RunDialog();
64
65 // Show the dialog corresponding to |name| and leave it open.
66 virtual void ShowDialog(const std::string& name) = 0;
67
68 // The window that owns the dialogs. Used to find where the dialog appears.
69 virtual gfx::NativeWindow DialogParent() = 0;
70
71 private:
72 DISALLOW_COPY_AND_ASSIGN(TestBrowserDialog);
73 };
74
75 // Helper to mix in a TestBrowserDialog to an existing test harness. |Base|
76 // must be a descendant of InProcessBrowserTest.
77 template <class Base>
78 class SupportsTestDialog : public Base, public TestBrowserDialog {
79 protected:
80 SupportsTestDialog() {}
81
82 // TestBrowserDialog:
83 gfx::NativeWindow DialogParent() override {
84 return this->browser()->window()->GetNativeWindow();
85 }
86
87 private:
88 DISALLOW_COPY_AND_ASSIGN(SupportsTestDialog);
89 };
90
91 using DialogBrowserTest = SupportsTestDialog<InProcessBrowserTest>;
92
93 namespace internal {
94
95 // When present on the command line, runs the test in an interactive mode.
96 constexpr const char kInteractiveSwitch[] = "interactive";
97
98 } // namespace internal
99
100 #endif // CHROME_BROWSER_UI_TEST_TEST_BROWSER_DIALOG_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/test/browser_dialog_browsertest.cc ('k') | chrome/browser/ui/test/test_browser_dialog.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698