File: test_browser_dialog.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (100 lines) | stat: -rw-r--r-- 3,470 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright 2016 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_UI_TEST_TEST_BROWSER_DIALOG_H_
#define CHROME_BROWSER_UI_TEST_TEST_BROWSER_DIALOG_H_

#include <string>
#include <vector>

#include "base/macros.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/native_widget_types.h"

// TestBrowserDialog provides a way to register an InProcessBrowserTest testing
// harness with a framework that invokes Chrome browser dialogs in a consistent
// way. It optionally provides a way to invoke dialogs "interactively". This
// allows screenshots to be generated easily, with the same test data, to assist
// with UI review. It also provides a registry of dialogs so they can be
// systematically checked for subtle changes and regressions.
//
// To use TestBrowserDialog, a test harness should inherit from
// DialogBrowserTest rather than InProcessBrowserTest. If the dialog under test
// has only a single mode of operation, the only other requirement on the test
// harness is an override:
//
// class FooDialogTest : public DialogBrowserTest {
//  public:
//   ..
//   // DialogBrowserTest:
//   void ShowDialog(const std::string& name) override {
//     /* Show dialog attached to browser() and leave it open. */
//   }
//   ..
// };
//
// then in the foo_dialog_browsertest.cc, define any number of
//
// IN_PROC_BROWSER_TEST_F(FooDialogTest, InvokeDialog_name) {
//   RunDialog();
// }
//
// The string after "InvokeDialog_" (here, "name") is the argument given to
// ShowDialog(). In a regular test suite run, RunDialog() shows the dialog and
// immediately closes it (after ensuring it was actually created).
//
// To get a list of all available dialogs, run the `BrowserDialogTest.Invoke`
// test case without other arguments. I.e.
//
//   browser_tests --gtest_filter=BrowserDialogTest.Invoke
//
// Dialogs listed can be shown interactively using the --dialog argument. E.g.
//
//   browser_tests --gtest_filter=BrowserDialogTest.Invoke --interactive \
//       --dialog=FooDialogTest.InvokeDialog_name
class TestBrowserDialog {
 protected:
  TestBrowserDialog();

  // Runs the dialog whose name corresponds to the current test case.
  void RunDialog();

  // Show the dialog corresponding to |name| and leave it open.
  virtual void ShowDialog(const std::string& name) = 0;

  // The window that owns the dialogs. Used to find where the dialog appears.
  virtual gfx::NativeWindow DialogParent() = 0;

 private:
  DISALLOW_COPY_AND_ASSIGN(TestBrowserDialog);
};

// Helper to mix in a TestBrowserDialog to an existing test harness. |Base|
// must be a descendant of InProcessBrowserTest.
template <class Base>
class SupportsTestDialog : public Base, public TestBrowserDialog {
 protected:
  SupportsTestDialog() {}

  // TestBrowserDialog:
  gfx::NativeWindow DialogParent() override {
    return this->browser()->window()->GetNativeWindow();
  }

 private:
  DISALLOW_COPY_AND_ASSIGN(SupportsTestDialog);
};

using DialogBrowserTest = SupportsTestDialog<InProcessBrowserTest>;

namespace internal {

// When present on the command line, runs the test in an interactive mode.
constexpr const char kInteractiveSwitch[] = "interactive";

}  // namespace internal

#endif  // CHROME_BROWSER_UI_TEST_TEST_BROWSER_DIALOG_H_