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

Unified Diff: ash/shelf/shelf_window_watcher_unittest.cc

Issue 2833173002: mash: Support ShelfModel access in Chrome. (Closed)
Patch Set: Address comments; fix test failures. Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: ash/shelf/shelf_window_watcher_unittest.cc
diff --git a/ash/shelf/shelf_window_watcher_unittest.cc b/ash/shelf/shelf_window_watcher_unittest.cc
index 836a06e730958c0bc8424572e1d297f62cb951df..ad97f4e0142a5c53b3e3b0178209d64d55c6f9b5 100644
--- a/ash/shelf/shelf_window_watcher_unittest.cc
+++ b/ash/shelf/shelf_window_watcher_unittest.cc
@@ -17,11 +17,25 @@
#include "ash/wm/window_resizer.h"
#include "ash/wm/window_state.h"
#include "base/strings/string_number_conversions.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h"
#include "ui/base/hit_test.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/image/image_skia.h"
+#include "ui/resources/grit/ui_resources.h"
#include "ui/views/widget/widget.h"
namespace ash {
+namespace {
+
+// Create a test 1x1 icon image with a given |color|.
+gfx::ImageSkia CreateImageSkiaIcon(SkColor color) {
+ SkBitmap bitmap;
+ bitmap.allocN32Pixels(1, 1);
+ bitmap.eraseColor(color);
+ return gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
+}
class ShelfWindowWatcherTest : public test::AshTestBase {
public:
@@ -301,6 +315,37 @@ TEST_F(ShelfWindowWatcherTest, PanelWindow) {
EXPECT_EQ(1, model_->item_count());
}
+// Ensure items use the app icon and window icon aura::Window properties.
+TEST_F(ShelfWindowWatcherTest, ItemIcon) {
+ // ShelfModel only has an APP_LIST item.
+ EXPECT_EQ(1, model_->item_count());
+
+ // Create a ShelfItem for a window; it should have a default icon.
+ std::unique_ptr<views::Widget> widget =
+ CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
+ aura::Window* window = widget->GetNativeWindow();
+ ShelfID id = CreateShelfItem(window);
+ EXPECT_EQ(2, model_->item_count());
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ gfx::Image default_image = rb.GetImageNamed(IDR_DEFAULT_FAVICON_32);
+ EXPECT_TRUE(model_->items()[1].image.BackedBySameObjectAs(
+ default_image.AsImageSkia()));
+
+ // Setting a window icon should update the item icon.
+ const gfx::ImageSkia red = CreateImageSkiaIcon(SK_ColorRED);
+ window->SetProperty(aura::client::kWindowIconKey, new gfx::ImageSkia(red));
+ EXPECT_EQ(SK_ColorRED, model_->items()[1].image.bitmap()->getColor(0, 0));
+
+ // Setting an app icon should override the window icon.
+ const gfx::ImageSkia blue = CreateImageSkiaIcon(SK_ColorBLUE);
+ window->SetProperty(aura::client::kAppIconKey, new gfx::ImageSkia(blue));
+ EXPECT_EQ(SK_ColorBLUE, model_->items()[1].image.bitmap()->getColor(0, 0));
+
+ // Clearing the app icon should restore the window icon to the shelf item.
+ window->ClearProperty(aura::client::kAppIconKey);
+ EXPECT_EQ(SK_ColorRED, model_->items()[1].image.bitmap()->getColor(0, 0));
+}
+
TEST_F(ShelfWindowWatcherTest, DontCreateShelfEntriesForChildWindows) {
const int initial_item_count = model_->item_count();
@@ -350,4 +395,5 @@ TEST_F(ShelfWindowWatcherSessionStartTest, PreExistingWindow) {
EXPECT_EQ(2, model->item_count());
}
+} // namespace
} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698