nine_patch_layer_unittest.cc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "cc/layers/nine_patch_layer.h"
  5. #include "cc/animation/animation_host.h"
  6. #include "cc/resources/scoped_ui_resource.h"
  7. #include "cc/test/fake_layer_tree_host.h"
  8. #include "cc/test/fake_layer_tree_host_client.h"
  9. #include "cc/test/fake_output_surface_client.h"
  10. #include "cc/test/test_task_graph_runner.h"
  11. #include "cc/trees/layer_tree_host.h"
  12. #include "cc/trees/single_thread_proxy.h"
  13. #include "testing/gmock/include/gmock/gmock.h"
  14. #include "testing/gtest/include/gtest/gtest.h"
  15. #include "third_party/skia/include/core/SkBitmap.h"
  16. using ::testing::Mock;
  17. using ::testing::_;
  18. using ::testing::AtLeast;
  19. using ::testing::AnyNumber;
  20. namespace cc {
  21. namespace {
  22. class NinePatchLayerTest : public testing::Test {
  23. protected:
  24. void SetUp() override {
  25. animation_host_ = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
  26. layer_tree_host_ = FakeLayerTreeHost::Create(
  27. &fake_client_, &task_graph_runner_, animation_host_.get());
  28. }
  29. void TearDown() override {
  30. Mock::VerifyAndClearExpectations(layer_tree_host_.get());
  31. }
  32. FakeLayerTreeHostClient fake_client_;
  33. TestTaskGraphRunner task_graph_runner_;
  34. std::unique_ptr<AnimationHost> animation_host_;
  35. std::unique_ptr<FakeLayerTreeHost> layer_tree_host_;
  36. };
  37. TEST_F(NinePatchLayerTest, SetLayerProperties) {
  38. scoped_refptr<NinePatchLayer> test_layer = NinePatchLayer::Create();
  39. ASSERT_TRUE(test_layer.get());
  40. test_layer->SetIsDrawable(true);
  41. test_layer->SetBounds(gfx::Size(100, 100));
  42. layer_tree_host_->SetRootLayer(test_layer);
  43. Mock::VerifyAndClearExpectations(layer_tree_host_.get());
  44. EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get());
  45. test_layer->Update();
  46. EXPECT_FALSE(test_layer->draws_content());
  47. bool is_opaque = false;
  48. std::unique_ptr<ScopedUIResource> resource =
  49. ScopedUIResource::Create(layer_tree_host_->GetUIResourceManager(),
  50. UIResourceBitmap(gfx::Size(10, 10), is_opaque));
  51. gfx::Rect aperture(5, 5, 1, 1);
  52. bool fill_center = true;
  53. test_layer->SetAperture(aperture);
  54. test_layer->SetUIResourceId(resource->id());
  55. test_layer->SetFillCenter(fill_center);
  56. test_layer->Update();
  57. EXPECT_TRUE(test_layer->draws_content());
  58. }
  59. } // namespace
  60. } // namespace cc