Commit d2d81b54 authored by mukai's avatar mukai Committed by Commit bot

Adds the test expectations of home card bounds.

BUG=403813
R=oshima@chromium.org
TEST=athena_unittests

Review URL: https://codereview.chromium.org/516643005

Cr-Commit-Position: refs/heads/master@{#292430}
parent 077d1b20
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "athena/home/public/home_card.h" #include "athena/home/home_card_impl.h"
#include <cmath> #include <cmath>
#include <limits> #include <limits>
...@@ -12,27 +12,22 @@ ...@@ -12,27 +12,22 @@
#include "athena/home/app_list_view_delegate.h" #include "athena/home/app_list_view_delegate.h"
#include "athena/home/athena_start_page_view.h" #include "athena/home/athena_start_page_view.h"
#include "athena/home/home_card_constants.h" #include "athena/home/home_card_constants.h"
#include "athena/home/home_card_gesture_manager.h"
#include "athena/home/minimized_home.h" #include "athena/home/minimized_home.h"
#include "athena/home/public/app_model_builder.h" #include "athena/home/public/app_model_builder.h"
#include "athena/input/public/accelerator_manager.h"
#include "athena/screen/public/screen_manager.h" #include "athena/screen/public/screen_manager.h"
#include "athena/wm/public/window_manager.h" #include "athena/wm/public/window_manager.h"
#include "athena/wm/public/window_manager_observer.h"
#include "ui/app_list/search_provider.h" #include "ui/app_list/search_provider.h"
#include "ui/app_list/views/app_list_main_view.h" #include "ui/app_list/views/app_list_main_view.h"
#include "ui/app_list/views/contents_view.h" #include "ui/app_list/views/contents_view.h"
#include "ui/aura/layout_manager.h" #include "ui/aura/layout_manager.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/compositor/layer.h" #include "ui/compositor/layer.h"
#include "ui/compositor/layer_owner.h"
#include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/views/layout/fill_layout.h" #include "ui/views/layout/fill_layout.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h" #include "ui/views/widget/widget_delegate.h"
#include "ui/wm/core/shadow_types.h" #include "ui/wm/core/shadow_types.h"
#include "ui/wm/core/visibility_controller.h" #include "ui/wm/core/visibility_controller.h"
#include "ui/wm/public/activation_change_observer.h"
#include "ui/wm/public/activation_client.h" #include "ui/wm/public/activation_client.h"
namespace athena { namespace athena {
...@@ -67,6 +62,8 @@ gfx::Rect GetBoundsForState(const gfx::Rect& screen_bounds, ...@@ -67,6 +62,8 @@ gfx::Rect GetBoundsForState(const gfx::Rect& screen_bounds,
return gfx::Rect(); return gfx::Rect();
} }
} // namespace
// Makes sure the homecard is center-aligned horizontally and bottom-aligned // Makes sure the homecard is center-aligned horizontally and bottom-aligned
// vertically. // vertically.
class HomeCardLayoutManager : public aura::LayoutManager { class HomeCardLayoutManager : public aura::LayoutManager {
...@@ -226,73 +223,6 @@ class HomeCardView : public views::WidgetDelegateView { ...@@ -226,73 +223,6 @@ class HomeCardView : public views::WidgetDelegateView {
DISALLOW_COPY_AND_ASSIGN(HomeCardView); DISALLOW_COPY_AND_ASSIGN(HomeCardView);
}; };
class HomeCardImpl : public HomeCard,
public AcceleratorHandler,
public HomeCardGestureManager::Delegate,
public WindowManagerObserver,
public aura::client::ActivationChangeObserver {
public:
explicit HomeCardImpl(AppModelBuilder* model_builder);
virtual ~HomeCardImpl();
void Init();
private:
enum Command {
COMMAND_SHOW_HOME_CARD,
};
void InstallAccelerators();
void UpdateMinimizedHomeBounds();
// Overridden from HomeCard:
virtual void SetState(State state) OVERRIDE;
virtual State GetState() OVERRIDE;
virtual void RegisterSearchProvider(
app_list::SearchProvider* search_provider) OVERRIDE;
virtual void UpdateVirtualKeyboardBounds(
const gfx::Rect& bounds) OVERRIDE;
// AcceleratorHandler:
virtual bool IsCommandEnabled(int command_id) const OVERRIDE { return true; }
virtual bool OnAcceleratorFired(int command_id,
const ui::Accelerator& accelerator) OVERRIDE;
// HomeCardGestureManager::Delegate:
virtual void OnGestureEnded(State final_state) OVERRIDE;
virtual void OnGestureProgressed(
State from_state, State to_state, float progress) OVERRIDE;
// WindowManagerObserver:
virtual void OnOverviewModeEnter() OVERRIDE;
virtual void OnOverviewModeExit() OVERRIDE;
virtual void OnActivityOrderHasChanged() OVERRIDE;
// aura::client::ActivationChangeObserver:
virtual void OnWindowActivated(aura::Window* gained_active,
aura::Window* lost_active) OVERRIDE;
scoped_ptr<AppModelBuilder> model_builder_;
HomeCard::State state_;
// original_state_ is the state which the home card should go back to after
// the virtual keyboard is hidden.
HomeCard::State original_state_;
views::Widget* home_card_widget_;
HomeCardView* home_card_view_;
scoped_ptr<AppListViewDelegate> view_delegate_;
HomeCardLayoutManager* layout_manager_;
aura::client::ActivationClient* activation_client_; // Not owned
scoped_ptr<ui::LayerOwner> minimized_home_;
// Right now HomeCard allows only one search provider.
// TODO(mukai): port app-list's SearchController and Mixer.
scoped_ptr<app_list::SearchProvider> search_provider_;
DISALLOW_COPY_AND_ASSIGN(HomeCardImpl);
};
HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder) HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder)
: model_builder_(model_builder), : model_builder_(model_builder),
state_(HIDDEN), state_(HIDDEN),
...@@ -360,6 +290,10 @@ void HomeCardImpl::Init() { ...@@ -360,6 +290,10 @@ void HomeCardImpl::Init() {
gfx::Insets(0, 0, kHomeCardMinimizedHeight, 0)); gfx::Insets(0, 0, kHomeCardMinimizedHeight, 0));
} }
aura::Window* HomeCardImpl::GetHomeCardWindowForTest() const {
return home_card_widget_ ? home_card_widget_->GetNativeWindow() : NULL;
}
void HomeCardImpl::InstallAccelerators() { void HomeCardImpl::InstallAccelerators() {
const AcceleratorData accelerator_data[] = { const AcceleratorData accelerator_data[] = {
{TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN, {TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN,
...@@ -426,6 +360,10 @@ void HomeCardImpl::UpdateVirtualKeyboardBounds( ...@@ -426,6 +360,10 @@ void HomeCardImpl::UpdateVirtualKeyboardBounds(
} }
} }
bool HomeCardImpl::IsCommandEnabled(int command_id) const {
return true;
}
bool HomeCardImpl::OnAcceleratorFired(int command_id, bool HomeCardImpl::OnAcceleratorFired(int command_id,
const ui::Accelerator& accelerator) { const ui::Accelerator& accelerator) {
DCHECK_EQ(COMMAND_SHOW_HOME_CARD, command_id); DCHECK_EQ(COMMAND_SHOW_HOME_CARD, command_id);
...@@ -491,8 +429,6 @@ void HomeCardImpl::OnWindowActivated(aura::Window* gained_active, ...@@ -491,8 +429,6 @@ void HomeCardImpl::OnWindowActivated(aura::Window* gained_active,
} }
} }
} // namespace
// static // static
HomeCard* HomeCard::Create(AppModelBuilder* model_builder) { HomeCard* HomeCard::Create(AppModelBuilder* model_builder) {
(new HomeCardImpl(model_builder))->Init(); (new HomeCardImpl(model_builder))->Init();
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ATHENA_HOME_HOME_CARD_IMPL_H_
#define ATHENA_HOME_HOME_CARD_IMPL_H_
#include "athena/athena_export.h"
#include "athena/home/home_card_gesture_manager.h"
#include "athena/home/public/home_card.h"
#include "athena/input/public/accelerator_manager.h"
#include "athena/wm/public/window_manager_observer.h"
#include "ui/wm/public/activation_change_observer.h"
namespace app_list {
class SearchProvider;
}
namespace aura {
class Window;
namespace client {
class ActivationClient;
}
}
namespace gfx {
class Rect;
}
namespace ui {
class LayerOwner;
}
namespace views {
class Widget;
}
namespace athena {
class AppModelBuilder;
class AppListViewDelegate;
class HomeCardLayoutManager;
class HomeCardView;
class ATHENA_EXPORT HomeCardImpl
: public HomeCard,
public AcceleratorHandler,
public HomeCardGestureManager::Delegate,
public WindowManagerObserver,
public aura::client::ActivationChangeObserver {
public:
explicit HomeCardImpl(AppModelBuilder* model_builder);
virtual ~HomeCardImpl();
void Init();
aura::Window* GetHomeCardWindowForTest() const;
private:
enum Command {
COMMAND_SHOW_HOME_CARD,
};
void InstallAccelerators();
// Overridden from HomeCard:
virtual void SetState(HomeCard::State state) OVERRIDE;
virtual State GetState() OVERRIDE;
virtual void RegisterSearchProvider(
app_list::SearchProvider* search_provider) OVERRIDE;
virtual void UpdateVirtualKeyboardBounds(
const gfx::Rect& bounds) OVERRIDE;
// AcceleratorHandler:
virtual bool IsCommandEnabled(int command_id) const OVERRIDE;
virtual bool OnAcceleratorFired(int command_id,
const ui::Accelerator& accelerator) OVERRIDE;
// HomeCardGestureManager::Delegate:
virtual void OnGestureEnded(HomeCard::State final_state) OVERRIDE;
virtual void OnGestureProgressed(
HomeCard::State from_state,
HomeCard::State to_state,
float progress) OVERRIDE;
// WindowManagerObserver:
virtual void OnOverviewModeEnter() OVERRIDE;
virtual void OnOverviewModeExit() OVERRIDE;
virtual void OnActivityOrderHasChanged() OVERRIDE;
// aura::client::ActivationChangeObserver:
virtual void OnWindowActivated(aura::Window* gained_active,
aura::Window* lost_active) OVERRIDE;
scoped_ptr<AppModelBuilder> model_builder_;
HomeCard::State state_;
// original_state_ is the state which the home card should go back to after
// the virtual keyboard is hidden.
HomeCard::State original_state_;
views::Widget* home_card_widget_;
HomeCardView* home_card_view_;
scoped_ptr<AppListViewDelegate> view_delegate_;
HomeCardLayoutManager* layout_manager_;
aura::client::ActivationClient* activation_client_; // Not owned
scoped_ptr<ui::LayerOwner> minimized_home_;
// Right now HomeCard allows only one search provider.
// TODO(mukai): port app-list's SearchController and Mixer.
scoped_ptr<app_list::SearchProvider> search_provider_;
DISALLOW_COPY_AND_ASSIGN(HomeCardImpl);
};
} // namespace athena
#endif // ATHENA_HOME_HOME_CARD_IMPL_H_
...@@ -6,23 +6,44 @@ ...@@ -6,23 +6,44 @@
#include "athena/activity/public/activity_factory.h" #include "athena/activity/public/activity_factory.h"
#include "athena/activity/public/activity_manager.h" #include "athena/activity/public/activity_manager.h"
#include "athena/home/home_card_constants.h"
#include "athena/home/home_card_impl.h"
#include "athena/test/athena_test_base.h" #include "athena/test/athena_test_base.h"
#include "athena/wm/public/window_manager.h" #include "athena/wm/public/window_manager.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/events/test/event_generator.h" #include "ui/events/test/event_generator.h"
#include "ui/gfx/display.h"
#include "ui/gfx/screen.h"
namespace athena { namespace athena {
aura::Window* GetHomeCardWindow() {
return static_cast<HomeCardImpl*>(HomeCard::Get())->
GetHomeCardWindowForTest();
}
typedef test::AthenaTestBase HomeCardTest; typedef test::AthenaTestBase HomeCardTest;
TEST_F(HomeCardTest, BasicTransition) { TEST_F(HomeCardTest, BasicTransition) {
EXPECT_EQ(HomeCard::VISIBLE_MINIMIZED, HomeCard::Get()->GetState()); ASSERT_EQ(HomeCard::VISIBLE_MINIMIZED, HomeCard::Get()->GetState());
aura::Window* home_card = GetHomeCardWindow();
const int screen_height = root_window()->bounds().height();
const int work_area_height = gfx::Screen::GetScreenFor(root_window())->
GetDisplayNearestWindow(root_window()).work_area().height();
ASSERT_TRUE(home_card);
// In the minimized state, home card should be outside (below) the work area.
EXPECT_EQ(screen_height - kHomeCardMinimizedHeight,
home_card->GetTargetBounds().y());
EXPECT_EQ(work_area_height, home_card->GetTargetBounds().y());
WindowManager::GetInstance()->ToggleOverview(); WindowManager::GetInstance()->ToggleOverview();
EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, HomeCard::Get()->GetState()); EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, HomeCard::Get()->GetState());
EXPECT_EQ(screen_height - kHomeCardHeight, home_card->GetTargetBounds().y());
WindowManager::GetInstance()->ToggleOverview(); WindowManager::GetInstance()->ToggleOverview();
EXPECT_EQ(HomeCard::VISIBLE_MINIMIZED, HomeCard::Get()->GetState()); EXPECT_EQ(HomeCard::VISIBLE_MINIMIZED, HomeCard::Get()->GetState());
EXPECT_EQ(work_area_height, home_card->GetTargetBounds().y());
} }
TEST_F(HomeCardTest, VirtualKeyboardTransition) { TEST_F(HomeCardTest, VirtualKeyboardTransition) {
...@@ -39,6 +60,7 @@ TEST_F(HomeCardTest, VirtualKeyboardTransition) { ...@@ -39,6 +60,7 @@ TEST_F(HomeCardTest, VirtualKeyboardTransition) {
EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, HomeCard::Get()->GetState()); EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, HomeCard::Get()->GetState());
HomeCard::Get()->UpdateVirtualKeyboardBounds(vk_bounds); HomeCard::Get()->UpdateVirtualKeyboardBounds(vk_bounds);
EXPECT_EQ(HomeCard::VISIBLE_CENTERED, HomeCard::Get()->GetState()); EXPECT_EQ(HomeCard::VISIBLE_CENTERED, HomeCard::Get()->GetState());
EXPECT_EQ(0, GetHomeCardWindow()->GetTargetBounds().y());
HomeCard::Get()->UpdateVirtualKeyboardBounds(gfx::Rect()); HomeCard::Get()->UpdateVirtualKeyboardBounds(gfx::Rect());
EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, HomeCard::Get()->GetState()); EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, HomeCard::Get()->GetState());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment