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 8872044: Add test cases for panel overflow handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Final patch to land 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"
7 #include "base/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/browser_process.h" 7 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/download/download_service.h" 8 #include "chrome/browser/download/download_service.h"
10 #include "chrome/browser/download/download_service_factory.h" 9 #include "chrome/browser/download/download_service_factory.h"
11 #include "chrome/browser/net/url_request_mock_util.h" 10 #include "chrome/browser/net/url_request_mock_util.h"
12 #include "chrome/browser/notifications/balloon_collection_impl.h" 11 #include "chrome/browser/notifications/balloon_collection_impl.h"
13 #include "chrome/browser/notifications/desktop_notification_service.h" 12 #include "chrome/browser/notifications/desktop_notification_service.h"
14 #include "chrome/browser/notifications/notification.h" 13 #include "chrome/browser/notifications/notification.h"
15 #include "chrome/browser/notifications/notification_ui_manager.h" 14 #include "chrome/browser/notifications/notification_ui_manager.h"
16 #include "chrome/browser/prefs/browser_prefs.h" 15 #include "chrome/browser/prefs/browser_prefs.h"
17 #include "chrome/browser/prefs/pref_service.h" 16 #include "chrome/browser/prefs/pref_service.h"
18 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/tabs/tab_strip_model.h" 18 #include "chrome/browser/tabs/tab_strip_model.h"
20 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" 19 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h"
21 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" 20 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h"
22 #include "chrome/browser/ui/browser_list.h" 21 #include "chrome/browser/ui/browser_list.h"
23 #include "chrome/browser/ui/browser_window.h" 22 #include "chrome/browser/ui/browser_window.h"
24 #include "chrome/browser/ui/find_bar/find_bar.h" 23 #include "chrome/browser/ui/find_bar/find_bar.h"
25 #include "chrome/browser/ui/find_bar/find_bar_controller.h" 24 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
26 #include "chrome/browser/ui/panels/base_panel_browser_test.h" 25 #include "chrome/browser/ui/panels/base_panel_browser_test.h"
27 #include "chrome/browser/ui/panels/native_panel.h" 26 #include "chrome/browser/ui/panels/native_panel.h"
28 #include "chrome/browser/ui/panels/panel.h" 27 #include "chrome/browser/ui/panels/panel.h"
29 #include "chrome/browser/ui/panels/panel_manager.h" 28 #include "chrome/browser/ui/panels/panel_manager.h"
30 #include "chrome/browser/ui/panels/panel_overflow_strip.h"
31 #include "chrome/browser/ui/panels/panel_settings_menu_model.h" 29 #include "chrome/browser/ui/panels/panel_settings_menu_model.h"
32 #include "chrome/browser/ui/panels/panel_strip.h" 30 #include "chrome/browser/ui/panels/panel_strip.h"
33 #include "chrome/browser/ui/panels/test_panel_mouse_watcher.h" 31 #include "chrome/browser/ui/panels/test_panel_mouse_watcher.h"
34 #include "chrome/browser/web_applications/web_app.h" 32 #include "chrome/browser/web_applications/web_app.h"
35 #include "chrome/common/chrome_notification_types.h" 33 #include "chrome/common/chrome_notification_types.h"
36 #include "chrome/common/pref_names.h" 34 #include "chrome/common/pref_names.h"
37 #include "chrome/common/url_constants.h" 35 #include "chrome/common/url_constants.h"
38 #include "chrome/test/base/ui_test_utils.h" 36 #include "chrome/test/base/ui_test_utils.h"
39 #include "content/browser/download/download_manager.h" 37 #include "content/browser/download/download_manager.h"
40 #include "content/browser/net/url_request_mock_http_job.h" 38 #include "content/browser/net/url_request_mock_http_job.h"
41 #include "content/browser/tab_contents/tab_contents.h" 39 #include "content/browser/tab_contents/tab_contents.h"
42 #include "content/public/browser/notification_service.h" 40 #include "content/public/browser/notification_service.h"
43 #include "content/public/common/show_desktop_notification_params.h" 41 #include "content/public/common/show_desktop_notification_params.h"
44 #include "content/public/common/url_constants.h" 42 #include "content/public/common/url_constants.h"
45 #include "net/base/net_util.h" 43 #include "net/base/net_util.h"
46 #include "testing/gtest/include/gtest/gtest.h" 44 #include "testing/gtest/include/gtest/gtest.h"
47 #include "ui/gfx/screen.h" 45 #include "ui/gfx/screen.h"
48 46
49 using content::BrowserThread; 47 using content::BrowserThread;
50 48
51 class PanelBrowserTest : public BasePanelBrowserTest { 49 class PanelBrowserTest : public BasePanelBrowserTest {
52 public: 50 public:
53 PanelBrowserTest() : BasePanelBrowserTest() { 51 PanelBrowserTest() : BasePanelBrowserTest() {
54 } 52 }
55 53
56 protected: 54 protected:
57 void CloseWindowAndWait(Browser* browser) {
58 // Closing a browser window may involve several async tasks. Need to use
59 // message pump and wait for the notification.
60 size_t browser_count = BrowserList::size();
61 ui_test_utils::WindowedNotificationObserver signal(
62 chrome::NOTIFICATION_BROWSER_CLOSED,
63 content::Source<Browser>(browser));
64 browser->CloseWindow();
65 signal.Wait();
66 // Now we have one less browser instance.
67 EXPECT_EQ(browser_count - 1, BrowserList::size());
68 }
69
70 void MoveMouse(const gfx::Point& position) {
71 PanelManager::GetInstance()->mouse_watcher()->NotifyMouseMovement(position);
72 MessageLoopForUI::current()->RunAllPending();
73 }
74
75 void MoveMouseAndWaitForExpansionStateChange(Panel* panel, 55 void MoveMouseAndWaitForExpansionStateChange(Panel* panel,
76 const gfx::Point& position) { 56 const gfx::Point& position) {
77 ui_test_utils::WindowedNotificationObserver signal( 57 ui_test_utils::WindowedNotificationObserver signal(
78 chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE, 58 chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE,
79 content::Source<Panel>(panel)); 59 content::Source<Panel>(panel));
80 MoveMouse(position); 60 MoveMouse(position);
81 signal.Wait(); 61 signal.Wait();
82 } 62 }
83 63
84 void TestCreatePanelOnOverflow() {
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();
89 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially.
90
91 // Create testing extensions.
92 DictionaryValue empty_value;
93 scoped_refptr<Extension> extension1 =
94 CreateExtension(FILE_PATH_LITERAL("extension1"),
95 Extension::INVALID, empty_value);
96 scoped_refptr<Extension> extension2 =
97 CreateExtension(FILE_PATH_LITERAL("extension2"),
98 Extension::INVALID, empty_value);
99 scoped_refptr<Extension> extension3 =
100 CreateExtension(FILE_PATH_LITERAL("extension3"),
101 Extension::INVALID, empty_value);
102
103 // First, create 3 panels.
104 Panel* panel1 = CreatePanelWithBounds(
105 web_app::GenerateApplicationNameFromExtensionId(extension1->id()),
106 gfx::Rect(0, 0, 250, 200));
107 Panel* panel2 = CreatePanelWithBounds(
108 web_app::GenerateApplicationNameFromExtensionId(extension2->id()),
109 gfx::Rect(0, 0, 300, 200));
110 Panel* panel3 = CreatePanelWithBounds(
111 web_app::GenerateApplicationNameFromExtensionId(extension1->id()),
112 gfx::Rect(0, 0, 200, 200));
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());
116
117 // Open a panel that would overflow.
118 CreatePanelParams params4(
119 web_app::GenerateApplicationNameFromExtensionId(extension2->id()),
120 gfx::Rect(0, 0, 280, 200),
121 SHOW_AS_INACTIVE);
122 Panel* panel4 = CreatePanelWithParams(params4);
123 WaitForExpansionStateChanged(panel4, Panel::IN_OVERFLOW);
124 ASSERT_EQ(4, panel_manager->num_panels());
125 EXPECT_EQ(3, panel_strip->num_panels());
126 EXPECT_EQ(1, panel_overflow_strip->num_panels());
127
128 // Open another panel that would overflow.
129 CreatePanelParams params5(
130 web_app::GenerateApplicationNameFromExtensionId(extension3->id()),
131 gfx::Rect(0, 0, 300, 200),
132 SHOW_AS_INACTIVE);
133 Panel* panel5 = CreatePanelWithParams(params5);
134 WaitForExpansionStateChanged(panel5, Panel::IN_OVERFLOW);
135 ASSERT_EQ(5, panel_manager->num_panels());
136 EXPECT_EQ(3, panel_strip->num_panels());
137 EXPECT_EQ(2, panel_overflow_strip->num_panels());
138 EXPECT_EQ(Panel::IN_OVERFLOW, panel4->expansion_state());
139
140 // Close a visible panel. Expect an overflow panel to move over.
141 CloseWindowAndWait(panel2->browser());
142 ASSERT_EQ(4, panel_manager->num_panels());
143 EXPECT_EQ(3, panel_strip->num_panels());
144 EXPECT_EQ(1, panel_overflow_strip->num_panels());
145 EXPECT_NE(Panel::IN_OVERFLOW, panel4->expansion_state());
146 EXPECT_EQ(Panel::IN_OVERFLOW, panel5->expansion_state());
147
148 // Close another visible panel. Remaining overflow panel cannot move over
149 // due to not enough room.
150 CloseWindowAndWait(panel3->browser());
151 ASSERT_EQ(3, panel_manager->num_panels());
152 EXPECT_EQ(2, panel_strip->num_panels());
153 EXPECT_EQ(1, panel_overflow_strip->num_panels());
154 EXPECT_EQ(Panel::IN_OVERFLOW, panel5->expansion_state());
155
156 // Closing one more panel makes room for all panels to fit on screen.
157 CloseWindowAndWait(panel4->browser());
158 ASSERT_EQ(2, panel_manager->num_panels());
159 EXPECT_EQ(2, panel_strip->num_panels());
160 EXPECT_EQ(0, panel_overflow_strip->num_panels());
161 EXPECT_NE(Panel::IN_OVERFLOW, panel5->expansion_state());
162
163 panel1->Close();
164 panel5->Close();
165 }
166
167 // Helper function for debugging. 64 // Helper function for debugging.
168 void PrintAllPanelBounds() { 65 void PrintAllPanelBounds() {
169 const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels(); 66 const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels();
170 DLOG(WARNING) << "PanelBounds:"; 67 DLOG(WARNING) << "PanelBounds:";
171 for (size_t i = 0; i < panels.size(); ++i) { 68 for (size_t i = 0; i < panels.size(); ++i) {
172 DLOG(WARNING) << "#=" << i 69 DLOG(WARNING) << "#=" << i
173 << ", ptr=" << panels[i] 70 << ", ptr=" << panels[i]
174 << ", x=" << panels[i]->GetBounds().x() 71 << ", x=" << panels[i]->GetBounds().x()
175 << ", y=" << panels[i]->GetBounds().y() 72 << ", y=" << panels[i]->GetBounds().y()
176 << ", width=" << panels[i]->GetBounds().width() 73 << ", width=" << panels[i]->GetBounds().width()
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, FindBar) { 436 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, FindBar) {
540 Panel* panel = CreatePanelWithBounds("PanelTest", gfx::Rect(0, 0, 400, 400)); 437 Panel* panel = CreatePanelWithBounds("PanelTest", gfx::Rect(0, 0, 400, 400));
541 Browser* browser = panel->browser(); 438 Browser* browser = panel->browser();
542 // FindBar needs tab contents. 439 // FindBar needs tab contents.
543 CreateTestTabContents(browser); 440 CreateTestTabContents(browser);
544 browser->ShowFindBar(); 441 browser->ShowFindBar();
545 ASSERT_TRUE(browser->GetFindBarController()->find_bar()->IsFindBarVisible()); 442 ASSERT_TRUE(browser->GetFindBarController()->find_bar()->IsFindBarVisible());
546 panel->Close(); 443 panel->Close();
547 } 444 }
548 445
549 // TODO(jianli): remove the guard when overflow support is enabled on other
550 // platforms. http://crbug.com/105073
551 #if defined(OS_WIN)
552 #define MAYBE_CreatePanelOnOverflow CreatePanelOnOverflow
553 #else
554 #define MAYBE_CreatePanelOnOverflow DISABLED_CreatePanelOnOverflow
555 #endif
556 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_CreatePanelOnOverflow) {
557 TestCreatePanelOnOverflow();
558 }
559
560 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DragOnePanel) { 446 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DragOnePanel) {
561 static const int num_panels = 1; 447 static const int num_panels = 1;
562 static const int zero_delta = 0; 448 static const int zero_delta = 0;
563 static const int big_delta = 70; 449 static const int big_delta = 70;
564 450
565 static const std::vector<int> zero_deltas(num_panels, zero_delta); 451 static const std::vector<int> zero_deltas(num_panels, zero_delta);
566 std::vector<int> expected_delta_x_after_drag(num_panels, zero_delta); 452 std::vector<int> expected_delta_x_after_drag(num_panels, zero_delta);
567 std::vector<int> expected_delta_x_after_finish(num_panels, zero_delta); 453 std::vector<int> expected_delta_x_after_finish(num_panels, zero_delta);
568 454
569 Panel* panel1 = 455 Panel* panel1 =
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 #else 1013 #else
1128 #define MAYBE_ActivateDeactivateMultiple DISABLED_ActivateDeactivateMultiple 1014 #define MAYBE_ActivateDeactivateMultiple DISABLED_ActivateDeactivateMultiple
1129 #endif 1015 #endif
1130 1016
1131 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_ActivateDeactivateMultiple) { 1017 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_ActivateDeactivateMultiple) {
1132 BrowserWindow* tabbed_window = BrowserList::GetLastActive()->window(); 1018 BrowserWindow* tabbed_window = BrowserList::GetLastActive()->window();
1133 1019
1134 // Create 4 panels in the following screen layout: 1020 // Create 4 panels in the following screen layout:
1135 // P3 P2 P1 P0 1021 // P3 P2 P1 P0
1136 const int kNumPanels = 4; 1022 const int kNumPanels = 4;
1137 std::string panel_name_base("PanelTest"); 1023 for (int i = 0; i < kNumPanels; ++i)
1138 for (int i = 0; i < kNumPanels; ++i) { 1024 CreatePanelWithBounds(MakePanelName(i), gfx::Rect(0, 0, 100, 100));
1139 CreatePanelWithBounds(panel_name_base + base::IntToString(i),
1140 gfx::Rect(0, 0, 100, 100));
1141 }
1142 const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels(); 1025 const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels();
1143 1026
1144 std::vector<bool> expected_active_states; 1027 std::vector<bool> expected_active_states;
1145 std::vector<bool> last_active_states; 1028 std::vector<bool> last_active_states;
1146 1029
1147 // The last created panel, P3, should be active. 1030 // The last created panel, P3, should be active.
1148 expected_active_states = ProduceExpectedActiveStates(3); 1031 expected_active_states = ProduceExpectedActiveStates(3);
1149 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates()); 1032 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
1150 EXPECT_FALSE(tabbed_window->IsActive()); 1033 EXPECT_FALSE(tabbed_window->IsActive());
1151 1034
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after
1981 // position when tall panel brings up its titlebar. 1864 // position when tall panel brings up its titlebar.
1982 CloseWindowAndWait(panel1->browser()); 1865 CloseWindowAndWait(panel1->browser());
1983 EXPECT_EQ(balloon_bottom_after_tall_panel_titlebar_up, 1866 EXPECT_EQ(balloon_bottom_after_tall_panel_titlebar_up,
1984 GetBalloonBottomPosition(balloon)); 1867 GetBalloonBottomPosition(balloon));
1985 1868
1986 // Closing the remaining tall panel should move the notification balloon back 1869 // Closing the remaining tall panel should move the notification balloon back
1987 // to its original position. 1870 // to its original position.
1988 CloseWindowAndWait(panel2->browser()); 1871 CloseWindowAndWait(panel2->browser());
1989 EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon)); 1872 EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon));
1990 } 1873 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/panels/base_panel_browser_test.cc ('k') | chrome/browser/ui/panels/panel_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698