This source file includes following definitions.
- GetModalType
- OnMouseEvent
- SetUp
- TearDown
- CheckContainersAreVisible
- CheckContainersAreHidden
- helper
- cancelled_times
- OnCancelled
- TEST_F
- TEST_F
- TEST_F
#include "ash/first_run/first_run_helper.h"
#include "ash/first_run/desktop_cleaner.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/test/ash_test_base.h"
#include "ui/aura/test/event_generator.h"
#include "ui/events/event_handler.h"
#include "ui/views/window/dialog_delegate.h"
namespace ash {
namespace test {
namespace {
class TestModalDialogDelegate : public views::DialogDelegateView {
public:
TestModalDialogDelegate() {}
virtual ~TestModalDialogDelegate() {}
virtual ui::ModalType GetModalType() const OVERRIDE {
return ui::MODAL_TYPE_SYSTEM;
}
private:
DISALLOW_COPY_AND_ASSIGN(TestModalDialogDelegate);
};
class CountingEventHandler : public ui::EventHandler {
public:
explicit CountingEventHandler(int* mouse_events_registered)
: mouse_events_registered_(mouse_events_registered) {
*mouse_events_registered = 0;
}
virtual ~CountingEventHandler() {}
private:
virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
++*mouse_events_registered_;
}
int* mouse_events_registered_;
DISALLOW_COPY_AND_ASSIGN(CountingEventHandler);
};
}
class FirstRunHelperTest : public AshTestBase,
public FirstRunHelper::Observer {
public:
FirstRunHelperTest() : cancelled_times_(0) {}
virtual ~FirstRunHelperTest() {}
virtual void SetUp() OVERRIDE {
AshTestBase::SetUp();
CheckContainersAreVisible();
helper_.reset(ash::Shell::GetInstance()->CreateFirstRunHelper());
helper_->AddObserver(this);
helper_->GetOverlayWidget()->Show();
}
virtual void TearDown() OVERRIDE {
EXPECT_TRUE(helper_.get());
helper_.reset();
CheckContainersAreVisible();
AshTestBase::TearDown();
}
void CheckContainersAreVisible() const {
aura::Window* root_window = Shell::GetInstance()->GetPrimaryRootWindow();
std::vector<int> containers_to_check =
DesktopCleaner::GetContainersToHideForTest();
for (size_t i = 0; i < containers_to_check.size(); ++i) {
aura::Window* container =
Shell::GetContainer(root_window, containers_to_check[i]);
EXPECT_TRUE(container->IsVisible());
}
}
void CheckContainersAreHidden() const {
aura::Window* root_window = Shell::GetInstance()->GetPrimaryRootWindow();
std::vector<int> containers_to_check =
DesktopCleaner::GetContainersToHideForTest();
for (size_t i = 0; i < containers_to_check.size(); ++i) {
aura::Window* container =
Shell::GetContainer(root_window, containers_to_check[i]);
EXPECT_TRUE(!container->IsVisible());
}
}
FirstRunHelper* helper() { return helper_.get(); }
int cancelled_times() const { return cancelled_times_; }
private:
virtual void OnCancelled() OVERRIDE {
++cancelled_times_;
}
scoped_ptr<FirstRunHelper> helper_;
int cancelled_times_;
DISALLOW_COPY_AND_ASSIGN(FirstRunHelperTest);
};
TEST_F(FirstRunHelperTest, ContainersAreHidden) {
CheckContainersAreHidden();
}
TEST_F(FirstRunHelperTest, Cancel) {
GetEventGenerator().PressKey(ui::VKEY_ESCAPE, 0);
EXPECT_EQ(cancelled_times(), 1);
}
TEST_F(FirstRunHelperTest, ModalWindowDoesNotBlock) {
views::Widget* modal_dialog = views::DialogDelegate::CreateDialogWidget(
new TestModalDialogDelegate(), CurrentContext(), NULL);
modal_dialog->Show();
aura::Window* overlay_window = helper()->GetOverlayWidget()->GetNativeView();
overlay_window->Focus();
EXPECT_TRUE(overlay_window->HasFocus());
int mouse_events;
overlay_window->SetEventFilter(new CountingEventHandler(&mouse_events));
GetEventGenerator().PressLeftButton();
GetEventGenerator().ReleaseLeftButton();
EXPECT_EQ(mouse_events, 2);
}
}
}