| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 EXPECT_EQ(18 * 2 + default_height, styled()->GetHeightForWidth(100)); | 415 EXPECT_EQ(18 * 2 + default_height, styled()->GetHeightForWidth(100)); |
| 416 } | 416 } |
| 417 | 417 |
| 418 TEST_F(StyledLabelTest, HandleEmptyLayout) { | 418 TEST_F(StyledLabelTest, HandleEmptyLayout) { |
| 419 const std::string text("This is a test block of text."); | 419 const std::string text("This is a test block of text."); |
| 420 InitStyledLabel(text); | 420 InitStyledLabel(text); |
| 421 styled()->Layout(); | 421 styled()->Layout(); |
| 422 EXPECT_EQ(0, styled()->child_count()); | 422 EXPECT_EQ(0, styled()->child_count()); |
| 423 } | 423 } |
| 424 | 424 |
| 425 TEST_F(StyledLabelTest, CacheSize) { | |
| 426 const int preferred_height = 50; | |
| 427 const int preferred_width = 100; | |
| 428 const std::string text("This is a test block of text."); | |
| 429 const base::string16 another_text(base::ASCIIToUTF16( | |
| 430 "This is a test block of text. This text is much longer than previous")); | |
| 431 | |
| 432 InitStyledLabel(text); | |
| 433 | |
| 434 // we should be able to calculate height without any problem | |
| 435 // no controls should be created | |
| 436 int precalculated_height = styled()->GetHeightForWidth(preferred_width); | |
| 437 EXPECT_LT(0, precalculated_height); | |
| 438 EXPECT_EQ(0, styled()->child_count()); | |
| 439 | |
| 440 styled()->SetBounds(0, 0, preferred_width, preferred_height); | |
| 441 styled()->Layout(); | |
| 442 | |
| 443 // controls should be created after layout | |
| 444 // height should be the same as precalculated | |
| 445 int real_height = styled()->GetHeightForWidth(styled()->width()); | |
| 446 View* first_child_after_layout = styled()->has_children() ? | |
| 447 styled()->child_at(0) : nullptr; | |
| 448 EXPECT_LT(0, styled()->child_count()); | |
| 449 EXPECT_LT(0, real_height); | |
| 450 EXPECT_EQ(real_height, precalculated_height); | |
| 451 | |
| 452 // another call to Layout should not kill and recreate all controls | |
| 453 styled()->Layout(); | |
| 454 View* first_child_after_second_layout = styled()->has_children() ? | |
| 455 styled()->child_at(0) : nullptr; | |
| 456 EXPECT_EQ(first_child_after_layout, first_child_after_second_layout); | |
| 457 | |
| 458 // if text is changed: | |
| 459 // layout should be recalculated | |
| 460 // all controls should be recreated | |
| 461 styled()->SetText(another_text); | |
| 462 int updated_height = styled()->GetHeightForWidth(styled()->width()); | |
| 463 EXPECT_NE(updated_height, real_height); | |
| 464 View* first_child_after_text_update = styled()->has_children() ? | |
| 465 styled()->child_at(0) : nullptr; | |
| 466 EXPECT_NE(first_child_after_text_update, first_child_after_layout); | |
| 467 } | |
| 468 | |
| 469 } // namespace views | 425 } // namespace views |
| OLD | NEW |