Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Side by Side Diff: cc/resources/scoped_resource_unittest.cc

Issue 2697353003: cc: Make ScopedResource constructor public, use MakeUnique to construct (Closed)
Patch Set: construct: . Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/resources/scoped_resource.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 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 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 "cc/resources/scoped_resource.h" 5 #include "cc/resources/scoped_resource.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "cc/test/fake_resource_provider.h" 9 #include "cc/test/fake_resource_provider.h"
10 #include "cc/test/test_context_provider.h" 10 #include "cc/test/test_context_provider.h"
11 #include "cc/test/test_shared_bitmap_manager.h" 11 #include "cc/test/test_shared_bitmap_manager.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace cc { 14 namespace cc {
15 namespace { 15 namespace {
16 16
17 TEST(ScopedResourceTest, NewScopedResource) { 17 TEST(ScopedResourceTest, NewScopedResource) {
18 scoped_refptr<TestContextProvider> context_provider = 18 scoped_refptr<TestContextProvider> context_provider =
19 TestContextProvider::Create(); 19 TestContextProvider::Create();
20 ASSERT_TRUE(context_provider->BindToCurrentThread()); 20 ASSERT_TRUE(context_provider->BindToCurrentThread());
21 21
22 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager( 22 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager(
23 new TestSharedBitmapManager()); 23 new TestSharedBitmapManager());
24 std::unique_ptr<ResourceProvider> resource_provider = 24 std::unique_ptr<ResourceProvider> resource_provider =
25 FakeResourceProvider::Create(context_provider.get(), 25 FakeResourceProvider::Create(context_provider.get(),
26 shared_bitmap_manager.get()); 26 shared_bitmap_manager.get());
27 std::unique_ptr<ScopedResource> texture = 27 auto texture = base::MakeUnique<ScopedResource>(resource_provider.get());
28 ScopedResource::Create(resource_provider.get());
29 28
30 // New scoped textures do not hold a texture yet. 29 // New scoped textures do not hold a texture yet.
31 EXPECT_EQ(0u, texture->id()); 30 EXPECT_EQ(0u, texture->id());
32 31
33 // New scoped textures do not have a size yet. 32 // New scoped textures do not have a size yet.
34 EXPECT_EQ(gfx::Size(), texture->size()); 33 EXPECT_EQ(gfx::Size(), texture->size());
35 EXPECT_EQ(0u, ResourceUtil::UncheckedSizeInBytes<size_t>(texture->size(), 34 EXPECT_EQ(0u, ResourceUtil::UncheckedSizeInBytes<size_t>(texture->size(),
36 texture->format())); 35 texture->format()));
37 } 36 }
38 37
39 TEST(ScopedResourceTest, CreateScopedResource) { 38 TEST(ScopedResourceTest, CreateScopedResource) {
40 scoped_refptr<TestContextProvider> context_provider = 39 scoped_refptr<TestContextProvider> context_provider =
41 TestContextProvider::Create(); 40 TestContextProvider::Create();
42 ASSERT_TRUE(context_provider->BindToCurrentThread()); 41 ASSERT_TRUE(context_provider->BindToCurrentThread());
43 42
44 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager( 43 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager(
45 new TestSharedBitmapManager()); 44 new TestSharedBitmapManager());
46 std::unique_ptr<ResourceProvider> resource_provider = 45 std::unique_ptr<ResourceProvider> resource_provider =
47 FakeResourceProvider::Create(context_provider.get(), 46 FakeResourceProvider::Create(context_provider.get(),
48 shared_bitmap_manager.get()); 47 shared_bitmap_manager.get());
49 std::unique_ptr<ScopedResource> texture = 48 auto texture = base::MakeUnique<ScopedResource>(resource_provider.get());
50 ScopedResource::Create(resource_provider.get());
51 texture->Allocate(gfx::Size(30, 30), ResourceProvider::TEXTURE_HINT_IMMUTABLE, 49 texture->Allocate(gfx::Size(30, 30), ResourceProvider::TEXTURE_HINT_IMMUTABLE,
52 RGBA_8888, gfx::ColorSpace()); 50 RGBA_8888, gfx::ColorSpace());
53 51
54 // The texture has an allocated byte-size now. 52 // The texture has an allocated byte-size now.
55 size_t expected_bytes = 30 * 30 * 4; 53 size_t expected_bytes = 30 * 30 * 4;
56 EXPECT_EQ(expected_bytes, ResourceUtil::UncheckedSizeInBytes<size_t>( 54 EXPECT_EQ(expected_bytes, ResourceUtil::UncheckedSizeInBytes<size_t>(
57 texture->size(), texture->format())); 55 texture->size(), texture->format()));
58 56
59 EXPECT_LT(0u, texture->id()); 57 EXPECT_LT(0u, texture->id());
60 EXPECT_EQ(static_cast<unsigned>(RGBA_8888), texture->format()); 58 EXPECT_EQ(static_cast<unsigned>(RGBA_8888), texture->format());
61 EXPECT_EQ(gfx::Size(30, 30), texture->size()); 59 EXPECT_EQ(gfx::Size(30, 30), texture->size());
62 } 60 }
63 61
64 TEST(ScopedResourceTest, ScopedResourceIsDeleted) { 62 TEST(ScopedResourceTest, ScopedResourceIsDeleted) {
65 scoped_refptr<TestContextProvider> context_provider = 63 scoped_refptr<TestContextProvider> context_provider =
66 TestContextProvider::Create(); 64 TestContextProvider::Create();
67 ASSERT_TRUE(context_provider->BindToCurrentThread()); 65 ASSERT_TRUE(context_provider->BindToCurrentThread());
68 66
69 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager( 67 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager(
70 new TestSharedBitmapManager()); 68 new TestSharedBitmapManager());
71 std::unique_ptr<ResourceProvider> resource_provider = 69 std::unique_ptr<ResourceProvider> resource_provider =
72 FakeResourceProvider::Create(context_provider.get(), 70 FakeResourceProvider::Create(context_provider.get(),
73 shared_bitmap_manager.get()); 71 shared_bitmap_manager.get());
74 { 72 {
75 std::unique_ptr<ScopedResource> texture = 73 auto texture = base::MakeUnique<ScopedResource>(resource_provider.get());
76 ScopedResource::Create(resource_provider.get());
77 74
78 EXPECT_EQ(0u, resource_provider->num_resources()); 75 EXPECT_EQ(0u, resource_provider->num_resources());
79 texture->Allocate(gfx::Size(30, 30), 76 texture->Allocate(gfx::Size(30, 30),
80 ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888, 77 ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888,
81 gfx::ColorSpace()); 78 gfx::ColorSpace());
82 EXPECT_LT(0u, texture->id()); 79 EXPECT_LT(0u, texture->id());
83 EXPECT_EQ(1u, resource_provider->num_resources()); 80 EXPECT_EQ(1u, resource_provider->num_resources());
84 } 81 }
85 82
86 EXPECT_EQ(0u, resource_provider->num_resources()); 83 EXPECT_EQ(0u, resource_provider->num_resources());
87 { 84 {
88 std::unique_ptr<ScopedResource> texture = 85 auto texture = base::MakeUnique<ScopedResource>(resource_provider.get());
89 ScopedResource::Create(resource_provider.get());
90 EXPECT_EQ(0u, resource_provider->num_resources()); 86 EXPECT_EQ(0u, resource_provider->num_resources());
91 texture->Allocate(gfx::Size(30, 30), 87 texture->Allocate(gfx::Size(30, 30),
92 ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888, 88 ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888,
93 gfx::ColorSpace()); 89 gfx::ColorSpace());
94 EXPECT_LT(0u, texture->id()); 90 EXPECT_LT(0u, texture->id());
95 EXPECT_EQ(1u, resource_provider->num_resources()); 91 EXPECT_EQ(1u, resource_provider->num_resources());
96 texture->Free(); 92 texture->Free();
97 EXPECT_EQ(0u, resource_provider->num_resources()); 93 EXPECT_EQ(0u, resource_provider->num_resources());
98 } 94 }
99 } 95 }
100 96
101 } // namespace 97 } // namespace
102 } // namespace cc 98 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/scoped_resource.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698