OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/extensions/extension_apitest.h" | 5 #include "chrome/browser/extensions/extension_apitest.h" |
6 #include "chrome/browser/extensions/extension_service.h" | 6 #include "chrome/browser/extensions/extension_service.h" |
7 #include "chrome/browser/extensions/extension_test_message_listener.h" | 7 #include "chrome/browser/extensions/extension_test_message_listener.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_finder.h" |
10 #include "chrome/browser/ui/browser_list.h" | 11 #include "chrome/browser/ui/browser_list.h" |
11 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
12 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 // Find a browser other than |browser|. | 18 // Find a browser other than |browser|. |
18 Browser* FindOtherBrowser(Browser* browser) { | 19 Browser* FindOtherBrowser(Browser* browser) { |
19 Browser* found = NULL; | 20 Browser* found = NULL; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 ASSERT_TRUE(LoadExtension( | 86 ASSERT_TRUE(LoadExtension( |
86 test_data_dir_.AppendASCII("management/launch_on_install"))); | 87 test_data_dir_.AppendASCII("management/launch_on_install"))); |
87 ASSERT_TRUE(launcher_loaded.WaitUntilSatisfied()); | 88 ASSERT_TRUE(launcher_loaded.WaitUntilSatisfied()); |
88 | 89 |
89 // Load an app with app.launch.container = "panel". | 90 // Load an app with app.launch.container = "panel". |
90 std::string app_id; | 91 std::string app_id; |
91 LoadAndWaitForLaunch("management/launch_app_panel", &app_id); | 92 LoadAndWaitForLaunch("management/launch_app_panel", &app_id); |
92 ASSERT_FALSE(HasFatalFailure()); // Stop the test if any ASSERT failed. | 93 ASSERT_FALSE(HasFatalFailure()); // Stop the test if any ASSERT failed. |
93 | 94 |
94 // Find the app's browser. Check that it is a panel. | 95 // Find the app's browser. Check that it is a panel. |
95 ASSERT_EQ(2u, BrowserList::GetBrowserCount(browser()->profile())); | 96 ASSERT_EQ(2u, browser::GetBrowserCount(browser()->profile())); |
96 Browser* app_browser = FindOtherBrowser(browser()); | 97 Browser* app_browser = FindOtherBrowser(browser()); |
97 ASSERT_TRUE(app_browser->is_type_panel()); | 98 ASSERT_TRUE(app_browser->is_type_panel()); |
98 ASSERT_TRUE(app_browser->is_app()); | 99 ASSERT_TRUE(app_browser->is_app()); |
99 | 100 |
100 // Close the app panel. | 101 // Close the app panel. |
101 ui_test_utils::WindowedNotificationObserver signal( | 102 ui_test_utils::WindowedNotificationObserver signal( |
102 chrome::NOTIFICATION_BROWSER_CLOSED, | 103 chrome::NOTIFICATION_BROWSER_CLOSED, |
103 content::Source<Browser>(app_browser)); | 104 content::Source<Browser>(app_browser)); |
104 | 105 |
105 app_browser->CloseWindow(); | 106 app_browser->CloseWindow(); |
106 signal.Wait(); | 107 signal.Wait(); |
107 | 108 |
108 // Unload the extension. | 109 // Unload the extension. |
109 UninstallExtension(app_id); | 110 UninstallExtension(app_id); |
110 ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile())); | 111 ASSERT_EQ(1u, browser::GetBrowserCount(browser()->profile())); |
111 ASSERT_FALSE(service->GetExtensionById(app_id, true)); | 112 ASSERT_FALSE(service->GetExtensionById(app_id, true)); |
112 | 113 |
113 // Set a pref indicating that the user wants to launch in a regular tab. | 114 // Set a pref indicating that the user wants to launch in a regular tab. |
114 // This should be ignored, because panel apps always load in a panel. | 115 // This should be ignored, because panel apps always load in a panel. |
115 service->extension_prefs()->SetLaunchType( | 116 service->extension_prefs()->SetLaunchType( |
116 app_id, ExtensionPrefs::LAUNCH_REGULAR); | 117 app_id, ExtensionPrefs::LAUNCH_REGULAR); |
117 | 118 |
118 // Load the extension again. | 119 // Load the extension again. |
119 std::string app_id_new; | 120 std::string app_id_new; |
120 LoadAndWaitForLaunch("management/launch_app_panel", &app_id_new); | 121 LoadAndWaitForLaunch("management/launch_app_panel", &app_id_new); |
121 ASSERT_FALSE(HasFatalFailure()); | 122 ASSERT_FALSE(HasFatalFailure()); |
122 | 123 |
123 // If the ID changed, then the pref will not apply to the app. | 124 // If the ID changed, then the pref will not apply to the app. |
124 ASSERT_EQ(app_id, app_id_new); | 125 ASSERT_EQ(app_id, app_id_new); |
125 | 126 |
126 // Find the app's browser. Apps that should load in a panel ignore | 127 // Find the app's browser. Apps that should load in a panel ignore |
127 // prefs, so we should still see the launch in a panel. | 128 // prefs, so we should still see the launch in a panel. |
128 ASSERT_EQ(2u, BrowserList::GetBrowserCount(browser()->profile())); | 129 ASSERT_EQ(2u, browser::GetBrowserCount(browser()->profile())); |
129 app_browser = FindOtherBrowser(browser()); | 130 app_browser = FindOtherBrowser(browser()); |
130 ASSERT_TRUE(app_browser->is_type_panel()); | 131 ASSERT_TRUE(app_browser->is_type_panel()); |
131 ASSERT_TRUE(app_browser->is_app()); | 132 ASSERT_TRUE(app_browser->is_app()); |
132 } | 133 } |
133 | 134 |
134 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, LaunchTabApp) { | 135 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, LaunchTabApp) { |
135 ExtensionService* service = browser()->profile()->GetExtensionService(); | 136 ExtensionService* service = browser()->profile()->GetExtensionService(); |
136 | 137 |
137 // Load an extension that calls launchApp() on any app that gets | 138 // Load an extension that calls launchApp() on any app that gets |
138 // installed. | 139 // installed. |
139 ExtensionTestMessageListener launcher_loaded("launcher loaded", false); | 140 ExtensionTestMessageListener launcher_loaded("launcher loaded", false); |
140 ASSERT_TRUE(LoadExtension( | 141 ASSERT_TRUE(LoadExtension( |
141 test_data_dir_.AppendASCII("management/launch_on_install"))); | 142 test_data_dir_.AppendASCII("management/launch_on_install"))); |
142 ASSERT_TRUE(launcher_loaded.WaitUntilSatisfied()); | 143 ASSERT_TRUE(launcher_loaded.WaitUntilSatisfied()); |
143 | 144 |
144 // Code below assumes that the test starts with a single browser window | 145 // Code below assumes that the test starts with a single browser window |
145 // hosting one tab. | 146 // hosting one tab. |
146 ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile())); | 147 ASSERT_EQ(1u, browser::GetBrowserCount(browser()->profile())); |
147 ASSERT_EQ(1, browser()->tab_count()); | 148 ASSERT_EQ(1, browser()->tab_count()); |
148 | 149 |
149 // Load an app with app.launch.container = "tab". | 150 // Load an app with app.launch.container = "tab". |
150 std::string app_id; | 151 std::string app_id; |
151 LoadAndWaitForLaunch("management/launch_app_tab", &app_id); | 152 LoadAndWaitForLaunch("management/launch_app_tab", &app_id); |
152 ASSERT_FALSE(HasFatalFailure()); | 153 ASSERT_FALSE(HasFatalFailure()); |
153 | 154 |
154 // Check that the app opened in a new tab of the existing browser. | 155 // Check that the app opened in a new tab of the existing browser. |
155 ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile())); | 156 ASSERT_EQ(1u, browser::GetBrowserCount(browser()->profile())); |
156 ASSERT_EQ(2, browser()->tab_count()); | 157 ASSERT_EQ(2, browser()->tab_count()); |
157 | 158 |
158 // Unload the extension. | 159 // Unload the extension. |
159 UninstallExtension(app_id); | 160 UninstallExtension(app_id); |
160 ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile())); | 161 ASSERT_EQ(1u, browser::GetBrowserCount(browser()->profile())); |
161 ASSERT_FALSE(service->GetExtensionById(app_id, true)); | 162 ASSERT_FALSE(service->GetExtensionById(app_id, true)); |
162 | 163 |
163 // Set a pref indicating that the user wants to launch in a window. | 164 // Set a pref indicating that the user wants to launch in a window. |
164 service->extension_prefs()->SetLaunchType( | 165 service->extension_prefs()->SetLaunchType( |
165 app_id, ExtensionPrefs::LAUNCH_WINDOW); | 166 app_id, ExtensionPrefs::LAUNCH_WINDOW); |
166 | 167 |
167 std::string app_id_new; | 168 std::string app_id_new; |
168 LoadAndWaitForLaunch("management/launch_app_tab", &app_id_new); | 169 LoadAndWaitForLaunch("management/launch_app_tab", &app_id_new); |
169 ASSERT_FALSE(HasFatalFailure()); | 170 ASSERT_FALSE(HasFatalFailure()); |
170 | 171 |
171 // If the ID changed, then the pref will not apply to the app. | 172 // If the ID changed, then the pref will not apply to the app. |
172 ASSERT_EQ(app_id, app_id_new); | 173 ASSERT_EQ(app_id, app_id_new); |
173 | 174 |
174 #if defined(OS_MACOSX) | 175 #if defined(OS_MACOSX) |
175 // App windows are not yet implemented on mac os. We should fall back | 176 // App windows are not yet implemented on mac os. We should fall back |
176 // to a normal tab. | 177 // to a normal tab. |
177 ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile())); | 178 ASSERT_EQ(1u, browser::GetBrowserCount(browser()->profile())); |
178 ASSERT_EQ(2, browser()->tab_count()); | 179 ASSERT_EQ(2, browser()->tab_count()); |
179 #else | 180 #else |
180 // Find the app's browser. Opening in a new window will create | 181 // Find the app's browser. Opening in a new window will create |
181 // a new browser. | 182 // a new browser. |
182 ASSERT_EQ(2u, BrowserList::GetBrowserCount(browser()->profile())); | 183 ASSERT_EQ(2u, browser::GetBrowserCount(browser()->profile())); |
183 Browser* app_browser = FindOtherBrowser(browser()); | 184 Browser* app_browser = FindOtherBrowser(browser()); |
184 ASSERT_TRUE(app_browser->is_app()); | 185 ASSERT_TRUE(app_browser->is_app()); |
185 ASSERT_FALSE(app_browser->is_type_panel()); | 186 ASSERT_FALSE(app_browser->is_type_panel()); |
186 #endif | 187 #endif |
187 } | 188 } |
OLD | NEW |