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

Unified Diff: chrome/browser/ui/views/validation_message_bubble_view_unittest.cc

Issue 2861533003: Backfill some UI tests. (Closed)
Patch Set: fix silent merge conflict 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/test/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/validation_message_bubble_view_unittest.cc
diff --git a/chrome/browser/ui/views/validation_message_bubble_view_unittest.cc b/chrome/browser/ui/views/validation_message_bubble_view_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..954c4021ce53f49aedc92bc387665bdc0b83b908
--- /dev/null
+++ b/chrome/browser/ui/views/validation_message_bubble_view_unittest.cc
@@ -0,0 +1,60 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/views/validation_message_bubble_view.h"
+
+#include "base/command_line.h"
+#include "base/strings/utf_string_conversions.h"
+#include "chrome/test/base/chrome_render_view_host_test_harness.h"
+#include "content/public/browser/web_contents.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/display/display_switches.h"
+#include "ui/views/layout/layout_provider.h"
+#include "ui/views/test/scoped_views_test_helper.h"
+#include "ui/views/test/test_views_delegate.h"
+
+namespace {
+constexpr float kScaleFactor = 1.5;
+constexpr gfx::Rect kInitialAnchorRect = gfx::Rect(10, 20, 30, 40);
+} // namespace
+
+class ValidationMessageBubbleViewTest : public ChromeRenderViewHostTestHarness {
+ public:
+ ValidationMessageBubbleViewTest() = default;
+
+ void SetUp() override {
+ // Append the switch before any other setup.
+ base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ switches::kForceDeviceScaleFactor, std::to_string(kScaleFactor));
+
+ ChromeRenderViewHostTestHarness::SetUp();
+
+ bubble_ = new ValidationMessageBubbleView(
+ web_contents(), kInitialAnchorRect, base::ASCIIToUTF16("MAIN TEXT"),
+ base::ASCIIToUTF16("SUB TEXT"));
+ }
+
+ ValidationMessageBubbleView& bubble() { return *bubble_; }
+
+ private:
+ views::LayoutProvider provider_; // Creates a singleton.
+ ValidationMessageBubbleView* bubble_;
+
+ DISALLOW_COPY_AND_ASSIGN(ValidationMessageBubbleViewTest);
+};
+
+TEST_F(ValidationMessageBubbleViewTest,
+ AnchorRectIsCorrectForDeviceScaleFactor) {
+ constexpr float inverse_scale_factor = 1 / kScaleFactor;
+ EXPECT_EQ(gfx::ScaleToEnclosingRect(kInitialAnchorRect, inverse_scale_factor),
+ bubble().anchor_rect());
+
+ const gfx::Rect updated_anchor_rect(50, 60, 70, 80);
+ bubble().SetPositionRelativeToAnchor(
+ web_contents()->GetRenderWidgetHostView()->GetRenderWidgetHost(),
+ updated_anchor_rect);
+ EXPECT_EQ(
+ gfx::ScaleToEnclosingRect(updated_anchor_rect, inverse_scale_factor),
+ bubble().anchor_rect());
+}
« no previous file with comments | « no previous file | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698