This source file includes following definitions.
- PrintAllPanelBounds
- GetAllPanelBounds
- AddXDeltaToBounds
- GetAllPanelExpansionStates
- GetAllPanelActiveStates
- ProduceExpectedActiveStates
- WaitForPanelActiveStates
- TestMinimizeRestore
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- panel_
- AtExpectedState
- initial_size_
- AtExpectedState
- initial_size_
- AtExpectedState
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- SetUpCommandLine
- IN_PROC_BROWSER_TEST_F
#include "base/bind.h"
#include "base/prefs/pref_service.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/devtools/devtools_window.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/net/url_request_mock_util.h"
#include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h"
#include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_iterator.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/panels/base_panel_browser_test.h"
#include "chrome/browser/ui/panels/docked_panel_collection.h"
#include "chrome/browser/ui/panels/native_panel.h"
#include "chrome/browser/ui/panels/panel.h"
#include "chrome/browser/ui/panels/panel_manager.h"
#include "chrome/browser/ui/panels/test_panel_active_state_observer.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/browser_test_utils.h"
#include "content/test/net/url_request_mock_http_job.h"
#include "extensions/common/constants.h"
#include "net/base/net_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/event_utils.h"
#include "ui/gfx/screen.h"
using content::WebContents;
class PanelBrowserTest : public BasePanelBrowserTest {
public:
PanelBrowserTest() : BasePanelBrowserTest() {
}
protected:
void PrintAllPanelBounds() {
const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels();
DLOG(WARNING) << "PanelBounds:";
for (size_t i = 0; i < panels.size(); ++i) {
DLOG(WARNING) << "#=" << i
<< ", ptr=" << panels[i]
<< ", x=" << panels[i]->GetBounds().x()
<< ", y=" << panels[i]->GetBounds().y()
<< ", width=" << panels[i]->GetBounds().width()
<< ", height" << panels[i]->GetBounds().height();
}
}
std::vector<gfx::Rect> GetAllPanelBounds() {
std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
std::vector<gfx::Rect> bounds;
for (size_t i = 0; i < panels.size(); i++)
bounds.push_back(panels[i]->GetBounds());
return bounds;
}
std::vector<gfx::Rect> AddXDeltaToBounds(const std::vector<gfx::Rect>& bounds,
const std::vector<int>& delta_x) {
std::vector<gfx::Rect> new_bounds = bounds;
for (size_t i = 0; i < bounds.size(); ++i)
new_bounds[i].Offset(delta_x[i], 0);
return new_bounds;
}
std::vector<Panel::ExpansionState> GetAllPanelExpansionStates() {
std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
std::vector<Panel::ExpansionState> expansion_states;
for (size_t i = 0; i < panels.size(); i++)
expansion_states.push_back(panels[i]->expansion_state());
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 TestMinimizeRestore() {
const int kFarEnoughFromHoverArea = 153;
PanelManager* panel_manager = PanelManager::GetInstance();
std::vector<Panel*> panels = panel_manager->panels();
std::vector<gfx::Rect> test_begin_bounds = GetAllPanelBounds();
std::vector<gfx::Rect> expected_bounds = test_begin_bounds;
std::vector<Panel::ExpansionState> expected_expansion_states(
panels.size(), Panel::EXPANDED);
std::vector<NativePanelTesting*> native_panels_testing(panels.size());
for (size_t i = 0; i < panels.size(); ++i) {
native_panels_testing[i] = CreateNativePanelTesting(panels[i]);
}
for (size_t index = 0; index < panels.size(); ++index) {
native_panels_testing[index]->PressLeftMouseButtonTitlebar(
panels[index]->GetBounds().origin());
EXPECT_EQ(expected_bounds, GetAllPanelBounds());
EXPECT_EQ(expected_expansion_states, GetAllPanelExpansionStates());
native_panels_testing[index]->ReleaseMouseButtonTitlebar();
EXPECT_EQ(expected_bounds, GetAllPanelBounds());
EXPECT_EQ(expected_expansion_states, GetAllPanelExpansionStates());
}
for (size_t index = 0; index < panels.size(); ++index) {
panels[index]->Minimize();
expected_bounds[index].set_height(panel::kMinimizedPanelHeight);
expected_bounds[index].set_y(
test_begin_bounds[index].y() +
test_begin_bounds[index].height() - panel::kMinimizedPanelHeight);
expected_expansion_states[index] = Panel::MINIMIZED;
EXPECT_EQ(expected_bounds, GetAllPanelBounds());
EXPECT_EQ(expected_expansion_states, GetAllPanelExpansionStates());
}
std::vector<Panel::ExpansionState> titlebar_exposed_states(
panels.size(), Panel::TITLE_ONLY);
std::vector<gfx::Rect> minimized_bounds = expected_bounds;
std::vector<Panel::ExpansionState> minimized_states(
panels.size(), Panel::MINIMIZED);
std::vector<gfx::Rect> titlebar_exposed_bounds = test_begin_bounds;
for (size_t index = 0; index < panels.size(); ++index) {
titlebar_exposed_bounds[index].set_height(
panels[index]->native_panel()->TitleOnlyHeight());
titlebar_exposed_bounds[index].set_y(
test_begin_bounds[index].y() +
test_begin_bounds[index].height() -
panels[index]->native_panel()->TitleOnlyHeight());
}
EXPECT_EQ(minimized_states, GetAllPanelExpansionStates());
for (size_t index = 0; index < panels.size(); ++index) {
gfx::Point hover_point(panels[index]->GetBounds().origin());
MoveMouseAndWaitForExpansionStateChange(panels[index], hover_point);
EXPECT_EQ(titlebar_exposed_bounds, GetAllPanelBounds());
EXPECT_EQ(titlebar_exposed_states, GetAllPanelExpansionStates());
hover_point.set_y(
panels[index]->GetBounds().y() - kFarEnoughFromHoverArea);
MoveMouseAndWaitForExpansionStateChange(panels[index], hover_point);
EXPECT_EQ(minimized_bounds, GetAllPanelBounds());
EXPECT_EQ(minimized_states, GetAllPanelExpansionStates());
hover_point.set_y(panels[index]->GetBounds().y() +
panels[index]->GetBounds().height() + 5);
MoveMouseAndWaitForExpansionStateChange(panels[index], hover_point);
EXPECT_EQ(titlebar_exposed_bounds, GetAllPanelBounds());
EXPECT_EQ(titlebar_exposed_states, GetAllPanelExpansionStates());
hover_point.set_y(panels[index]->GetBounds().y() +
panels[index]->GetBounds().height() + 6);
MoveMouse(hover_point);
EXPECT_EQ(titlebar_exposed_bounds, GetAllPanelBounds());
EXPECT_EQ(titlebar_exposed_states, GetAllPanelExpansionStates());
hover_point.set_y(
panels[index]->GetBounds().y() - kFarEnoughFromHoverArea);
MoveMouseAndWaitForExpansionStateChange(panels[index], hover_point);
EXPECT_EQ(minimized_bounds, GetAllPanelBounds());
EXPECT_EQ(minimized_states, GetAllPanelExpansionStates());
}
for (size_t index = 0; index < panels.size(); ++index) {
if (index == panels.size() - 1)
MoveMouse(minimized_bounds[index].origin());
native_panels_testing[index]->PressLeftMouseButtonTitlebar(
panels[index]->GetBounds().origin());
native_panels_testing[index]->ReleaseMouseButtonTitlebar();
expected_bounds[index].set_height(
test_begin_bounds[index].height());
expected_bounds[index].set_y(test_begin_bounds[index].y());
expected_expansion_states[index] = Panel::EXPANDED;
EXPECT_EQ(expected_bounds, GetAllPanelBounds());
EXPECT_EQ(expected_expansion_states, GetAllPanelExpansionStates());
if (index == panels.size() - 1)
MoveMouse(minimized_bounds[index].origin());
}
for (size_t i = 0; i < panels.size(); ++i)
delete native_panels_testing[i];
}
};
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CheckDockedPanelProperties) {
PanelManager* panel_manager = PanelManager::GetInstance();
DockedPanelCollection* docked_collection = panel_manager->docked_collection();
Panel* panel1 = CreatePanelWithBounds("1", gfx::Rect(0, 0, 100, 100));
Panel* panel2 = CreatePanelWithBounds("2", gfx::Rect(0, 0, 100, 100));
Panel* panel3 = CreatePanelWithBounds("3", gfx::Rect(0, 0, 100, 100));
panel2->SetExpansionState(Panel::TITLE_ONLY);
EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state());
panel3->SetExpansionState(Panel::MINIMIZED);
EXPECT_EQ(Panel::MINIMIZED, panel3->expansion_state());
scoped_ptr<NativePanelTesting> panel1_testing(
CreateNativePanelTesting(panel1));
scoped_ptr<NativePanelTesting> panel2_testing(
CreateNativePanelTesting(panel2));
scoped_ptr<NativePanelTesting> panel3_testing(
CreateNativePanelTesting(panel3));
base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(3, panel_manager->num_panels());
EXPECT_TRUE(docked_collection->HasPanel(panel1));
EXPECT_TRUE(docked_collection->HasPanel(panel2));
EXPECT_TRUE(docked_collection->HasPanel(panel3));
EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state());
EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state());
EXPECT_EQ(Panel::MINIMIZED, panel3->expansion_state());
EXPECT_TRUE(panel1->IsAlwaysOnTop());
EXPECT_TRUE(panel2->IsAlwaysOnTop());
EXPECT_TRUE(panel3->IsAlwaysOnTop());
EXPECT_TRUE(panel1_testing->IsButtonVisible(panel::CLOSE_BUTTON));
EXPECT_TRUE(panel2_testing->IsButtonVisible(panel::CLOSE_BUTTON));
EXPECT_TRUE(panel3_testing->IsButtonVisible(panel::CLOSE_BUTTON));
EXPECT_TRUE(panel1_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
EXPECT_FALSE(panel2_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
EXPECT_FALSE(panel3_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
EXPECT_FALSE(panel1_testing->IsButtonVisible(panel::RESTORE_BUTTON));
EXPECT_TRUE(panel2_testing->IsButtonVisible(panel::RESTORE_BUTTON));
EXPECT_TRUE(panel3_testing->IsButtonVisible(panel::RESTORE_BUTTON));
EXPECT_EQ(panel::RESIZABLE_EXCEPT_BOTTOM, panel1->CanResizeByMouse());
EXPECT_EQ(panel::NOT_RESIZABLE, panel2->CanResizeByMouse());
EXPECT_EQ(panel::NOT_RESIZABLE, panel3->CanResizeByMouse());
EXPECT_EQ(panel::TOP_ROUNDED, panel1_testing->GetWindowCornerStyle());
EXPECT_EQ(panel::TOP_ROUNDED, panel1_testing->GetWindowCornerStyle());
EXPECT_EQ(panel::TOP_ROUNDED, panel3_testing->GetWindowCornerStyle());
EXPECT_EQ(Panel::USE_PANEL_ATTENTION, panel1->attention_mode());
EXPECT_EQ(Panel::USE_PANEL_ATTENTION, panel2->attention_mode());
EXPECT_EQ(Panel::USE_PANEL_ATTENTION, panel3->attention_mode());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) {
PanelManager* panel_manager = PanelManager::GetInstance();
EXPECT_EQ(0, panel_manager->num_panels());
Panel* panel = CreatePanel("PanelTest");
EXPECT_EQ(1, panel_manager->num_panels());
gfx::Rect bounds = panel->GetBounds();
EXPECT_GT(bounds.x(), 0);
EXPECT_GT(bounds.y(), 0);
EXPECT_GT(bounds.width(), 0);
EXPECT_GT(bounds.height(), 0);
EXPECT_EQ(bounds.right(),
panel_manager->docked_collection()->StartingRightPosition());
CloseWindowAndWait(panel);
EXPECT_EQ(0, panel_manager->num_panels());
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreateBigPanel) {
gfx::Rect work_area = PanelManager::GetInstance()->
display_settings_provider()->GetPrimaryWorkArea();
Panel* panel = CreatePanelWithBounds("BigPanel", work_area);
gfx::Rect bounds = panel->GetBounds();
EXPECT_EQ(panel->max_size().width(), bounds.width());
EXPECT_LT(bounds.width(), work_area.width());
EXPECT_EQ(panel->max_size().height(), bounds.height());
EXPECT_LT(bounds.height(), work_area.height());
panel->Close();
}
class WaitForStableInitialSize : public TestPanelNotificationObserver {
public:
explicit WaitForStableInitialSize(Panel* panel)
: TestPanelNotificationObserver(
chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED,
content::NotificationService::AllSources()),
panel_(panel) {}
virtual ~WaitForStableInitialSize() {}
protected:
virtual bool AtExpectedState() OVERRIDE {
return panel_->GetBounds().height() > panel_->TitleOnlyHeight();
}
Panel* panel_;
};
class WaitForAutoResizeWider : public TestPanelNotificationObserver {
public:
explicit WaitForAutoResizeWider(Panel* panel)
: TestPanelNotificationObserver(
chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED,
content::NotificationService::AllSources()),
panel_(panel),
initial_size_(panel->GetBounds().size()) {}
virtual ~WaitForAutoResizeWider() {}
protected:
virtual bool AtExpectedState() OVERRIDE {
return panel_->GetBounds().width() > initial_size_.width();
}
Panel* panel_;
gfx::Size initial_size_;
};
class WaitForAutoResizeNarrower : public TestPanelNotificationObserver {
public:
explicit WaitForAutoResizeNarrower(Panel* panel)
: TestPanelNotificationObserver(
chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED,
content::NotificationService::AllSources()),
panel_(panel),
initial_size_(panel->GetBounds().size()) {}
virtual ~WaitForAutoResizeNarrower() {}
protected:
virtual bool AtExpectedState() OVERRIDE {
return panel_->GetBounds().width() < initial_size_.width();
}
Panel* panel_;
gfx::Size initial_size_;
};
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DISABLED_AutoResize) {
PanelManager* panel_manager = PanelManager::GetInstance();
panel_manager->enable_auto_sizing(true);
mock_display_settings_provider()->SetPrimaryDisplay(
gfx::Rect(0, 0, 1200, 900), gfx::Rect(0, 0, 1200, 900));
CreatePanelParams params("PanelTest1", gfx::Rect(), SHOW_AS_ACTIVE);
GURL url(ui_test_utils::GetTestUrl(
base::FilePath(kTestDir),
base::FilePath(FILE_PATH_LITERAL("update-preferred-size.html"))));
params.url = url;
Panel* panel = CreatePanelWithParams(params);
WaitForStableInitialSize initial_resize(panel);
initial_resize.Wait();
gfx::Rect initial_bounds = panel->GetBounds();
WaitForAutoResizeWider enlarge(panel);
EXPECT_TRUE(content::ExecuteScript(
panel->GetWebContents(), "changeSize(50);"));
enlarge.Wait();
gfx::Rect bounds_on_grow = panel->GetBounds();
EXPECT_GT(bounds_on_grow.width(), initial_bounds.width());
EXPECT_EQ(bounds_on_grow.height(), initial_bounds.height());
WaitForAutoResizeNarrower shrink(panel);
EXPECT_TRUE(content::ExecuteScript(
panel->GetWebContents(), "changeSize(-30);"));
shrink.Wait();
gfx::Rect bounds_on_shrink = panel->GetBounds();
EXPECT_LT(bounds_on_shrink.width(), bounds_on_grow.width());
EXPECT_GT(bounds_on_shrink.width(), initial_bounds.width());
EXPECT_EQ(bounds_on_shrink.height(), initial_bounds.height());
gfx::Rect previous_bounds = panel->GetBounds();
EXPECT_EQ(previous_bounds.size(), panel->GetRestoredBounds().size());
gfx::Size new_size(previous_bounds.size());
new_size.Enlarge(5, 5);
gfx::Rect new_bounds(previous_bounds.origin(), new_size);
panel->SetBounds(new_bounds);
EXPECT_FALSE(panel->auto_resizable());
EXPECT_EQ(new_bounds.size(), panel->GetBounds().size());
EXPECT_EQ(new_bounds.size(), panel->GetRestoredBounds().size());
content::WindowedNotificationObserver auto_resize_enabled(
chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED,
content::NotificationService::AllSources());
panel->SetAutoResizable(true);
auto_resize_enabled.Wait();
gfx::Rect bounds_auto_resize_enabled = panel->GetBounds();
EXPECT_EQ(bounds_on_shrink.width(), bounds_auto_resize_enabled.width());
EXPECT_EQ(bounds_on_shrink.height(), bounds_auto_resize_enabled.height());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, ResizePanel) {
PanelManager* panel_manager = PanelManager::GetInstance();
panel_manager->enable_auto_sizing(true);
Panel* panel = CreatePanel("TestPanel");
EXPECT_TRUE(panel->auto_resizable());
EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
gfx::Rect original_bounds = panel->GetBounds();
EXPECT_EQ(original_bounds.size(), panel->GetRestoredBounds().size());
gfx::Size new_size(original_bounds.size());
new_size.Enlarge(5, 5);
gfx::Rect new_bounds(original_bounds.origin(), new_size);
panel->SetBounds(new_bounds);
EXPECT_FALSE(panel->auto_resizable());
EXPECT_EQ(new_bounds.size(), panel->GetBounds().size());
EXPECT_EQ(new_bounds.size(), panel->GetRestoredBounds().size());
panel->SetExpansionState(Panel::MINIMIZED);
int original_height = panel->GetBounds().height();
new_size.Enlarge(5, 5);
new_bounds.set_size(new_size);
panel->SetBounds(new_bounds);
EXPECT_EQ(new_bounds.size().width(), panel->GetBounds().width());
EXPECT_EQ(original_height, panel->GetBounds().height());
EXPECT_EQ(new_bounds.size(), panel->GetRestoredBounds().size());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, AnimateBounds) {
Panel* panel = CreateDetachedPanel("1", gfx::Rect(200, 100, 100, 100));
scoped_ptr<NativePanelTesting> panel_testing(
CreateNativePanelTesting(panel));
gfx::Point mouse_location(panel->GetBounds().origin());
panel_testing->PressLeftMouseButtonTitlebar(mouse_location);
panel_testing->DragTitlebar(mouse_location + gfx::Vector2d(-100, 5));
EXPECT_FALSE(panel_testing->IsAnimatingBounds());
panel_testing->FinishDragTitlebar();
gfx::Rect bounds = gfx::Rect(10, 20, 150, 160);
panel->SetPanelBounds(bounds);
#if !defined(OS_LINUX)
EXPECT_TRUE(panel_testing->IsAnimatingBounds());
WaitForBoundsAnimationFinished(panel);
#endif
EXPECT_FALSE(panel_testing->IsAnimatingBounds());
EXPECT_EQ(bounds, panel->GetBounds());
bounds = gfx::Rect(30, 40, 200, 220);
panel->SetPanelBoundsInstantly(bounds);
EXPECT_FALSE(panel_testing->IsAnimatingBounds());
EXPECT_EQ(bounds, panel->GetBounds());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, RestoredBounds) {
Panel* panel = CreatePanelWithBounds("PanelTest", gfx::Rect(0, 0, 100, 100));
EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
EXPECT_EQ(panel->GetBounds(), panel->GetRestoredBounds());
panel->SetExpansionState(Panel::MINIMIZED);
EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
gfx::Rect bounds = panel->GetBounds();
gfx::Rect restored = panel->GetRestoredBounds();
EXPECT_EQ(bounds.x(), restored.x());
EXPECT_GT(bounds.y(), restored.y());
EXPECT_EQ(bounds.width(), restored.width());
EXPECT_LT(bounds.height(), restored.height());
panel->SetExpansionState(Panel::TITLE_ONLY);
EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state());
bounds = panel->GetBounds();
restored = panel->GetRestoredBounds();
EXPECT_EQ(bounds.x(), restored.x());
EXPECT_GT(bounds.y(), restored.y());
EXPECT_EQ(bounds.width(), restored.width());
EXPECT_LT(bounds.height(), restored.height());
panel->SetExpansionState(Panel::MINIMIZED);
EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
bounds = panel->GetBounds();
restored = panel->GetRestoredBounds();
EXPECT_EQ(bounds.x(), restored.x());
EXPECT_GT(bounds.y(), restored.y());
EXPECT_EQ(bounds.width(), restored.width());
EXPECT_LT(bounds.height(), restored.height());
panel->SetExpansionState(Panel::EXPANDED);
EXPECT_EQ(panel->GetBounds(), panel->GetRestoredBounds());
int saved_restored_height = restored.height();
panel->SetExpansionState(Panel::MINIMIZED);
bounds = gfx::Rect(10, 20, 300, 400);
panel->SetPanelBounds(bounds);
EXPECT_EQ(saved_restored_height, panel->GetRestoredBounds().height());
panel->SetExpansionState(Panel::TITLE_ONLY);
bounds = gfx::Rect(20, 30, 100, 200);
panel->SetPanelBounds(bounds);
EXPECT_EQ(saved_restored_height, panel->GetRestoredBounds().height());
panel->SetExpansionState(Panel::EXPANDED);
bounds = gfx::Rect(40, 60, 300, 400);
panel->SetPanelBounds(bounds);
EXPECT_EQ(saved_restored_height, panel->GetRestoredBounds().height());
panel->set_full_size(bounds.size());
EXPECT_NE(saved_restored_height, panel->GetRestoredBounds().height());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MinimizeRestore) {
CreatePanelWithBounds("PanelTest1", gfx::Rect(0, 0, 100, 100));
TestMinimizeRestore();
PanelManager::GetInstance()->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MinimizeRestoreTwoPanels) {
CreatePanelWithBounds("PanelTest1", gfx::Rect(0, 0, 100, 100));
CreatePanelWithBounds("PanelTest2", gfx::Rect(0, 0, 110, 110));
TestMinimizeRestore();
PanelManager::GetInstance()->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MinimizeRestoreThreePanels) {
CreatePanelWithBounds("PanelTest1", gfx::Rect(0, 0, 100, 100));
CreatePanelWithBounds("PanelTest2", gfx::Rect(0, 0, 110, 110));
CreatePanelWithBounds("PanelTest3", gfx::Rect(0, 0, 120, 120));
TestMinimizeRestore();
PanelManager::GetInstance()->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MinimizeRestoreButtonClick) {
Panel* panel1 = CreatePanel("PanelTest1");
Panel* panel2 = CreatePanel("PanelTest2");
Panel* panel3 = CreatePanel("PanelTest3");
EXPECT_FALSE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
panel1->OnRestoreButtonClicked(panel::NO_MODIFIER);
EXPECT_FALSE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
panel1->OnMinimizeButtonClicked(panel::NO_MODIFIER);
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
panel1->OnMinimizeButtonClicked(panel::NO_MODIFIER);
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
panel2->OnMinimizeButtonClicked(panel::APPLY_TO_ALL);
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_TRUE(panel2->IsMinimized());
EXPECT_TRUE(panel3->IsMinimized());
panel2->OnRestoreButtonClicked(panel::NO_MODIFIER);
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_TRUE(panel3->IsMinimized());
panel3->OnRestoreButtonClicked(panel::APPLY_TO_ALL);
EXPECT_FALSE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
}
#if defined(OS_LINUX)
#define MAYBE_RestoreAllWithTitlebarClick DISABLED_RestoreAllWithTitlebarClick
#else
#define MAYBE_RestoreAllWithTitlebarClick RestoreAllWithTitlebarClick
#endif
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_RestoreAllWithTitlebarClick) {
Panel* panel1 = CreatePanel("PanelTest1");
Panel* panel2 = CreatePanel("PanelTest2");
Panel* panel3 = CreatePanel("PanelTest3");
EXPECT_FALSE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
scoped_ptr<NativePanelTesting> test_panel1(
CreateNativePanelTesting(panel1));
scoped_ptr<NativePanelTesting> test_panel2(
CreateNativePanelTesting(panel2));
scoped_ptr<NativePanelTesting> test_panel3(
CreateNativePanelTesting(panel3));
test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(),
panel::APPLY_TO_ALL);
test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
EXPECT_FALSE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
panel1->Minimize();
panel2->Minimize();
panel3->Minimize();
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_TRUE(panel2->IsMinimized());
EXPECT_TRUE(panel3->IsMinimized());
test_panel1->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin(),
panel::APPLY_TO_ALL);
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_TRUE(panel2->IsMinimized());
EXPECT_TRUE(panel3->IsMinimized());
test_panel1->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
EXPECT_FALSE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
panel1->Minimize();
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(),
panel::APPLY_TO_ALL);
test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
panel2->Minimize();
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_TRUE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(),
panel::APPLY_TO_ALL);
test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
EXPECT_FALSE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
panel1->Minimize();
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
test_panel1->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin(),
panel::APPLY_TO_ALL);
test_panel1->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
EXPECT_FALSE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
panel1->Minimize();
panel3->Minimize();
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_TRUE(panel3->IsMinimized());
test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(),
panel::APPLY_TO_ALL);
test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_TRUE(panel3->IsMinimized());
panel2->Minimize();
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_TRUE(panel2->IsMinimized());
EXPECT_TRUE(panel3->IsMinimized());
MoveMouseAndWaitForExpansionStateChange(panel2, panel2->GetBounds().origin());
EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state());
EXPECT_EQ(Panel::TITLE_ONLY, panel3->expansion_state());
test_panel3->PressLeftMouseButtonTitlebar(panel3->GetBounds().origin(),
panel::APPLY_TO_ALL);
test_panel3->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
EXPECT_FALSE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
panel1->Minimize();
panel2->Minimize();
panel3->Minimize();
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_TRUE(panel2->IsMinimized());
EXPECT_TRUE(panel3->IsMinimized());
panel1->FlashFrame(true);
EXPECT_TRUE(panel1->IsDrawingAttention());
test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(),
panel::APPLY_TO_ALL);
test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
EXPECT_FALSE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
EXPECT_TRUE(panel1->IsDrawingAttention());
panel1->Minimize();
panel2->Minimize();
panel3->Minimize();
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_TRUE(panel2->IsMinimized());
EXPECT_TRUE(panel3->IsMinimized());
test_panel1->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin(),
panel::APPLY_TO_ALL);
test_panel1->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
EXPECT_FALSE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
EXPECT_FALSE(panel1->IsDrawingAttention());
PanelManager::GetInstance()->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
MinimizeRestoreOnAutoHidingDesktopBar) {
PanelManager* panel_manager = PanelManager::GetInstance();
DockedPanelCollection* docked_collection = panel_manager->docked_collection();
int expected_bottom_on_expanded = docked_collection->work_area().bottom();
int expected_bottom_on_title_only = expected_bottom_on_expanded;
int expected_bottom_on_minimized = expected_bottom_on_expanded;
static const int bottom_bar_thickness = 40;
mock_display_settings_provider()->EnableAutoHidingDesktopBar(
DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM,
true,
bottom_bar_thickness);
expected_bottom_on_title_only -= bottom_bar_thickness;
Panel* panel = CreatePanel("1");
int initial_height = panel->GetBounds().height();
EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
EXPECT_EQ(expected_bottom_on_expanded, panel->GetBounds().bottom());
panel->Minimize();
WaitForBoundsAnimationFinished(panel);
EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
EXPECT_EQ(panel::kMinimizedPanelHeight, panel->GetBounds().height());
EXPECT_EQ(expected_bottom_on_minimized, panel->GetBounds().bottom());
panel->SetExpansionState(Panel::TITLE_ONLY);
WaitForBoundsAnimationFinished(panel);
EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state());
EXPECT_EQ(panel::kTitlebarHeight, panel->GetBounds().height());
EXPECT_EQ(expected_bottom_on_title_only, panel->GetBounds().bottom());
panel->Restore();
WaitForBoundsAnimationFinished(panel);
EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
EXPECT_EQ(initial_height, panel->GetBounds().height());
EXPECT_EQ(expected_bottom_on_expanded, panel->GetBounds().bottom());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, ChangeAutoHideTaskBarThickness) {
PanelManager* manager = PanelManager::GetInstance();
DockedPanelCollection* docked_collection = manager->docked_collection();
int initial_starting_right_position =
docked_collection->StartingRightPosition();
int bottom_bar_thickness = 20;
int right_bar_thickness = 30;
mock_display_settings_provider()->EnableAutoHidingDesktopBar(
DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM,
true,
bottom_bar_thickness);
mock_display_settings_provider()->EnableAutoHidingDesktopBar(
DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT,
true,
right_bar_thickness);
EXPECT_EQ(initial_starting_right_position,
docked_collection->StartingRightPosition());
Panel* panel = CreatePanel("PanelTest");
panel->SetExpansionState(Panel::TITLE_ONLY);
WaitForBoundsAnimationFinished(panel);
EXPECT_EQ(docked_collection->work_area().bottom() - bottom_bar_thickness,
panel->GetBounds().bottom());
EXPECT_EQ(docked_collection->StartingRightPosition(),
panel->GetBounds().right());
initial_starting_right_position = docked_collection->StartingRightPosition();
int bottom_bar_thickness_delta = 10;
bottom_bar_thickness += bottom_bar_thickness_delta;
int right_bar_thickness_delta = 15;
right_bar_thickness += right_bar_thickness_delta;
mock_display_settings_provider()->SetDesktopBarThickness(
DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM,
bottom_bar_thickness);
mock_display_settings_provider()->SetDesktopBarThickness(
DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT,
right_bar_thickness);
base::MessageLoopForUI::current()->RunUntilIdle();
EXPECT_EQ(initial_starting_right_position,
docked_collection->StartingRightPosition());
EXPECT_EQ(docked_collection->work_area().bottom() - bottom_bar_thickness,
panel->GetBounds().bottom());
EXPECT_EQ(docked_collection->StartingRightPosition(),
panel->GetBounds().right());
initial_starting_right_position = docked_collection->StartingRightPosition();
bottom_bar_thickness_delta = 20;
bottom_bar_thickness -= bottom_bar_thickness_delta;
right_bar_thickness_delta = 10;
right_bar_thickness -= right_bar_thickness_delta;
mock_display_settings_provider()->SetDesktopBarThickness(
DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM,
bottom_bar_thickness);
mock_display_settings_provider()->SetDesktopBarThickness(
DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT,
right_bar_thickness);
base::MessageLoopForUI::current()->RunUntilIdle();
EXPECT_EQ(docked_collection->StartingRightPosition(),
initial_starting_right_position);
EXPECT_EQ(docked_collection->work_area().bottom() - bottom_bar_thickness,
panel->GetBounds().bottom());
EXPECT_EQ(docked_collection->StartingRightPosition(),
panel->GetBounds().right());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, ActivatePanelOrTabbedWindow) {
if (!WmSupportWindowActivation()) {
LOG(WARNING) << "Skipping test due to WM problems.";
return;
}
Panel* panel1 = CreatePanel("Panel1");
Panel* panel2 = CreatePanel("Panel2");
browser()->window()->Activate();
WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE);
panel2->Activate();
WaitForPanelActiveState(panel2, SHOW_AS_ACTIVE);
browser()->window()->Activate();
WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE);
panel1->Activate();
WaitForPanelActiveState(panel1, SHOW_AS_ACTIVE);
WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE);
panel2->Activate();
WaitForPanelActiveState(panel2, SHOW_AS_ACTIVE);
WaitForPanelActiveState(panel1, SHOW_AS_INACTIVE);
PanelManager::GetInstance()->CloseAll();
}
#if defined(OS_WIN) || defined(OS_LINUX)
#define MAYBE_ActivateDeactivateBasic ActivateDeactivateBasic
#else
#define MAYBE_ActivateDeactivateBasic DISABLED_ActivateDeactivateBasic
#endif
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_ActivateDeactivateBasic) {
if (!WmSupportWindowActivation()) {
LOG(WARNING) << "Skipping test due to WM problems.";
return;
}
Panel* panel = CreatePanel("PanelTest");
scoped_ptr<NativePanelTesting> native_panel_testing(
CreateNativePanelTesting(panel));
WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
EXPECT_TRUE(native_panel_testing->VerifyActiveState(true));
panel->Deactivate();
WaitForPanelActiveState(panel, SHOW_AS_INACTIVE);
#if !defined(OS_LINUX)
EXPECT_TRUE(native_panel_testing->VerifyActiveState(false));
#endif
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, ActivateDeactivateMultiple) {
if (!WmSupportWindowActivation()) {
LOG(WARNING) << "Skipping test due to WM problems.";
return;
}
BrowserWindow* tabbed_window = browser()->window();
const int kNumPanels = 4;
for (int i = 0; i < kNumPanels; ++i)
CreatePanelWithBounds(MakePanelName(i), 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;
expected_active_states = ProduceExpectedActiveStates(3);
EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
EXPECT_FALSE(tabbed_window->IsActive());
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[2]->SetExpansionState(Panel::MINIMIZED);
EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
EXPECT_FALSE(tabbed_window->IsActive());
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionBasic) {
Panel* panel = CreateInactivePanel("P1");
scoped_ptr<NativePanelTesting> native_panel_testing(
CreateNativePanelTesting(panel));
EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
EXPECT_FALSE(panel->IsActive());
EXPECT_FALSE(panel->IsDrawingAttention());
panel->FlashFrame(true);
EXPECT_TRUE(panel->IsDrawingAttention());
EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention());
panel->FlashFrame(false);
EXPECT_FALSE(panel->IsDrawingAttention());
EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
panel->FlashFrame(true);
EXPECT_TRUE(panel->IsDrawingAttention());
panel->Minimize();
EXPECT_TRUE(panel->IsDrawingAttention());
EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state());
panel->FlashFrame(false);
EXPECT_FALSE(panel->IsDrawingAttention());
EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionWhileMinimized) {
Panel* panel1 = CreateInactivePanel("P1");
Panel* panel2 = CreateInactivePanel("P2");
scoped_ptr<NativePanelTesting> native_panel1_testing(
CreateNativePanelTesting(panel1));
panel1->Minimize();
EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
panel1->FlashFrame(true);
EXPECT_TRUE(panel1->IsDrawingAttention());
EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
EXPECT_TRUE(native_panel1_testing->VerifyDrawingAttention());
panel2->Minimize();
gfx::Point hover_point(panel1->GetBounds().origin());
MoveMouse(hover_point);
EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state());
hover_point.set_y(hover_point.y() - 200);
MoveMouse(hover_point);
EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
panel1->Activate();
WaitForPanelActiveState(panel1, SHOW_AS_ACTIVE);
EXPECT_FALSE(panel1->IsDrawingAttention());
EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state());
EXPECT_FALSE(native_panel1_testing->VerifyDrawingAttention());
PanelManager::GetInstance()->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, StopDrawingAttentionWhileMinimized) {
Panel* panel1 = CreateInactivePanel("P1");
Panel* panel2 = CreateInactivePanel("P2");
panel1->Minimize();
EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
panel2->Minimize();
EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state());
panel1->FlashFrame(true);
EXPECT_TRUE(panel1->IsDrawingAttention());
EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
panel1->FlashFrame(false);
EXPECT_FALSE(panel1->IsDrawingAttention());
EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
gfx::Point hover_point(panel2->GetBounds().origin());
MoveMouseAndWaitForExpansionStateChange(panel1, hover_point);
EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state());
panel1->FlashFrame(true);
EXPECT_TRUE(panel1->IsDrawingAttention());
EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
panel1->FlashFrame(false);
EXPECT_FALSE(panel1->IsDrawingAttention());
EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
hover_point.set_y(hover_point.y() - 200);
MoveMouseAndWaitForExpansionStateChange(panel1, hover_point);
EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state());
panel1->FlashFrame(true);
EXPECT_TRUE(panel1->IsDrawingAttention());
EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
gfx::Point hover_point_in_panel(panel1->GetBounds().origin());
MoveMouse(hover_point_in_panel);
panel1->FlashFrame(false);
EXPECT_FALSE(panel1->IsDrawingAttention());
EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state());
MoveMouseAndWaitForExpansionStateChange(panel2, hover_point_in_panel);
EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state());
MoveMouseAndWaitForExpansionStateChange(panel1, hover_point);
EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state());
PanelManager::GetInstance()->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionWhenActive) {
Panel* panel = CreatePanel("P1");
scoped_ptr<NativePanelTesting> native_panel_testing(
CreateNativePanelTesting(panel));
panel->FlashFrame(true);
EXPECT_FALSE(panel->IsDrawingAttention());
EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionResetOnActivate) {
Panel* panel = CreateInactivePanel("P1");
scoped_ptr<NativePanelTesting> native_panel_testing(
CreateNativePanelTesting(panel));
panel->FlashFrame(true);
EXPECT_TRUE(panel->IsDrawingAttention());
EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention());
panel->Activate();
WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
EXPECT_FALSE(panel->IsDrawingAttention());
EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
DrawAttentionMinimizedNotResetOnActivate) {
Panel* panel = CreateInactivePanel("P1");
panel->Minimize();
EXPECT_TRUE(panel->IsMinimized());
panel->FlashFrame(true);
EXPECT_TRUE(panel->IsDrawingAttention());
panel->OnActiveStateChanged(true);
EXPECT_TRUE(panel->IsDrawingAttention());
panel->Restore();
EXPECT_FALSE(panel->IsMinimized());
EXPECT_TRUE(panel->IsDrawingAttention());
panel->OnActiveStateChanged(true);
EXPECT_FALSE(panel->IsDrawingAttention());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionResetOnClick) {
Panel* panel = CreateInactivePanel("P1");
scoped_ptr<NativePanelTesting> native_panel_testing(
CreateNativePanelTesting(panel));
panel->FlashFrame(true);
EXPECT_TRUE(panel->IsDrawingAttention());
EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention());
native_panel_testing->PressLeftMouseButtonTitlebar(
panel->GetBounds().origin());
native_panel_testing->ReleaseMouseButtonTitlebar();
WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
EXPECT_FALSE(panel->IsDrawingAttention());
EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
panel->Close();
}
#if defined(OS_MACOSX)
#define MAYBE_MinimizeImmediatelyAfterRestore \
DISABLED_MinimizeImmediatelyAfterRestore
#else
#define MAYBE_MinimizeImmediatelyAfterRestore MinimizeImmediatelyAfterRestore
#endif
IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
MAYBE_MinimizeImmediatelyAfterRestore) {
CreatePanelParams params("Panel Test", gfx::Rect(), SHOW_AS_ACTIVE);
Panel* panel = CreatePanelWithParams(params);
scoped_ptr<NativePanelTesting> native_panel_testing(
CreateNativePanelTesting(panel));
PanelActiveStateObserver signal(panel, false);
panel->Minimize();
signal.Wait();
EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
panel->Restore();
EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
panel->Minimize();
EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, FocusLostOnMinimize) {
CreatePanelParams params("Initially Active", gfx::Rect(), SHOW_AS_ACTIVE);
Panel* panel = CreatePanelWithParams(params);
EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
PanelActiveStateObserver signal(panel, false);
panel->Minimize();
signal.Wait();
panel->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreateInactiveSwitchToActive) {
Panel* panel = CreateInactivePanel("1");
panel->Activate();
WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
panel->Close();
}
#if defined(OS_MACOSX)
#define MAYBE_MinimizeTwoPanelsWithoutTabbedWindow \
MinimizeTwoPanelsWithoutTabbedWindow
#else
#define MAYBE_MinimizeTwoPanelsWithoutTabbedWindow \
DISABLED_MinimizeTwoPanelsWithoutTabbedWindow
#endif
IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
MAYBE_MinimizeTwoPanelsWithoutTabbedWindow) {
CreatePanelParams params("Initially Inactive", gfx::Rect(), SHOW_AS_INACTIVE);
Panel* panel1 = CreatePanelWithParams(params);
Panel* panel2 = CreatePanelWithParams(params);
content::WindowedNotificationObserver signal(
chrome::NOTIFICATION_BROWSER_CLOSED,
content::Source<Browser>(browser()));
chrome::CloseWindow(browser());
signal.Wait();
EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state());
EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state());
panel1->Activate();
WaitForPanelActiveState(panel1, SHOW_AS_ACTIVE);
panel1->SetExpansionState(Panel::MINIMIZED);
base::MessageLoop::current()->RunUntilIdle();
WaitForPanelActiveState(panel1, SHOW_AS_INACTIVE);
EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
panel2->SetExpansionState(Panel::MINIMIZED);
base::MessageLoop::current()->RunUntilIdle();
WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE);
EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state());
WaitForPanelActiveState(panel1, SHOW_AS_INACTIVE);
EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
EXPECT_FALSE(panel1->IsActive());
EXPECT_FALSE(panel2->IsActive());
panel1->Close();
panel2->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
NonExtensionDomainPanelsCloseOnUninstall) {
base::DictionaryValue empty_value;
scoped_refptr<extensions::Extension> extension =
CreateExtension(FILE_PATH_LITERAL("TestExtension"),
extensions::Manifest::INTERNAL, empty_value);
std::string extension_app_name =
web_app::GenerateApplicationNameFromExtensionId(extension->id());
PanelManager* panel_manager = PanelManager::GetInstance();
EXPECT_EQ(0, panel_manager->num_panels());
CreatePanelParams params(extension_app_name, gfx::Rect(), SHOW_AS_ACTIVE);
std::string extension_domain_url(extensions::kExtensionScheme);
extension_domain_url += "://";
extension_domain_url += extension->id();
extension_domain_url += "/hello.html";
params.url = GURL(extension_domain_url);
Panel* panel = CreatePanelWithParams(params);
EXPECT_EQ(1, panel_manager->num_panels());
CreatePanelParams params1(extension_app_name, gfx::Rect(), SHOW_AS_ACTIVE);
params1.url = GURL(content::kAboutBlankURL);
Panel* panel1 = CreatePanelWithParams(params1);
EXPECT_EQ(2, panel_manager->num_panels());
scoped_refptr<extensions::Extension> extension_other =
CreateExtension(FILE_PATH_LITERAL("TestExtensionOther"),
extensions::Manifest::INTERNAL, empty_value);
std::string extension_app_name_other =
web_app::GenerateApplicationNameFromExtensionId(extension_other->id());
Panel* panel_other = CreatePanel(extension_app_name_other);
content::WindowedNotificationObserver signal(
chrome::NOTIFICATION_PANEL_CLOSED,
content::Source<Panel>(panel));
content::WindowedNotificationObserver signal1(
chrome::NOTIFICATION_PANEL_CLOSED,
content::Source<Panel>(panel1));
extensions::UnloadedExtensionInfo details(
extension.get(), extensions::UnloadedExtensionInfo::REASON_UNINSTALL);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
content::Source<Profile>(browser()->profile()),
content::Details<extensions::UnloadedExtensionInfo>(&details));
signal.Wait();
signal1.Wait();
EXPECT_EQ(panel_other, panel_manager->panels()[0]);
panel_other->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, OnBeforeUnloadOnClose) {
PanelManager* panel_manager = PanelManager::GetInstance();
EXPECT_EQ(0, panel_manager->num_panels());
const base::string16 title_first_close = base::UTF8ToUTF16("TitleFirstClose");
const base::string16 title_second_close =
base::UTF8ToUTF16("TitleSecondClose");
CreatePanelParams params("PanelTest1", gfx::Rect(0, 0, 300, 300),
SHOW_AS_ACTIVE);
params.url = ui_test_utils::GetTestUrl(
base::FilePath(kTestDir),
base::FilePath(FILE_PATH_LITERAL("onbeforeunload.html")));
Panel* panel = CreatePanelWithParams(params);
EXPECT_EQ(1, panel_manager->num_panels());
CloseWindowAndWait(panel);
EXPECT_EQ(0, panel_manager->num_panels());
}
#if defined(OS_MACOSX)
#define MAYBE_SizeClamping DISABLED_SizeClamping
#else
#define MAYBE_SizeClamping SizeClamping
#endif
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_SizeClamping) {
CreatePanelParams params("Panel", gfx::Rect(), SHOW_AS_ACTIVE);
Panel* panel = CreatePanelWithParams(params);
EXPECT_EQ(panel->min_size().width(), panel->GetBounds().width());
EXPECT_EQ(panel->min_size().height(), panel->GetBounds().height());
int reasonable_width = panel->min_size().width() + 10;
int reasonable_height = panel->min_size().height() + 20;
panel->Close();
CreatePanelParams params1("Panel1",
gfx::Rect(0, 0,
reasonable_width, reasonable_height),
SHOW_AS_ACTIVE);
panel = CreatePanelWithParams(params1);
EXPECT_EQ(reasonable_width, panel->GetBounds().width());
EXPECT_EQ(reasonable_height, panel->GetBounds().height());
panel->Close();
int given_height = 200;
CreatePanelParams params2("Panel2", gfx::Rect(0, 0, 0, given_height),
SHOW_AS_ACTIVE);
panel = CreatePanelWithParams(params2);
EXPECT_GT(panel->GetBounds().width(), 0);
EXPECT_EQ(given_height, panel->GetBounds().height());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
DISABLED_TightAutosizeAroundSingleLine) {
PanelManager::GetInstance()->enable_auto_sizing(true);
CreatePanelParams params("Panel", gfx::Rect(), SHOW_AS_ACTIVE);
params.url = GURL("data:text/html;charset=utf-8,<!doctype html><body>");
Panel* panel = CreatePanelWithParams(params);
WaitForStableInitialSize initial_resize(panel);
initial_resize.Wait();
int initial_width = panel->GetBounds().width();
int initial_height = panel->GetBounds().height();
WaitForAutoResizeWider enlarge(panel);
EXPECT_TRUE(content::ExecuteScript(
panel->GetWebContents(),
"document.body.innerHTML ="
" '<nobr>line of text and a <button>Button</button>';"));
enlarge.Wait();
EXPECT_GT(panel->GetBounds().width(), initial_width);
EXPECT_GT(panel->GetBounds().height(), initial_height);
panel->Close();
}
#if defined(OS_MACOSX)
#define MAYBE_DefaultMaxSizeOnDisplaySettingsChange \
DISABLED_DefaultMaxSizeOnDisplaySettingsChange
#else
#define MAYBE_DefaultMaxSizeOnDisplaySettingsChange \
DefaultMaxSizeOnDisplaySettingsChange
#endif
IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
MAYBE_DefaultMaxSizeOnDisplaySettingsChange) {
Panel* panel = CreatePanelWithBounds("1", gfx::Rect(0, 0, 240, 220));
gfx::Size old_max_size = panel->max_size();
gfx::Size old_full_size = panel->full_size();
gfx::Rect smaller_work_area(0, 0, 500, 300);
mock_display_settings_provider()->SetPrimaryDisplay(
smaller_work_area, smaller_work_area);
EXPECT_GT(old_max_size.width(), panel->max_size().width());
EXPECT_GT(old_max_size.height(), panel->max_size().height());
EXPECT_GT(smaller_work_area.width(), panel->max_size().width());
EXPECT_GT(smaller_work_area.height(), panel->max_size().height());
EXPECT_GT(old_full_size.width(), panel->full_size().width());
EXPECT_GT(old_full_size.height(), panel->full_size().height());
EXPECT_GE(panel->max_size().width(), panel->full_size().width());
EXPECT_GE(panel->max_size().height(), panel->full_size().height());
panel->Close();
}
#if defined(OS_MACOSX)
#define MAYBE_CustomMaxSizeOnDisplaySettingsChange \
DISABLED_CustomMaxSizeOnDisplaySettingsChange
#else
#define MAYBE_CustomMaxSizeOnDisplaySettingsChange \
CustomMaxSizeOnDisplaySettingsChange
#endif
IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
MAYBE_CustomMaxSizeOnDisplaySettingsChange) {
PanelManager* panel_manager = PanelManager::GetInstance();
Panel* panel = CreatePanelWithBounds("1", gfx::Rect(0, 0, 240, 220));
gfx::Size bigger_size = gfx::Size(550, 400);
gfx::Point mouse_location = panel->GetBounds().origin();
panel_manager->StartResizingByMouse(panel,
mouse_location,
panel::RESIZE_TOP_LEFT);
mouse_location.Offset(panel->GetBounds().width() - bigger_size.width(),
panel->GetBounds().height() - bigger_size.height());
panel_manager->ResizeByMouse(mouse_location);
panel_manager->EndResizingByMouse(false);
gfx::Size old_max_size = panel->max_size();
EXPECT_EQ(bigger_size, old_max_size);
gfx::Size old_full_size = panel->full_size();
EXPECT_EQ(bigger_size, old_full_size);
gfx::Rect smaller_work_area(0, 0, 500, 300);
mock_display_settings_provider()->SetPrimaryDisplay(
smaller_work_area, smaller_work_area);
EXPECT_GT(old_max_size.width(), panel->max_size().width());
EXPECT_GT(old_max_size.height(), panel->max_size().height());
EXPECT_GE(smaller_work_area.width(), panel->max_size().width());
EXPECT_EQ(smaller_work_area.height(), panel->max_size().height());
EXPECT_GT(old_full_size.width(), panel->full_size().width());
EXPECT_GT(old_full_size.height(), panel->full_size().height());
EXPECT_GE(panel->max_size().width(), panel->full_size().width());
EXPECT_GE(panel->max_size().height(), panel->full_size().height());
EXPECT_EQ(smaller_work_area.height(), panel->full_size().height());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DevTools) {
CreatePanelParams params("1", gfx::Rect(0, 0, 200, 220), SHOW_AS_ACTIVE);
GURL url(ui_test_utils::GetTestUrl(
base::FilePath(kTestDir),
base::FilePath(FILE_PATH_LITERAL("update-preferred-size.html"))));
params.url = url;
Panel* panel = CreatePanelWithParams(params);
size_t num_browsers = 1;
EXPECT_EQ(num_browsers, chrome::GetBrowserCount(
browser()->profile(),
browser()->host_desktop_type()));
content::WindowedNotificationObserver signal(
chrome::NOTIFICATION_BROWSER_WINDOW_READY,
content::NotificationService::AllSources());
EXPECT_TRUE(panel->ExecuteCommandIfEnabled(IDC_DEV_TOOLS));
signal.Wait();
++num_browsers;
EXPECT_EQ(num_browsers, chrome::GetBrowserCount(
browser()->profile(),
browser()->host_desktop_type()));
for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) {
if (*iter == browser())
continue;
ASSERT_TRUE((*iter)->is_devtools());
}
panel->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DevToolsConsole) {
CreatePanelParams params("1", gfx::Rect(0, 0, 200, 220), SHOW_AS_ACTIVE);
GURL url(ui_test_utils::GetTestUrl(
base::FilePath(kTestDir),
base::FilePath(FILE_PATH_LITERAL("update-preferred-size.html"))));
params.url = url;
Panel* panel = CreatePanelWithParams(params);
size_t num_browsers = 1;
EXPECT_EQ(num_browsers, chrome::GetBrowserCount(
browser()->profile(),
browser()->host_desktop_type()));
content::WindowedNotificationObserver signal(
chrome::NOTIFICATION_BROWSER_WINDOW_READY,
content::NotificationService::AllSources());
EXPECT_TRUE(panel->ExecuteCommandIfEnabled(IDC_DEV_TOOLS_CONSOLE));
signal.Wait();
++num_browsers;
EXPECT_EQ(num_browsers, chrome::GetBrowserCount(
browser()->profile(),
browser()->host_desktop_type()));
for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) {
if (*iter == browser())
continue;
ASSERT_TRUE((*iter)->is_devtools());
}
panel->Close();
}
#if defined(OS_WIN)
#define MAYBE_Accelerator Accelerator
#else
#define MAYBE_Accelerator DISABLED_Accelerator
#endif
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_Accelerator) {
PanelManager* panel_manager = PanelManager::GetInstance();
CreatePanelParams params("1", gfx::Rect(), SHOW_AS_ACTIVE);
GURL url(ui_test_utils::GetTestUrl(
base::FilePath(kTestDir),
base::FilePath(FILE_PATH_LITERAL("update-preferred-size.html"))));
params.url = url;
Panel* panel = CreatePanelWithParams(params);
EXPECT_EQ(1, panel_manager->num_panels());
content::WindowedNotificationObserver signal(
chrome::NOTIFICATION_PANEL_CLOSED,
content::Source<Panel>(panel));
#if defined(USE_AURA)
double now = ui::EventTimeForNow().InSecondsF();
content::NativeWebKeyboardEvent key_event(
ui::ET_KEY_PRESSED,
false,
ui::VKEY_W,
ui::EF_CONTROL_DOWN,
now);
#elif defined(OS_WIN)
::MSG key_msg = { NULL, WM_KEYDOWN, ui::VKEY_W, 0 };
content::NativeWebKeyboardEvent key_event(key_msg);
key_event.modifiers = content::NativeWebKeyboardEvent::ControlKey;
#else
content::NativeWebKeyboardEvent key_event;
#endif
panel->HandleKeyboardEvent(key_event);
signal.Wait();
EXPECT_EQ(0, panel_manager->num_panels());
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
HideDockedPanelCreatedBeforeFullScreenMode) {
Panel* panel = CreatePanel("PanelTest");
scoped_ptr<NativePanelTesting> panel_testing(CreateNativePanelTesting(panel));
EXPECT_TRUE(panel_testing->IsWindowVisible());
mock_display_settings_provider()->EnableFullScreenMode(true);
#if defined(OS_LINUX)
EXPECT_TRUE(panel_testing->IsWindowVisible());
#else
EXPECT_FALSE(panel_testing->IsWindowVisible());
#endif
mock_display_settings_provider()->EnableFullScreenMode(false);
EXPECT_TRUE(panel_testing->IsWindowVisible());
PanelManager::GetInstance()->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
HideDockedPanelCreatedOnFullScreenMode) {
mock_display_settings_provider()->EnableFullScreenMode(true);
CreatePanelParams params("1", gfx::Rect(0, 0, 250, 200), SHOW_AS_ACTIVE);
params.wait_for_fully_created = false;
Panel* panel = CreatePanelWithParams(params);
scoped_ptr<NativePanelTesting> panel_testing(
CreateNativePanelTesting(panel));
EXPECT_FALSE(panel_testing->IsWindowVisible());
mock_display_settings_provider()->EnableFullScreenMode(false);
EXPECT_TRUE(panel_testing->IsWindowVisible());
PanelManager::GetInstance()->CloseAll();
}
class PanelExtensionApiTest : public ExtensionApiTest {
protected:
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
ExtensionApiTest::SetUpCommandLine(command_line);
command_line->AppendSwitch(switches::kEnablePanels);
}
};
#if defined(OS_LINUX) || (!defined(OS_WIN) && defined(USE_AURA)) || \
defined(OS_MACOSX)
#define MAYBE_FocusChangeEventOnMinimize DISABLED_FocusChangeEventOnMinimize
#else
#define MAYBE_FocusChangeEventOnMinimize FocusChangeEventOnMinimize
#endif
IN_PROC_BROWSER_TEST_F(PanelExtensionApiTest,
MAYBE_FocusChangeEventOnMinimize) {
ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
ASSERT_TRUE(RunExtensionTest("panels/focus_change_on_minimize")) << message_;
}