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 "base/macros.h" 9 #include "build/build_config.h" 10 #include "chrome/browser/ui/test/test_browser_ui.h" 11 #include "chrome/test/base/in_process_browser_test.h" 12 13 #if defined(TOOLKIT_VIEWS) 14 #include "ui/views/widget/widget.h" 15 #endif 16 17 // A dialog-specific subclass of TestBrowserUi, which will verify that a test 18 // showed a single dialog. 19 class TestBrowserDialog : public TestBrowserUi { 20 protected: 21 TestBrowserDialog(); 22 ~TestBrowserDialog() override; 23 set_should_verify_dialog_bounds(bool value)24 void set_should_verify_dialog_bounds(bool value) { 25 should_verify_dialog_bounds_ = value; 26 } 27 28 // TestBrowserUi: 29 void PreShow() override; 30 bool VerifyUi() override; 31 void WaitForUserDismissal() override; 32 void DismissUi() override; 33 34 // Verify UI. 35 // When pixel verifcation is enabled(--browser-ui-tests-verify-pixels), 36 // this function will also verify pixels using Skia Gold. Call set_baseline() 37 // and SetPixelMatchAlgorithm() to adjust parameters used for verification. 38 void ShowAndVerifyUi(); 39 40 // Only useful when pixel verification is enabled. 41 // Set pixel test baseline so previous gold images become invalid. 42 // Call this method before ShowAndVerifyUi(). 43 // For example, a cl changes a dialog's text, and all previously approved 44 // gold images become invalid. Then in the same cl you should set a new 45 // baseline. Or else the previous gold image are still valid (which they 46 // should not be because they have wrong text). 47 // Consider using the cl number as baseline. set_baseline(const std::string & baseline)48 void set_baseline(const std::string& baseline) { baseline_ = baseline; } 49 50 // Whether to close asynchronously using Widget::Close(). This covers 51 // codepaths relying on DialogDelegate::Close(), which isn't invoked by 52 // Widget::CloseNow(). Dialogs should support both, since the OS can initiate 53 // the destruction of dialogs, e.g., during logoff which bypass 54 // Widget::CanClose() and DialogDelegate::Close(). 55 virtual bool AlwaysCloseAsynchronously(); 56 57 // Get the name of a non-dialog window that should be included in testing. 58 // VerifyUi() only considers dialog windows and windows with a matching name. 59 virtual std::string GetNonDialogName(); 60 61 private: 62 #if defined(TOOLKIT_VIEWS) 63 // Stores the current widgets in |widgets_|. 64 void UpdateWidgets(); 65 66 // The widgets present before/after showing UI. 67 views::Widget::Widgets widgets_; 68 #endif // defined(TOOLKIT_VIEWS) 69 70 // The baseline to use for the next pixel verification. 71 std::string baseline_; 72 73 // If set to true, the dialog bounds will be verified to fit inside the 74 // display's work area. 75 // This should always be true, but some dialogs don't yet size themselves 76 // properly. https://crbug.com/893292. 77 bool should_verify_dialog_bounds_ = true; 78 79 DISALLOW_COPY_AND_ASSIGN(TestBrowserDialog); 80 }; 81 82 template <class Base> 83 using SupportsTestDialog = SupportsTestUi<Base, TestBrowserDialog>; 84 85 using DialogBrowserTest = SupportsTestDialog<InProcessBrowserTest>; 86 87 #endif // CHROME_BROWSER_UI_TEST_TEST_BROWSER_DIALOG_H_ 88