diff options
author | clholgat@chromium.org <clholgat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-04 00:35:13 +0000 |
---|---|---|
committer | clholgat@chromium.org <clholgat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-04 00:35:13 +0000 |
commit | efbdb3ac428aa1829161729189604865e606691b (patch) | |
tree | e2b465b299b54934d06c020c0ea514292841aa15 /cc/layers/ui_resource_layer_unittest.cc | |
parent | 18ae4320efce8e3342c3a5048569a25c4f2498ab (diff) | |
download | chromium_src-efbdb3ac428aa1829161729189604865e606691b.zip chromium_src-efbdb3ac428aa1829161729189604865e606691b.tar.gz chromium_src-efbdb3ac428aa1829161729189604865e606691b.tar.bz2 |
Generic UIResourceLayer for shared resources.
Separated the UIResource management from the
NinePatchLayer because we need it for other
things as well.
BUG=235290
Review URL: https://codereview.chromium.org/24716003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@226908 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/layers/ui_resource_layer_unittest.cc')
-rw-r--r-- | cc/layers/ui_resource_layer_unittest.cc | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/cc/layers/ui_resource_layer_unittest.cc b/cc/layers/ui_resource_layer_unittest.cc new file mode 100644 index 0000000..1720b81 --- /dev/null +++ b/cc/layers/ui_resource_layer_unittest.cc @@ -0,0 +1,122 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "cc/layers/ui_resource_layer.h" + +#include "cc/debug/overdraw_metrics.h" +#include "cc/resources/prioritized_resource_manager.h" +#include "cc/resources/resource_provider.h" +#include "cc/resources/resource_update_queue.h" +#include "cc/resources/scoped_ui_resource.h" +#include "cc/scheduler/texture_uploader.h" +#include "cc/test/fake_layer_tree_host_client.h" +#include "cc/test/fake_output_surface.h" +#include "cc/test/fake_output_surface_client.h" +#include "cc/test/geometry_test_utils.h" +#include "cc/trees/layer_tree_host.h" +#include "cc/trees/occlusion_tracker.h" +#include "cc/trees/single_thread_proxy.h" +#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "third_party/skia/include/core/SkBitmap.h" + +using ::testing::Mock; +using ::testing::_; +using ::testing::AtLeast; +using ::testing::AnyNumber; + +namespace cc { +namespace { + +class MockLayerTreeHost : public LayerTreeHost { + public: + explicit MockLayerTreeHost(LayerTreeHostClient* client) + : LayerTreeHost(client, LayerTreeSettings()) { + Initialize(NULL); + } +}; + +class UIResourceLayerTest : public testing::Test { + public: + UIResourceLayerTest() : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} + + cc::Proxy* Proxy() const { return layer_tree_host_->proxy(); } + + protected: + virtual void SetUp() { + layer_tree_host_.reset(new MockLayerTreeHost(&fake_client_)); + } + + virtual void TearDown() { + Mock::VerifyAndClearExpectations(layer_tree_host_.get()); + } + + scoped_ptr<MockLayerTreeHost> layer_tree_host_; + FakeLayerTreeHostClient fake_client_; +}; + +TEST_F(UIResourceLayerTest, SetBitmap) { + scoped_refptr<UIResourceLayer> test_layer = UIResourceLayer::Create(); + ASSERT_TRUE(test_layer.get()); + test_layer->SetIsDrawable(true); + test_layer->SetBounds(gfx::Size(100, 100)); + + layer_tree_host_->SetRootLayer(test_layer); + Mock::VerifyAndClearExpectations(layer_tree_host_.get()); + EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get()); + + layer_tree_host_->InitializeOutputSurfaceIfNeeded(); + + ResourceUpdateQueue queue; + OcclusionTracker occlusion_tracker(gfx::Rect(), false); + test_layer->SavePaintProperties(); + test_layer->Update(&queue, &occlusion_tracker); + + EXPECT_FALSE(test_layer->DrawsContent()); + + SkBitmap bitmap; + bitmap.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); + bitmap.allocPixels(); + bitmap.setImmutable(); + + test_layer->SetBitmap(bitmap); + test_layer->Update(&queue, &occlusion_tracker); + + EXPECT_TRUE(test_layer->DrawsContent()); +} + +TEST_F(UIResourceLayerTest, SetUIResourceId) { + scoped_refptr<UIResourceLayer> test_layer = UIResourceLayer::Create(); + ASSERT_TRUE(test_layer.get()); + test_layer->SetIsDrawable(true); + test_layer->SetBounds(gfx::Size(100, 100)); + + layer_tree_host_->SetRootLayer(test_layer); + Mock::VerifyAndClearExpectations(layer_tree_host_.get()); + EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get()); + + layer_tree_host_->InitializeOutputSurfaceIfNeeded(); + + ResourceUpdateQueue queue; + OcclusionTracker occlusion_tracker(gfx::Rect(), false); + test_layer->SavePaintProperties(); + test_layer->Update(&queue, &occlusion_tracker); + + EXPECT_FALSE(test_layer->DrawsContent()); + + SkBitmap bitmap; + bitmap.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); + bitmap.allocPixels(); + bitmap.setImmutable(); + + scoped_ptr<ScopedUIResource> resource = ScopedUIResource::Create( + layer_tree_host_.get(), UIResourceBitmap(bitmap)); + test_layer->SetUIResourceId(resource->id()); + test_layer->Update(&queue, &occlusion_tracker); + + EXPECT_TRUE(test_layer->DrawsContent()); +} + +} // namespace +} // namespace cc |