Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Side by Side Diff: chrome/browser/ui/panels/panel_browsertest.cc

Issue 8776035: Add PanelOverflowStrip to handle panel overflow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/string_number_conversions.h" 6 #include "base/string_number_conversions.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/download/download_service.h" 9 #include "chrome/browser/download/download_service.h"
10 #include "chrome/browser/download/download_service_factory.h" 10 #include "chrome/browser/download/download_service_factory.h"
11 #include "chrome/browser/net/url_request_mock_util.h" 11 #include "chrome/browser/net/url_request_mock_util.h"
12 #include "chrome/browser/notifications/balloon_collection_impl.h" 12 #include "chrome/browser/notifications/balloon_collection_impl.h"
13 #include "chrome/browser/notifications/desktop_notification_service.h" 13 #include "chrome/browser/notifications/desktop_notification_service.h"
14 #include "chrome/browser/notifications/notification.h" 14 #include "chrome/browser/notifications/notification.h"
15 #include "chrome/browser/notifications/notification_ui_manager.h" 15 #include "chrome/browser/notifications/notification_ui_manager.h"
16 #include "chrome/browser/prefs/browser_prefs.h" 16 #include "chrome/browser/prefs/browser_prefs.h"
17 #include "chrome/browser/prefs/pref_service.h" 17 #include "chrome/browser/prefs/pref_service.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/tabs/tab_strip_model.h" 19 #include "chrome/browser/tabs/tab_strip_model.h"
20 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" 20 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h"
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/native_panel.h" 27 #include "chrome/browser/ui/panels/native_panel.h"
28 #include "chrome/browser/ui/panels/panel.h" 28 #include "chrome/browser/ui/panels/panel.h"
29 #include "chrome/browser/ui/panels/panel_manager.h" 29 #include "chrome/browser/ui/panels/panel_manager.h"
30 #include "chrome/browser/ui/panels/panel_overflow_strip.h"
30 #include "chrome/browser/ui/panels/panel_settings_menu_model.h" 31 #include "chrome/browser/ui/panels/panel_settings_menu_model.h"
32 #include "chrome/browser/ui/panels/panel_strip.h"
31 #include "chrome/browser/ui/panels/test_panel_mouse_watcher.h" 33 #include "chrome/browser/ui/panels/test_panel_mouse_watcher.h"
32 #include "chrome/browser/web_applications/web_app.h" 34 #include "chrome/browser/web_applications/web_app.h"
33 #include "chrome/common/chrome_notification_types.h" 35 #include "chrome/common/chrome_notification_types.h"
34 #include "chrome/common/pref_names.h" 36 #include "chrome/common/pref_names.h"
35 #include "chrome/common/url_constants.h" 37 #include "chrome/common/url_constants.h"
36 #include "chrome/test/base/ui_test_utils.h" 38 #include "chrome/test/base/ui_test_utils.h"
37 #include "content/browser/download/download_manager.h" 39 #include "content/browser/download/download_manager.h"
38 #include "content/browser/net/url_request_mock_http_job.h" 40 #include "content/browser/net/url_request_mock_http_job.h"
39 #include "content/browser/tab_contents/tab_contents.h" 41 #include "content/browser/tab_contents/tab_contents.h"
40 #include "content/public/browser/notification_service.h" 42 #include "content/public/browser/notification_service.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 const gfx::Point& position) { 76 const gfx::Point& position) {
75 ui_test_utils::WindowedNotificationObserver signal( 77 ui_test_utils::WindowedNotificationObserver signal(
76 chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE, 78 chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE,
77 content::Source<Panel>(panel)); 79 content::Source<Panel>(panel));
78 MoveMouse(position); 80 MoveMouse(position);
79 signal.Wait(); 81 signal.Wait();
80 } 82 }
81 83
82 void TestCreatePanelOnOverflow() { 84 void TestCreatePanelOnOverflow() {
83 PanelManager* panel_manager = PanelManager::GetInstance(); 85 PanelManager* panel_manager = PanelManager::GetInstance();
86 PanelStrip* panel_strip = panel_manager->panel_strip();
87 PanelOverflowStrip* panel_overflow_strip =
88 panel_manager->panel_overflow_strip();
84 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially. 89 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially.
85 90
86 // Create testing extensions. 91 // Create testing extensions.
87 DictionaryValue empty_value; 92 DictionaryValue empty_value;
88 scoped_refptr<Extension> extension1 = 93 scoped_refptr<Extension> extension1 =
89 CreateExtension(FILE_PATH_LITERAL("extension1"), 94 CreateExtension(FILE_PATH_LITERAL("extension1"),
90 Extension::INVALID, empty_value); 95 Extension::INVALID, empty_value);
91 scoped_refptr<Extension> extension2 = 96 scoped_refptr<Extension> extension2 =
92 CreateExtension(FILE_PATH_LITERAL("extension2"), 97 CreateExtension(FILE_PATH_LITERAL("extension2"),
93 Extension::INVALID, empty_value); 98 Extension::INVALID, empty_value);
94 scoped_refptr<Extension> extension3 = 99 scoped_refptr<Extension> extension3 =
95 CreateExtension(FILE_PATH_LITERAL("extension3"), 100 CreateExtension(FILE_PATH_LITERAL("extension3"),
96 Extension::INVALID, empty_value); 101 Extension::INVALID, empty_value);
97 102
98 // First, create 3 panels. 103 // First, create 3 panels.
99 Panel* panel1 = CreatePanelWithBounds( 104 Panel* panel1 = CreatePanelWithBounds(
100 web_app::GenerateApplicationNameFromExtensionId(extension1->id()), 105 web_app::GenerateApplicationNameFromExtensionId(extension1->id()),
101 gfx::Rect(0, 0, 250, 200)); 106 gfx::Rect(0, 0, 250, 200));
102 Panel* panel2 = CreatePanelWithBounds( 107 Panel* panel2 = CreatePanelWithBounds(
103 web_app::GenerateApplicationNameFromExtensionId(extension2->id()), 108 web_app::GenerateApplicationNameFromExtensionId(extension2->id()),
104 gfx::Rect(0, 0, 300, 200)); 109 gfx::Rect(0, 0, 300, 200));
105 Panel* panel3 = CreatePanelWithBounds( 110 Panel* panel3 = CreatePanelWithBounds(
106 web_app::GenerateApplicationNameFromExtensionId(extension1->id()), 111 web_app::GenerateApplicationNameFromExtensionId(extension1->id()),
107 gfx::Rect(0, 0, 200, 200)); 112 gfx::Rect(0, 0, 200, 200));
108 ASSERT_EQ(3, panel_manager->num_panels()); 113 ASSERT_EQ(3, panel_manager->num_panels());
114 EXPECT_EQ(3, panel_strip->num_panels());
115 EXPECT_EQ(0, panel_overflow_strip->num_panels());
109 116
110 // Open a panel that would overflow. 117 // Open a panel that would overflow.
111 Panel* panel4 = CreatePanelWithBounds( 118 Panel* panel4 = CreatePanelWithBounds(
jennb 2011/12/02 22:28:57 Looks like we shouldn't watch for remove_delays_fo
jianli 2011/12/02 23:23:46 Will fix in another patch.
112 web_app::GenerateApplicationNameFromExtensionId(extension2->id()), 119 web_app::GenerateApplicationNameFromExtensionId(extension2->id()),
113 gfx::Rect(0, 0, 280, 200)); 120 gfx::Rect(0, 0, 280, 200));
114 ASSERT_EQ(4, panel_manager->num_panels()); 121 ASSERT_EQ(4, panel_manager->num_panels());
115 EXPECT_LT(panel4->GetBounds().right(), panel3->GetBounds().x()); 122 EXPECT_EQ(3, panel_strip->num_panels());
116 EXPECT_GT(0, panel4->GetBounds().x()); 123 EXPECT_EQ(1, panel_overflow_strip->num_panels());
124 EXPECT_EQ(Panel::IN_OVERFLOW, panel4->expansion_state());
117 125
118 // Open another panel that would overflow. 126 // Open another panel that would overflow.
119 Panel* panel5 = CreatePanelWithBounds( 127 Panel* panel5 = CreatePanelWithBounds(
120 web_app::GenerateApplicationNameFromExtensionId(extension3->id()), 128 web_app::GenerateApplicationNameFromExtensionId(extension3->id()),
121 gfx::Rect(0, 0, 300, 200)); 129 gfx::Rect(0, 0, 300, 200));
122 ASSERT_EQ(5, panel_manager->num_panels()); 130 ASSERT_EQ(5, panel_manager->num_panels());
123 EXPECT_LT(panel5->GetBounds().right(), panel4->GetBounds().x()); 131 EXPECT_EQ(3, panel_strip->num_panels());
124 EXPECT_GT(0, panel5->GetBounds().x()); 132 EXPECT_EQ(2, panel_overflow_strip->num_panels());
133 EXPECT_EQ(Panel::IN_OVERFLOW, panel4->expansion_state());
134 EXPECT_EQ(Panel::IN_OVERFLOW, panel5->expansion_state());
125 135
126 // Close a visible panel. Expect an overflow panel to slide over. 136 // Close a visible panel. Expect an overflow panel to move over.
127 CloseWindowAndWait(panel2->browser()); 137 CloseWindowAndWait(panel2->browser());
128 ASSERT_EQ(4, panel_manager->num_panels()); 138 ASSERT_EQ(4, panel_manager->num_panels());
129 EXPECT_LT(panel4->GetBounds().right(), panel3->GetBounds().x()); 139 EXPECT_EQ(3, panel_strip->num_panels());
130 EXPECT_LE(0, panel4->GetBounds().x()); 140 EXPECT_EQ(1, panel_overflow_strip->num_panels());
131 EXPECT_GT(0, panel5->GetBounds().x()); 141 EXPECT_NE(Panel::IN_OVERFLOW, panel4->expansion_state());
142 EXPECT_EQ(Panel::IN_OVERFLOW, panel5->expansion_state());
132 143
133 // Close another visible panel. Remaining overflow panel should slide over 144 // Close another visible panel. Remaining overflow panel cannot move over
134 // but still not enough room to be fully visible. 145 // due to not enough room.
135 CloseWindowAndWait(panel3->browser()); 146 CloseWindowAndWait(panel3->browser());
136 ASSERT_EQ(3, panel_manager->num_panels()); 147 ASSERT_EQ(3, panel_manager->num_panels());
137 EXPECT_LT(panel5->GetBounds().right(), panel4->GetBounds().x()); 148 EXPECT_EQ(2, panel_strip->num_panels());
138 EXPECT_GT(0, panel5->GetBounds().x()); 149 EXPECT_EQ(1, panel_overflow_strip->num_panels());
150 EXPECT_EQ(Panel::IN_OVERFLOW, panel5->expansion_state());
139 151
140 // Closing one more panel makes room for all panels to fit on screen. 152 // Closing one more panel makes room for all panels to fit on screen.
141 CloseWindowAndWait(panel4->browser()); 153 CloseWindowAndWait(panel4->browser());
142 ASSERT_EQ(2, panel_manager->num_panels()); 154 ASSERT_EQ(2, panel_manager->num_panels());
143 EXPECT_LT(panel5->GetBounds().right(), panel1->GetBounds().x()); 155 EXPECT_EQ(2, panel_strip->num_panels());
144 EXPECT_LE(0, panel5->GetBounds().x()); 156 EXPECT_EQ(0, panel_overflow_strip->num_panels());
157 EXPECT_NE(Panel::IN_OVERFLOW, panel5->expansion_state());
145 158
146 panel1->Close(); 159 panel1->Close();
147 panel5->Close(); 160 panel5->Close();
148 } 161 }
149 162
150 int horizontal_spacing() { 163 int horizontal_spacing() {
151 return PanelManager::horizontal_spacing(); 164 return PanelManager::horizontal_spacing();
152 } 165 }
153 166
154 // Helper function for debugging. 167 // Helper function for debugging.
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, FindBar) { 539 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, FindBar) {
527 Panel* panel = CreatePanelWithBounds("PanelTest", gfx::Rect(0, 0, 400, 400)); 540 Panel* panel = CreatePanelWithBounds("PanelTest", gfx::Rect(0, 0, 400, 400));
528 Browser* browser = panel->browser(); 541 Browser* browser = panel->browser();
529 // FindBar needs tab contents. 542 // FindBar needs tab contents.
530 CreateTestTabContents(browser); 543 CreateTestTabContents(browser);
531 browser->ShowFindBar(); 544 browser->ShowFindBar();
532 ASSERT_TRUE(browser->GetFindBarController()->find_bar()->IsFindBarVisible()); 545 ASSERT_TRUE(browser->GetFindBarController()->find_bar()->IsFindBarVisible());
533 panel->Close(); 546 panel->Close();
534 } 547 }
535 548
536 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DISABLED_CreatePanelOnOverflow) { 549 #if defined(OS_WIN) && !defined(USE_AURA)
550 #define MAYBE_CreatePanelOnOverflow CreatePanelOnOverflow
551 #else
552 #define MAYBE_CreatePanelOnOverflow DISABLED_CreatePanelOnOverflow
553 #endif
554 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_CreatePanelOnOverflow) {
537 TestCreatePanelOnOverflow(); 555 TestCreatePanelOnOverflow();
538 } 556 }
539 557
540 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DragPanels) { 558 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DragPanels) {
541 static const int max_panels = 3; 559 static const int max_panels = 3;
542 static const int zero_delta = 0; 560 static const int zero_delta = 0;
543 static const int small_delta = 10; 561 static const int small_delta = 10;
544 static const int big_delta = 70; 562 static const int big_delta = 70;
545 static const int bigger_delta = 120; 563 static const int bigger_delta = 120;
546 static const int biggest_delta = 200; 564 static const int biggest_delta = 200;
(...skipping 1300 matching lines...) Expand 10 before | Expand all | Expand 10 after
1847 const BalloonCollection::Balloons& balloons() const { 1865 const BalloonCollection::Balloons& balloons() const {
1848 return balloons_->GetActiveBalloons(); 1866 return balloons_->GetActiveBalloons();
1849 } 1867 }
1850 1868
1851 private: 1869 private:
1852 BalloonCollectionImpl* balloons_; // Owned by NotificationUIManager. 1870 BalloonCollectionImpl* balloons_; // Owned by NotificationUIManager.
1853 scoped_ptr<NotificationUIManager> ui_manager_; 1871 scoped_ptr<NotificationUIManager> ui_manager_;
1854 scoped_ptr<DesktopNotificationService> service_; 1872 scoped_ptr<DesktopNotificationService> service_;
1855 }; 1873 };
1856 1874
1857 IN_PROC_BROWSER_TEST_F(PanelAndNotificationTest, DISABLED_NoOverlapping) { 1875 IN_PROC_BROWSER_TEST_F(PanelAndNotificationTest, NoOverlapping) {
1858 const int kPanelWidth = 200; 1876 const int kPanelWidth = 200;
1859 const int kShortPanelHeight = 150; 1877 const int kShortPanelHeight = 150;
1860 const int kTallPanelHeight = 200; 1878 const int kTallPanelHeight = 200;
1861 1879
1862 content::ShowDesktopNotificationHostMsgParams params = 1880 content::ShowDesktopNotificationHostMsgParams params =
1863 StandardTestNotification(); 1881 StandardTestNotification();
1864 EXPECT_TRUE(service()->ShowDesktopNotification( 1882 EXPECT_TRUE(service()->ShowDesktopNotification(
1865 params, 0, 0, DesktopNotificationService::PageNotification)); 1883 params, 0, 0, DesktopNotificationService::PageNotification));
1866 MessageLoopForUI::current()->RunAllPending(); 1884 MessageLoopForUI::current()->RunAllPending();
1867 Balloon* balloon = balloons().front(); 1885 Balloon* balloon = balloons().front();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1938 // position when tall panel brings up its titlebar. 1956 // position when tall panel brings up its titlebar.
1939 CloseWindowAndWait(panel1->browser()); 1957 CloseWindowAndWait(panel1->browser());
1940 EXPECT_EQ(balloon_bottom_after_tall_panel_titlebar_up, 1958 EXPECT_EQ(balloon_bottom_after_tall_panel_titlebar_up,
1941 GetBalloonBottomPosition(balloon)); 1959 GetBalloonBottomPosition(balloon));
1942 1960
1943 // Closing the remaining tall panel should move the notification balloon back 1961 // Closing the remaining tall panel should move the notification balloon back
1944 // to its original position. 1962 // to its original position.
1945 CloseWindowAndWait(panel2->browser()); 1963 CloseWindowAndWait(panel2->browser());
1946 EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon)); 1964 EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon));
1947 } 1965 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698