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/file_path.h" | |
7 #include "chrome/browser/extensions/extension_browsertest.h" | |
8 #include "chrome/browser/extensions/extension_service.h" | |
9 #include "chrome/browser/profiles/profile.h" | |
10 #include "chrome/browser/ui/browser.h" | |
11 #include "chrome/browser/ui/browser_list.h" | |
12 #include "chrome/browser/ui/extensions/application_launch.h" | |
13 #include "chrome/browser/ui/panels/panel_manager.h" | |
14 #include "chrome/common/chrome_notification_types.h" | |
15 #include "chrome/common/chrome_switches.h" | |
16 #include "chrome/test/base/in_process_browser_test.h" | |
17 #include "chrome/test/base/ui_test_utils.h" | |
18 #include "testing/gtest/include/gtest/gtest.h" | |
19 | |
20 #if defined(OS_MACOSX) | |
21 #include "base/mac/scoped_nsautorelease_pool.h" | |
22 #endif | |
23 | |
24 // Refactor has only been done for Mac panels so far. | |
25 #if defined(OS_MACOSX) | |
26 | |
27 class PanelAppBrowserTest : public ExtensionBrowserTest { | |
28 public: | |
29 virtual void SetUpCommandLine(CommandLine* command_line) { | |
30 ExtensionBrowserTest::SetUpCommandLine(command_line); | |
31 command_line->AppendSwitch(switches::kBrowserlessPanels); | |
32 } | |
33 | |
34 void LoadAndLaunchExtension(const char* name) { | |
35 #if defined(OS_MACOSX) | |
36 // Opening panels on a Mac causes NSWindowController of the Panel window | |
37 // to be autoreleased. We need a pool drained after it's done so the test | |
38 // can close correctly. The NSWindowController of the Panel window controls | |
39 // lifetime of the Panel object so we want to release it as soon as | |
40 // possible. In real Chrome, this is done by message pump. | |
41 // On non-Mac platform, this is an empty class. | |
42 base::mac::ScopedNSAutoreleasePool autorelease_pool; | |
43 #endif | |
44 | |
45 EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII(name))); | |
46 | |
47 ExtensionService* service = browser()->profile()->GetExtensionService(); | |
48 const extensions::Extension* extension = service->GetExtensionById( | |
49 last_loaded_extension_id_, false); | |
50 EXPECT_TRUE(extension); | |
51 | |
52 PanelManager* manager = PanelManager::GetInstance(); | |
53 int panel_count = manager->num_panels(); | |
54 | |
55 application_launch::OpenApplication( | |
56 browser()->profile(), | |
57 extension, | |
58 // Overriding manifest to open in a panel. | |
59 extension_misc::LAUNCH_PANEL, | |
60 GURL(), | |
61 NEW_WINDOW, | |
62 NULL); | |
63 | |
64 // Now we have a new browser instance. | |
65 EXPECT_EQ(panel_count + 1, manager->num_panels()); | |
66 } | |
67 | |
68 void ClosePanelAndWait(Panel* panel) { | |
69 // Closing a panel window may involve several async tasks. Need to use | |
70 // message pump and wait for the notification. | |
71 int panel_count = PanelManager::GetInstance()->num_panels(); | |
72 ui_test_utils::WindowedNotificationObserver signal( | |
73 chrome::NOTIFICATION_PANEL_CLOSED, | |
74 content::Source<Panel>(panel)); | |
75 panel->Close(); | |
76 signal.Wait(); | |
77 // Now we have one less panel instance. | |
78 EXPECT_EQ(panel_count - 1, PanelManager::GetInstance()->num_panels()); | |
79 } | |
80 }; | |
81 | |
82 IN_PROC_BROWSER_TEST_F(PanelAppBrowserTest, OpenAppInPanel) { | |
83 // Start with one browser, new Panel will NOT create another. | |
84 ASSERT_EQ(1u, BrowserList::size()); | |
85 | |
86 // No Panels initially. | |
87 PanelManager* panel_manager = PanelManager::GetInstance(); | |
88 ASSERT_EQ(0, panel_manager->num_panels()); // No panels initially. | |
89 | |
90 LoadAndLaunchExtension("app_with_panel_container"); | |
91 | |
92 // The launch should have created no new browsers. | |
93 ASSERT_EQ(1u, BrowserList::size()); | |
94 | |
95 // Now also check that PanelManager has one new Panel under management. | |
96 EXPECT_EQ(1, panel_manager->num_panels()); | |
97 | |
98 Panel* panel = panel_manager->panels()[0]; | |
99 ClosePanelAndWait(panel); | |
100 | |
101 EXPECT_EQ(0, panel_manager->num_panels()); | |
102 EXPECT_EQ(1u, BrowserList::size()); | |
103 } | |
104 | |
105 #endif // OS_MACOSX | |
OLD | NEW |