| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/location_bar/icon_label_bubble_view.h" | 5 #include "chrome/browser/ui/views/location_bar/icon_label_bubble_view.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/ui/layout_constants.h" |
| 8 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 9 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "ui/views/controls/image_view.h" | 11 #include "ui/views/controls/image_view.h" |
| 11 #include "ui/views/test/views_test_base.h" | 12 #include "ui/views/test/views_test_base.h" |
| 12 | 13 |
| 13 #if defined(USE_ASH) | 14 #if defined(USE_ASH) |
| 14 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 15 #endif | 16 #endif |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 return STEADY; | 59 return STEADY; |
| 59 } | 60 } |
| 60 | 61 |
| 61 protected: | 62 protected: |
| 62 // IconLabelBubbleView: | 63 // IconLabelBubbleView: |
| 63 SkColor GetTextColor() const override { return kTestColor; } | 64 SkColor GetTextColor() const override { return kTestColor; } |
| 64 | 65 |
| 65 bool ShouldShowLabel() const override { | 66 bool ShouldShowLabel() const override { |
| 66 return !IsShrinking() || | 67 return !IsShrinking() || |
| 67 (width() > (image()->GetPreferredSize().width() + | 68 (width() > (image()->GetPreferredSize().width() + |
| 68 2 * LocationBarView::kHorizontalPadding)); | 69 2 * LocationBarView::kIconInteriorPadding + |
| 70 2 * GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING))); |
| 69 } | 71 } |
| 70 | 72 |
| 71 double WidthMultiplier() const override { | 73 double WidthMultiplier() const override { |
| 72 const double kOpenFraction = | 74 const double kOpenFraction = |
| 73 static_cast<double>(kOpenTimeMS) / kAnimationDurationMS; | 75 static_cast<double>(kOpenTimeMS) / kAnimationDurationMS; |
| 74 double fraction = value_ / (double)kNumberOfSteps; | 76 double fraction = value_ / (double)kNumberOfSteps; |
| 75 switch (state()) { | 77 switch (state()) { |
| 76 case GROWING: | 78 case GROWING: |
| 77 return fraction / kOpenFraction; | 79 return fraction / kOpenFraction; |
| 78 case STEADY: | 80 case STEADY: |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 125 |
| 124 private: | 126 private: |
| 125 void Reset() { | 127 void Reset() { |
| 126 view_->SetLabelVisible(true); | 128 view_->SetLabelVisible(true); |
| 127 SetValue(0); | 129 SetValue(0); |
| 128 steady_reached_ = false; | 130 steady_reached_ = false; |
| 129 shrinking_reached_ = false; | 131 shrinking_reached_ = false; |
| 130 minimum_size_reached_ = false; | 132 minimum_size_reached_ = false; |
| 131 previous_width_ = 0; | 133 previous_width_ = 0; |
| 132 initial_image_x_ = GetImageBounds().x(); | 134 initial_image_x_ = GetImageBounds().x(); |
| 133 EXPECT_NE(0, initial_image_x_); | 135 EXPECT_EQ(0, initial_image_x_); |
| 134 } | 136 } |
| 135 | 137 |
| 136 void VerifyAnimationStep() { | 138 void VerifyAnimationStep() { |
| 137 switch (state()) { | 139 switch (state()) { |
| 138 case TestIconLabelBubbleView::State::GROWING: { | 140 case TestIconLabelBubbleView::State::GROWING: { |
| 139 EXPECT_GE(width(), previous_width_); | 141 EXPECT_GE(width(), previous_width_); |
| 140 EXPECT_EQ(initial_image_x_, GetImageBounds().x()); | 142 EXPECT_EQ(initial_image_x_, GetImageBounds().x()); |
| 141 EXPECT_GE(GetImageBounds().x(), 0); | 143 EXPECT_GE(GetImageBounds().x(), 0); |
| 142 if (GetImageBounds().width() > 0) | 144 if (GetImageBounds().width() > 0) |
| 143 EXPECT_LE(GetImageBounds().right(), width()); | 145 EXPECT_LE(GetImageBounds().right(), width()); |
| 144 EXPECT_TRUE(IsLabelVisible()); | 146 EXPECT_TRUE(IsLabelVisible()); |
| 145 if (GetLabelBounds().width() > 0) { | 147 if (GetLabelBounds().width() > 0) { |
| 146 EXPECT_GT(GetLabelBounds().x(), GetImageBounds().right()); | 148 EXPECT_GT(GetLabelBounds().x(), GetImageBounds().right()); |
| 147 EXPECT_LT(GetLabelBounds().right(), width()); | 149 EXPECT_LT(GetLabelBounds().right(), width()); |
| 148 } | 150 } |
| 149 break; | 151 break; |
| 150 } | 152 } |
| 151 case TestIconLabelBubbleView::State::STEADY: { | 153 case TestIconLabelBubbleView::State::STEADY: { |
| 152 if (steady_reached_) | 154 if (steady_reached_) |
| 153 EXPECT_EQ(previous_width_, width()); | 155 EXPECT_EQ(previous_width_, width()); |
| 154 EXPECT_EQ(initial_image_x_, GetImageBounds().x()); | 156 EXPECT_EQ(initial_image_x_, GetImageBounds().x()); |
| 155 EXPECT_GT(GetImageBounds().x(), 0); | |
| 156 EXPECT_LT(GetImageBounds().right(), width()); | 157 EXPECT_LT(GetImageBounds().right(), width()); |
| 157 EXPECT_TRUE(IsLabelVisible()); | 158 EXPECT_TRUE(IsLabelVisible()); |
| 158 EXPECT_GT(GetLabelBounds().x(), GetImageBounds().right()); | 159 EXPECT_GT(GetLabelBounds().x(), GetImageBounds().right()); |
| 159 EXPECT_LT(GetLabelBounds().right(), width()); | 160 EXPECT_LT(GetLabelBounds().right(), width()); |
| 160 steady_reached_ = true; | 161 steady_reached_ = true; |
| 161 break; | 162 break; |
| 162 } | 163 } |
| 163 case TestIconLabelBubbleView::State::SHRINKING: { | 164 case TestIconLabelBubbleView::State::SHRINKING: { |
| 164 if (shrinking_reached_) | 165 if (shrinking_reached_) |
| 165 EXPECT_LE(width(), previous_width_); | 166 EXPECT_LE(width(), previous_width_); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 widget.GetContentsView()->AddChildView(icon_label_bubble_view); | 242 widget.GetContentsView()->AddChildView(icon_label_bubble_view); |
| 242 aura::Window* widget_native_view = widget.GetNativeView(); | 243 aura::Window* widget_native_view = widget.GetNativeView(); |
| 243 // Remove the window from its parent. This means GetWidget() in | 244 // Remove the window from its parent. This means GetWidget() in |
| 244 // IconLabelBubbleView will return non-null, but GetWidget()->GetCompositor() | 245 // IconLabelBubbleView will return non-null, but GetWidget()->GetCompositor() |
| 245 // will return null. | 246 // will return null. |
| 246 ASSERT_TRUE(widget_native_view->parent()); | 247 ASSERT_TRUE(widget_native_view->parent()); |
| 247 widget_native_view->parent()->RemoveChild(widget_native_view); | 248 widget_native_view->parent()->RemoveChild(widget_native_view); |
| 248 static_cast<views::View*>(icon_label_bubble_view)->GetPreferredSize(); | 249 static_cast<views::View*>(icon_label_bubble_view)->GetPreferredSize(); |
| 249 } | 250 } |
| 250 #endif | 251 #endif |
| OLD | NEW |