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

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

Issue 8183005: Choose the right window to switch to when a panel is deactivated on Windows. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 2 months 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 "chrome/browser/net/url_request_mock_util.h" 6 #include "chrome/browser/net/url_request_mock_util.h"
7 #include "chrome/browser/prefs/pref_service.h" 7 #include "chrome/browser/prefs/pref_service.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser_list.h" 9 #include "chrome/browser/ui/browser_list.h"
10 #include "chrome/browser/ui/browser_window.h" 10 #include "chrome/browser/ui/browser_window.h"
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 } 170 }
171 171
172 std::vector<Panel::ExpansionState> GetAllPanelExpansionStates() { 172 std::vector<Panel::ExpansionState> GetAllPanelExpansionStates() {
173 std::vector<Panel*> panels = PanelManager::GetInstance()->panels(); 173 std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
174 std::vector<Panel::ExpansionState> expansion_states; 174 std::vector<Panel::ExpansionState> expansion_states;
175 for (size_t i = 0; i < panels.size(); i++) 175 for (size_t i = 0; i < panels.size(); i++)
176 expansion_states.push_back(panels[i]->expansion_state()); 176 expansion_states.push_back(panels[i]->expansion_state());
177 return expansion_states; 177 return expansion_states;
178 } 178 }
179 179
180 std::vector<bool> GetAllPanelActiveStates() {
181 std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
182 std::vector<bool> active_states;
183 for (size_t i = 0; i < panels.size(); i++)
184 active_states.push_back(panels[i]->IsActive());
185 return active_states;
186 }
187
188 std::vector<bool> ProduceExpectedActiveStates(
189 int expected_active_panel_index) {
190 std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
191 std::vector<bool> active_states;
192 for (int i = 0; i < static_cast<int>(panels.size()); i++)
193 active_states.push_back(i == expected_active_panel_index);
194 return active_states;
195 }
196
197 void WaitForPanelActiveStates(const std::vector<bool>& old_states,
198 const std::vector<bool>& new_states) {
199 DCHECK(old_states.size() == new_states.size());
200 std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
201 for (size_t i = 0; i < old_states.size(); i++) {
202 if (old_states[i] != new_states[i]){
203 WaitForPanelActiveState(
204 panels[i], new_states[i] ? SHOW_AS_ACTIVE : SHOW_AS_INACTIVE);
205 }
206 }
207 }
208
180 void TestDragging(int delta_x, 209 void TestDragging(int delta_x,
181 int delta_y, 210 int delta_y,
182 size_t drag_index, 211 size_t drag_index,
183 std::vector<int> expected_delta_x_after_drag, 212 std::vector<int> expected_delta_x_after_drag,
184 std::vector<int> expected_delta_x_after_finish, 213 std::vector<int> expected_delta_x_after_finish,
185 std::vector<gfx::Rect> expected_bounds_after_cancel, 214 std::vector<gfx::Rect> expected_bounds_after_cancel,
186 int drag_action) { 215 int drag_action) {
187 std::vector<Panel*> panels = PanelManager::GetInstance()->panels(); 216 std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
188 217
189 // These are bounds at the beginning of this test. This would be different 218 // 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
1009 // Test that the attention is cleared when panel gets focus. 1038 // Test that the attention is cleared when panel gets focus.
1010 panel->Activate(); 1039 panel->Activate();
1011 MessageLoop::current()->RunAllPending(); 1040 MessageLoop::current()->RunAllPending();
1012 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE); 1041 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
1013 EXPECT_FALSE(panel->IsDrawingAttention()); 1042 EXPECT_FALSE(panel->IsDrawingAttention());
1014 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention()); 1043 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
1015 1044
1016 panel->Close(); 1045 panel->Close();
1017 } 1046 }
1018 1047
1048 // TODO(jianli): To be enabled for other platforms.
1049 #if defined(OS_WIN)
1050 #define MAYBE_ActivateDeactivateBasic ActivateDeactivateBasic
1051 #else
1052 #define MAYBE_ActivateDeactivateBasic DISABLED_ActivateDeactivateBasic
1053 #endif
1054 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_ActivateDeactivateBasic) {
1055 // When a panel is created, it should be active at first.
jennb 2011/10/07 20:34:16 This comment makes it sound like this is default b
jianli 2011/10/07 22:01:54 Done.
1056 Panel* panel = CreatePanel("PanelTest");
1057 scoped_ptr<NativePanelTesting> native_panel_testing(
1058 NativePanelTesting::Create(panel->native_panel()));
1059 EXPECT_TRUE(panel->IsActive());
1060 EXPECT_TRUE(native_panel_testing->VerifyTitlebarPaintedAsActive(true));
1061
1062 // Deactivate the panel.
1063 panel->Deactivate();
1064 WaitForPanelActiveState(panel, SHOW_AS_INACTIVE);
1065 EXPECT_FALSE(panel->IsActive());
1066 EXPECT_TRUE(native_panel_testing->VerifyTitlebarPaintedAsActive(false));
1067
1068 // Reactivate the panel.
1069 panel->Activate();
1070 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
1071 EXPECT_TRUE(panel->IsActive());
1072 EXPECT_TRUE(native_panel_testing->VerifyTitlebarPaintedAsActive(true));
1073 }
1074
1075 // TODO(jianli): To be enabled for other platforms.
1076 #if defined(OS_WIN)
1077 #define MAYBE_ActivateDeactivateMultiple ActivateDeactivateMultiple
1078 #else
1079 #define MAYBE_ActivateDeactivateMultiple DISABLED_ActivateDeactivateMultiple
1080 #endif
1081 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_ActivateDeactivateMultiple) {
1082 // Create testing extensions.
1083 DictionaryValue empty_value;
1084 scoped_refptr<Extension> extension1 =
1085 CreateExtension(FILE_PATH_LITERAL("extension1"),
1086 Extension::INVALID, empty_value);
1087 scoped_refptr<Extension> extension2 =
1088 CreateExtension(FILE_PATH_LITERAL("extension2"),
1089 Extension::INVALID, empty_value);
1090
1091 BrowserWindow* tabbed_window = BrowserList::GetLastActive()->window();
1092
1093 // Create 5 panels in the following screen layout:
jennb 2011/10/07 20:34:16 layout shows 6 panels
jianli 2011/10/07 22:01:54 Done.
1094 // P5 P4 P3 P2 P1 P0
1095 // (E2) (E1) (E2) (E1) (E1) (E1)
1096 const int kNumPanels = 6;
1097 Extension* extensions[] = {
1098 extension1.get(), extension1.get(), extension1.get(),
1099 extension2.get(), extension1.get(), extension2.get()
1100 };
1101 for (int i = 0; i < kNumPanels; ++i) {
1102 CreatePanelWithBounds(
1103 web_app::GenerateApplicationNameFromExtensionId(extensions[i]->id()),
1104 gfx::Rect(0, 0, 100, 100));
1105 }
1106 const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels();
1107
1108 std::vector<bool> expected_active_states;
1109 std::vector<bool> last_active_states;
1110
1111 // The last created one should be active.
1112 expected_active_states = ProduceExpectedActiveStates(5);
1113 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
1114 EXPECT_FALSE(tabbed_window->IsActive());
1115
1116 // Minimizing P4 that is inactive should not activate any other panel.
1117 panels[4]->SetExpansionState(Panel::MINIMIZED);
1118 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
1119 EXPECT_FALSE(tabbed_window->IsActive());
1120
1121 // Minimizing P1 that is active should make P2 be activated.
1122 // Both P2 and P0 are equally close to P1 and the left one wins.
1123 panels[1]->Activate();
1124 last_active_states = expected_active_states;
1125 expected_active_states = ProduceExpectedActiveStates(1);
1126 WaitForPanelActiveStates(last_active_states, expected_active_states);
1127 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
1128
1129 panels[1]->SetExpansionState(Panel::MINIMIZED);
1130 last_active_states = expected_active_states;
1131 expected_active_states = ProduceExpectedActiveStates(2);
1132 WaitForPanelActiveStates(last_active_states, expected_active_states);
1133 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
1134 EXPECT_FALSE(tabbed_window->IsActive());
1135
1136 // Minimizing P0 that is active should make P2 be activated.
1137 panels[0]->Activate();
1138 last_active_states = expected_active_states;
1139 expected_active_states = ProduceExpectedActiveStates(0);
1140 WaitForPanelActiveStates(last_active_states, expected_active_states);
1141 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
1142
1143 panels[0]->SetExpansionState(Panel::MINIMIZED);
1144 last_active_states = expected_active_states;
1145 expected_active_states = ProduceExpectedActiveStates(2);
1146 WaitForPanelActiveStates(last_active_states, expected_active_states);
1147 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
1148
1149 // Minimizing P3 that is active should make P5 be activated.
1150 panels[3]->Activate();
1151 last_active_states = expected_active_states;
1152 expected_active_states = ProduceExpectedActiveStates(3);
1153 WaitForPanelActiveStates(last_active_states, expected_active_states);
1154 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
1155
1156 panels[3]->SetExpansionState(Panel::MINIMIZED);
1157 last_active_states = expected_active_states;
1158 expected_active_states = ProduceExpectedActiveStates(5);
1159 WaitForPanelActiveStates(last_active_states, expected_active_states);
1160 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
1161 EXPECT_FALSE(tabbed_window->IsActive());
1162
1163 // Minimizing P5 should not activate any other panel. Instead, the tabbed
1164 // window should be activated.
1165 panels[5]->SetExpansionState(Panel::MINIMIZED);
1166 last_active_states = expected_active_states;
1167 expected_active_states = ProduceExpectedActiveStates(-1); // -1 means none.
1168 WaitForPanelActiveStates(last_active_states, expected_active_states);
1169 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
1170 EXPECT_TRUE(tabbed_window->IsActive());
1171 }
1172
1019 class PanelDownloadTest : public PanelBrowserTest { 1173 class PanelDownloadTest : public PanelBrowserTest {
1020 public: 1174 public:
1021 PanelDownloadTest() : PanelBrowserTest() { } 1175 PanelDownloadTest() : PanelBrowserTest() { }
1022 1176
1023 // Creates a temporary directory for downloads that is auto-deleted 1177 // Creates a temporary directory for downloads that is auto-deleted
1024 // on destruction. 1178 // on destruction.
1025 bool CreateDownloadDirectory(Profile* profile) { 1179 bool CreateDownloadDirectory(Profile* profile) {
1026 bool created = downloads_directory_.CreateUniqueTempDir(); 1180 bool created = downloads_directory_.CreateUniqueTempDir();
1027 if (!created) 1181 if (!created)
1028 return false; 1182 return false;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 EXPECT_EQ(1, tabbed_browser->tab_count()); 1336 EXPECT_EQ(1, tabbed_browser->tab_count());
1183 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); 1337 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible());
1184 tabbed_browser->CloseWindow(); 1338 tabbed_browser->CloseWindow();
1185 #endif 1339 #endif
1186 1340
1187 EXPECT_EQ(1, panel_browser->tab_count()); 1341 EXPECT_EQ(1, panel_browser->tab_count());
1188 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); 1342 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible());
1189 1343
1190 panel_browser->CloseWindow(); 1344 panel_browser->CloseWindow();
1191 } 1345 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698