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

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

Issue 2861533003: Backfill some UI tests. (Closed)
Patch Set: minor edits 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
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..0b1c97898133356428e05054139c1e245c2a685c
--- /dev/null
+++ b/chrome/browser/ui/views/validation_message_bubble_view_unittest.cc
@@ -0,0 +1,64 @@
+// 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 "content/test/test_render_view_host.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:
+ void SetUp() override {
+ // Append the switch before any other setup.
+ base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ switches::kForceDeviceScaleFactor, std::to_string(kScaleFactor));
+
+ ChromeRenderViewHostTestHarness::SetUp();
+
+ // Gives the validation bubble a parent, which is required on widget
+ // creation.
+ static_cast<content::TestRenderWidgetHostView*>(
+ web_contents()->GetRenderWidgetHostView())
+ ->set_native_view(root_window());
+
+ // Owned by the parent view.
+ bubble_ = new ValidationMessageBubbleView(
+ web_contents(), kInitialAnchorRect, base::ASCIIToUTF16("MAIN TEXT"),
+ base::ASCIIToUTF16("SUB TEXT"));
+ }
+
+ 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.
+
+ private:
+ views::LayoutProvider provider; // Creates a singleton.
sky 2017/05/05 14:43:22 Add trailing '_'.
Bret 2017/05/06 01:15:11 Done.
+ ValidationMessageBubbleView* bubble_;
+};
sky 2017/05/05 14:43:21 DISALLOW...
Bret 2017/05/06 01:15:11 Done.
+
+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(66, 99, 44, 33);
+ bubble().SetPositionRelativeToAnchor(
+ web_contents()->GetRenderWidgetHostView()->GetRenderWidgetHost(),
+ updated_anchor_rect);
+ EXPECT_EQ(
+ gfx::ScaleToEnclosingRect(updated_anchor_rect, inverse_scale_factor),
+ bubble().anchor_rect());
+}

Powered by Google App Engine
This is Rietveld 408576698