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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 #include "chrome/browser/apps/app_browsertest_util.h" | 6 #include "chrome/browser/apps/app_browsertest_util.h" |
7 #include "extensions/browser/app_window/native_app_window.h" | 7 #include "extensions/browser/app_window/native_app_window.h" |
| 8 #include "extensions/browser/test_image_loader.h" |
| 9 #include "extensions/grit/extensions_browser_resources.h" |
| 10 #include "ui/base/resource/resource_bundle.h" |
| 11 #include "ui/gfx/image/image_skia_operations.h" |
| 12 #include "ui/gfx/image/image_skia_source.h" |
| 13 #include "ui/gfx/skia_util.h" |
8 | 14 |
9 namespace extensions { | 15 namespace extensions { |
10 | 16 |
11 namespace { | 17 namespace { |
12 | 18 |
13 typedef PlatformAppBrowserTest AppWindowBrowserTest; | 19 typedef PlatformAppBrowserTest AppWindowBrowserTest; |
14 | 20 |
15 // This test is disabled on Linux because of the unpredictable nature of native | 21 // This test is disabled on Linux because of the unpredictable nature of native |
16 // windows. We cannot assume that the window manager will insert any title bar | 22 // windows. We cannot assume that the window manager will insert any title bar |
17 // at all, so the test may fail on certain window managers. | 23 // at all, so the test may fail on certain window managers. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 | 65 |
60 // All insets must be zero. | 66 // All insets must be zero. |
61 EXPECT_EQ(0, insets.top()); | 67 EXPECT_EQ(0, insets.top()); |
62 EXPECT_EQ(0, insets.bottom()); | 68 EXPECT_EQ(0, insets.bottom()); |
63 EXPECT_EQ(0, insets.left()); | 69 EXPECT_EQ(0, insets.left()); |
64 EXPECT_EQ(0, insets.right()); | 70 EXPECT_EQ(0, insets.right()); |
65 | 71 |
66 CloseAppWindow(app_window); | 72 CloseAppWindow(app_window); |
67 } | 73 } |
68 | 74 |
| 75 // Verifies that a window created with showInShelf set to true is properly |
| 76 // enabled in AppWindow. |
| 77 IN_PROC_BROWSER_TEST_F(AppWindowBrowserTest, |
| 78 ShowInShelfWindowWithWindowKeySet) { |
| 79 AppWindow* app_window = |
| 80 CreateTestAppWindow("{ \"id\": \"appwindow\", \"showInShelf\": true }"); |
| 81 |
| 82 ASSERT_TRUE(app_window); |
| 83 |
| 84 // showInShelf must be true. |
| 85 EXPECT_EQ(true, app_window->show_in_shelf()); |
| 86 |
| 87 CloseAppWindow(app_window); |
| 88 } |
| 89 |
| 90 // Verifies that a window created with showInShelf=true and an icon URL has |
| 91 // the icon properly set in AppWindow. |
| 92 IN_PROC_BROWSER_TEST_F(AppWindowBrowserTest, ShowInShelfWindowIcon) { |
| 93 AppWindow* app_window = CreateTestAppWindow( |
| 94 "{ \"id\": \"appwindow\", \"showInShelf\": true, " |
| 95 "\"icon\":\"icon_128.png\" }"); |
| 96 |
| 97 ASSERT_TRUE(app_window); |
| 98 |
| 99 // showInShelf must be true. |
| 100 EXPECT_EQ(true, app_window->show_in_shelf()); |
| 101 |
| 102 // Check for local window icon URL. |
| 103 EXPECT_EQ( |
| 104 "chrome-extension://" + app_window->extension_id() + "/icon_128.png", |
| 105 app_window->window_icon_url().spec()); |
| 106 |
| 107 // Get the window base image that is set using the icon URL property. |
| 108 SkBitmap window_icon_bitmap = TestImageLoader::LoadAndGetExtensionBitmap( |
| 109 app_window->GetExtension(), "icon_128.png", 128); |
| 110 // Create the window icon using the window base image and the extension app |
| 111 // icon badge. |
| 112 gfx::Image window_icon_with_badge = |
| 113 gfx::Image(gfx::ImageSkiaOperations::CreateIconWithBadge( |
| 114 gfx::Image::CreateFrom1xBitmap(window_icon_bitmap).AsImageSkia(), |
| 115 GetAppIconImage(app_window))); |
| 116 |
| 117 // Check app icon and window icon not empty. |
| 118 EXPECT_EQ(false, app_window->app_icon().IsEmpty()); |
| 119 EXPECT_EQ(false, window_icon_bitmap.empty()); |
| 120 EXPECT_EQ(false, window_icon_with_badge.IsEmpty()); |
| 121 |
| 122 // Check icons width. |
| 123 EXPECT_EQ(128, app_window->app_icon().Width()); |
| 124 EXPECT_EQ(128, window_icon_bitmap.width()); |
| 125 EXPECT_EQ(128, window_icon_with_badge.Width()); |
| 126 |
| 127 // Check icons height. |
| 128 EXPECT_EQ(128, app_window->app_icon().Height()); |
| 129 EXPECT_EQ(128, window_icon_bitmap.height()); |
| 130 EXPECT_EQ(128, window_icon_with_badge.Height()); |
| 131 |
| 132 // Check window icon is set properly. |
| 133 EXPECT_EQ(true, gfx::BitmapsAreEqual(app_window->app_icon().AsBitmap(), |
| 134 window_icon_with_badge.AsBitmap())); |
| 135 |
| 136 CloseAppWindow(app_window); |
| 137 } |
| 138 |
69 } // namespace | 139 } // namespace |
70 | 140 |
71 } // namespace extensions | 141 } // namespace extensions |
OLD | NEW |