OLD | NEW |
| (Empty) |
1 // Copyright 2017 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 #include "chrome/browser/ui/views/validation_message_bubble_view.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/strings/utf_string_conversions.h" | |
9 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | |
10 #include "content/public/browser/web_contents.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 #include "ui/display/display_switches.h" | |
13 #include "ui/views/layout/layout_provider.h" | |
14 #include "ui/views/test/scoped_views_test_helper.h" | |
15 #include "ui/views/test/test_views_delegate.h" | |
16 | |
17 namespace { | |
18 constexpr float kScaleFactor = 1.5; | |
19 constexpr gfx::Rect kInitialAnchorRect = gfx::Rect(10, 20, 30, 40); | |
20 } // namespace | |
21 | |
22 class ValidationMessageBubbleViewTest : public ChromeRenderViewHostTestHarness { | |
23 public: | |
24 ValidationMessageBubbleViewTest() = default; | |
25 | |
26 void SetUp() override { | |
27 // Append the switch before any other setup. | |
28 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
29 switches::kForceDeviceScaleFactor, std::to_string(kScaleFactor)); | |
30 | |
31 ChromeRenderViewHostTestHarness::SetUp(); | |
32 | |
33 bubble_ = new ValidationMessageBubbleView( | |
34 web_contents(), kInitialAnchorRect, base::ASCIIToUTF16("MAIN TEXT"), | |
35 base::ASCIIToUTF16("SUB TEXT")); | |
36 } | |
37 | |
38 ValidationMessageBubbleView& bubble() { return *bubble_; } | |
39 | |
40 private: | |
41 views::LayoutProvider provider_; // Creates a singleton. | |
42 ValidationMessageBubbleView* bubble_; | |
43 | |
44 DISALLOW_COPY_AND_ASSIGN(ValidationMessageBubbleViewTest); | |
45 }; | |
46 | |
47 TEST_F(ValidationMessageBubbleViewTest, | |
48 AnchorRectIsCorrectForDeviceScaleFactor) { | |
49 constexpr float inverse_scale_factor = 1 / kScaleFactor; | |
50 EXPECT_EQ(gfx::ScaleToEnclosingRect(kInitialAnchorRect, inverse_scale_factor), | |
51 bubble().anchor_rect()); | |
52 | |
53 const gfx::Rect updated_anchor_rect(50, 60, 70, 80); | |
54 bubble().SetPositionRelativeToAnchor( | |
55 web_contents()->GetRenderWidgetHostView()->GetRenderWidgetHost(), | |
56 updated_anchor_rect); | |
57 EXPECT_EQ( | |
58 gfx::ScaleToEnclosingRect(updated_anchor_rect, inverse_scale_factor), | |
59 bubble().anchor_rect()); | |
60 } | |
OLD | NEW |