Index: ash/login/ui/login_test_base.cc |
diff --git a/ash/login/ui/login_test_base.cc b/ash/login/ui/login_test_base.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..35e4c0f0611cddbe00331beeb37dddaa66e34203 |
--- /dev/null |
+++ b/ash/login/ui/login_test_base.cc |
@@ -0,0 +1,69 @@ |
+// Copyright 2017 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/login/ui/login_test_base.h" |
+ |
+#include "components/user_manager/fake_user_manager.h" |
+#include "ui/views/widget/widget.h" |
+#include "ui/views/widget/widget_delegate.h" |
+ |
+namespace ash { |
+ |
+// A WidgetDelegate which ensures that |initially_focused| gets focus. |
+class LoginTestBase::WidgetDelegate : public views::WidgetDelegate { |
+ public: |
+ WidgetDelegate(views::View* initially_focused) |
+ : initially_focused_(initially_focused) {} |
+ ~WidgetDelegate() override = default; |
+ |
+ // views::WidgetDelegate: |
+ views::View* GetInitiallyFocusedView() override { return initially_focused_; } |
+ views::Widget* GetWidget() override { |
+ return initially_focused_->GetWidget(); |
+ } |
+ const views::Widget* GetWidget() const override { |
+ return initially_focused_->GetWidget(); |
+ } |
+ |
+ private: |
+ views::View* initially_focused_; |
xiyuan
2017/05/24 20:11:02
nit: IMHO, it is easier to read if this is called
jdufault
2017/06/07 18:09:14
Done.
|
+ |
+ DISALLOW_COPY_AND_ASSIGN(WidgetDelegate); |
+}; |
+ |
+LoginTestBase::LoginTestBase() {} |
+ |
+LoginTestBase::~LoginTestBase() {} |
+ |
+void LoginTestBase::ShowWidgetWithContent(views::View* content) { |
+ EXPECT_FALSE(widget_) << "CreateWidget can only be called once."; |
+ |
+ delegate_ = base::MakeUnique<WidgetDelegate>(content); |
+ |
+ views::Widget::InitParams params( |
+ views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
+ params.context = CurrentContext(); |
+ params.bounds = gfx::Rect(0, 0, 800, 800); |
+ params.delegate = delegate_.get(); |
+ widget_ = new views::Widget(); |
+ widget_->Init(params); |
+ widget_->SetContentsView(content); |
+ widget_->Show(); |
+} |
+ |
+void LoginTestBase::SetUp() { |
+ AshTestBase::SetUp(); |
+ fake_user_manager_ = base::MakeUnique<user_manager::FakeUserManager>(); |
xiyuan
2017/05/24 20:11:02
I don't think we will have a UserManager running i
jdufault
2017/06/07 18:09:14
Done.
|
+} |
+ |
+void LoginTestBase::TearDown() { |
+ if (widget_) { |
+ widget_->Close(); |
+ widget_ = nullptr; |
+ } |
+ |
+ test::AshTestBase::TearDown(); |
+} |
+ |
+} // namespace ash |