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

Side by Side Diff: chrome/browser/ui/views/validation_message_bubble_view_unittest.cc

Issue 2861533003: Backfill some UI tests. (Closed)
Patch Set: comments 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 | « no previous file | chrome/test/BUILD.gn » ('j') | content/public/test/test_renderer_host.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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));
sky 2017/05/07 22:44:23 Wow, I didn't realize std got a std::to_string fun
30
31 ChromeRenderViewHostTestHarness::SetUp();
32
33 // Owned by the parent view.
sky 2017/05/07 22:44:23 This comment is mildly confusing given there is no
Bret 2017/05/09 23:44:42 You're right. I thought the NativeView shenanigans
34 bubble_ = new ValidationMessageBubbleView(
35 web_contents(), kInitialAnchorRect, base::ASCIIToUTF16("MAIN TEXT"),
36 base::ASCIIToUTF16("SUB TEXT"));
37 }
38
39 ValidationMessageBubbleView& bubble() { return *bubble_; }
40
41 private:
42 views::LayoutProvider provider_; // Creates a singleton.
43 ValidationMessageBubbleView* bubble_;
44
45 DISALLOW_COPY_AND_ASSIGN(ValidationMessageBubbleViewTest);
46 };
47
48 TEST_F(ValidationMessageBubbleViewTest,
49 AnchorRectIsCorrectForDeviceScaleFactor) {
50 constexpr float inverse_scale_factor = 1 / kScaleFactor;
51 EXPECT_EQ(gfx::ScaleToEnclosingRect(kInitialAnchorRect, inverse_scale_factor),
52 bubble().anchor_rect());
53
54 const gfx::Rect updated_anchor_rect(66, 99, 44, 33);
sky 2017/05/07 22:44:23 Add comment as to where these values come from.
Bret 2017/05/09 23:44:42 They're just arbitrary test values. I made them sl
55 bubble().SetPositionRelativeToAnchor(
56 web_contents()->GetRenderWidgetHostView()->GetRenderWidgetHost(),
57 updated_anchor_rect);
58 EXPECT_EQ(
59 gfx::ScaleToEnclosingRect(updated_anchor_rect, inverse_scale_factor),
60 bubble().anchor_rect());
61 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/BUILD.gn » ('j') | content/public/test/test_renderer_host.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698