OLD | NEW |
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 "chrome/browser/net/url_request_mock_util.h" | 7 #include "chrome/browser/net/url_request_mock_util.h" |
7 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
8 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/ui/browser_list.h" | 10 #include "chrome/browser/ui/browser_list.h" |
10 #include "chrome/browser/ui/browser_window.h" | 11 #include "chrome/browser/ui/browser_window.h" |
11 #include "chrome/browser/ui/find_bar/find_bar.h" | 12 #include "chrome/browser/ui/find_bar/find_bar.h" |
12 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 13 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
13 #include "chrome/browser/ui/panels/base_panel_browser_test.h" | 14 #include "chrome/browser/ui/panels/base_panel_browser_test.h" |
14 #include "chrome/browser/ui/panels/native_panel.h" | 15 #include "chrome/browser/ui/panels/native_panel.h" |
15 #include "chrome/browser/ui/panels/panel.h" | 16 #include "chrome/browser/ui/panels/panel.h" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 } | 171 } |
171 | 172 |
172 std::vector<Panel::ExpansionState> GetAllPanelExpansionStates() { | 173 std::vector<Panel::ExpansionState> GetAllPanelExpansionStates() { |
173 std::vector<Panel*> panels = PanelManager::GetInstance()->panels(); | 174 std::vector<Panel*> panels = PanelManager::GetInstance()->panels(); |
174 std::vector<Panel::ExpansionState> expansion_states; | 175 std::vector<Panel::ExpansionState> expansion_states; |
175 for (size_t i = 0; i < panels.size(); i++) | 176 for (size_t i = 0; i < panels.size(); i++) |
176 expansion_states.push_back(panels[i]->expansion_state()); | 177 expansion_states.push_back(panels[i]->expansion_state()); |
177 return expansion_states; | 178 return expansion_states; |
178 } | 179 } |
179 | 180 |
| 181 std::vector<bool> GetAllPanelActiveStates() { |
| 182 std::vector<Panel*> panels = PanelManager::GetInstance()->panels(); |
| 183 std::vector<bool> active_states; |
| 184 for (size_t i = 0; i < panels.size(); i++) |
| 185 active_states.push_back(panels[i]->IsActive()); |
| 186 return active_states; |
| 187 } |
| 188 |
| 189 std::vector<bool> ProduceExpectedActiveStates( |
| 190 int expected_active_panel_index) { |
| 191 std::vector<Panel*> panels = PanelManager::GetInstance()->panels(); |
| 192 std::vector<bool> active_states; |
| 193 for (int i = 0; i < static_cast<int>(panels.size()); i++) |
| 194 active_states.push_back(i == expected_active_panel_index); |
| 195 return active_states; |
| 196 } |
| 197 |
| 198 void WaitForPanelActiveStates(const std::vector<bool>& old_states, |
| 199 const std::vector<bool>& new_states) { |
| 200 DCHECK(old_states.size() == new_states.size()); |
| 201 std::vector<Panel*> panels = PanelManager::GetInstance()->panels(); |
| 202 for (size_t i = 0; i < old_states.size(); i++) { |
| 203 if (old_states[i] != new_states[i]){ |
| 204 WaitForPanelActiveState( |
| 205 panels[i], new_states[i] ? SHOW_AS_ACTIVE : SHOW_AS_INACTIVE); |
| 206 } |
| 207 } |
| 208 } |
| 209 |
180 void TestDragging(int delta_x, | 210 void TestDragging(int delta_x, |
181 int delta_y, | 211 int delta_y, |
182 size_t drag_index, | 212 size_t drag_index, |
183 std::vector<int> expected_delta_x_after_drag, | 213 std::vector<int> expected_delta_x_after_drag, |
184 std::vector<int> expected_delta_x_after_finish, | 214 std::vector<int> expected_delta_x_after_finish, |
185 std::vector<gfx::Rect> expected_bounds_after_cancel, | 215 std::vector<gfx::Rect> expected_bounds_after_cancel, |
186 int drag_action) { | 216 int drag_action) { |
187 std::vector<Panel*> panels = PanelManager::GetInstance()->panels(); | 217 std::vector<Panel*> panels = PanelManager::GetInstance()->panels(); |
188 | 218 |
189 // These are bounds at the beginning of this test. This would be different | 219 // These are bounds at the beginning of this test. This would be different |
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1009 // Test that the attention is cleared when panel gets focus. | 1039 // Test that the attention is cleared when panel gets focus. |
1010 panel->Activate(); | 1040 panel->Activate(); |
1011 MessageLoop::current()->RunAllPending(); | 1041 MessageLoop::current()->RunAllPending(); |
1012 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE); | 1042 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE); |
1013 EXPECT_FALSE(panel->IsDrawingAttention()); | 1043 EXPECT_FALSE(panel->IsDrawingAttention()); |
1014 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention()); | 1044 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention()); |
1015 | 1045 |
1016 panel->Close(); | 1046 panel->Close(); |
1017 } | 1047 } |
1018 | 1048 |
| 1049 // TODO(jianli): To be enabled for other platforms. |
| 1050 #if defined(OS_WIN) |
| 1051 #define MAYBE_ActivateDeactivateBasic ActivateDeactivateBasic |
| 1052 #else |
| 1053 #define MAYBE_ActivateDeactivateBasic DISABLED_ActivateDeactivateBasic |
| 1054 #endif |
| 1055 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_ActivateDeactivateBasic) { |
| 1056 // Create an active panel. |
| 1057 Panel* panel = CreatePanel("PanelTest"); |
| 1058 scoped_ptr<NativePanelTesting> native_panel_testing( |
| 1059 NativePanelTesting::Create(panel->native_panel())); |
| 1060 EXPECT_TRUE(panel->IsActive()); |
| 1061 EXPECT_TRUE(native_panel_testing->VerifyActiveState(true)); |
| 1062 |
| 1063 // Deactivate the panel. |
| 1064 panel->Deactivate(); |
| 1065 WaitForPanelActiveState(panel, SHOW_AS_INACTIVE); |
| 1066 EXPECT_FALSE(panel->IsActive()); |
| 1067 EXPECT_TRUE(native_panel_testing->VerifyActiveState(false)); |
| 1068 |
| 1069 // Reactivate the panel. |
| 1070 panel->Activate(); |
| 1071 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE); |
| 1072 EXPECT_TRUE(panel->IsActive()); |
| 1073 EXPECT_TRUE(native_panel_testing->VerifyActiveState(true)); |
| 1074 } |
| 1075 |
| 1076 // TODO(jianli): To be enabled for other platforms. |
| 1077 #if defined(OS_WIN) |
| 1078 #define MAYBE_ActivateDeactivateMultiple ActivateDeactivateMultiple |
| 1079 #else |
| 1080 #define MAYBE_ActivateDeactivateMultiple DISABLED_ActivateDeactivateMultiple |
| 1081 #endif |
| 1082 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_ActivateDeactivateMultiple) { |
| 1083 BrowserWindow* tabbed_window = BrowserList::GetLastActive()->window(); |
| 1084 |
| 1085 // Create 4 panels in the following screen layout: |
| 1086 // P3 P2 P1 P0 |
| 1087 const int kNumPanels = 4; |
| 1088 std::string panel_name_base("PanelTest"); |
| 1089 for (int i = 0; i < kNumPanels; ++i) { |
| 1090 CreatePanelWithBounds(panel_name_base + base::IntToString(i), |
| 1091 gfx::Rect(0, 0, 100, 100)); |
| 1092 } |
| 1093 const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels(); |
| 1094 |
| 1095 std::vector<bool> expected_active_states; |
| 1096 std::vector<bool> last_active_states; |
| 1097 |
| 1098 // The last created panel, P3, should be active. |
| 1099 expected_active_states = ProduceExpectedActiveStates(3); |
| 1100 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates()); |
| 1101 EXPECT_FALSE(tabbed_window->IsActive()); |
| 1102 |
| 1103 // Activating P1 should cause P3 to lose focus. |
| 1104 panels[1]->Activate(); |
| 1105 last_active_states = expected_active_states; |
| 1106 expected_active_states = ProduceExpectedActiveStates(1); |
| 1107 WaitForPanelActiveStates(last_active_states, expected_active_states); |
| 1108 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates()); |
| 1109 |
| 1110 // Minimizing inactive panel P2 should not affect other panels' active states. |
| 1111 panels[2]->SetExpansionState(Panel::MINIMIZED); |
| 1112 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates()); |
| 1113 EXPECT_FALSE(tabbed_window->IsActive()); |
| 1114 |
| 1115 // Minimizing active panel P1 should activate last active panel P3. |
| 1116 panels[1]->SetExpansionState(Panel::MINIMIZED); |
| 1117 last_active_states = expected_active_states; |
| 1118 expected_active_states = ProduceExpectedActiveStates(3); |
| 1119 WaitForPanelActiveStates(last_active_states, expected_active_states); |
| 1120 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates()); |
| 1121 EXPECT_FALSE(tabbed_window->IsActive()); |
| 1122 |
| 1123 // Minimizing active panel P3 should activate last active panel P0. |
| 1124 panels[3]->SetExpansionState(Panel::MINIMIZED); |
| 1125 last_active_states = expected_active_states; |
| 1126 expected_active_states = ProduceExpectedActiveStates(0); |
| 1127 WaitForPanelActiveStates(last_active_states, expected_active_states); |
| 1128 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates()); |
| 1129 EXPECT_FALSE(tabbed_window->IsActive()); |
| 1130 |
| 1131 // Minimizing active panel P0 should activate last active tabbed window. |
| 1132 panels[0]->SetExpansionState(Panel::MINIMIZED); |
| 1133 last_active_states = expected_active_states; |
| 1134 expected_active_states = ProduceExpectedActiveStates(-1); // -1 means none. |
| 1135 WaitForPanelActiveStates(last_active_states, expected_active_states); |
| 1136 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates()); |
| 1137 EXPECT_TRUE(tabbed_window->IsActive()); |
| 1138 } |
| 1139 |
1019 class PanelDownloadTest : public PanelBrowserTest { | 1140 class PanelDownloadTest : public PanelBrowserTest { |
1020 public: | 1141 public: |
1021 PanelDownloadTest() : PanelBrowserTest() { } | 1142 PanelDownloadTest() : PanelBrowserTest() { } |
1022 | 1143 |
1023 // Creates a temporary directory for downloads that is auto-deleted | 1144 // Creates a temporary directory for downloads that is auto-deleted |
1024 // on destruction. | 1145 // on destruction. |
1025 bool CreateDownloadDirectory(Profile* profile) { | 1146 bool CreateDownloadDirectory(Profile* profile) { |
1026 bool created = downloads_directory_.CreateUniqueTempDir(); | 1147 bool created = downloads_directory_.CreateUniqueTempDir(); |
1027 if (!created) | 1148 if (!created) |
1028 return false; | 1149 return false; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 EXPECT_EQ(1, tabbed_browser->tab_count()); | 1303 EXPECT_EQ(1, tabbed_browser->tab_count()); |
1183 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); | 1304 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); |
1184 tabbed_browser->CloseWindow(); | 1305 tabbed_browser->CloseWindow(); |
1185 #endif | 1306 #endif |
1186 | 1307 |
1187 EXPECT_EQ(1, panel_browser->tab_count()); | 1308 EXPECT_EQ(1, panel_browser->tab_count()); |
1188 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); | 1309 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); |
1189 | 1310 |
1190 panel_browser->CloseWindow(); | 1311 panel_browser->CloseWindow(); |
1191 } | 1312 } |
OLD | NEW |