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

Unified Diff: ui/views/window/dialog_client_view_unittest.cc

Issue 2860953002: Harmony: Apply the upper bound on equal-sized button widths in DialogClientView. (Closed)
Patch Set: Make it 112, per http://crbug.com/671820#c19 Created 3 years, 8 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/window/dialog_client_view.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/window/dialog_client_view_unittest.cc
diff --git a/ui/views/window/dialog_client_view_unittest.cc b/ui/views/window/dialog_client_view_unittest.cc
index 26ef3e303aa8042c0f19363f5e91fb020fb8a08b..d58e2272dcf8e02d4504ccb1bae3f57f9b44f097 100644
--- a/ui/views/window/dialog_client_view_unittest.cc
+++ b/ui/views/window/dialog_client_view_unittest.cc
@@ -4,10 +4,11 @@
#include "ui/views/window/dialog_client_view.h"
+#include <map>
+
#include "base/macros.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
-#include "ui/base/test/material_design_controller_test_api.h"
#include "ui/base/ui_base_types.h"
#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/button/label_button.h"
@@ -131,7 +132,8 @@ class DialogClientViewTest : public test::WidgetTest,
}
// Set a longer than normal Cancel label so that the minimum button width is
- // exceeded.
+ // exceeded. The resulting width is around 160 pixels, but depends on system
+ // fonts.
void SetLongCancelLabel() {
cancel_label_ = base::ASCIIToUTF16("Cancel Cancel Cancel");
}
@@ -162,6 +164,26 @@ class DialogClientViewTest : public test::WidgetTest,
DISALLOW_COPY_AND_ASSIGN(DialogClientViewTest);
};
+// Helper to test LayoutProvider metric overrides.
+class TestLayoutProvider : public LayoutProvider {
msw 2017/05/05 18:07:43 nit: Can you move this to its own file and use tha
tapted 2017/05/08 06:53:57 Done.
+ public:
+ TestLayoutProvider() {}
+
+ void Set(int metric, int value) { metrics_[metric] = value; }
+
+ // LayoutProvider:
+ int GetDistanceMetric(int metric) const override {
+ if (metrics_.count(metric))
+ return metrics_.find(metric)->second;
+ return LayoutProvider::GetDistanceMetric(metric);
+ }
+
+ private:
+ std::map<int, int> metrics_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestLayoutProvider);
+};
+
TEST_F(DialogClientViewTest, UpdateButtons) {
// This dialog should start with no buttons.
EXPECT_EQ(GetDialogButtons(), ui::DIALOG_BUTTON_NONE);
@@ -360,9 +382,8 @@ TEST_F(DialogClientViewTest, MinMaxPreferredSize) {
// Ensure button widths are linked under MD.
TEST_F(DialogClientViewTest, LinkedWidths) {
- ui::test::MaterialDesignControllerTestAPI md_test_api(
- ui::MaterialDesignController::MATERIAL_NORMAL);
- md_test_api.SetSecondaryUiMaterial(true);
+ TestLayoutProvider layout_provider;
+ layout_provider.Set(DISTANCE_BUTTON_MAX_LINKABLE_WIDTH, 200);
SetLongCancelLabel();
SetDialogButtons(ui::DIALOG_BUTTON_OK);
@@ -383,12 +404,12 @@ TEST_F(DialogClientViewTest, LinkedWidths) {
// OK button should now match the bigger, cancel button.
EXPECT_EQ(cancel_button_width, client_view()->ok_button()->width());
- // But not under non-MD.
- md_test_api.SetSecondaryUiMaterial(false);
+ // But not when the size of the cancel button exceeds the max linkable width.
+ layout_provider.Set(DISTANCE_BUTTON_MAX_LINKABLE_WIDTH, 100);
msw 2017/05/05 18:07:43 nit: EXPECT_GT(cancel_button_width, 100)?
tapted 2017/05/08 06:53:57 Done.
client_view()->UpdateDialogButtons();
CheckContentsIsSetToPreferredSize();
EXPECT_EQ(ok_button_only_width, client_view()->ok_button()->width());
- md_test_api.SetSecondaryUiMaterial(true);
+ layout_provider.Set(DISTANCE_BUTTON_MAX_LINKABLE_WIDTH, 200);
// The extra view should also match, if it's a matching button type.
LabelButton* extra_button = new LabelButton(nullptr, base::string16());
« no previous file with comments | « ui/views/window/dialog_client_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698