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

Side by Side Diff: content/browser/android/system_ui_resource_manager_impl_unittest.cc

Issue 679493002: [Android] Add a native pull-to-refresh overscroll effect (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix findbugs... Created 6 years, 1 month 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
OLDNEW
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 "content/browser/android/system_ui_resource_manager_impl.h" 6 #include "content/browser/android/system_ui_resource_manager_impl.h"
7 #include "content/public/browser/android/ui_resource_client_android.h" 7 #include "content/public/browser/android/ui_resource_client_android.h"
8 #include "content/public/browser/android/ui_resource_provider.h" 8 #include "content/public/browser/android/ui_resource_provider.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/skia/include/core/SkBitmap.h" 10 #include "third_party/skia/include/core/SkBitmap.h"
11 #include "third_party/skia/include/core/SkCanvas.h" 11 #include "third_party/skia/include/core/SkCanvas.h"
12 12
13 namespace content { 13 namespace content {
14 14
15 class TestSystemUIResourceManagerImpl 15 class TestSystemUIResourceManagerImpl
16 : public content::SystemUIResourceManagerImpl { 16 : public content::SystemUIResourceManagerImpl {
17 public: 17 public:
18 TestSystemUIResourceManagerImpl(content::UIResourceProvider* provider) 18 TestSystemUIResourceManagerImpl(content::UIResourceProvider* provider)
19 : SystemUIResourceManagerImpl(provider) {} 19 : SystemUIResourceManagerImpl(provider) {}
20 20
21 virtual ~TestSystemUIResourceManagerImpl() {} 21 virtual ~TestSystemUIResourceManagerImpl() {}
22 22
23 virtual void BuildResource( 23 virtual void BuildResource(ui::SystemUIResourceType type) override {}
24 ui::SystemUIResourceManager::ResourceType type) override {}
25 24
26 void SetResourceAsLoaded(ui::SystemUIResourceManager::ResourceType type) { 25 void SetResourceAsLoaded(ui::SystemUIResourceType type) {
27 SkBitmap small_bitmap; 26 SkBitmap small_bitmap;
28 SkCanvas canvas(small_bitmap); 27 SkCanvas canvas(small_bitmap);
29 small_bitmap.allocPixels( 28 small_bitmap.allocPixels(
30 SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType)); 29 SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType));
31 canvas.drawColor(SK_ColorWHITE); 30 canvas.drawColor(SK_ColorWHITE);
32 small_bitmap.setImmutable(); 31 small_bitmap.setImmutable();
33 OnFinishedLoadBitmap(type, &small_bitmap); 32 OnFinishedLoadBitmap(type, &small_bitmap);
34 } 33 }
35 }; 34 };
36 35
37 namespace { 36 namespace {
38 37
39 const ui::SystemUIResourceManager::ResourceType TEST_RESOURCE_TYPE = 38 const ui::SystemUIResourceType kTestResourceType = ui::OVERSCROLL_GLOW;
40 ui::SystemUIResourceManager::OVERSCROLL_GLOW;
41 39
42 class MockUIResourceProvider : public content::UIResourceProvider { 40 class MockUIResourceProvider : public content::UIResourceProvider {
43 public: 41 public:
44 MockUIResourceProvider() 42 MockUIResourceProvider()
45 : next_ui_resource_id_(1), 43 : next_ui_resource_id_(1),
46 has_layer_tree_host_(true), 44 has_layer_tree_host_(true),
47 system_ui_resource_manager_(this) {} 45 system_ui_resource_manager_(this) {}
48 46
49 virtual ~MockUIResourceProvider() {} 47 virtual ~MockUIResourceProvider() {}
50 48
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 bool has_layer_tree_host_; 91 bool has_layer_tree_host_;
94 92
95 // The UIResourceProvider owns the SystemUIResourceManager. 93 // The UIResourceProvider owns the SystemUIResourceManager.
96 TestSystemUIResourceManagerImpl system_ui_resource_manager_; 94 TestSystemUIResourceManagerImpl system_ui_resource_manager_;
97 }; 95 };
98 96
99 } // namespace 97 } // namespace
100 98
101 class SystemUIResourceManagerImplTest : public testing::Test { 99 class SystemUIResourceManagerImplTest : public testing::Test {
102 public: 100 public:
103 void PreloadResource(ui::SystemUIResourceManager::ResourceType type) { 101 void PreloadResource(ui::SystemUIResourceType type) {
104 ui_resource_provider_.GetSystemUIResourceManager().PreloadResource(type); 102 ui_resource_provider_.GetSystemUIResourceManager().PreloadResource(type);
105 } 103 }
106 104
107 cc::UIResourceId GetUIResourceId( 105 cc::UIResourceId GetUIResourceId(ui::SystemUIResourceType type) {
108 ui::SystemUIResourceManager::ResourceType type) {
109 return ui_resource_provider_.GetSystemUIResourceManager().GetUIResourceId( 106 return ui_resource_provider_.GetSystemUIResourceManager().GetUIResourceId(
110 type); 107 type);
111 } 108 }
112 109
113 void LayerTreeHostCleared() { ui_resource_provider_.LayerTreeHostCleared(); } 110 void LayerTreeHostCleared() { ui_resource_provider_.LayerTreeHostCleared(); }
114 111
115 void LayerTreeHostReturned() { 112 void LayerTreeHostReturned() {
116 ui_resource_provider_.LayerTreeHostReturned(); 113 ui_resource_provider_.LayerTreeHostReturned();
117 } 114 }
118 115
119 void SetResourceAsLoaded(ui::SystemUIResourceManager::ResourceType type) { 116 void SetResourceAsLoaded(ui::SystemUIResourceType type) {
120 ui_resource_provider_.GetSystemUIResourceManager().SetResourceAsLoaded( 117 ui_resource_provider_.GetSystemUIResourceManager().SetResourceAsLoaded(
121 type); 118 type);
122 } 119 }
123 120
124 cc::UIResourceId GetNextUIResourceId() const { 121 cc::UIResourceId GetNextUIResourceId() const {
125 return ui_resource_provider_.next_ui_resource_id(); 122 return ui_resource_provider_.next_ui_resource_id();
126 } 123 }
127 124
128 private: 125 private:
129 MockUIResourceProvider ui_resource_provider_; 126 MockUIResourceProvider ui_resource_provider_;
130 }; 127 };
131 128
132 TEST_F(SystemUIResourceManagerImplTest, GetResourceAfterBitmapLoaded) { 129 TEST_F(SystemUIResourceManagerImplTest, GetResourceAfterBitmapLoaded) {
133 SetResourceAsLoaded(TEST_RESOURCE_TYPE); 130 SetResourceAsLoaded(kTestResourceType);
134 EXPECT_NE(0, GetUIResourceId(TEST_RESOURCE_TYPE)); 131 EXPECT_NE(0, GetUIResourceId(kTestResourceType));
135 } 132 }
136 133
137 TEST_F(SystemUIResourceManagerImplTest, GetResourceBeforeLoadBitmap) { 134 TEST_F(SystemUIResourceManagerImplTest, GetResourceBeforeLoadBitmap) {
138 EXPECT_EQ(0, GetUIResourceId(TEST_RESOURCE_TYPE)); 135 EXPECT_EQ(0, GetUIResourceId(kTestResourceType));
139 SetResourceAsLoaded(TEST_RESOURCE_TYPE); 136 SetResourceAsLoaded(kTestResourceType);
140 EXPECT_NE(0, GetUIResourceId(TEST_RESOURCE_TYPE)); 137 EXPECT_NE(0, GetUIResourceId(kTestResourceType));
141 } 138 }
142 139
143 TEST_F(SystemUIResourceManagerImplTest, PreloadEnsureResource) { 140 TEST_F(SystemUIResourceManagerImplTest, PreloadEnsureResource) {
144 // Preloading the resource should trigger bitmap loading, but the actual 141 // Preloading the resource should trigger bitmap loading, but the actual
145 // resource id will not be generated until it is explicitly requested. 142 // resource id will not be generated until it is explicitly requested.
146 cc::UIResourceId first_resource_id = GetNextUIResourceId(); 143 cc::UIResourceId first_resource_id = GetNextUIResourceId();
147 PreloadResource(TEST_RESOURCE_TYPE); 144 PreloadResource(kTestResourceType);
148 SetResourceAsLoaded(TEST_RESOURCE_TYPE); 145 SetResourceAsLoaded(kTestResourceType);
149 EXPECT_EQ(first_resource_id, GetNextUIResourceId()); 146 EXPECT_EQ(first_resource_id, GetNextUIResourceId());
150 EXPECT_NE(0, GetUIResourceId(TEST_RESOURCE_TYPE)); 147 EXPECT_NE(0, GetUIResourceId(kTestResourceType));
151 EXPECT_NE(first_resource_id, GetNextUIResourceId()); 148 EXPECT_NE(first_resource_id, GetNextUIResourceId());
152 } 149 }
153 150
154 TEST_F(SystemUIResourceManagerImplTest, ResetLayerTreeHost) { 151 TEST_F(SystemUIResourceManagerImplTest, ResetLayerTreeHost) {
155 EXPECT_EQ(0, GetUIResourceId(TEST_RESOURCE_TYPE)); 152 EXPECT_EQ(0, GetUIResourceId(kTestResourceType));
156 LayerTreeHostCleared(); 153 LayerTreeHostCleared();
157 EXPECT_EQ(0, GetUIResourceId(TEST_RESOURCE_TYPE)); 154 EXPECT_EQ(0, GetUIResourceId(kTestResourceType));
158 LayerTreeHostReturned(); 155 LayerTreeHostReturned();
159 EXPECT_EQ(0, GetUIResourceId(TEST_RESOURCE_TYPE)); 156 EXPECT_EQ(0, GetUIResourceId(kTestResourceType));
160 157
161 SetResourceAsLoaded(TEST_RESOURCE_TYPE); 158 SetResourceAsLoaded(kTestResourceType);
162 EXPECT_NE(0, GetUIResourceId(TEST_RESOURCE_TYPE)); 159 EXPECT_NE(0, GetUIResourceId(kTestResourceType));
163 LayerTreeHostCleared(); 160 LayerTreeHostCleared();
164 EXPECT_EQ(0, GetUIResourceId(TEST_RESOURCE_TYPE)); 161 EXPECT_EQ(0, GetUIResourceId(kTestResourceType));
165 LayerTreeHostReturned(); 162 LayerTreeHostReturned();
166 EXPECT_NE(0, GetUIResourceId(TEST_RESOURCE_TYPE)); 163 EXPECT_NE(0, GetUIResourceId(kTestResourceType));
167 } 164 }
168 165
169 } // namespace content 166 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698