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 "content/test/test_render_view_host.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 #include "ui/display/display_switches.h" | |
14 #include "ui/views/layout/layout_provider.h" | |
15 #include "ui/views/test/scoped_views_test_helper.h" | |
16 #include "ui/views/test/test_views_delegate.h" | |
17 | |
18 namespace { | |
19 constexpr float kScaleFactor = 1.5; | |
20 constexpr gfx::Rect kInitialAnchorRect = gfx::Rect(10, 20, 30, 40); | |
21 } // namespace | |
22 | |
23 class ValidationMessageBubbleViewTest : public ChromeRenderViewHostTestHarness { | |
24 public: | |
25 void SetUp() override { | |
26 // Append the switch before any other setup. | |
27 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
28 switches::kForceDeviceScaleFactor, std::to_string(kScaleFactor)); | |
29 | |
30 ChromeRenderViewHostTestHarness::SetUp(); | |
31 | |
32 // Gives the validation bubble a parent, which is required on widget | |
33 // creation. | |
34 static_cast<content::TestRenderWidgetHostView*>( | |
35 web_contents()->GetRenderWidgetHostView()) | |
36 ->set_native_view(root_window()); | |
37 | |
38 // Owned by the parent view. | |
39 bubble_ = new ValidationMessageBubbleView( | |
40 web_contents(), kInitialAnchorRect, base::ASCIIToUTF16("MAIN TEXT"), | |
41 base::ASCIIToUTF16("SUB TEXT")); | |
42 } | |
43 | |
44 ValidationMessageBubbleView& bubble() const { return *bubble_; } | |
sky
2017/05/05 14:43:21
Either make this return a const ValidationMessageB
Bret
2017/05/06 01:15:11
Done.
| |
45 | |
46 private: | |
47 views::LayoutProvider provider; // Creates a singleton. | |
sky
2017/05/05 14:43:22
Add trailing '_'.
Bret
2017/05/06 01:15:11
Done.
| |
48 ValidationMessageBubbleView* bubble_; | |
49 }; | |
sky
2017/05/05 14:43:21
DISALLOW...
Bret
2017/05/06 01:15:11
Done.
| |
50 | |
51 TEST_F(ValidationMessageBubbleViewTest, | |
52 AnchorRectIsCorrectForDeviceScaleFactor) { | |
53 constexpr float inverse_scale_factor = 1 / kScaleFactor; | |
54 EXPECT_EQ(gfx::ScaleToEnclosingRect(kInitialAnchorRect, inverse_scale_factor), | |
55 bubble().anchor_rect()); | |
56 | |
57 const gfx::Rect updated_anchor_rect(66, 99, 44, 33); | |
58 bubble().SetPositionRelativeToAnchor( | |
59 web_contents()->GetRenderWidgetHostView()->GetRenderWidgetHost(), | |
60 updated_anchor_rect); | |
61 EXPECT_EQ( | |
62 gfx::ScaleToEnclosingRect(updated_anchor_rect, inverse_scale_factor), | |
63 bubble().anchor_rect()); | |
64 } | |
OLD | NEW |