OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/gfx/render_text.h" | 5 #include "ui/gfx/render_text.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.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 1352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1363 } | 1363 } |
1364 | 1364 |
1365 // Make sure the caret width is always >=1 so that the correct | 1365 // Make sure the caret width is always >=1 so that the correct |
1366 // caret is drawn at high DPI. crbug.com/164100. | 1366 // caret is drawn at high DPI. crbug.com/164100. |
1367 TEST_F(RenderTextTest, CaretWidth) { | 1367 TEST_F(RenderTextTest, CaretWidth) { |
1368 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1368 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1369 render_text->SetText(ASCIIToUTF16("abcdefg")); | 1369 render_text->SetText(ASCIIToUTF16("abcdefg")); |
1370 EXPECT_GE(render_text->GetUpdatedCursorBounds().width(), 1); | 1370 EXPECT_GE(render_text->GetUpdatedCursorBounds().width(), 1); |
1371 } | 1371 } |
1372 | 1372 |
| 1373 TEST_F(RenderTextTest, SelectWord) { |
| 1374 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
| 1375 render_text->SetText(ASCIIToUTF16(" foo a.bc.d bar")); |
| 1376 |
| 1377 struct { |
| 1378 size_t cursor; |
| 1379 size_t selection_start; |
| 1380 size_t selection_end; |
| 1381 } cases[] = { |
| 1382 { 0, 0, 1 }, |
| 1383 { 1, 1, 4 }, |
| 1384 { 2, 1, 4 }, |
| 1385 { 3, 1, 4 }, |
| 1386 { 4, 4, 6 }, |
| 1387 { 5, 4, 6 }, |
| 1388 { 6, 6, 7 }, |
| 1389 { 7, 7, 8 }, |
| 1390 { 8, 8, 10 }, |
| 1391 { 9, 8, 10 }, |
| 1392 { 10, 10, 11 }, |
| 1393 { 11, 11, 12 }, |
| 1394 { 12, 12, 13 }, |
| 1395 { 13, 13, 16 }, |
| 1396 { 14, 13, 16 }, |
| 1397 { 15, 13, 16 }, |
| 1398 { 16, 13, 16 }, |
| 1399 }; |
| 1400 |
| 1401 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
| 1402 render_text->SetCursorPosition(cases[i].cursor); |
| 1403 render_text->SelectWord(); |
| 1404 EXPECT_EQ(ui::Range(cases[i].selection_start, cases[i].selection_end), |
| 1405 render_text->selection()); |
| 1406 } |
| 1407 } |
| 1408 |
1373 // Make sure the last word is selected when the cursor is at text.length(). | 1409 // Make sure the last word is selected when the cursor is at text.length(). |
1374 TEST_F(RenderTextTest, LastWordSelected) { | 1410 TEST_F(RenderTextTest, LastWordSelected) { |
1375 const std::string kTestURL1 = "http://www.google.com"; | 1411 const std::string kTestURL1 = "http://www.google.com"; |
1376 const std::string kTestURL2 = "http://www.google.com/something/"; | 1412 const std::string kTestURL2 = "http://www.google.com/something/"; |
1377 | 1413 |
1378 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1414 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1379 | 1415 |
1380 render_text->SetText(ASCIIToUTF16(kTestURL1)); | 1416 render_text->SetText(ASCIIToUTF16(kTestURL1)); |
1381 render_text->SetCursorPosition(kTestURL1.length()); | 1417 render_text->SetCursorPosition(kTestURL1.length()); |
1382 render_text->SelectWord(); | 1418 render_text->SelectWord(); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1543 render_text->set_selection_color(SK_ColorRED); | 1579 render_text->set_selection_color(SK_ColorRED); |
1544 render_text->SetText(kTestLigature); | 1580 render_text->SetText(kTestLigature); |
1545 | 1581 |
1546 const int expected_width = render_text->GetStringSize().width(); | 1582 const int expected_width = render_text->GetStringSize().width(); |
1547 render_text->MoveCursorTo(SelectionModel(ui::Range(0, 1), CURSOR_FORWARD)); | 1583 render_text->MoveCursorTo(SelectionModel(ui::Range(0, 1), CURSOR_FORWARD)); |
1548 EXPECT_EQ(expected_width, render_text->GetStringSize().width()); | 1584 EXPECT_EQ(expected_width, render_text->GetStringSize().width()); |
1549 } | 1585 } |
1550 #endif // defined(OS_WIN) | 1586 #endif // defined(OS_WIN) |
1551 | 1587 |
1552 } // namespace gfx | 1588 } // namespace gfx |
OLD | NEW |