Vectorize website settings icons in omnibox
[chromium-blink-merge.git] / cc / resources / scoped_resource_unittest.cc
blobcb41bf6fc8a978ba0a359abc40168766a5d705d6
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.
5 #include "cc/resources/scoped_resource.h"
7 #include "cc/output/renderer.h"
8 #include "cc/test/fake_output_surface.h"
9 #include "cc/test/fake_output_surface_client.h"
10 #include "cc/test/fake_resource_provider.h"
11 #include "cc/test/test_shared_bitmap_manager.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace cc {
15 namespace {
17 TEST(ScopedResourceTest, NewScopedResource) {
18 FakeOutputSurfaceClient output_surface_client;
19 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d());
20 CHECK(output_surface->BindToClient(&output_surface_client));
22 scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
23 new TestSharedBitmapManager());
24 scoped_ptr<ResourceProvider> resource_provider = FakeResourceProvider::Create(
25 output_surface.get(), shared_bitmap_manager.get());
26 scoped_ptr<ScopedResource> texture =
27 ScopedResource::Create(resource_provider.get());
29 // New scoped textures do not hold a texture yet.
30 EXPECT_EQ(0u, texture->id());
32 // New scoped textures do not have a size yet.
33 EXPECT_EQ(gfx::Size(), texture->size());
34 EXPECT_EQ(0u, ResourceUtil::UncheckedSizeInBytes<size_t>(texture->size(),
35 texture->format()));
38 TEST(ScopedResourceTest, CreateScopedResource) {
39 FakeOutputSurfaceClient output_surface_client;
40 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d());
41 CHECK(output_surface->BindToClient(&output_surface_client));
43 scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
44 new TestSharedBitmapManager());
45 scoped_ptr<ResourceProvider> resource_provider = FakeResourceProvider::Create(
46 output_surface.get(), shared_bitmap_manager.get());
47 scoped_ptr<ScopedResource> texture =
48 ScopedResource::Create(resource_provider.get());
49 texture->Allocate(gfx::Size(30, 30), ResourceProvider::TEXTURE_HINT_IMMUTABLE,
50 RGBA_8888);
52 // The texture has an allocated byte-size now.
53 size_t expected_bytes = 30 * 30 * 4;
54 EXPECT_EQ(expected_bytes, ResourceUtil::UncheckedSizeInBytes<size_t>(
55 texture->size(), texture->format()));
57 EXPECT_LT(0u, texture->id());
58 EXPECT_EQ(static_cast<unsigned>(RGBA_8888), texture->format());
59 EXPECT_EQ(gfx::Size(30, 30), texture->size());
62 TEST(ScopedResourceTest, ScopedResourceIsDeleted) {
63 FakeOutputSurfaceClient output_surface_client;
64 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d());
65 CHECK(output_surface->BindToClient(&output_surface_client));
67 scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
68 new TestSharedBitmapManager());
69 scoped_ptr<ResourceProvider> resource_provider = FakeResourceProvider::Create(
70 output_surface.get(), shared_bitmap_manager.get());
72 scoped_ptr<ScopedResource> texture =
73 ScopedResource::Create(resource_provider.get());
75 EXPECT_EQ(0u, resource_provider->num_resources());
76 texture->Allocate(gfx::Size(30, 30),
77 ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888);
78 EXPECT_LT(0u, texture->id());
79 EXPECT_EQ(1u, resource_provider->num_resources());
82 EXPECT_EQ(0u, resource_provider->num_resources());
84 scoped_ptr<ScopedResource> texture =
85 ScopedResource::Create(resource_provider.get());
86 EXPECT_EQ(0u, resource_provider->num_resources());
87 texture->Allocate(gfx::Size(30, 30),
88 ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888);
89 EXPECT_LT(0u, texture->id());
90 EXPECT_EQ(1u, resource_provider->num_resources());
91 texture->Free();
92 EXPECT_EQ(0u, resource_provider->num_resources());
96 } // namespace
97 } // namespace cc