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

Side by Side Diff: ui/views/bubble/bubble_frame_view_unittest.cc

Issue 2821413002: views: support dialog width snapping once and for all (Closed)
Patch Set: rebase Created 3 years, 7 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 unified diff | Download patch
« no previous file with comments | « ui/views/bubble/bubble_frame_view.cc ('k') | ui/views/layout/layout_provider.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/bubble/bubble_frame_view.h" 5 #include "ui/views/bubble/bubble_frame_view.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "ui/gfx/geometry/insets.h" 11 #include "ui/gfx/geometry/insets.h"
12 #include "ui/gfx/geometry/rect.h" 12 #include "ui/gfx/geometry/rect.h"
13 #include "ui/gfx/geometry/size.h" 13 #include "ui/gfx/geometry/size.h"
14 #include "ui/views/bubble/bubble_border.h" 14 #include "ui/views/bubble/bubble_border.h"
15 #include "ui/views/bubble/bubble_dialog_delegate.h"
15 #include "ui/views/controls/button/label_button.h" 16 #include "ui/views/controls/button/label_button.h"
16 #include "ui/views/test/test_views.h" 17 #include "ui/views/test/test_views.h"
17 #include "ui/views/test/views_test_base.h" 18 #include "ui/views/test/views_test_base.h"
18 #include "ui/views/widget/widget.h" 19 #include "ui/views/widget/widget.h"
19 #include "ui/views/widget/widget_delegate.h" 20 #include "ui/views/widget/widget_delegate.h"
20 21
21 namespace views { 22 namespace views {
22 23
23 typedef ViewsTestBase BubbleFrameViewTest; 24 typedef ViewsTestBase BubbleFrameViewTest;
24 25
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 #else 482 #else
482 maximum_rect.Inset(frame.bubble_border()->GetInsets()); 483 maximum_rect.Inset(frame.bubble_border()->GetInsets());
483 484
484 // Should ignore the contents view's maximum size and use the preferred size. 485 // Should ignore the contents view's maximum size and use the preferred size.
485 gfx::Size expected_size(kPreferredClientWidth + kExpectedAdditionalWidth, 486 gfx::Size expected_size(kPreferredClientWidth + kExpectedAdditionalWidth,
486 kPreferredClientHeight + kExpectedAdditionalHeight); 487 kPreferredClientHeight + kExpectedAdditionalHeight);
487 EXPECT_EQ(expected_size, maximum_rect.size()); 488 EXPECT_EQ(expected_size, maximum_rect.size());
488 #endif 489 #endif
489 } 490 }
490 491
492 namespace {
493
494 class TestBubbleDialogDelegateView : public BubbleDialogDelegateView {
495 public:
496 TestBubbleDialogDelegateView()
497 : BubbleDialogDelegateView(nullptr, BubbleBorder::NONE) {
498 set_shadow(BubbleBorder::NO_ASSETS);
499 SetAnchorRect(gfx::Rect());
500 }
501 ~TestBubbleDialogDelegateView() override {}
502
503 // BubbleDialogDelegateView:
504 void DeleteDelegate() override {
505 // This delegate is owned by the test case itself, so it should not delete
506 // itself here.
507 }
508
509 int GetDialogButtons() const override { return ui::DIALOG_BUTTON_NONE; }
510
511 gfx::Size GetPreferredSize() const override { return gfx::Size(200, 200); }
512
513 private:
514 DISALLOW_COPY_AND_ASSIGN(TestBubbleDialogDelegateView);
515 };
516
517 class TestLayoutProvider : public LayoutProvider {
518 public:
519 TestLayoutProvider() : LayoutProvider() {}
520 ~TestLayoutProvider() override {}
521
522 // LayoutProvider:
523 int GetSnappedDialogWidth(int min_width) const override {
524 return snap_to_ ? snap_to_ : min_width;
525 }
526
527 void set_snap_to(int width) { snap_to_ = width; }
528
529 private:
530 int snap_to_ = 0;
531
532 DISALLOW_COPY_AND_ASSIGN(TestLayoutProvider);
533 };
534
535 } // namespace
536
537 // This test ensures that if the installed LayoutProvider snaps dialog widths,
538 // BubbleFrameView correctly sizes itself to that width.
539 TEST_F(BubbleFrameViewTest, WidthSnaps) {
540 TestLayoutProvider provider;
541 TestBubbleDialogDelegateView delegate;
542
543 delegate.set_margins(gfx::Insets());
544
545 constexpr int kTestWidth = 300;
Peter Kasting 2017/04/24 23:06:31 Nit: Declare as close as possible to first use (se
Elly Fong-Jones 2017/04/25 13:03:52 Done.
546
547 Widget* w0 = BubbleDialogDelegateView::CreateBubble(&delegate);
548 w0->Show();
549 EXPECT_EQ(delegate.GetPreferredSize().width(),
550 w0->GetWindowBoundsInScreen().width());
551 w0->CloseNow();
552
553 provider.set_snap_to(kTestWidth);
554
555 // The Widget's snapped width should exactly match the width returned by the
556 // LayoutProvider.
557 Widget* w1 = BubbleDialogDelegateView::CreateBubble(&delegate);
558 w1->Show();
559 EXPECT_EQ(kTestWidth, w1->GetWindowBoundsInScreen().width());
560 w1->CloseNow();
561 }
562
491 } // namespace views 563 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/bubble/bubble_frame_view.cc ('k') | ui/views/layout/layout_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698