| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/command_line.h" |
| 6 #include "base/path_service.h" |
| 7 #include "chrome/browser/extensions/extension_browsertest.h" |
| 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/panels/native_panel.h" |
| 11 #include "chrome/browser/ui/panels/panel.h" |
| 12 #include "chrome/browser/ui/panels/panel_constants.h" |
| 13 #include "chrome/browser/ui/panels/panel_manager.h" |
| 14 #include "chrome/browser/web_applications/web_app.h" |
| 15 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "chrome/common/chrome_paths.h" |
| 17 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/common/extensions/extension.h" |
| 19 #include "content/public/test/test_utils.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 |
| 22 #if defined(OS_MACOSX) |
| 23 #include "base/mac/scoped_nsautorelease_pool.h" |
| 24 #endif |
| 25 |
| 26 using extensions::Extension; |
| 27 |
| 28 namespace { |
| 29 // This test extension has icons specified. |
| 30 const FilePath::CharType* kPanelTestExtensionFilePath = |
| 31 FILE_PATH_LITERAL("panels/test_extension"); |
| 32 }; |
| 33 |
| 34 class PanelExtensionBrowserTest : public ExtensionBrowserTest { |
| 35 protected: |
| 36 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 37 ExtensionBrowserTest::SetUpCommandLine(command_line); |
| 38 command_line->AppendSwitch(switches::kEnablePanels); |
| 39 } |
| 40 |
| 41 const Extension* LoadTestExtension() { |
| 42 FilePath manifest_path; |
| 43 PathService::Get(chrome::DIR_TEST_DATA, &manifest_path); |
| 44 manifest_path = manifest_path.Append(kPanelTestExtensionFilePath); |
| 45 return LoadExtension(manifest_path); |
| 46 } |
| 47 |
| 48 Panel* CreatePanelFromExtension(const Extension* extension) const { |
| 49 #if defined(OS_MACOSX) |
| 50 // Opening panels on a Mac causes NSWindowController of the Panel window |
| 51 // to be autoreleased. We need a pool drained after it's done so the test |
| 52 // can close correctly. The NSWindowController of the Panel window controls |
| 53 // lifetime of the Panel object so we want to release it as soon as |
| 54 // possible. In real Chrome, this is done by message pump. |
| 55 // On non-Mac platform, this is an empty class. |
| 56 base::mac::ScopedNSAutoreleasePool autorelease_pool; |
| 57 #endif |
| 58 |
| 59 Panel* panel = PanelManager::GetInstance()->CreatePanel( |
| 60 web_app::GenerateApplicationNameFromExtensionId(extension->id()), |
| 61 browser()->profile(), |
| 62 GURL(), |
| 63 gfx::Rect(), |
| 64 PanelManager::CREATE_AS_DETACHED); |
| 65 panel->ShowInactive(); |
| 66 return panel; |
| 67 } |
| 68 |
| 69 void WaitForAppIconAvailable(Panel* panel) const { |
| 70 content::WindowedNotificationObserver signal( |
| 71 chrome::NOTIFICATION_PANEL_APP_ICON_LOADED, |
| 72 content::Source<Panel>(panel)); |
| 73 if (!panel->app_icon().IsEmpty()) |
| 74 return; |
| 75 signal.Wait(); |
| 76 EXPECT_FALSE(panel->app_icon().IsEmpty()); |
| 77 } |
| 78 |
| 79 static NativePanelTesting* CreateNativePanelTesting(Panel* panel) { |
| 80 return panel->native_panel()->CreateNativePanelTesting(); |
| 81 } |
| 82 }; |
| 83 |
| 84 IN_PROC_BROWSER_TEST_F(PanelExtensionBrowserTest, PanelAppIcon) { |
| 85 const Extension* extension = LoadTestExtension(); |
| 86 Panel* panel = CreatePanelFromExtension(extension); |
| 87 |
| 88 // Wait for the app icon gets fully loaded. |
| 89 WaitForAppIconAvailable(panel); |
| 90 |
| 91 // First verify on the panel level. |
| 92 gfx::ImageSkia app_icon = panel->app_icon().AsImageSkia(); |
| 93 EXPECT_EQ(panel::kPanelAppIconSize, app_icon.width()); |
| 94 EXPECT_EQ(panel::kPanelAppIconSize, app_icon.height()); |
| 95 |
| 96 // Then verify on the native panel level. |
| 97 scoped_ptr<NativePanelTesting> native_panel_testing( |
| 98 CreateNativePanelTesting(panel)); |
| 99 EXPECT_TRUE(native_panel_testing->VerifyAppIcon()); |
| 100 |
| 101 panel->Close(); |
| 102 } |
| 103 |
| 104 // Tests that icon loading might not be completed when the panel is closed. |
| 105 // (crbug.com/151484) |
| 106 IN_PROC_BROWSER_TEST_F(PanelExtensionBrowserTest, |
| 107 ClosePanelBeforeIconLoadingCompleted) { |
| 108 const Extension* extension = LoadTestExtension(); |
| 109 Panel* panel = CreatePanelFromExtension(extension); |
| 110 |
| 111 // Close tha panel without waiting for the app icon loaded. |
| 112 panel->Close(); |
| 113 } |
| OLD | NEW |