File: test_browser_dialog.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (88 lines) | stat: -rw-r--r-- 3,292 bytes parent folder | download | duplicates (7)
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
// Copyright 2016 The Chromium Authors
// 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 "build/build_config.h"
#include "chrome/browser/ui/test/test_browser_ui.h"
#include "chrome/test/base/in_process_browser_test.h"

#if defined(TOOLKIT_VIEWS)
#include "ui/views/widget/widget.h"
#endif

// A dialog-specific subclass of TestBrowserUi, which will verify that a test
// showed a single dialog.
class TestBrowserDialog : public TestBrowserUi {
 public:
  TestBrowserDialog(const TestBrowserDialog&) = delete;
  TestBrowserDialog& operator=(const TestBrowserDialog&) = delete;

 protected:
  TestBrowserDialog();
  ~TestBrowserDialog() override;

  void set_should_verify_dialog_bounds(bool value) {
    should_verify_dialog_bounds_ = value;
  }

  // TestBrowserUi:
  void PreShow() override;
  bool VerifyUi() override;
  void WaitForUserDismissal() override;
  void DismissUi() override;

  // Verify UI.
  // When pixel verifcation is enabled(--browser-ui-tests-verify-pixels),
  // this function will also verify pixels using Skia Gold. Call set_baseline()
  // and SetPixelMatchAlgorithm() to adjust parameters used for verification.
  void ShowAndVerifyUi();

  // Only useful when pixel verification is enabled.
  // Set pixel test baseline so previous gold images become invalid.
  // Call this method before ShowAndVerifyUi().
  // For example, a cl changes a dialog's text, and all previously approved
  // gold images become invalid. Then in the same cl you should set a new
  // baseline. Or else the previous gold image are still valid (which they
  // should not be because they have wrong text).
  // Consider using the cl number as baseline.
  void set_baseline(const std::string& baseline) { baseline_ = baseline; }

  // Whether to close asynchronously using Widget::Close(). This covers
  // codepaths relying on DialogDelegate::Close(), which isn't invoked by
  // Widget::CloseNow(). Dialogs should support both, since the OS can initiate
  // the destruction of dialogs, e.g., during logoff which bypass
  // Widget::CanClose() and DialogDelegate::Close().
  virtual bool AlwaysCloseAsynchronously();

  // Get the name of a non-dialog window that should be included in testing.
  // VerifyUi() only considers dialog windows and windows with a matching name.
  virtual std::string GetNonDialogName();

 private:
#if defined(TOOLKIT_VIEWS)
  // Stores the current widgets in |widgets_|.
  void UpdateWidgets();

  // The widgets present before/after showing UI.
  views::Widget::Widgets widgets_;
#endif  // defined(TOOLKIT_VIEWS)

  // The baseline to use for the next pixel verification.
  std::string baseline_;

  // If set to true, the dialog bounds will be verified to fit inside the
  // display's work area.
  // This should always be true, but some dialogs don't yet size themselves
  // properly. https://crbug.com/893292.
  bool should_verify_dialog_bounds_ = true;
};

template <class Base>
using SupportsTestDialog = SupportsTestUi<Base, TestBrowserDialog>;

using DialogBrowserTest = SupportsTestDialog<InProcessBrowserTest>;

#endif  // CHROME_BROWSER_UI_TEST_TEST_BROWSER_DIALOG_H_