This source file includes following definitions.
- visible_fraction_
- OnImmersiveRevealStarted
- OnImmersiveRevealEnded
- OnImmersiveFullscreenExited
- SetVisibleFraction
- GetVisibleBoundsInScreen
- is_enabled
- visible_fraction
- OnEvent
- content_view_
- controller
- content_view
- top_container
- widget
- window
- delegate
- top_edge_hover_timer_running
- mouse_x_when_hit_top
- SetUp
- SetEnabled
- AttemptReveal
- AttemptUnreveal
- SetHovered
- MoveMouse
- AttemptRevealStateChange
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "ash/wm/immersive_fullscreen_controller.h"
#include "ash/display/display_manager.h"
#include "ash/root_window_controller.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shelf/shelf_types.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/cursor_client.h"
#include "ui/aura/env.h"
#include "ui/aura/test/event_generator.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/events/event_utils.h"
#include "ui/events/test/test_event_handler.h"
#include "ui/gfx/animation/slide_animation.h"
#include "ui/views/bubble/bubble_delegate.h"
#include "ui/views/controls/native/native_view_host.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
#if defined(OS_CHROMEOS)
namespace ash {
namespace {
class MockImmersiveFullscreenControllerDelegate
: public ImmersiveFullscreenController::Delegate {
public:
MockImmersiveFullscreenControllerDelegate(views::View* top_container_view)
: top_container_view_(top_container_view),
enabled_(false),
visible_fraction_(1) {
}
virtual ~MockImmersiveFullscreenControllerDelegate() {}
virtual void OnImmersiveRevealStarted() OVERRIDE {
enabled_ = true;
visible_fraction_ = 0;
}
virtual void OnImmersiveRevealEnded() OVERRIDE {
visible_fraction_ = 0;
}
virtual void OnImmersiveFullscreenExited() OVERRIDE {
enabled_ = false;
visible_fraction_ = 1;
}
virtual void SetVisibleFraction(double visible_fraction) OVERRIDE {
visible_fraction_ = visible_fraction;
}
virtual std::vector<gfx::Rect> GetVisibleBoundsInScreen() const OVERRIDE {
std::vector<gfx::Rect> bounds_in_screen;
bounds_in_screen.push_back(top_container_view_->GetBoundsInScreen());
return bounds_in_screen;
}
bool is_enabled() const {
return enabled_;
}
double visible_fraction() const {
return visible_fraction_;
}
private:
views::View* top_container_view_;
bool enabled_;
double visible_fraction_;
DISALLOW_COPY_AND_ASSIGN(MockImmersiveFullscreenControllerDelegate);
};
class ConsumeEventHandler : public ui::test::TestEventHandler {
public:
ConsumeEventHandler() {}
virtual ~ConsumeEventHandler() {}
private:
virtual void OnEvent(ui::Event* event) OVERRIDE {
ui::test::TestEventHandler::OnEvent(event);
if (event->cancelable())
event->SetHandled();
}
DISALLOW_COPY_AND_ASSIGN(ConsumeEventHandler);
};
}
class ImmersiveFullscreenControllerTest : public ash::test::AshTestBase {
public:
enum Modality {
MODALITY_MOUSE,
MODALITY_GESTURE_TAP,
MODALITY_GESTURE_SCROLL
};
ImmersiveFullscreenControllerTest()
: widget_(NULL),
top_container_(NULL),
content_view_(NULL) {}
virtual ~ImmersiveFullscreenControllerTest() {}
ImmersiveFullscreenController* controller() {
return controller_.get();
}
views::NativeViewHost* content_view() {
return content_view_;
}
views::View* top_container() {
return top_container_;
}
views::Widget* widget() { return widget_; }
aura::Window* window() {
return widget_->GetNativeWindow();
}
MockImmersiveFullscreenControllerDelegate* delegate() {
return delegate_.get();
}
bool top_edge_hover_timer_running() const {
return controller_->top_edge_hover_timer_.IsRunning();
}
int mouse_x_when_hit_top() const {
return controller_->mouse_x_when_hit_top_in_screen_;
}
virtual void SetUp() OVERRIDE {
ash::test::AshTestBase::SetUp();
widget_ = new views::Widget();
views::Widget::InitParams params;
params.context = CurrentContext();
widget_->Init(params);
widget_->Show();
window()->SetProperty(aura::client::kShowStateKey,
ui::SHOW_STATE_FULLSCREEN);
gfx::Size window_size = widget_->GetWindowBoundsInScreen().size();
content_view_ = new views::NativeViewHost();
content_view_->SetBounds(0, 0, window_size.width(), window_size.height());
widget_->GetContentsView()->AddChildView(content_view_);
top_container_ = new views::View();
top_container_->SetBounds(
0, 0, window_size.width(), 100);
top_container_->SetFocusable(true);
widget_->GetContentsView()->AddChildView(top_container_);
delegate_.reset(
new MockImmersiveFullscreenControllerDelegate(top_container_));
controller_.reset(new ImmersiveFullscreenController);
controller_->Init(delegate_.get(), widget_, top_container_);
controller_->SetupForTest();
}
void SetEnabled(bool enabled) {
controller_->SetEnabled(ImmersiveFullscreenController::WINDOW_TYPE_OTHER,
enabled);
}
void AttemptReveal(Modality modality) {
ASSERT_NE(modality, MODALITY_GESTURE_TAP);
AttemptRevealStateChange(true, modality);
}
void AttemptUnreveal(Modality modality) {
AttemptRevealStateChange(false, modality);
}
void SetHovered(bool is_mouse_hovered) {
MoveMouse(0, is_mouse_hovered ? 10 : top_container_->height() + 100);
}
void MoveMouse(int x, int y) {
gfx::Point screen_position(x, y);
views::View::ConvertPointToScreen(top_container_, &screen_position);
GetEventGenerator().MoveMouseTo(screen_position.x(), screen_position.y());
if (controller()->top_edge_hover_timer_.IsRunning()) {
controller()->top_edge_hover_timer_.user_task().Run();
controller()->top_edge_hover_timer_.Stop();
}
}
private:
void AttemptRevealStateChange(bool revealed, Modality modality) {
gfx::Point event_position(0, revealed ? 0 : top_container_->height() + 100);
switch (modality) {
case MODALITY_MOUSE: {
MoveMouse(event_position.x(), event_position.y());
break;
}
case MODALITY_GESTURE_TAP: {
gfx::Point screen_position = event_position;
views::View::ConvertPointToScreen(top_container_, &screen_position);
aura::test::EventGenerator& event_generator(GetEventGenerator());
event_generator.MoveTouch(event_position);
event_generator.PressTouch();
event_generator.ReleaseTouch();
break;
}
case MODALITY_GESTURE_SCROLL: {
gfx::Point start(0, revealed ? 0 : top_container_->height() - 2);
gfx::Vector2d scroll_delta(0, 40);
gfx::Point end = revealed ? start + scroll_delta : start - scroll_delta;
views::View::ConvertPointToScreen(top_container_, &start);
views::View::ConvertPointToScreen(top_container_, &end);
aura::test::EventGenerator& event_generator(GetEventGenerator());
event_generator.GestureScrollSequence(
start, end,
base::TimeDelta::FromMilliseconds(30), 1);
break;
}
}
}
scoped_ptr<ImmersiveFullscreenController> controller_;
scoped_ptr<MockImmersiveFullscreenControllerDelegate> delegate_;
views::Widget* widget_;
views::View* top_container_;
views::NativeViewHost* content_view_;
DISALLOW_COPY_AND_ASSIGN(ImmersiveFullscreenControllerTest);
};
TEST_F(ImmersiveFullscreenControllerTest, Delegate) {
EXPECT_FALSE(controller()->IsEnabled());
EXPECT_FALSE(controller()->IsRevealed());
EXPECT_FALSE(delegate()->is_enabled());
SetEnabled(true);
EXPECT_TRUE(controller()->IsEnabled());
EXPECT_FALSE(controller()->IsRevealed());
EXPECT_TRUE(delegate()->is_enabled());
EXPECT_EQ(0, delegate()->visible_fraction());
AttemptReveal(MODALITY_MOUSE);
EXPECT_TRUE(controller()->IsEnabled());
EXPECT_TRUE(controller()->IsRevealed());
EXPECT_TRUE(delegate()->is_enabled());
EXPECT_EQ(1, delegate()->visible_fraction());
SetEnabled(false);
EXPECT_FALSE(controller()->IsEnabled());
EXPECT_FALSE(controller()->IsRevealed());
EXPECT_FALSE(delegate()->is_enabled());
}
TEST_F(ImmersiveFullscreenControllerTest, RevealedLock) {
scoped_ptr<ImmersiveRevealedLock> lock1;
scoped_ptr<ImmersiveRevealedLock> lock2;
EXPECT_FALSE(controller()->IsEnabled());
lock1.reset(controller()->GetRevealedLock(
ImmersiveFullscreenController::ANIMATE_REVEAL_NO));
EXPECT_FALSE(controller()->IsEnabled());
EXPECT_FALSE(controller()->IsRevealed());
SetEnabled(true);
EXPECT_TRUE(controller()->IsEnabled());
EXPECT_TRUE(controller()->IsRevealed());
SetEnabled(false);
EXPECT_FALSE(controller()->IsEnabled());
EXPECT_FALSE(controller()->IsRevealed());
lock1.reset();
EXPECT_FALSE(controller()->IsEnabled());
EXPECT_FALSE(controller()->IsRevealed());
SetEnabled(true);
EXPECT_TRUE(controller()->IsEnabled());
EXPECT_FALSE(controller()->IsRevealed());
lock1.reset(controller()->GetRevealedLock(
ImmersiveFullscreenController::ANIMATE_REVEAL_NO));
EXPECT_TRUE(controller()->IsRevealed());
lock2.reset(controller()->GetRevealedLock(
ImmersiveFullscreenController::ANIMATE_REVEAL_NO));
lock1.reset();
EXPECT_TRUE(controller()->IsRevealed());
lock2.reset();
EXPECT_FALSE(controller()->IsRevealed());
}
TEST_F(ImmersiveFullscreenControllerTest, OnMouseEvent) {
UpdateDisplay("800x600,800x600");
ash::DisplayLayout display_layout(ash::DisplayLayout::RIGHT, 0);
ash::Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays(
display_layout);
SetEnabled(true);
ASSERT_TRUE(controller()->IsEnabled());
ASSERT_FALSE(controller()->IsRevealed());
aura::test::EventGenerator& event_generator(GetEventGenerator());
gfx::Rect top_container_bounds_in_screen =
top_container()->GetBoundsInScreen();
gfx::Point top_edge_pos(top_container_bounds_in_screen.x() + 100,
top_container_bounds_in_screen.y());
ui::MouseEvent wheel(
ui::ET_MOUSEWHEEL, top_edge_pos, top_edge_pos, ui::EF_NONE, ui::EF_NONE);
event_generator.Dispatch(&wheel);
EXPECT_FALSE(top_edge_hover_timer_running());
event_generator.MoveMouseTo(top_edge_pos);
EXPECT_TRUE(top_edge_hover_timer_running());
EXPECT_EQ(top_edge_pos.x(), mouse_x_when_hit_top());
event_generator.MoveMouseBy(0, 3);
EXPECT_FALSE(top_edge_hover_timer_running());
event_generator.MoveMouseTo(top_edge_pos);
EXPECT_TRUE(top_edge_hover_timer_running());
EXPECT_EQ(top_edge_pos.x(), mouse_x_when_hit_top());
event_generator.MoveMouseBy(1, 0);
EXPECT_TRUE(top_edge_hover_timer_running());
EXPECT_EQ(top_edge_pos.x(), mouse_x_when_hit_top());
event_generator.MoveMouseBy(-1, 0);
EXPECT_TRUE(top_edge_hover_timer_running());
EXPECT_EQ(top_edge_pos.x(), mouse_x_when_hit_top());
event_generator.MoveMouseTo(top_edge_pos.x() + 100, top_edge_pos.y());
EXPECT_TRUE(top_edge_hover_timer_running());
EXPECT_EQ(top_edge_pos.x() + 100, mouse_x_when_hit_top());
event_generator.MoveMouseTo(top_container_bounds_in_screen.right() + 1,
top_container_bounds_in_screen.y());
EXPECT_FALSE(top_edge_hover_timer_running());
AttemptReveal(MODALITY_MOUSE);
event_generator.MoveMouseTo(top_container_bounds_in_screen.x(),
top_container_bounds_in_screen.bottom() + 1);
EXPECT_TRUE(controller()->IsRevealed());
event_generator.ClickLeftButton();
EXPECT_FALSE(controller()->IsRevealed());
AttemptReveal(MODALITY_MOUSE);
EXPECT_TRUE(controller()->IsRevealed());
event_generator.MoveMouseTo(top_container_bounds_in_screen.x(),
top_container_bounds_in_screen.bottom() + 50);
EXPECT_FALSE(controller()->IsRevealed());
views::Widget* widget = top_container()->GetWidget();
widget->SetCapture(top_container());
AttemptReveal(MODALITY_MOUSE);
EXPECT_FALSE(controller()->IsRevealed());
widget->ReleaseCapture();
AttemptReveal(MODALITY_MOUSE);
EXPECT_TRUE(controller()->IsRevealed());
widget->SetCapture(top_container());
event_generator.MoveMouseTo(top_container_bounds_in_screen.x(),
top_container_bounds_in_screen.bottom() + 51);
EXPECT_TRUE(controller()->IsRevealed());
widget->ReleaseCapture();
EXPECT_FALSE(controller()->IsRevealed());
}
TEST_F(ImmersiveFullscreenControllerTest, Inactive) {
views::Widget* popup_widget = views::Widget::CreateWindowWithContextAndBounds(
NULL,
CurrentContext(),
gfx::Rect(0, 0, 200, 200));
popup_widget->Show();
ASSERT_FALSE(top_container()->GetWidget()->IsActive());
SetEnabled(true);
ASSERT_TRUE(controller()->IsEnabled());
ASSERT_FALSE(controller()->IsRevealed());
gfx::Rect top_container_bounds_in_screen =
top_container()->GetBoundsInScreen();
gfx::Rect popup_bounds_in_screen = popup_widget->GetWindowBoundsInScreen();
ASSERT_EQ(top_container_bounds_in_screen.origin().ToString(),
popup_bounds_in_screen.origin().ToString());
ASSERT_GT(top_container_bounds_in_screen.right(),
popup_bounds_in_screen.right());
MoveMouse(popup_bounds_in_screen.x(),
top_container_bounds_in_screen.y());
EXPECT_FALSE(controller()->IsRevealed());
MoveMouse(top_container_bounds_in_screen.right() - 1,
top_container_bounds_in_screen.y());
EXPECT_TRUE(controller()->IsRevealed());
MoveMouse(top_container_bounds_in_screen.right() - 1,
top_container_bounds_in_screen.bottom() - 1);
EXPECT_TRUE(controller()->IsRevealed());
MoveMouse(top_container_bounds_in_screen.right() - 1,
top_container_bounds_in_screen.bottom() + 50);
EXPECT_FALSE(controller()->IsRevealed());
MoveMouse(top_container_bounds_in_screen.right() - 1,
top_container_bounds_in_screen.y());
EXPECT_TRUE(controller()->IsRevealed());
MoveMouse(top_container_bounds_in_screen.x(),
top_container_bounds_in_screen.bottom() + 50);
EXPECT_FALSE(controller()->IsRevealed());
}
TEST_F(ImmersiveFullscreenControllerTest, MouseEventsVerticalDisplayLayout) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("800x600,800x600");
ash::DisplayLayout display_layout(ash::DisplayLayout::TOP, 0);
ash::Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays(
display_layout);
SetEnabled(true);
ASSERT_TRUE(controller()->IsEnabled());
ASSERT_FALSE(controller()->IsRevealed());
aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows();
ASSERT_EQ(root_windows[0],
top_container()->GetWidget()->GetNativeWindow()->GetRootWindow());
gfx::Rect primary_root_window_bounds_in_screen =
root_windows[0]->GetBoundsInScreen();
int x = primary_root_window_bounds_in_screen.x() + 10;
int y_top_edge = primary_root_window_bounds_in_screen.y();
aura::test::EventGenerator& event_generator(GetEventGenerator());
event_generator.MoveMouseTo(x, y_top_edge + 1);
EXPECT_TRUE(top_edge_hover_timer_running());
EXPECT_EQ(y_top_edge + 1,
aura::Env::GetInstance()->last_mouse_location().y());
event_generator.MoveMouseTo(x, y_top_edge);
EXPECT_TRUE(top_edge_hover_timer_running());
EXPECT_NE(y_top_edge,
aura::Env::GetInstance()->last_mouse_location().y());
event_generator.MoveMouseTo(x, y_top_edge - 2);
EXPECT_TRUE(top_edge_hover_timer_running());
event_generator.MoveMouseTo(x, y_top_edge - 20);
EXPECT_FALSE(top_edge_hover_timer_running());
event_generator.MoveMouseTo(x, y_top_edge - 2);
event_generator.MoveMouseTo(x, y_top_edge + 1);
MoveMouse(x, y_top_edge - 2);
EXPECT_TRUE(controller()->IsRevealed());
event_generator.MoveMouseTo(x + 10, y_top_edge - 3);
EXPECT_TRUE(controller()->IsRevealed());
event_generator.MoveMouseTo(x, y_top_edge - 20);
EXPECT_FALSE(controller()->IsRevealed());
views::Widget* popup_widget = views::Widget::CreateWindowWithContextAndBounds(
NULL,
CurrentContext(),
gfx::Rect(0, 200, 100, 100));
popup_widget->Show();
ASSERT_FALSE(top_container()->GetWidget()->IsActive());
ASSERT_FALSE(top_container()->GetBoundsInScreen().Intersects(
popup_widget->GetWindowBoundsInScreen()));
event_generator.MoveMouseTo(x, y_top_edge + 1);
MoveMouse(x, y_top_edge - 2);
EXPECT_TRUE(controller()->IsRevealed());
}
TEST_F(ImmersiveFullscreenControllerTest, MouseHoveredWithoutMoving) {
SetEnabled(true);
scoped_ptr<ImmersiveRevealedLock> lock;
SetHovered(true);
EXPECT_FALSE(controller()->IsRevealed());
lock.reset(controller()->GetRevealedLock(
ImmersiveFullscreenController::ANIMATE_REVEAL_NO));
EXPECT_TRUE(controller()->IsRevealed());
lock.reset();
EXPECT_TRUE(controller()->IsRevealed());
SetHovered(false);
EXPECT_FALSE(controller()->IsRevealed());
SetEnabled(false);
SetHovered(true);
EXPECT_FALSE(controller()->IsRevealed());
SetEnabled(true);
EXPECT_FALSE(controller()->IsRevealed());
SetEnabled(false);
SetHovered(true);
lock.reset(controller()->GetRevealedLock(
ImmersiveFullscreenController::ANIMATE_REVEAL_NO));
EXPECT_FALSE(controller()->IsRevealed());
SetEnabled(true);
EXPECT_TRUE(controller()->IsRevealed());
lock.reset();
EXPECT_TRUE(controller()->IsRevealed());
SetHovered(false);
EXPECT_FALSE(controller()->IsRevealed());
}
TEST_F(ImmersiveFullscreenControllerTest, DifferentModalityEnterExit) {
SetEnabled(true);
EXPECT_TRUE(controller()->IsEnabled());
EXPECT_FALSE(controller()->IsRevealed());
AttemptReveal(MODALITY_GESTURE_SCROLL);
EXPECT_TRUE(controller()->IsRevealed());
MoveMouse(1, 1);
EXPECT_TRUE(controller()->IsRevealed());
AttemptUnreveal(MODALITY_MOUSE);
EXPECT_FALSE(controller()->IsRevealed());
AttemptReveal(MODALITY_GESTURE_SCROLL);
EXPECT_TRUE(controller()->IsRevealed());
AttemptUnreveal(MODALITY_GESTURE_TAP);
EXPECT_FALSE(controller()->IsRevealed());
AttemptReveal(MODALITY_MOUSE);
EXPECT_TRUE(controller()->IsRevealed());
AttemptUnreveal(MODALITY_GESTURE_SCROLL);
EXPECT_FALSE(controller()->IsRevealed());
AttemptReveal(MODALITY_MOUSE);
EXPECT_TRUE(controller()->IsRevealed());
AttemptUnreveal(MODALITY_GESTURE_TAP);
EXPECT_FALSE(controller()->IsRevealed());
}
TEST_F(ImmersiveFullscreenControllerTest, EndRevealViaGesture) {
SetEnabled(true);
EXPECT_TRUE(controller()->IsEnabled());
EXPECT_FALSE(controller()->IsRevealed());
AttemptReveal(MODALITY_MOUSE);
top_container()->RequestFocus();
EXPECT_TRUE(controller()->IsRevealed());
AttemptUnreveal(MODALITY_GESTURE_SCROLL);
EXPECT_FALSE(controller()->IsRevealed());
EXPECT_FALSE(top_container()->HasFocus());
AttemptReveal(MODALITY_MOUSE);
scoped_ptr<ImmersiveRevealedLock> lock(controller()->GetRevealedLock(
ImmersiveFullscreenController::ANIMATE_REVEAL_NO));
EXPECT_TRUE(controller()->IsRevealed());
AttemptUnreveal(MODALITY_GESTURE_SCROLL);
EXPECT_TRUE(controller()->IsRevealed());
lock.reset();
EXPECT_FALSE(controller()->IsRevealed());
}
TEST_F(ImmersiveFullscreenControllerTest, RevealViaGestureChildConsumesEvents) {
SetEnabled(true);
EXPECT_TRUE(controller()->IsEnabled());
EXPECT_FALSE(controller()->IsRevealed());
aura::test::TestWindowDelegate child_delegate;
scoped_ptr<aura::Window> child(
CreateTestWindowInShellWithDelegateAndType(&child_delegate,
ui::wm::WINDOW_TYPE_CONTROL,
1234,
gfx::Rect()));
content_view()->Attach(child.get());
child->Show();
ConsumeEventHandler handler;
child->AddPreTargetHandler(&handler);
AttemptReveal(MODALITY_GESTURE_SCROLL);
EXPECT_TRUE(controller()->IsRevealed());
EXPECT_EQ(0, handler.num_touch_events());
AttemptUnreveal(MODALITY_GESTURE_TAP);
EXPECT_FALSE(controller()->IsRevealed());
EXPECT_GT(handler.num_touch_events(), 0);
child->RemovePreTargetHandler(&handler);
}
TEST_F(ImmersiveFullscreenControllerTest, EventsDoNotLeakToWindowUnderneath) {
gfx::Rect window_bounds = window()->GetBoundsInScreen();
aura::test::TestWindowDelegate child_delegate;
scoped_ptr<aura::Window> behind(CreateTestWindowInShellWithDelegate(
&child_delegate, 1234, window_bounds));
behind->Show();
behind->SetBounds(window_bounds);
widget()->StackAbove(behind.get());
EXPECT_EQ(behind->GetBoundsInScreen().y(), window()->GetBoundsInScreen().y());
int top = behind->GetBoundsInScreen().y();
ui::TouchEvent touch(ui::ET_TOUCH_MOVED, gfx::Point(10, top), 0,
ui::EventTimeForNow());
ui::EventTarget* root = window()->GetRootWindow();
ui::EventTargeter* targeter = root->GetEventTargeter();
EXPECT_EQ(window(), targeter->FindTargetForEvent(root, &touch));
SetEnabled(true);
EXPECT_FALSE(controller()->IsRevealed());
EXPECT_EQ(behind->GetBoundsInScreen().y(), window()->GetBoundsInScreen().y());
top = behind->GetBoundsInScreen().y();
ui::TouchEvent touch2(ui::ET_TOUCH_MOVED, gfx::Point(10, top), 0,
ui::EventTimeForNow());
EXPECT_EQ(window(), targeter->FindTargetForEvent(root, &touch2));
}
#if !defined(OS_WIN)
TEST_F(ImmersiveFullscreenControllerTest, Focus) {
views::View* child_view = new views::View();
child_view->SetBounds(0, 0, 10, 10);
child_view->SetFocusable(true);
top_container()->AddChildView(child_view);
views::View* unrelated_view = new views::View();
unrelated_view->SetBounds(0, 100, 10, 10);
unrelated_view->SetFocusable(true);
top_container()->parent()->AddChildView(unrelated_view);
views::FocusManager* focus_manager =
top_container()->GetWidget()->GetFocusManager();
SetEnabled(true);
AttemptReveal(MODALITY_MOUSE);
child_view->RequestFocus();
focus_manager->ClearFocus();
EXPECT_TRUE(controller()->IsRevealed());
child_view->RequestFocus();
SetHovered(false);
EXPECT_TRUE(controller()->IsRevealed());
focus_manager->ClearFocus();
EXPECT_FALSE(controller()->IsRevealed());
child_view->RequestFocus();
EXPECT_TRUE(controller()->IsRevealed());
unrelated_view->RequestFocus();
EXPECT_FALSE(controller()->IsRevealed());
child_view->RequestFocus();
EXPECT_TRUE(controller()->IsRevealed());
SetEnabled(false);
EXPECT_FALSE(controller()->IsRevealed());
unrelated_view->RequestFocus();
SetEnabled(true);
EXPECT_FALSE(controller()->IsRevealed());
child_view->RequestFocus();
EXPECT_TRUE(controller()->IsRevealed());
SetEnabled(false);
scoped_ptr<ImmersiveRevealedLock> lock(controller()->GetRevealedLock(
ImmersiveFullscreenController::ANIMATE_REVEAL_NO));
EXPECT_FALSE(controller()->IsRevealed());
unrelated_view->RequestFocus();
SetEnabled(true);
EXPECT_TRUE(controller()->IsRevealed());
lock.reset();
EXPECT_FALSE(controller()->IsRevealed());
}
TEST_F(ImmersiveFullscreenControllerTest, Transient) {
views::Widget* top_container_widget = top_container()->GetWidget();
SetEnabled(true);
ASSERT_FALSE(controller()->IsRevealed());
views::Widget::InitParams transient_params;
transient_params.ownership =
views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
transient_params.parent = top_container_widget->GetNativeView();
transient_params.bounds = gfx::Rect(0, 100, 100, 100);
scoped_ptr<views::Widget> transient_widget(new views::Widget());
transient_widget->Init(transient_params);
EXPECT_FALSE(controller()->IsRevealed());
AttemptReveal(MODALITY_MOUSE);
EXPECT_TRUE(controller()->IsRevealed());
transient_widget->Show();
SetHovered(false);
EXPECT_TRUE(controller()->IsRevealed());
transient_widget.reset();
EXPECT_FALSE(controller()->IsRevealed());
views::Widget::InitParams non_transient_params;
non_transient_params.ownership =
views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
non_transient_params.context = top_container_widget->GetNativeView();
non_transient_params.bounds = gfx::Rect(0, 100, 100, 100);
scoped_ptr<views::Widget> non_transient_widget(new views::Widget());
non_transient_widget->Init(non_transient_params);
EXPECT_FALSE(controller()->IsRevealed());
AttemptReveal(MODALITY_MOUSE);
EXPECT_TRUE(controller()->IsRevealed());
non_transient_widget->Show();
SetHovered(false);
EXPECT_FALSE(controller()->IsRevealed());
}
TEST_F(ImmersiveFullscreenControllerTest, Bubbles) {
scoped_ptr<ImmersiveRevealedLock> revealed_lock;
views::Widget* top_container_widget = top_container()->GetWidget();
views::View* child_view = new views::View();
child_view->SetBounds(0, 0, 10, 10);
top_container()->AddChildView(child_view);
views::View* unrelated_view = new views::View();
unrelated_view->SetBounds(0, 100, 10, 10);
top_container()->parent()->AddChildView(unrelated_view);
SetEnabled(true);
ASSERT_FALSE(controller()->IsRevealed());
views::Widget* bubble_widget1(views::BubbleDelegateView::CreateBubble(
new views::BubbleDelegateView(child_view, views::BubbleBorder::NONE)));
bubble_widget1->Show();
EXPECT_TRUE(controller()->IsRevealed());
top_container_widget->Activate();
AttemptReveal(MODALITY_MOUSE);
revealed_lock.reset(controller()->GetRevealedLock(
ImmersiveFullscreenController::ANIMATE_REVEAL_NO));
EXPECT_TRUE(controller()->IsRevealed());
views::Widget* bubble_widget2 = views::BubbleDelegateView::CreateBubble(
new views::BubbleDelegateView(child_view, views::BubbleBorder::NONE));
bubble_widget2->Show();
EXPECT_TRUE(controller()->IsRevealed());
revealed_lock.reset();
SetHovered(false);
EXPECT_TRUE(controller()->IsRevealed());
bubble_widget2->Close();
EXPECT_FALSE(controller()->IsRevealed());
views::Widget* bubble_widget3 = views::BubbleDelegateView::CreateBubble(
new views::BubbleDelegateView(child_view, views::BubbleBorder::NONE));
bubble_widget3->Show();
SetHovered(true);
EXPECT_TRUE(controller()->IsRevealed());
top_container_widget->Activate();
EXPECT_TRUE(controller()->IsRevealed());
SetHovered(false);
EXPECT_FALSE(controller()->IsRevealed());
views::BubbleDelegateView* bubble_delegate4(new views::BubbleDelegateView(
child_view, views::BubbleBorder::NONE));
bubble_delegate4->set_use_focusless(true);
views::Widget* bubble_widget4(views::BubbleDelegateView::CreateBubble(
bubble_delegate4));
bubble_widget4->Show();
views::BubbleDelegateView* bubble_delegate5(new views::BubbleDelegateView(
child_view, views::BubbleBorder::NONE));
bubble_delegate5->set_use_focusless(true);
views::Widget* bubble_widget5(views::BubbleDelegateView::CreateBubble(
bubble_delegate5));
bubble_widget5->Show();
EXPECT_TRUE(controller()->IsRevealed());
bubble_widget4->Hide();
EXPECT_TRUE(controller()->IsRevealed());
bubble_widget5->Hide();
EXPECT_FALSE(controller()->IsRevealed());
bubble_widget5->Show();
EXPECT_TRUE(controller()->IsRevealed());
SetEnabled(false);
bubble_widget5->Hide();
SetEnabled(true);
EXPECT_FALSE(controller()->IsRevealed());
bubble_widget4->Close();
bubble_widget5->Close();
SetEnabled(false);
views::Widget* bubble_widget6 = views::BubbleDelegateView::CreateBubble(
new views::BubbleDelegateView(child_view, views::BubbleBorder::NONE));
bubble_widget6->Show();
SetEnabled(true);
EXPECT_TRUE(controller()->IsRevealed());
bubble_widget6->Close();
views::Widget* bubble_widget7 = views::BubbleDelegateView::CreateBubble(
new views::BubbleDelegateView(unrelated_view, views::BubbleBorder::NONE));
bubble_widget7->Show();
EXPECT_FALSE(controller()->IsRevealed());
top_container_widget->Activate();
AttemptReveal(MODALITY_MOUSE);
EXPECT_TRUE(controller()->IsRevealed());
views::Widget* bubble_widget8 = views::BubbleDelegateView::CreateBubble(
new views::BubbleDelegateView(unrelated_view, views::BubbleBorder::NONE));
bubble_widget8->Show();
SetHovered(false);
EXPECT_FALSE(controller()->IsRevealed());
bubble_widget8->Close();
}
#endif
TEST_F(ImmersiveFullscreenControllerTest, Shelf) {
ash::ShelfLayoutManager* shelf =
ash::Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
window()->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
ASSERT_FALSE(controller()->IsEnabled());
ASSERT_EQ(ash::SHELF_VISIBLE, shelf->visibility_state());
window()->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
SetEnabled(true);
EXPECT_EQ(ash::SHELF_AUTO_HIDE, shelf->visibility_state());
SetEnabled(false);
window()->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
ASSERT_FALSE(controller()->IsEnabled());
EXPECT_EQ(ash::SHELF_VISIBLE, shelf->visibility_state());
shelf->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
EXPECT_EQ(ash::SHELF_AUTO_HIDE, shelf->visibility_state());
window()->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
SetEnabled(true);
EXPECT_EQ(ash::SHELF_AUTO_HIDE, shelf->visibility_state());
SetEnabled(false);
window()->SetProperty(aura::client::kShowStateKey,
ui::SHOW_STATE_NORMAL);
EXPECT_EQ(ash::SHELF_AUTO_HIDE, shelf->visibility_state());
}
}
#endif