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 <limits.h> | 7 #include <limits.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <algorithm> | 11 #include <algorithm> |
12 #include <memory> | 12 #include <memory> |
13 #include <numeric> | 13 #include <numeric> |
14 | 14 |
15 #include "base/format_macros.h" | 15 #include "base/format_macros.h" |
16 #include "base/i18n/break_iterator.h" | 16 #include "base/i18n/break_iterator.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
19 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
20 #include "base/strings/string_split.h" | 20 #include "base/strings/string_split.h" |
21 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
22 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
23 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 24 #include "base/test/scoped_task_environment.h" |
24 #include "build/build_config.h" | 25 #include "build/build_config.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
26 #include "third_party/skia/include/core/SkRefCnt.h" | 27 #include "third_party/skia/include/core/SkRefCnt.h" |
27 #include "third_party/skia/include/core/SkSurface.h" | 28 #include "third_party/skia/include/core/SkSurface.h" |
28 #include "third_party/skia/include/core/SkTypeface.h" | 29 #include "third_party/skia/include/core/SkTypeface.h" |
29 #include "ui/gfx/break_list.h" | 30 #include "ui/gfx/break_list.h" |
30 #include "ui/gfx/canvas.h" | 31 #include "ui/gfx/canvas.h" |
31 #include "ui/gfx/color_utils.h" | 32 #include "ui/gfx/color_utils.h" |
32 #include "ui/gfx/decorated_text.h" | 33 #include "ui/gfx/decorated_text.h" |
33 #include "ui/gfx/font.h" | 34 #include "ui/gfx/font.h" |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 }; | 421 }; |
421 | 422 |
422 } // namespace | 423 } // namespace |
423 | 424 |
424 // Test fixture class used to run parameterized tests for all RenderText | 425 // Test fixture class used to run parameterized tests for all RenderText |
425 // implementations. | 426 // implementations. |
426 class RenderTextTest : public testing::Test, | 427 class RenderTextTest : public testing::Test, |
427 public ::testing::WithParamInterface<RenderTextBackend> { | 428 public ::testing::WithParamInterface<RenderTextBackend> { |
428 public: | 429 public: |
429 RenderTextTest() | 430 RenderTextTest() |
430 : render_text_(CreateRenderTextInstance()), | 431 : scoped_task_environment_( |
| 432 base::test::ScopedTaskEnvironment::MainThreadType::UI), |
| 433 render_text_(CreateRenderTextInstance()), |
431 test_api_(new test::RenderTextTestApi(render_text_.get())), | 434 test_api_(new test::RenderTextTestApi(render_text_.get())), |
432 renderer_(canvas()) {} | 435 renderer_(canvas()) {} |
433 | 436 |
434 protected: | 437 protected: |
435 std::unique_ptr<RenderText> CreateRenderTextInstance() const { | 438 std::unique_ptr<RenderText> CreateRenderTextInstance() const { |
436 switch (GetParam()) { | 439 switch (GetParam()) { |
437 case RENDER_TEXT_HARFBUZZ: | 440 case RENDER_TEXT_HARFBUZZ: |
438 return base::MakeUnique<RenderTextHarfBuzz>(); | 441 return base::MakeUnique<RenderTextHarfBuzz>(); |
439 | 442 |
440 case RENDER_TEXT_MAC: | 443 case RENDER_TEXT_MAC: |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 | 489 |
487 Rect GetSelectionBoundsUnion() { | 490 Rect GetSelectionBoundsUnion() { |
488 return GetSubstringBoundsUnion(render_text_->selection()); | 491 return GetSubstringBoundsUnion(render_text_->selection()); |
489 } | 492 } |
490 | 493 |
491 Canvas* canvas() { return &canvas_; } | 494 Canvas* canvas() { return &canvas_; } |
492 TestSkiaTextRenderer* renderer() { return &renderer_; } | 495 TestSkiaTextRenderer* renderer() { return &renderer_; } |
493 test::RenderTextTestApi* test_api() { return test_api_.get(); }; | 496 test::RenderTextTestApi* test_api() { return test_api_.get(); }; |
494 | 497 |
495 private: | 498 private: |
| 499 // Needed to bypass DCHECK in GetFallbackFont. |
| 500 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 501 |
496 std::unique_ptr<RenderText> render_text_; | 502 std::unique_ptr<RenderText> render_text_; |
497 std::unique_ptr<test::RenderTextTestApi> test_api_; | 503 std::unique_ptr<test::RenderTextTestApi> test_api_; |
498 Canvas canvas_; | 504 Canvas canvas_; |
499 TestSkiaTextRenderer renderer_; | 505 TestSkiaTextRenderer renderer_; |
500 | 506 |
501 #if defined(OS_WIN) | |
502 // Needed to bypass DCHECK in GetFallbackFont. | |
503 base::MessageLoopForUI message_loop_; | |
504 #endif | |
505 | |
506 DISALLOW_COPY_AND_ASSIGN(RenderTextTest); | 507 DISALLOW_COPY_AND_ASSIGN(RenderTextTest); |
507 }; | 508 }; |
508 | 509 |
509 // Test fixture class. Use for tests which are only to be run for | 510 // Test fixture class. Use for tests which are only to be run for |
510 // RenderTextHarfBuzz. | 511 // RenderTextHarfBuzz. |
511 class RenderTextHarfBuzzTest : public RenderTextTest { | 512 class RenderTextHarfBuzzTest : public RenderTextTest { |
512 public: | 513 public: |
513 RenderTextHarfBuzzTest() {} | 514 RenderTextHarfBuzzTest() {} |
514 | 515 |
515 // Overridden from testing::Test: | 516 // Overridden from testing::Test: |
(...skipping 4032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4548 ::testing::Values(RENDER_TEXT_HARFBUZZ), | 4549 ::testing::Values(RENDER_TEXT_HARFBUZZ), |
4549 PrintRenderTextBackend()); | 4550 PrintRenderTextBackend()); |
4550 #endif | 4551 #endif |
4551 | 4552 |
4552 INSTANTIATE_TEST_CASE_P(, | 4553 INSTANTIATE_TEST_CASE_P(, |
4553 RenderTextHarfBuzzTest, | 4554 RenderTextHarfBuzzTest, |
4554 ::testing::Values(RENDER_TEXT_HARFBUZZ), | 4555 ::testing::Values(RENDER_TEXT_HARFBUZZ), |
4555 PrintRenderTextBackend()); | 4556 PrintRenderTextBackend()); |
4556 | 4557 |
4557 } // namespace gfx | 4558 } // namespace gfx |
OLD | NEW |