OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/surface/transport_dib.h" | 5 #include "app/surface/transport_dib.h" |
6 #include "base/basictypes.h" | 6 #include "base/basictypes.h" |
7 #include "chrome/browser/renderer_host/backing_store_manager.h" | 7 #include "chrome/browser/renderer_host/backing_store_manager.h" |
8 #include "chrome/browser/renderer_host/mock_render_process_host.h" | 8 #include "chrome/browser/renderer_host/mock_render_process_host.h" |
9 #include "chrome/browser/renderer_host/test/test_render_view_host.h" | 9 #include "chrome/browser/renderer_host/test/test_render_view_host.h" |
10 #include "chrome/browser/tab_contents/thumbnail_generator.h" | 10 #include "chrome/browser/tab_contents/thumbnail_generator.h" |
11 #include "chrome/common/notification_service.h" | 11 #include "chrome/common/notification_service.h" |
12 #include "chrome/common/render_messages.h" | 12 #include "chrome/common/render_messages.h" |
13 #include "chrome/test/testing_profile.h" | 13 #include "chrome/test/testing_profile.h" |
| 14 #include "skia/ext/platform_canvas.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "skia/ext/platform_canvas.h" | |
16 #include "third_party/skia/include/core/SkColorPriv.h" | 16 #include "third_party/skia/include/core/SkColorPriv.h" |
17 | 17 |
18 static const int kBitmapWidth = 100; | 18 static const int kBitmapWidth = 100; |
19 static const int kBitmapHeight = 100; | 19 static const int kBitmapHeight = 100; |
20 | 20 |
21 // TODO(brettw) enable this when GetThumbnailForBackingStore is implemented | 21 // TODO(brettw) enable this when GetThumbnailForBackingStore is implemented |
22 // for other platforms in thumbnail_generator.cc | 22 // for other platforms in thumbnail_generator.cc |
23 // #if defined(OS_WIN) | 23 // #if defined(OS_WIN) |
24 // TODO(brettw) enable this on Windows after we clobber a build to see if the | 24 // TODO(brettw) enable this on Windows after we clobber a build to see if the |
25 // failures of this on the buildbot can be resolved. | 25 // failures of this on the buildbot can be resolved. |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 SkBitmap result = generator_.GetThumbnailForRenderer(&widget_); | 135 SkBitmap result = generator_.GetThumbnailForRenderer(&widget_); |
136 EXPECT_TRUE(result.isNull()); | 136 EXPECT_TRUE(result.isNull()); |
137 } | 137 } |
138 | 138 |
139 // Tests basic thumbnail generation when a backing store is discarded. | 139 // Tests basic thumbnail generation when a backing store is discarded. |
140 TEST_F(ThumbnailGeneratorTest, DiscardBackingStore) { | 140 TEST_F(ThumbnailGeneratorTest, DiscardBackingStore) { |
141 // First set up a backing store and then discard it. | 141 // First set up a backing store and then discard it. |
142 SendPaint(TRANSPORT_BLACK); | 142 SendPaint(TRANSPORT_BLACK); |
143 widget_.WasHidden(); | 143 widget_.WasHidden(); |
144 ASSERT_TRUE(BackingStoreManager::ExpireBackingStoreForTest(&widget_)); | 144 ASSERT_TRUE(BackingStoreManager::ExpireBackingStoreForTest(&widget_)); |
145 ASSERT_FALSE(widget_.GetBackingStore(false)); | 145 ASSERT_FALSE(widget_.GetBackingStore(false, false)); |
146 | 146 |
147 // The thumbnail generator should have stashed a thumbnail of the page. | 147 // The thumbnail generator should have stashed a thumbnail of the page. |
148 SkBitmap result = generator_.GetThumbnailForRenderer(&widget_); | 148 SkBitmap result = generator_.GetThumbnailForRenderer(&widget_); |
149 ASSERT_FALSE(result.isNull()); | 149 ASSERT_FALSE(result.isNull()); |
150 EXPECT_EQ(TRANSPORT_BLACK, ClassifyFirstPixel(result)); | 150 EXPECT_EQ(TRANSPORT_BLACK, ClassifyFirstPixel(result)); |
151 } | 151 } |
152 | 152 |
153 TEST_F(ThumbnailGeneratorTest, QuickShow) { | 153 TEST_F(ThumbnailGeneratorTest, QuickShow) { |
154 // Set up a hidden widget with a black cached thumbnail and an expired | 154 // Set up a hidden widget with a black cached thumbnail and an expired |
155 // backing store. | 155 // backing store. |
156 SendPaint(TRANSPORT_BLACK); | 156 SendPaint(TRANSPORT_BLACK); |
157 widget_.WasHidden(); | 157 widget_.WasHidden(); |
158 ASSERT_TRUE(BackingStoreManager::ExpireBackingStoreForTest(&widget_)); | 158 ASSERT_TRUE(BackingStoreManager::ExpireBackingStoreForTest(&widget_)); |
159 ASSERT_FALSE(widget_.GetBackingStore(false)); | 159 ASSERT_FALSE(widget_.GetBackingStore(false, false)); |
160 | 160 |
161 // Now show the widget and paint white. | 161 // Now show the widget and paint white. |
162 widget_.WasRestored(); | 162 widget_.WasRestored(); |
163 SendPaint(TRANSPORT_WHITE); | 163 SendPaint(TRANSPORT_WHITE); |
164 | 164 |
165 // The black thumbnail should still be cached because it hasn't processed the | 165 // The black thumbnail should still be cached because it hasn't processed the |
166 // timer message yet. | 166 // timer message yet. |
167 SkBitmap result = generator_.GetThumbnailForRenderer(&widget_); | 167 SkBitmap result = generator_.GetThumbnailForRenderer(&widget_); |
168 ASSERT_FALSE(result.isNull()); | 168 ASSERT_FALSE(result.isNull()); |
169 EXPECT_EQ(TRANSPORT_BLACK, ClassifyFirstPixel(result)); | 169 EXPECT_EQ(TRANSPORT_BLACK, ClassifyFirstPixel(result)); |
170 | 170 |
171 // Running the message loop will process the timer, which should expire the | 171 // Running the message loop will process the timer, which should expire the |
172 // cached thumbnail. Asking again should give us a new one computed from the | 172 // cached thumbnail. Asking again should give us a new one computed from the |
173 // backing store. | 173 // backing store. |
174 message_loop_.RunAllPending(); | 174 message_loop_.RunAllPending(); |
175 result = generator_.GetThumbnailForRenderer(&widget_); | 175 result = generator_.GetThumbnailForRenderer(&widget_); |
176 ASSERT_FALSE(result.isNull()); | 176 ASSERT_FALSE(result.isNull()); |
177 EXPECT_EQ(TRANSPORT_WHITE, ClassifyFirstPixel(result)); | 177 EXPECT_EQ(TRANSPORT_WHITE, ClassifyFirstPixel(result)); |
178 } | 178 } |
179 | 179 |
180 #endif | 180 #endif |
OLD | NEW |