This source file includes following definitions.
- SetUp
- TearDown
- shadow_controller
- ActivateWindow
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "ui/wm/core/shadow_controller.h"
#include <algorithm>
#include <vector>
#include "base/memory/scoped_ptr.h"
#include "ui/aura/client/window_tree_client.h"
#include "ui/aura/test/aura_test_base.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/compositor/layer.h"
#include "ui/wm/core/shadow.h"
#include "ui/wm/core/shadow_types.h"
#include "ui/wm/core/window_util.h"
#include "ui/wm/core/wm_state.h"
#include "ui/wm/public/activation_client.h"
namespace wm {
class ShadowControllerTest : public aura::test::AuraTestBase {
public:
ShadowControllerTest() {}
virtual ~ShadowControllerTest() {}
virtual void SetUp() OVERRIDE {
wm_state_.reset(new wm::WMState);
AuraTestBase::SetUp();
aura::client::ActivationClient* activation_client =
aura::client::GetActivationClient(root_window());
shadow_controller_.reset(new ShadowController(activation_client));
}
virtual void TearDown() OVERRIDE {
shadow_controller_.reset();
AuraTestBase::TearDown();
wm_state_.reset();
}
protected:
ShadowController* shadow_controller() { return shadow_controller_.get(); }
void ActivateWindow(aura::Window* window) {
DCHECK(window);
DCHECK(window->GetRootWindow());
aura::client::GetActivationClient(window->GetRootWindow())->ActivateWindow(
window);
}
private:
scoped_ptr<ShadowController> shadow_controller_;
scoped_ptr<wm::WMState> wm_state_;
DISALLOW_COPY_AND_ASSIGN(ShadowControllerTest);
};
TEST_F(ShadowControllerTest, Shadow) {
scoped_ptr<aura::Window> window(new aura::Window(NULL));
window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
window->Init(aura::WINDOW_LAYER_TEXTURED);
ParentWindow(window.get());
ShadowController::TestApi api(shadow_controller());
const Shadow* shadow = api.GetShadowForWindow(window.get());
ASSERT_TRUE(shadow != NULL);
EXPECT_TRUE(shadow->layer()->visible());
window->Show();
EXPECT_TRUE(shadow->layer()->visible());
window->Hide();
EXPECT_TRUE(shadow->layer()->visible());
SetShadowType(window.get(), SHADOW_TYPE_NONE);
window->Show();
EXPECT_FALSE(shadow->layer()->visible());
SetShadowType(window.get(), SHADOW_TYPE_RECTANGULAR);
EXPECT_TRUE(shadow->layer()->visible());
EXPECT_EQ(window->layer(), shadow->layer()->parent());
window->parent()->RemoveChild(window.get());
aura::Window* window_ptr = window.get();
window.reset();
EXPECT_TRUE(api.GetShadowForWindow(window_ptr) == NULL);
}
TEST_F(ShadowControllerTest, ShadowBounds) {
scoped_ptr<aura::Window> window(new aura::Window(NULL));
window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
window->Init(aura::WINDOW_LAYER_TEXTURED);
ParentWindow(window.get());
window->Show();
const gfx::Rect kOldBounds(20, 30, 400, 300);
window->SetBounds(kOldBounds);
SetShadowType(window.get(), SHADOW_TYPE_RECTANGULAR);
ShadowController::TestApi api(shadow_controller());
const Shadow* shadow = api.GetShadowForWindow(window.get());
ASSERT_TRUE(shadow != NULL);
EXPECT_EQ(gfx::Rect(kOldBounds.size()).ToString(),
shadow->content_bounds().ToString());
gfx::Rect kNewBounds(50, 60, 500, 400);
window->SetBounds(kNewBounds);
EXPECT_EQ(gfx::Rect(kNewBounds.size()).ToString(),
shadow->content_bounds().ToString());
}
TEST_F(ShadowControllerTest, ShadowStyle) {
ShadowController::TestApi api(shadow_controller());
scoped_ptr<aura::Window> window1(new aura::Window(NULL));
window1->SetType(ui::wm::WINDOW_TYPE_NORMAL);
window1->Init(aura::WINDOW_LAYER_TEXTURED);
ParentWindow(window1.get());
window1->SetBounds(gfx::Rect(10, 20, 300, 400));
window1->Show();
ActivateWindow(window1.get());
Shadow* shadow1 = api.GetShadowForWindow(window1.get());
ASSERT_TRUE(shadow1 != NULL);
EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style());
scoped_ptr<aura::Window> window2(new aura::Window(NULL));
window2->SetType(ui::wm::WINDOW_TYPE_NORMAL);
window2->Init(aura::WINDOW_LAYER_TEXTURED);
ParentWindow(window2.get());
window2->SetBounds(gfx::Rect(11, 21, 301, 401));
window2->Show();
ActivateWindow(window2.get());
Shadow* shadow2 = api.GetShadowForWindow(window2.get());
ASSERT_TRUE(shadow2 != NULL);
EXPECT_EQ(Shadow::STYLE_INACTIVE, shadow1->style());
EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow2->style());
}
TEST_F(ShadowControllerTest, SmallShadowsForTooltipsAndMenus) {
ShadowController::TestApi api(shadow_controller());
scoped_ptr<aura::Window> tooltip_window(new aura::Window(NULL));
tooltip_window->SetType(ui::wm::WINDOW_TYPE_TOOLTIP);
tooltip_window->Init(aura::WINDOW_LAYER_TEXTURED);
ParentWindow(tooltip_window.get());
tooltip_window->SetBounds(gfx::Rect(10, 20, 300, 400));
tooltip_window->Show();
Shadow* tooltip_shadow = api.GetShadowForWindow(tooltip_window.get());
ASSERT_TRUE(tooltip_shadow != NULL);
EXPECT_EQ(Shadow::STYLE_SMALL, tooltip_shadow->style());
scoped_ptr<aura::Window> menu_window(new aura::Window(NULL));
menu_window->SetType(ui::wm::WINDOW_TYPE_MENU);
menu_window->Init(aura::WINDOW_LAYER_TEXTURED);
ParentWindow(menu_window.get());
menu_window->SetBounds(gfx::Rect(10, 20, 300, 400));
menu_window->Show();
Shadow* menu_shadow = api.GetShadowForWindow(tooltip_window.get());
ASSERT_TRUE(menu_shadow != NULL);
EXPECT_EQ(Shadow::STYLE_SMALL, menu_shadow->style());
}
TEST_F(ShadowControllerTest, TransientParentKeepsActiveShadow) {
ShadowController::TestApi api(shadow_controller());
scoped_ptr<aura::Window> window1(new aura::Window(NULL));
window1->SetType(ui::wm::WINDOW_TYPE_NORMAL);
window1->Init(aura::WINDOW_LAYER_TEXTURED);
ParentWindow(window1.get());
window1->SetBounds(gfx::Rect(10, 20, 300, 400));
window1->Show();
ActivateWindow(window1.get());
Shadow* shadow1 = api.GetShadowForWindow(window1.get());
ASSERT_TRUE(shadow1 != NULL);
EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style());
scoped_ptr<aura::Window> window2(new aura::Window(NULL));
window2->SetType(ui::wm::WINDOW_TYPE_NORMAL);
window2->Init(aura::WINDOW_LAYER_TEXTURED);
ParentWindow(window2.get());
window2->SetBounds(gfx::Rect(11, 21, 301, 401));
AddTransientChild(window1.get(), window2.get());
aura::client::SetHideOnDeactivate(window2.get(), true);
window2->Show();
ActivateWindow(window2.get());
EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style());
}
}