Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1750)

Unified Diff: ash/display/screen_position_controller_unittest.cc

Issue 10911342: Add ScreenPositionClient::ConvertNativePointToScreen. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/display/screen_position_controller_unittest.cc
diff --git a/ash/display/screen_position_controller_unittest.cc b/ash/display/screen_position_controller_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3d700bdecb3001e4b4e704e9ba59adcfd07decf8
--- /dev/null
+++ b/ash/display/screen_position_controller_unittest.cc
@@ -0,0 +1,264 @@
+// Copyright (c) 2012 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.
+
+#include "ash/display/screen_position_controller.h"
+
+#include "ash/shell.h"
+#include "ash/test/ash_test_base.h"
+#include "ui/aura/test/test_window_delegate.h"
+#include "ui/aura/env.h"
+#include "ui/aura/root_window.h"
+#include "ui/base/layout.h"
+#include "ash/display/display_controller.h"
oshima 2012/09/18 10:02:34 sort includes
mazda 2012/09/18 16:35:01 Done.
+
+namespace ash {
+namespace test {
+
+namespace {
+void SetSecondaryDisplayLayout(DisplayLayout::Position position) {
+ DisplayController* display_controller =
+ Shell::GetInstance()->display_controller();
+ DisplayLayout layout = display_controller->default_display_layout();
+ layout.position = position;
+ display_controller->SetDefaultDisplayLayout(layout);
+}
+
+const gfx::Display& GetDisplayAt(const gfx::Point& point) {
+ return aura::Env::GetInstance()->display_manager()->GetDisplayNearestPoint(
+ point);
oshima 2012/09/18 10:02:34 use gfx::Screen::GetDisplayNearestPoint()
mazda 2012/09/18 16:35:01 Done.
+}
+
+internal::ScreenPositionController* GetScreenPositionController() {
+ Shell::TestApi test_api(Shell::GetInstance());
+ return test_api.screen_position_controller();
+}
+
+class ScreenPositionControllerTest : public test::AshTestBase {
+ public:
+ ScreenPositionControllerTest() : window_(NULL) {}
+ virtual ~ScreenPositionControllerTest() {}
+
+ virtual void SetUp() OVERRIDE {
+ AshTestBase::SetUp();
+ window_.reset(new aura::Window(&window_delegate_));
+ window_->SetType(aura::client::WINDOW_TYPE_NORMAL);
+ window_->Init(ui::LAYER_NOT_DRAWN);
+ window_->SetParent(NULL);
+ window_->set_id(1);
+ }
+
+ virtual void TearDown() OVERRIDE {
+ window_.reset();
+ AshTestBase::TearDown();
+ }
+
+ protected:
+ scoped_ptr<aura::Window> window_;
+ aura::test::TestWindowDelegate window_delegate_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ScreenPositionControllerTest);
+};
+
+} // namespace
+
+TEST_F(ScreenPositionControllerTest, ConvertNativePointToScreen) {
+ UpdateDisplay("100+100-200x200,100+500-200x200");
+
+ Shell::RootWindowList root_windows =
+ Shell::GetInstance()->GetAllRootWindows();
+ EXPECT_EQ("100,100", root_windows[0]->GetHostOrigin().ToString());
+ EXPECT_EQ("200x200", root_windows[0]->GetHostSize().ToString());
+ EXPECT_EQ("100,500", root_windows[1]->GetHostOrigin().ToString());
+ EXPECT_EQ("200x200", root_windows[1]->GetHostSize().ToString());
+
+ internal::ScreenPositionController* controller =
+ GetScreenPositionController();
+
+ const gfx::Point window_pos(100, 100);
+ window_->SetBoundsInScreen(gfx::Rect(window_pos, gfx::Size(100, 100)),
+ GetDisplayAt(window_pos));
+ SetSecondaryDisplayLayout(DisplayLayout::RIGHT);
+ {
+ // |point| is on the primary root window.
+ gfx::Point point(50, 50);
+ controller->ConvertNativePointToScreen(window_.get(), &point);
+ EXPECT_EQ("150,150", point.ToString());
oshima 2012/09/18 10:02:34 since you have window_ as instance and controller
mazda 2012/09/18 16:35:01 Done. That's much simpler. Thanks.
+ }
+
+ {
+ // |point| is out of the all root windows.
+ gfx::Point point(250, 250);
+ controller->ConvertNativePointToScreen(window_.get(), &point);
+ EXPECT_EQ("350,350", point.ToString());
+ }
+
+ {
+ // |point| is on the secondary display.
+ gfx::Point point(50, 400);
+ controller->ConvertNativePointToScreen(window_.get(), &point);
+ EXPECT_EQ("350,100", point.ToString());
+ }
+
+ SetSecondaryDisplayLayout(DisplayLayout::BOTTOM);
+ {
+ // |point| is on the primary root window.
+ gfx::Point point(50, 50);
+ controller->ConvertNativePointToScreen(window_.get(), &point);
+ EXPECT_EQ("150,150", point.ToString());
+ }
+
+ {
+ // |point| is out of the all root windows.
+ gfx::Point point(250, 250);
+ controller->ConvertNativePointToScreen(window_.get(), &point);
+ EXPECT_EQ("350,350", point.ToString());
+ }
+
+ {
+ // |point| is on the secondary display.
+ gfx::Point point(50, 400);
+ controller->ConvertNativePointToScreen(window_.get(), &point);
+ EXPECT_EQ("150,300", point.ToString());
+ }
+
+ SetSecondaryDisplayLayout(DisplayLayout::LEFT);
+ {
+ // |point| is on the primary root window.
+ gfx::Point point(50, 50);
+ controller->ConvertNativePointToScreen(window_.get(), &point);
+ EXPECT_EQ("150,150", point.ToString());
+ }
+
+ {
+ // |point| is out of the all root windows.
+ gfx::Point point(250, 250);
+ controller->ConvertNativePointToScreen(window_.get(), &point);
+ EXPECT_EQ("350,350", point.ToString());
+ }
+
+ {
+ // |point| is on the secondary display.
+ gfx::Point point(50, 400);
+ controller->ConvertNativePointToScreen(window_.get(), &point);
+ EXPECT_EQ("-50,100", point.ToString());
+ }
+
+ SetSecondaryDisplayLayout(DisplayLayout::TOP);
+ {
+ // |point| is on the primary root window.
+ gfx::Point point(50, 50);
+ controller->ConvertNativePointToScreen(window_.get(), &point);
+ EXPECT_EQ("150,150", point.ToString());
+ }
+
+ {
+ // |point| is out of the all root windows.
+ gfx::Point point(250, 250);
+ controller->ConvertNativePointToScreen(window_.get(), &point);
+ EXPECT_EQ("350,350", point.ToString());
+ }
+
+ {
+ // |point| is on the secondary display.
+ gfx::Point point(50, 400);
+ controller->ConvertNativePointToScreen(window_.get(), &point);
+ EXPECT_EQ("150,-100", point.ToString());
+ }
+
+
+ SetSecondaryDisplayLayout(DisplayLayout::RIGHT);
+ const gfx::Point window_pos2(300, 100);
+ window_->SetBoundsInScreen(gfx::Rect(window_pos2, gfx::Size(100, 100)),
+ GetDisplayAt(window_pos2));
+ {
+ // |point| is on the secondary display.
+ gfx::Point point(50, 50);
+ controller->ConvertNativePointToScreen(window_.get(), &point);
+ EXPECT_EQ("350,150", point.ToString());
+ }
+
+ {
+ // |point| is out of the all root windows.
+ gfx::Point point(250, 250);
+ controller->ConvertNativePointToScreen(window_.get(), &point);
+ EXPECT_EQ("550,350", point.ToString());
+ }
+
+ {
+ // |point| is on the primary root window.
+ gfx::Point point(50, -400);
+ controller->ConvertNativePointToScreen(window_.get(), &point);
+ EXPECT_EQ("150,100", point.ToString());
+ }
+
+ SetSecondaryDisplayLayout(DisplayLayout::BOTTOM);
+ {
+ // |point| is on the secondary display.
+ gfx::Point point(50, 50);
+ controller->ConvertNativePointToScreen(window_.get(), &point);
+ EXPECT_EQ("150,350", point.ToString());
+ }
+
+ {
+ // |point| is out of the all root windows.
+ gfx::Point point(250, 250);
+ controller->ConvertNativePointToScreen(window_.get(), &point);
+ EXPECT_EQ("350,550", point.ToString());
+ }
+
+ {
+ // |point| is on the primary root window.
+ gfx::Point point(50, -400);
+ controller->ConvertNativePointToScreen(window_.get(), &point);
+ EXPECT_EQ("150,100", point.ToString());
+ }
+
+ SetSecondaryDisplayLayout(DisplayLayout::LEFT);
+ {
+ // |point| is on the secondary display.
+ gfx::Point point(50, 50);
+ controller->ConvertNativePointToScreen(window_.get(), &point);
+ EXPECT_EQ("-50,150", point.ToString());
+ }
+
+ {
+ // |point| is out of the all root windows.
+ gfx::Point point(250, 250);
+ controller->ConvertNativePointToScreen(window_.get(), &point);
+ EXPECT_EQ("150,350", point.ToString());
+ }
+
+ {
+ // |point| is on the primary root window.
+ gfx::Point point(50, -400);
+ controller->ConvertNativePointToScreen(window_.get(), &point);
+ EXPECT_EQ("150,100", point.ToString());
+ }
+
+ SetSecondaryDisplayLayout(DisplayLayout::TOP);
+ {
+ // |point| is on the secondary display.
+ gfx::Point point(50, 50);
+ controller->ConvertNativePointToScreen(window_.get(), &point);
+ EXPECT_EQ("150,-50", point.ToString());
+ }
+
+ {
+ // |point| is out of the all root windows.
+ gfx::Point point(250, 250);
+ controller->ConvertNativePointToScreen(window_.get(), &point);
+ EXPECT_EQ("350,150", point.ToString());
+ }
+
+ {
+ // |point| is on the primary root window.
+ gfx::Point point(50, -400);
+ controller->ConvertNativePointToScreen(window_.get(), &point);
+ EXPECT_EQ("150,100", point.ToString());
+ }
+}
+
+} // namespace test
+} // namespace ash
oshima 2012/09/18 10:02:34 two spaces before //
mazda 2012/09/18 16:35:01 Done.

Powered by Google App Engine
This is Rietveld 408576698