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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/panels/panel_browsertest.cc
===================================================================
--- chrome/browser/ui/panels/panel_browsertest.cc (revision 104349)
+++ chrome/browser/ui/panels/panel_browsertest.cc (working copy)
@@ -177,6 +177,35 @@
return expansion_states;
}
+ std::vector<bool> GetAllPanelActiveStates() {
+ std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
+ std::vector<bool> active_states;
+ for (size_t i = 0; i < panels.size(); i++)
+ active_states.push_back(panels[i]->IsActive());
+ return active_states;
+ }
+
+ std::vector<bool> ProduceExpectedActiveStates(
+ int expected_active_panel_index) {
+ std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
+ std::vector<bool> active_states;
+ for (int i = 0; i < static_cast<int>(panels.size()); i++)
+ active_states.push_back(i == expected_active_panel_index);
+ return active_states;
+ }
+
+ void WaitForPanelActiveStates(const std::vector<bool>& old_states,
+ const std::vector<bool>& new_states) {
+ DCHECK(old_states.size() == new_states.size());
+ std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
+ for (size_t i = 0; i < old_states.size(); i++) {
+ if (old_states[i] != new_states[i]){
+ WaitForPanelActiveState(
+ panels[i], new_states[i] ? SHOW_AS_ACTIVE : SHOW_AS_INACTIVE);
+ }
+ }
+ }
+
void TestDragging(int delta_x,
int delta_y,
size_t drag_index,
@@ -1016,6 +1045,131 @@
panel->Close();
}
+// TODO(jianli): To be enabled for other platforms.
+#if defined(OS_WIN)
+#define MAYBE_ActivateDeactivateBasic ActivateDeactivateBasic
+#else
+#define MAYBE_ActivateDeactivateBasic DISABLED_ActivateDeactivateBasic
+#endif
+IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_ActivateDeactivateBasic) {
+ // 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.
+ Panel* panel = CreatePanel("PanelTest");
+ scoped_ptr<NativePanelTesting> native_panel_testing(
+ NativePanelTesting::Create(panel->native_panel()));
+ EXPECT_TRUE(panel->IsActive());
+ EXPECT_TRUE(native_panel_testing->VerifyTitlebarPaintedAsActive(true));
+
+ // Deactivate the panel.
+ panel->Deactivate();
+ WaitForPanelActiveState(panel, SHOW_AS_INACTIVE);
+ EXPECT_FALSE(panel->IsActive());
+ EXPECT_TRUE(native_panel_testing->VerifyTitlebarPaintedAsActive(false));
+
+ // Reactivate the panel.
+ panel->Activate();
+ WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
+ EXPECT_TRUE(panel->IsActive());
+ EXPECT_TRUE(native_panel_testing->VerifyTitlebarPaintedAsActive(true));
+}
+
+// TODO(jianli): To be enabled for other platforms.
+#if defined(OS_WIN)
+#define MAYBE_ActivateDeactivateMultiple ActivateDeactivateMultiple
+#else
+#define MAYBE_ActivateDeactivateMultiple DISABLED_ActivateDeactivateMultiple
+#endif
+IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_ActivateDeactivateMultiple) {
+ // Create testing extensions.
+ DictionaryValue empty_value;
+ scoped_refptr<Extension> extension1 =
+ CreateExtension(FILE_PATH_LITERAL("extension1"),
+ Extension::INVALID, empty_value);
+ scoped_refptr<Extension> extension2 =
+ CreateExtension(FILE_PATH_LITERAL("extension2"),
+ Extension::INVALID, empty_value);
+
+ BrowserWindow* tabbed_window = BrowserList::GetLastActive()->window();
+
+ // 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.
+ // P5 P4 P3 P2 P1 P0
+ // (E2) (E1) (E2) (E1) (E1) (E1)
+ const int kNumPanels = 6;
+ Extension* extensions[] = {
+ extension1.get(), extension1.get(), extension1.get(),
+ extension2.get(), extension1.get(), extension2.get()
+ };
+ for (int i = 0; i < kNumPanels; ++i) {
+ CreatePanelWithBounds(
+ web_app::GenerateApplicationNameFromExtensionId(extensions[i]->id()),
+ gfx::Rect(0, 0, 100, 100));
+ }
+ const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels();
+
+ std::vector<bool> expected_active_states;
+ std::vector<bool> last_active_states;
+
+ // The last created one should be active.
+ expected_active_states = ProduceExpectedActiveStates(5);
+ EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
+ EXPECT_FALSE(tabbed_window->IsActive());
+
+ // Minimizing P4 that is inactive should not activate any other panel.
+ panels[4]->SetExpansionState(Panel::MINIMIZED);
+ EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
+ EXPECT_FALSE(tabbed_window->IsActive());
+
+ // Minimizing P1 that is active should make P2 be activated.
+ // Both P2 and P0 are equally close to P1 and the left one wins.
+ panels[1]->Activate();
+ last_active_states = expected_active_states;
+ expected_active_states = ProduceExpectedActiveStates(1);
+ WaitForPanelActiveStates(last_active_states, expected_active_states);
+ EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
+
+ panels[1]->SetExpansionState(Panel::MINIMIZED);
+ last_active_states = expected_active_states;
+ expected_active_states = ProduceExpectedActiveStates(2);
+ WaitForPanelActiveStates(last_active_states, expected_active_states);
+ EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
+ EXPECT_FALSE(tabbed_window->IsActive());
+
+ // Minimizing P0 that is active should make P2 be activated.
+ panels[0]->Activate();
+ last_active_states = expected_active_states;
+ expected_active_states = ProduceExpectedActiveStates(0);
+ WaitForPanelActiveStates(last_active_states, expected_active_states);
+ EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
+
+ panels[0]->SetExpansionState(Panel::MINIMIZED);
+ last_active_states = expected_active_states;
+ expected_active_states = ProduceExpectedActiveStates(2);
+ WaitForPanelActiveStates(last_active_states, expected_active_states);
+ EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
+
+ // Minimizing P3 that is active should make P5 be activated.
+ panels[3]->Activate();
+ last_active_states = expected_active_states;
+ expected_active_states = ProduceExpectedActiveStates(3);
+ WaitForPanelActiveStates(last_active_states, expected_active_states);
+ EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
+
+ panels[3]->SetExpansionState(Panel::MINIMIZED);
+ last_active_states = expected_active_states;
+ expected_active_states = ProduceExpectedActiveStates(5);
+ WaitForPanelActiveStates(last_active_states, expected_active_states);
+ EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
+ EXPECT_FALSE(tabbed_window->IsActive());
+
+ // Minimizing P5 should not activate any other panel. Instead, the tabbed
+ // window should be activated.
+ panels[5]->SetExpansionState(Panel::MINIMIZED);
+ last_active_states = expected_active_states;
+ expected_active_states = ProduceExpectedActiveStates(-1); // -1 means none.
+ WaitForPanelActiveStates(last_active_states, expected_active_states);
+ EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
+ EXPECT_TRUE(tabbed_window->IsActive());
+}
+
class PanelDownloadTest : public PanelBrowserTest {
public:
PanelDownloadTest() : PanelBrowserTest() { }

Powered by Google App Engine
This is Rietveld 408576698