| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ui_resource_bitmap.h" | 5 #include "cc/resources/ui_resource_bitmap.h" |
| 6 #include "cc/test/fake_layer_tree_host_client.h" | 6 #include "cc/test/fake_layer_tree_host_client.h" |
| 7 #include "cc/test/test_task_graph_runner.h" | 7 #include "cc/test/test_task_graph_runner.h" |
| 8 #include "cc/trees/layer_tree_host.h" | 8 #include "cc/trees/layer_tree_host.h" |
| 9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "third_party/skia/include/core/SkBitmap.h" | 11 #include "third_party/skia/include/core/SkBitmap.h" |
| 12 #include "third_party/skia/include/core/SkCanvas.h" | 12 #include "third_party/skia/include/core/SkCanvas.h" |
| 13 #include "ui/android/resources/resource_manager_impl.h" | 13 #include "ui/android/resources/resource_manager_impl.h" |
| 14 #include "ui/android/resources/system_ui_resource_type.h" | 14 #include "ui/android/resources/system_ui_resource_type.h" |
| 15 #include "ui/android/window_android.h" |
| 15 #include "ui/gfx/android/java_bitmap.h" | 16 #include "ui/gfx/android/java_bitmap.h" |
| 16 | 17 |
| 17 | 18 |
| 18 using ::testing::_; | 19 using ::testing::_; |
| 19 using ::testing::AtLeast; | 20 using ::testing::AtLeast; |
| 20 using ::testing::DoAll; | 21 using ::testing::DoAll; |
| 21 using ::testing::InSequence; | 22 using ::testing::InSequence; |
| 22 using ::testing::Invoke; | 23 using ::testing::Invoke; |
| 23 using ::testing::MatcherCast; | 24 using ::testing::MatcherCast; |
| 24 using ::testing::Mock; | 25 using ::testing::Mock; |
| 25 using ::testing::Pointee; | 26 using ::testing::Pointee; |
| 26 using ::testing::Return; | 27 using ::testing::Return; |
| 27 using ::testing::SaveArg; | 28 using ::testing::SaveArg; |
| 28 using ::testing::SetArrayArgument; | 29 using ::testing::SetArrayArgument; |
| 29 using ::testing::SetArgPointee; | 30 using ::testing::SetArgPointee; |
| 30 using ::testing::StrEq; | 31 using ::testing::StrEq; |
| 31 using ::testing::StrictMock; | 32 using ::testing::StrictMock; |
| 32 | 33 |
| 33 namespace ui { | 34 namespace ui { |
| 34 | 35 |
| 35 class TestResourceManagerImpl : public ResourceManagerImpl { | 36 class TestResourceManagerImpl : public ResourceManagerImpl { |
| 36 public: | 37 public: |
| 37 TestResourceManagerImpl() {} | 38 TestResourceManagerImpl(WindowAndroid* window_android) |
| 39 : ResourceManagerImpl(window_android) {} |
| 40 |
| 38 ~TestResourceManagerImpl() override {} | 41 ~TestResourceManagerImpl() override {} |
| 39 | 42 |
| 40 void SetResourceAsLoaded(AndroidResourceType res_type, int res_id) { | 43 void SetResourceAsLoaded(AndroidResourceType res_type, int res_id) { |
| 41 SkBitmap small_bitmap; | 44 SkBitmap small_bitmap; |
| 42 SkCanvas canvas(small_bitmap); | 45 SkCanvas canvas(small_bitmap); |
| 43 small_bitmap.allocPixels( | 46 small_bitmap.allocPixels( |
| 44 SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType)); | 47 SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType)); |
| 45 canvas.drawColor(SK_ColorWHITE); | 48 canvas.drawColor(SK_ColorWHITE); |
| 46 small_bitmap.setImmutable(); | 49 small_bitmap.setImmutable(); |
| 47 | 50 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 73 MOCK_METHOD1(DeleteUIResource, void(cc::UIResourceId)); | 76 MOCK_METHOD1(DeleteUIResource, void(cc::UIResourceId)); |
| 74 | 77 |
| 75 private: | 78 private: |
| 76 DISALLOW_COPY_AND_ASSIGN(MockLayerTreeHost); | 79 DISALLOW_COPY_AND_ASSIGN(MockLayerTreeHost); |
| 77 }; | 80 }; |
| 78 | 81 |
| 79 } // namespace | 82 } // namespace |
| 80 | 83 |
| 81 class ResourceManagerTest : public testing::Test { | 84 class ResourceManagerTest : public testing::Test { |
| 82 public: | 85 public: |
| 83 ResourceManagerTest() : fake_client_(cc::FakeLayerTreeHostClient::DIRECT_3D) { | 86 ResourceManagerTest() |
| 87 : window_android_(WindowAndroid::createForTesting()), |
| 88 resource_manager_(window_android_), |
| 89 fake_client_(cc::FakeLayerTreeHostClient::DIRECT_3D) { |
| 84 cc::LayerTreeHost::InitParams params; | 90 cc::LayerTreeHost::InitParams params; |
| 85 cc::LayerTreeSettings settings; | 91 cc::LayerTreeSettings settings; |
| 86 params.client = &fake_client_; | 92 params.client = &fake_client_; |
| 87 params.settings = &settings; | 93 params.settings = &settings; |
| 88 params.task_graph_runner = &task_graph_runner_; | 94 params.task_graph_runner = &task_graph_runner_; |
| 89 host_.reset(new MockLayerTreeHost(¶ms)); | 95 host_.reset(new MockLayerTreeHost(¶ms)); |
| 90 resource_manager_.Init(host_.get()); | 96 resource_manager_.Init(host_.get()); |
| 91 } | 97 } |
| 92 | 98 |
| 99 ~ResourceManagerTest() { window_android_->Destroy(NULL, NULL); } |
| 100 |
| 93 void PreloadResource(ui::SystemUIResourceType type) { | 101 void PreloadResource(ui::SystemUIResourceType type) { |
| 94 resource_manager_.PreloadResource(ui::ANDROID_RESOURCE_TYPE_SYSTEM, type); | 102 resource_manager_.PreloadResource(ui::ANDROID_RESOURCE_TYPE_SYSTEM, type); |
| 95 } | 103 } |
| 96 | 104 |
| 97 cc::UIResourceId GetUIResourceId(ui::SystemUIResourceType type) { | 105 cc::UIResourceId GetUIResourceId(ui::SystemUIResourceType type) { |
| 98 return resource_manager_.GetUIResourceId(ui::ANDROID_RESOURCE_TYPE_SYSTEM, | 106 return resource_manager_.GetUIResourceId(ui::ANDROID_RESOURCE_TYPE_SYSTEM, |
| 99 type); | 107 type); |
| 100 } | 108 } |
| 101 | 109 |
| 102 void SetResourceAsLoaded(ui::SystemUIResourceType type) { | 110 void SetResourceAsLoaded(ui::SystemUIResourceType type) { |
| 103 resource_manager_.SetResourceAsLoaded(ui::ANDROID_RESOURCE_TYPE_SYSTEM, | 111 resource_manager_.SetResourceAsLoaded(ui::ANDROID_RESOURCE_TYPE_SYSTEM, |
| 104 type); | 112 type); |
| 105 } | 113 } |
| 106 | 114 |
| 115 private: |
| 116 WindowAndroid* window_android_; |
| 117 |
| 107 protected: | 118 protected: |
| 108 scoped_ptr<MockLayerTreeHost> host_; | 119 scoped_ptr<MockLayerTreeHost> host_; |
| 109 TestResourceManagerImpl resource_manager_; | 120 TestResourceManagerImpl resource_manager_; |
| 110 cc::TestTaskGraphRunner task_graph_runner_; | 121 cc::TestTaskGraphRunner task_graph_runner_; |
| 111 cc::FakeLayerTreeHostClient fake_client_; | 122 cc::FakeLayerTreeHostClient fake_client_; |
| 112 }; | 123 }; |
| 113 | 124 |
| 114 TEST_F(ResourceManagerTest, GetResource) { | 125 TEST_F(ResourceManagerTest, GetResource) { |
| 115 const cc::UIResourceId kResourceId = 99; | 126 const cc::UIResourceId kResourceId = 99; |
| 116 EXPECT_CALL(*host_.get(), CreateUIResource(_)) | 127 EXPECT_CALL(*host_.get(), CreateUIResource(_)) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 EXPECT_EQ(kNumFrames, actual_rects.size()); | 173 EXPECT_EQ(kNumFrames, actual_rects.size()); |
| 163 for (size_t i = 0; i < kNumFrames; i++) { | 174 for (size_t i = 0; i < kNumFrames; i++) { |
| 164 EXPECT_EQ(expected_rects[i].size(), actual_rects[i].size()); | 175 EXPECT_EQ(expected_rects[i].size(), actual_rects[i].size()); |
| 165 for (size_t j = 0; j < actual_rects[i].size(); j++) { | 176 for (size_t j = 0; j < actual_rects[i].size(); j++) { |
| 166 EXPECT_EQ(expected_rects[i][j], actual_rects[i][j]); | 177 EXPECT_EQ(expected_rects[i][j], actual_rects[i][j]); |
| 167 } | 178 } |
| 168 } | 179 } |
| 169 } | 180 } |
| 170 | 181 |
| 171 } // namespace ui | 182 } // namespace ui |
| OLD | NEW |