OLD | NEW |
1 // Copyright (c) 2012 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
8 #include "chrome/browser/download/download_service.h" | 8 #include "chrome/browser/download/download_service.h" |
9 #include "chrome/browser/download/download_service_factory.h" | 9 #include "chrome/browser/download/download_service_factory.h" |
10 #include "chrome/browser/net/url_request_mock_util.h" | 10 #include "chrome/browser/net/url_request_mock_util.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" | 21 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" |
22 #include "chrome/browser/ui/browser_list.h" | 22 #include "chrome/browser/ui/browser_list.h" |
23 #include "chrome/browser/ui/browser_window.h" | 23 #include "chrome/browser/ui/browser_window.h" |
24 #include "chrome/browser/ui/find_bar/find_bar.h" | 24 #include "chrome/browser/ui/find_bar/find_bar.h" |
25 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 25 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
26 #include "chrome/browser/ui/panels/base_panel_browser_test.h" | 26 #include "chrome/browser/ui/panels/base_panel_browser_test.h" |
27 #include "chrome/browser/ui/panels/docked_panel_strip.h" | 27 #include "chrome/browser/ui/panels/docked_panel_strip.h" |
28 #include "chrome/browser/ui/panels/native_panel.h" | 28 #include "chrome/browser/ui/panels/native_panel.h" |
29 #include "chrome/browser/ui/panels/panel.h" | 29 #include "chrome/browser/ui/panels/panel.h" |
30 #include "chrome/browser/ui/panels/panel_manager.h" | 30 #include "chrome/browser/ui/panels/panel_manager.h" |
31 #include "chrome/browser/ui/panels/panel_settings_menu_model.h" | |
32 #include "chrome/browser/ui/panels/test_panel_mouse_watcher.h" | 31 #include "chrome/browser/ui/panels/test_panel_mouse_watcher.h" |
33 #include "chrome/browser/web_applications/web_app.h" | 32 #include "chrome/browser/web_applications/web_app.h" |
34 #include "chrome/common/chrome_notification_types.h" | 33 #include "chrome/common/chrome_notification_types.h" |
35 #include "chrome/common/extensions/extension_manifest_constants.h" | 34 #include "chrome/common/extensions/extension_manifest_constants.h" |
36 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
37 #include "chrome/common/url_constants.h" | 36 #include "chrome/common/url_constants.h" |
38 #include "chrome/test/base/ui_test_utils.h" | 37 #include "chrome/test/base/ui_test_utils.h" |
39 #include "content/public/browser/download_manager.h" | 38 #include "content/public/browser/download_manager.h" |
40 #include "content/public/browser/notification_service.h" | 39 #include "content/public/browser/notification_service.h" |
41 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 DCHECK(old_states.size() == new_states.size()); | 125 DCHECK(old_states.size() == new_states.size()); |
127 std::vector<Panel*> panels = PanelManager::GetInstance()->panels(); | 126 std::vector<Panel*> panels = PanelManager::GetInstance()->panels(); |
128 for (size_t i = 0; i < old_states.size(); i++) { | 127 for (size_t i = 0; i < old_states.size(); i++) { |
129 if (old_states[i] != new_states[i]){ | 128 if (old_states[i] != new_states[i]){ |
130 WaitForPanelActiveState( | 129 WaitForPanelActiveState( |
131 panels[i], new_states[i] ? SHOW_AS_ACTIVE : SHOW_AS_INACTIVE); | 130 panels[i], new_states[i] ? SHOW_AS_ACTIVE : SHOW_AS_INACTIVE); |
132 } | 131 } |
133 } | 132 } |
134 } | 133 } |
135 | 134 |
136 struct MenuItem { | |
137 int id; | |
138 bool enabled; | |
139 }; | |
140 | |
141 void ValidateSettingsMenuItems(ui::SimpleMenuModel* settings_menu_contents, | |
142 size_t num_expected_menu_items, | |
143 const MenuItem* expected_menu_items) { | |
144 ASSERT_TRUE(settings_menu_contents); | |
145 EXPECT_EQ(static_cast<int>(num_expected_menu_items), | |
146 settings_menu_contents->GetItemCount()); | |
147 for (size_t i = 0; i < num_expected_menu_items; ++i) { | |
148 if (expected_menu_items[i].id == -1) { | |
149 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, | |
150 settings_menu_contents->GetTypeAt(i)); | |
151 } else { | |
152 EXPECT_EQ(expected_menu_items[i].id, | |
153 settings_menu_contents->GetCommandIdAt(i)); | |
154 EXPECT_EQ(expected_menu_items[i].enabled, | |
155 settings_menu_contents->IsEnabledAt(i)); | |
156 } | |
157 } | |
158 } | |
159 | |
160 void TestCreateSettingsMenuForExtension(const FilePath::StringType& path, | |
161 Extension::Location location, | |
162 const std::string& homepage_url, | |
163 const std::string& options_page) { | |
164 // Creates a testing extension. | |
165 DictionaryValue extra_value; | |
166 if (!homepage_url.empty()) { | |
167 extra_value.SetString(extension_manifest_keys::kHomepageURL, | |
168 homepage_url); | |
169 } | |
170 if (!options_page.empty()) { | |
171 extra_value.SetString(extension_manifest_keys::kOptionsPage, | |
172 options_page); | |
173 } | |
174 scoped_refptr<Extension> extension = CreateExtension( | |
175 path, location, extra_value); | |
176 | |
177 // Creates a panel with the app name that comes from the extension ID. | |
178 Panel* panel = CreatePanel( | |
179 web_app::GenerateApplicationNameFromExtensionId(extension->id())); | |
180 | |
181 scoped_ptr<PanelSettingsMenuModel> settings_menu_model( | |
182 new PanelSettingsMenuModel(panel)); | |
183 | |
184 // Validates the settings menu items. | |
185 MenuItem expected_panel_menu_items[] = { | |
186 { PanelSettingsMenuModel::COMMAND_NAME, false }, | |
187 { -1, false }, // Separator | |
188 { PanelSettingsMenuModel::COMMAND_CONFIGURE, false }, | |
189 { PanelSettingsMenuModel::COMMAND_DISABLE, false }, | |
190 { PanelSettingsMenuModel::COMMAND_UNINSTALL, false }, | |
191 { -1, false }, // Separator | |
192 { PanelSettingsMenuModel::COMMAND_MANAGE, true } | |
193 }; | |
194 if (!homepage_url.empty()) | |
195 expected_panel_menu_items[0].enabled = true; | |
196 if (!options_page.empty()) | |
197 expected_panel_menu_items[2].enabled = true; | |
198 if (location != Extension::EXTERNAL_POLICY_DOWNLOAD) { | |
199 expected_panel_menu_items[3].enabled = true; | |
200 expected_panel_menu_items[4].enabled = true; | |
201 } | |
202 ValidateSettingsMenuItems(settings_menu_model.get(), | |
203 arraysize(expected_panel_menu_items), | |
204 expected_panel_menu_items); | |
205 | |
206 panel->Close(); | |
207 } | |
208 | |
209 void TestMinimizeRestore() { | 135 void TestMinimizeRestore() { |
210 // This constant is used to generate a point 'sufficiently higher then | 136 // This constant is used to generate a point 'sufficiently higher then |
211 // top edge of the panel'. On some platforms (Mac) we extend hover area | 137 // top edge of the panel'. On some platforms (Mac) we extend hover area |
212 // a bit above the minimized panel as well, so it takes significant | 138 // a bit above the minimized panel as well, so it takes significant |
213 // distance to 'move mouse out' of the hover-sensitive area. | 139 // distance to 'move mouse out' of the hover-sensitive area. |
214 const int kFarEnoughFromHoverArea = 153; | 140 const int kFarEnoughFromHoverArea = 153; |
215 | 141 |
216 PanelManager* panel_manager = PanelManager::GetInstance(); | 142 PanelManager* panel_manager = PanelManager::GetInstance(); |
217 std::vector<Panel*> panels = panel_manager->panels(); | 143 std::vector<Panel*> panels = panel_manager->panels(); |
218 std::vector<gfx::Rect> test_begin_bounds = GetAllPanelBounds(); | 144 std::vector<gfx::Rect> test_begin_bounds = GetAllPanelBounds(); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, FindBar) { | 297 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, FindBar) { |
372 Panel* panel = CreatePanelWithBounds("PanelTest", gfx::Rect(0, 0, 400, 400)); | 298 Panel* panel = CreatePanelWithBounds("PanelTest", gfx::Rect(0, 0, 400, 400)); |
373 Browser* browser = panel->browser(); | 299 Browser* browser = panel->browser(); |
374 // FindBar needs tab contents. | 300 // FindBar needs tab contents. |
375 CreateTestTabContents(browser); | 301 CreateTestTabContents(browser); |
376 browser->ShowFindBar(); | 302 browser->ShowFindBar(); |
377 ASSERT_TRUE(browser->GetFindBarController()->find_bar()->IsFindBarVisible()); | 303 ASSERT_TRUE(browser->GetFindBarController()->find_bar()->IsFindBarVisible()); |
378 panel->Close(); | 304 panel->Close(); |
379 } | 305 } |
380 | 306 |
381 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreateSettingsMenu) { | |
382 TestCreateSettingsMenuForExtension( | |
383 FILE_PATH_LITERAL("extension1"), Extension::EXTERNAL_POLICY_DOWNLOAD, | |
384 "", ""); | |
385 TestCreateSettingsMenuForExtension( | |
386 FILE_PATH_LITERAL("extension2"), Extension::INVALID, | |
387 "http://home", "options.html"); | |
388 } | |
389 | |
390 // Flaky: http://crbug.com/105445 | 307 // Flaky: http://crbug.com/105445 |
391 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DISABLED_AutoResize) { | 308 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DISABLED_AutoResize) { |
392 PanelManager* panel_manager = PanelManager::GetInstance(); | 309 PanelManager* panel_manager = PanelManager::GetInstance(); |
393 panel_manager->enable_auto_sizing(true); | 310 panel_manager->enable_auto_sizing(true); |
394 // Bigger space is needed by this test. | 311 // Bigger space is needed by this test. |
395 SetTestingWorkArea(gfx::Rect(0, 0, 1200, 900)); | 312 SetTestingWorkArea(gfx::Rect(0, 0, 1200, 900)); |
396 | 313 |
397 // Create a test panel with tab contents loaded. | 314 // Create a test panel with tab contents loaded. |
398 CreatePanelParams params("PanelTest1", gfx::Rect(), SHOW_AS_ACTIVE); | 315 CreatePanelParams params("PanelTest1", gfx::Rect(), SHOW_AS_ACTIVE); |
399 GURL url(ui_test_utils::GetTestUrl( | 316 GURL url(ui_test_utils::GetTestUrl( |
(...skipping 1351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1751 // position when tall panel brings up its titlebar. | 1668 // position when tall panel brings up its titlebar. |
1752 CloseWindowAndWait(panel1->browser()); | 1669 CloseWindowAndWait(panel1->browser()); |
1753 EXPECT_EQ(balloon_bottom_after_tall_panel_titlebar_up, | 1670 EXPECT_EQ(balloon_bottom_after_tall_panel_titlebar_up, |
1754 GetBalloonBottomPosition(balloon)); | 1671 GetBalloonBottomPosition(balloon)); |
1755 | 1672 |
1756 // Closing the remaining tall panel should move the notification balloon back | 1673 // Closing the remaining tall panel should move the notification balloon back |
1757 // to its original position. | 1674 // to its original position. |
1758 CloseWindowAndWait(panel2->browser()); | 1675 CloseWindowAndWait(panel2->browser()); |
1759 EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon)); | 1676 EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon)); |
1760 } | 1677 } |
OLD | NEW |