This source file includes following definitions.
- SetUp
- TearDown
- CreateShelfItem
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "ash/shelf/shelf_window_watcher.h"
#include "ash/ash_switches.h"
#include "ash/shelf/shelf_item_types.h"
#include "ash/shelf/shelf_model.h"
#include "ash/shelf/shelf_util.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/shell_test_api.h"
#include "ash/wm/window_resizer.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_util.h"
#include "base/command_line.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h"
#include "ui/base/hit_test.h"
namespace ash {
class ShelfWindowWatcherTest : public test::AshTestBase {
public:
ShelfWindowWatcherTest() : model_(NULL) {}
virtual ~ShelfWindowWatcherTest() {}
virtual void SetUp() OVERRIDE {
test::AshTestBase::SetUp();
model_ = test::ShellTestApi(Shell::GetInstance()).shelf_model();
}
virtual void TearDown() OVERRIDE {
model_ = NULL;
test::AshTestBase::TearDown();
}
ShelfID CreateShelfItem(aura::Window* window) {
ShelfID id = model_->next_id();
ShelfItemDetails item_details;
item_details.type = TYPE_PLATFORM_APP;
SetShelfItemDetailsForWindow(window, item_details);
return id;
}
protected:
ShelfModel* model_;
private:
DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcherTest);
};
TEST_F(ShelfWindowWatcherTest, CreateAndRemoveShelfItem) {
EXPECT_EQ(1, model_->item_count());
scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithId(0));
scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithId(0));
ShelfID id_w1 = CreateShelfItem(w1.get());
EXPECT_EQ(2, model_->item_count());
int index_w1 = model_->ItemIndexByID(id_w1);
EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status);
ShelfID id_w2 = CreateShelfItem(w2.get());
EXPECT_EQ(3, model_->item_count());
int index_w2 = model_->ItemIndexByID(id_w2);
EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w2].status);
ClearShelfItemDetailsForWindow(w1.get());
EXPECT_EQ(2, model_->item_count());
ClearShelfItemDetailsForWindow(w2.get());
EXPECT_EQ(1, model_->item_count());
ClearShelfItemDetailsForWindow(w2.get());
EXPECT_EQ(1, model_->item_count());
}
TEST_F(ShelfWindowWatcherTest, ActivateWindow) {
EXPECT_EQ(1, model_->item_count());
scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithId(0));
scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithId(0));
ShelfID id_w1 = CreateShelfItem(w1.get());
EXPECT_EQ(2, model_->item_count());
int index_w1 = model_->ItemIndexByID(id_w1);
EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status);
ShelfID id_w2 = CreateShelfItem(w2.get());
EXPECT_EQ(3, model_->item_count());
int index_w2 = model_->ItemIndexByID(id_w2);
EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status);
EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w2].status);
wm::ActivateWindow(w1.get());
EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w1].status);
wm::ActivateWindow(w2.get());
EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status);
EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w2].status);
}
TEST_F(ShelfWindowWatcherTest, UpdateWindowProperty) {
EXPECT_EQ(1, model_->item_count());
scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
ShelfID id = CreateShelfItem(window.get());
EXPECT_EQ(2, model_->item_count());
int index = model_->ItemIndexByID(id);
EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status);
ShelfItemDetails details;
details.type = TYPE_PLATFORM_APP;
SetShelfItemDetailsForWindow(window.get(), details);
EXPECT_EQ(2, model_->item_count());
EXPECT_EQ(index, model_->ItemIndexByID(id));
EXPECT_EQ(id, model_->items()[index].id);
}
TEST_F(ShelfWindowWatcherTest, MaximizeAndRestoreWindow) {
EXPECT_EQ(1, model_->item_count());
scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
wm::WindowState* window_state = wm::GetWindowState(window.get());
ShelfID id = CreateShelfItem(window.get());
EXPECT_EQ(2, model_->item_count());
int index = model_->ItemIndexByID(id);
EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status);
EXPECT_FALSE(window_state->IsMaximized());
window_state->Maximize();
EXPECT_TRUE(window_state->IsMaximized());
EXPECT_EQ(2, model_->item_count());
EXPECT_EQ(index, model_->ItemIndexByID(id));
EXPECT_EQ(id, model_->items()[index].id);
window_state->Restore();
EXPECT_FALSE(window_state->IsMaximized());
EXPECT_EQ(2, model_->item_count());
EXPECT_EQ(index, model_->ItemIndexByID(id));
EXPECT_EQ(id, model_->items()[index].id);
}
TEST_F(ShelfWindowWatcherTest, ReparentWindow) {
EXPECT_EQ(1, model_->item_count());
scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
window->set_owned_by_parent(false);
ShelfID id = CreateShelfItem(window.get());
EXPECT_EQ(2, model_->item_count());
int index = model_->ItemIndexByID(id);
EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status);
aura::Window* root_window = window->GetRootWindow();
aura::Window* default_container = Shell::GetContainer(
root_window,
kShellWindowId_DefaultContainer);
EXPECT_EQ(default_container, window->parent());
aura::Window* new_parent = Shell::GetContainer(
root_window,
kShellWindowId_PanelContainer);
new_parent->AddChild(window.get());
EXPECT_EQ(1, model_->item_count());
default_container->AddChild(window.get());
EXPECT_EQ(2, model_->item_count());
}
TEST_F(ShelfWindowWatcherTest, DragWindow) {
EXPECT_EQ(1, model_->item_count());
scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
ShelfID id = CreateShelfItem(window.get());
EXPECT_EQ(2, model_->item_count());
int index = model_->ItemIndexByID(id);
EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status);
scoped_ptr<WindowResizer> resizer(
CreateWindowResizer(window.get(),
gfx::Point(),
HTCAPTION,
aura::client::WINDOW_MOVE_SOURCE_MOUSE));
ASSERT_TRUE(resizer.get());
resizer->Drag(gfx::Point(50, 50), 0);
resizer->CompleteDrag();
EXPECT_EQ(index, model_->ItemIndexByID(id));
EXPECT_EQ(id, model_->items()[index].id);
}
TEST_F(ShelfWindowWatcherTest, ReparentWindowDuringTheDragging) {
EXPECT_EQ(1, model_->item_count());
scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
window->set_owned_by_parent(false);
ShelfID id = CreateShelfItem(window.get());
EXPECT_EQ(2, model_->item_count());
int index = model_->ItemIndexByID(id);
EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status);
aura::Window* root_window = window->GetRootWindow();
aura::Window* default_container = Shell::GetContainer(
root_window,
kShellWindowId_DefaultContainer);
EXPECT_EQ(default_container, window->parent());
aura::Window* new_parent = Shell::GetContainer(
root_window,
kShellWindowId_PanelContainer);
{
scoped_ptr<WindowResizer> resizer(
CreateWindowResizer(window.get(),
gfx::Point(),
HTCAPTION,
aura::client::WINDOW_MOVE_SOURCE_MOUSE));
ASSERT_TRUE(resizer.get());
resizer->Drag(gfx::Point(50, 50), 0);
resizer->CompleteDrag();
EXPECT_EQ(2, model_->item_count());
EXPECT_TRUE(wm::GetWindowState(window.get())->is_dragged());
new_parent->AddChild(window.get());
EXPECT_EQ(1, model_->item_count());
}
EXPECT_FALSE(wm::GetWindowState(window.get())->is_dragged());
EXPECT_EQ(1, model_->item_count());
}
}