Chromium Code Reviews| Index: ash/wm/partial_screenshot_view_unittest.cc |
| diff --git a/ash/wm/partial_screenshot_view_unittest.cc b/ash/wm/partial_screenshot_view_unittest.cc |
| index 3b763b42ff5045760a0dc723a2e1dabf67708da5..103d10a6b28d33e679ae4a100986484904f1a8d9 100644 |
| --- a/ash/wm/partial_screenshot_view_unittest.cc |
| +++ b/ash/wm/partial_screenshot_view_unittest.cc |
| @@ -8,33 +8,51 @@ |
| #include "ash/shell.h" |
| #include "ash/shell_window_ids.h" |
| #include "ash/test/ash_test_base.h" |
| +#include "ash/test/test_overlay_delegate.h" |
| #include "ash/test/test_screenshot_delegate.h" |
| #include "ui/aura/window_event_dispatcher.h" |
| #include "ui/events/test/event_generator.h" |
| +#include "ui/views/widget/widget.h" |
| +#include "ui/views/widget/widget_observer.h" |
| namespace ash { |
| -class PartialScreenshotViewTest : public test::AshTestBase { |
| +class PartialScreenshotViewTest : public test::AshTestBase, |
| + public views::WidgetObserver { |
| public: |
| PartialScreenshotViewTest() : view_(NULL) {} |
| - virtual ~PartialScreenshotViewTest() {} |
| + virtual ~PartialScreenshotViewTest() { |
| + if (view_) |
| + view_->GetWidget()->RemoveObserver(this); |
| + } |
| - virtual void SetUp() OVERRIDE { |
| - test::AshTestBase::SetUp(); |
| + void StartPartialScreenshot() { |
| std::vector<PartialScreenshotView*> views = |
| PartialScreenshotView::StartPartialScreenshot(GetScreenshotDelegate()); |
| - ASSERT_EQ(1u, views.size()); |
| - view_ = views[0]; |
| + if (!views.empty()) { |
| + view_ = views[0]; |
| + view_->GetWidget()->AddObserver(this); |
| + } |
| } |
| protected: |
| PartialScreenshotView* view_; |
| private: |
| + // views::WidgetObserver: |
| + virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE { |
| + if (view_ && view_->GetWidget() == widget) |
| + view_ = NULL; |
| + widget->RemoveObserver(this); |
| + } |
| + |
| DISALLOW_COPY_AND_ASSIGN(PartialScreenshotViewTest); |
| }; |
| TEST_F(PartialScreenshotViewTest, BasicMouse) { |
| + StartPartialScreenshot(); |
| + ASSERT_TRUE(view_); |
| + |
| ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
| generator.MoveMouseTo(100, 100); |
| @@ -53,6 +71,9 @@ TEST_F(PartialScreenshotViewTest, BasicMouse) { |
| } |
| TEST_F(PartialScreenshotViewTest, BasicTouch) { |
| + StartPartialScreenshot(); |
| + ASSERT_TRUE(view_); |
| + |
| ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
| generator.set_current_location(gfx::Point(100,100)); |
| @@ -74,4 +95,29 @@ TEST_F(PartialScreenshotViewTest, BasicTouch) { |
| EXPECT_EQ("100,100 100x100", GetScreenshotDelegate()->last_rect().ToString()); |
| } |
| +// Partial screenshot session should not start when there is already another |
| +// overlay. See: crbug.com/341958 |
|
James Cook
2014/08/12 21:51:14
nit: I've started putting the "http://" part into
Jun Mukai
2014/08/12 22:51:03
Done.
|
| +TEST_F(PartialScreenshotViewTest, DontStartOverOverlay) { |
| + OverlayEventFilter* overlay_filter = Shell::GetInstance()->overlay_filter(); |
| + test::TestOverlayDelegate delegate; |
| + overlay_filter->Activate(&delegate); |
| + |
| + EXPECT_EQ(&delegate, overlay_filter->delegate_); |
|
James Cook
2014/08/12 21:51:15
nit: Maybe move up a line?
Jun Mukai
2014/08/12 22:51:03
Done.
|
| + |
| + StartPartialScreenshot(); |
| + EXPECT_FALSE(view_); |
| + EXPECT_EQ(&delegate, overlay_filter->delegate_); |
| + overlay_filter->Deactivate(&delegate); |
| + |
| + StartPartialScreenshot(); |
| + EXPECT_TRUE(view_); |
| + |
| + // Someone else attempts to activate the overlay session, which should cancel |
| + // the current partial screenshot session. |
| + overlay_filter->Activate(&delegate); |
| + RunAllPendingInMessageLoop(); |
| + EXPECT_EQ(&delegate, overlay_filter->delegate_); |
| + EXPECT_FALSE(view_); |
| +} |
|
James Cook
2014/08/12 21:51:15
Nice test.
Jun Mukai
2014/08/12 22:51:03
thanks :)
|
| + |
| } // namespace ash |