| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "ui/views/corewm/tooltip_controller.h" | 5 #include "ui/views/corewm/tooltip_controller.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "ui/aura/client/cursor_client.h" | 8 #include "ui/aura/client/cursor_client.h" |
| 9 #include "ui/aura/client/tooltip_client.h" | 9 #include "ui/aura/client/tooltip_client.h" |
| 10 #include "ui/aura/client/window_types.h" | 10 #include "ui/aura/client/window_types.h" |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 EXPECT_FALSE(helper_->IsTooltipVisible()); | 207 EXPECT_FALSE(helper_->IsTooltipVisible()); |
| 208 | 208 |
| 209 // Enable tooltips back and check again. | 209 // Enable tooltips back and check again. |
| 210 helper_->controller()->SetTooltipsEnabled(true); | 210 helper_->controller()->SetTooltipsEnabled(true); |
| 211 EXPECT_FALSE(helper_->IsTooltipVisible()); | 211 EXPECT_FALSE(helper_->IsTooltipVisible()); |
| 212 helper_->FireTooltipTimer(); | 212 helper_->FireTooltipTimer(); |
| 213 EXPECT_TRUE(helper_->IsTooltipVisible()); | 213 EXPECT_TRUE(helper_->IsTooltipVisible()); |
| 214 } | 214 } |
| 215 | 215 |
| 216 TEST_F(TooltipControllerTest, TrimTooltipToFitTests) { | 216 TEST_F(TooltipControllerTest, TrimTooltipToFitTests) { |
| 217 const int max_width = 4000; | 217 const float max_width = 4000; |
| 218 string16 tooltip; | 218 string16 tooltip; |
| 219 int width, line_count, expect_lines; | 219 float width; |
| 220 int line_count, expect_lines; |
| 220 int max_pixel_width = 400; // copied from constants in tooltip_controller.cc | 221 int max_pixel_width = 400; // copied from constants in tooltip_controller.cc |
| 221 int max_lines = 10; // copied from constants in tooltip_controller.cc | 222 int max_lines = 10; // copied from constants in tooltip_controller.cc |
| 222 gfx::Font font = GetDefaultFont(); | 223 gfx::Font font = GetDefaultFont(); |
| 223 size_t tooltip_len; | 224 size_t tooltip_len; |
| 224 | 225 |
| 225 // Error in computed size vs. expected size should not be greater than the | 226 // Error in computed size vs. expected size should not be greater than the |
| 226 // size of the longest word. | 227 // size of the longest word. |
| 227 int error_in_pixel_width = font.GetStringWidth(ASCIIToUTF16("tooltip")); | 228 int error_in_pixel_width = font.GetStringWidth(ASCIIToUTF16("tooltip")); |
| 228 | 229 |
| 229 // Long tooltips should wrap to next line | 230 // Long tooltips should wrap to next line |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 EXPECT_EQ(font.GetStringWidth(ASCIIToUTF16("Small Tooltip")), width); | 289 EXPECT_EQ(font.GetStringWidth(ASCIIToUTF16("Small Tooltip")), width); |
| 289 EXPECT_EQ(1, line_count); | 290 EXPECT_EQ(1, line_count); |
| 290 EXPECT_EQ(ASCIIToUTF16("Small Tooltip"), tooltip); | 291 EXPECT_EQ(ASCIIToUTF16("Small Tooltip"), tooltip); |
| 291 | 292 |
| 292 // Normal small multi-line tooltip should stay as is. | 293 // Normal small multi-line tooltip should stay as is. |
| 293 tooltip.clear(); | 294 tooltip.clear(); |
| 294 width = line_count = -1; | 295 width = line_count = -1; |
| 295 tooltip = ASCIIToUTF16("Multi line\nTooltip"); | 296 tooltip = ASCIIToUTF16("Multi line\nTooltip"); |
| 296 TooltipControllerTestHelper::TrimTooltipToFit( | 297 TooltipControllerTestHelper::TrimTooltipToFit( |
| 297 max_width, &tooltip, &width, &line_count); | 298 max_width, &tooltip, &width, &line_count); |
| 298 int expected_width = font.GetStringWidth(ASCIIToUTF16("Multi line")); | 299 float expected_width = font.GetStringWidth(ASCIIToUTF16("Multi line")); |
| 299 expected_width = std::max(expected_width, | 300 expected_width = std::max(expected_width, |
| 300 font.GetStringWidth(ASCIIToUTF16("Tooltip"))); | 301 font.GetStringWidth(ASCIIToUTF16("Tooltip"))); |
| 301 EXPECT_EQ(expected_width, width); | 302 EXPECT_EQ(expected_width, width); |
| 302 EXPECT_EQ(2, line_count); | 303 EXPECT_EQ(2, line_count); |
| 303 EXPECT_EQ(ASCIIToUTF16("Multi line\nTooltip"), tooltip); | 304 EXPECT_EQ(ASCIIToUTF16("Multi line\nTooltip"), tooltip); |
| 304 | 305 |
| 305 // Whitespaces in tooltips are preserved. | 306 // Whitespaces in tooltips are preserved. |
| 306 tooltip.clear(); | 307 tooltip.clear(); |
| 307 width = line_count = -1; | 308 width = line_count = -1; |
| 308 tooltip = ASCIIToUTF16("Small Tool t\tip"); | 309 tooltip = ASCIIToUTF16("Small Tool t\tip"); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 EXPECT_EQ( | 539 EXPECT_EQ( |
| 539 widget_->GetNativeWindow()->GetRootWindow()->children().back()->type(), | 540 widget_->GetNativeWindow()->GetRootWindow()->children().back()->type(), |
| 540 aura::client::WINDOW_TYPE_TOOLTIP); | 541 aura::client::WINDOW_TYPE_TOOLTIP); |
| 541 } | 542 } |
| 542 | 543 |
| 543 #endif | 544 #endif |
| 544 | 545 |
| 545 } // namespace test | 546 } // namespace test |
| 546 } // namespace corewm | 547 } // namespace corewm |
| 547 } // namespace views | 548 } // namespace views |
| OLD | NEW |