Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/display/display_error_dialog.h" | 5 #include "ash/display/display_error_dialog.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
| 9 #include "grit/ash_strings.h" | |
| 9 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
| 11 #include "ui/base/l10n/l10n_util.h" | |
| 12 #include "ui/views/controls/label.h" | |
| 13 #include "ui/views/view.h" | |
| 10 #include "ui/views/widget/widget.h" | 14 #include "ui/views/widget/widget.h" |
| 11 | 15 |
| 12 namespace ash { | 16 namespace ash { |
| 13 namespace internal { | 17 namespace internal { |
| 18 namespace { | |
| 14 | 19 |
| 15 typedef test::AshTestBase DisplayErrorDialogTest; | 20 class DisplayErrorDialogTest : public test::AshTestBase { |
| 21 protected: | |
| 22 virtual void SetUp() OVERRIDE { | |
| 23 test::AshTestBase::SetUp(); | |
| 24 observer_.reset(new DisplayErrorObserver()); | |
| 25 } | |
| 26 | |
| 27 virtual void TearDown() OVERRIDE { | |
| 28 if (observer_->dialog()) { | |
| 29 views::Widget* widget = | |
| 30 const_cast<DisplayErrorDialog*>(observer_->dialog())->GetWidget(); | |
| 31 widget->CloseNow(); | |
| 32 } | |
| 33 observer_.reset(); | |
| 34 test::AshTestBase::TearDown(); | |
| 35 } | |
| 36 | |
| 37 DisplayErrorObserver* observer() { return observer_.get(); } | |
| 38 | |
| 39 const string16& GetMessageContents(const DisplayErrorDialog* dialog) { | |
| 40 const views::Label* label = static_cast<const views::Label*>( | |
| 41 static_cast<const views::View*>(dialog)->child_at(0)); | |
| 42 return label->text(); | |
| 43 } | |
| 44 | |
| 45 private: | |
| 46 scoped_ptr<DisplayErrorObserver> observer_; | |
| 47 }; | |
|
oshima
2013/02/28 23:00:36
DISALLOW_COPY_AND_ASSIGN
Jun Mukai
2013/02/28 23:03:12
Done.
| |
| 48 | |
| 49 } | |
| 16 | 50 |
| 17 // The test cases in this file usually check if the showing dialog doesn't | 51 // The test cases in this file usually check if the showing dialog doesn't |
| 18 // cause any crashes, and the code doesn't cause any memory leaks. | 52 // cause any crashes, and the code doesn't cause any memory leaks. |
| 19 TEST_F(DisplayErrorDialogTest, Normal) { | 53 TEST_F(DisplayErrorDialogTest, Normal) { |
| 20 UpdateDisplay("200x200,300x300"); | 54 UpdateDisplay("200x200,300x300"); |
| 21 DisplayErrorDialog::ShowDialog(); | 55 DisplayErrorDialog* dialog = |
| 22 DisplayErrorDialog* dialog = DisplayErrorDialog::GetInstanceForTest(); | 56 DisplayErrorDialog::ShowDialog(chromeos::STATE_DUAL_MIRROR); |
| 23 EXPECT_TRUE(dialog); | 57 EXPECT_TRUE(dialog); |
| 24 EXPECT_TRUE(dialog->GetWidget()->IsVisible()); | 58 EXPECT_TRUE(dialog->GetWidget()->IsVisible()); |
| 59 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_FAILURE_ON_MIRRORING), | |
| 60 GetMessageContents(dialog)); | |
| 25 EXPECT_EQ(Shell::GetAllRootWindows()[1], | 61 EXPECT_EQ(Shell::GetAllRootWindows()[1], |
| 26 dialog->GetWidget()->GetNativeView()->GetRootWindow()); | 62 dialog->GetWidget()->GetNativeView()->GetRootWindow()); |
| 27 } | 63 } |
| 28 | 64 |
| 29 TEST_F(DisplayErrorDialogTest, CallTwice) { | 65 TEST_F(DisplayErrorDialogTest, CallTwice) { |
| 30 UpdateDisplay("200x200,300x300"); | 66 UpdateDisplay("200x200,300x300"); |
| 31 DisplayErrorDialog::ShowDialog(); | 67 observer()->OnDisplayModeChangeFailed(chromeos::STATE_DUAL_MIRROR); |
| 32 DisplayErrorDialog* dialog = DisplayErrorDialog::GetInstanceForTest(); | 68 const DisplayErrorDialog* dialog = observer()->dialog(); |
| 33 EXPECT_TRUE(dialog); | 69 EXPECT_TRUE(dialog); |
| 34 DisplayErrorDialog::ShowDialog(); | 70 |
| 35 EXPECT_EQ(dialog, DisplayErrorDialog::GetInstanceForTest()); | 71 observer()->OnDisplayModeChangeFailed(chromeos::STATE_DUAL_MIRROR); |
| 72 EXPECT_EQ(dialog, observer()->dialog()); | |
| 73 } | |
| 74 | |
| 75 TEST_F(DisplayErrorDialogTest, CallWithDifferentState) { | |
| 76 UpdateDisplay("200x200,300x300"); | |
| 77 observer()->OnDisplayModeChangeFailed(chromeos::STATE_DUAL_MIRROR); | |
| 78 const DisplayErrorDialog* dialog = observer()->dialog(); | |
| 79 EXPECT_TRUE(dialog); | |
| 80 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_FAILURE_ON_MIRRORING), | |
| 81 GetMessageContents(dialog)); | |
| 82 | |
| 83 observer()->OnDisplayModeChangeFailed(chromeos::STATE_DUAL_EXTENDED); | |
| 84 EXPECT_EQ(dialog, observer()->dialog()); | |
| 85 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_FAILURE_ON_EXTENDED), | |
| 86 GetMessageContents(dialog)); | |
| 36 } | 87 } |
| 37 | 88 |
| 38 TEST_F(DisplayErrorDialogTest, SingleDisplay) { | 89 TEST_F(DisplayErrorDialogTest, SingleDisplay) { |
| 39 UpdateDisplay("200x200"); | 90 UpdateDisplay("200x200"); |
| 40 DisplayErrorDialog::ShowDialog(); | 91 DisplayErrorDialog* dialog = |
| 41 DisplayErrorDialog* dialog = DisplayErrorDialog::GetInstanceForTest(); | 92 DisplayErrorDialog::ShowDialog(chromeos::STATE_DUAL_MIRROR); |
| 42 EXPECT_TRUE(dialog); | 93 EXPECT_TRUE(dialog); |
| 43 EXPECT_TRUE(dialog->GetWidget()->IsVisible()); | 94 EXPECT_TRUE(dialog->GetWidget()->IsVisible()); |
| 44 EXPECT_EQ(Shell::GetInstance()->GetPrimaryRootWindow(), | 95 EXPECT_EQ(Shell::GetInstance()->GetPrimaryRootWindow(), |
| 45 dialog->GetWidget()->GetNativeView()->GetRootWindow()); | 96 dialog->GetWidget()->GetNativeView()->GetRootWindow()); |
| 46 } | 97 } |
| 47 | 98 |
| 48 TEST_F(DisplayErrorDialogTest, DisplayDisconnected) { | 99 TEST_F(DisplayErrorDialogTest, DisplayDisconnected) { |
| 49 UpdateDisplay("200x200,300x300"); | 100 UpdateDisplay("200x200,300x300"); |
| 50 DisplayErrorDialog::ShowDialog(); | 101 observer()->OnDisplayModeChangeFailed(chromeos::STATE_DUAL_MIRROR); |
| 51 DisplayErrorDialog* dialog = DisplayErrorDialog::GetInstanceForTest(); | 102 EXPECT_TRUE(observer()->dialog()); |
| 52 EXPECT_TRUE(dialog); | |
| 53 | 103 |
| 54 UpdateDisplay("200x200"); | 104 UpdateDisplay("200x200"); |
| 55 // Disconnection will close the dialog but we have to run all pending tasks | 105 // Disconnection will close the dialog but we have to run all pending tasks |
| 56 // to make the effect of the close. | 106 // to make the effect of the close. |
| 57 RunAllPendingInMessageLoop(); | 107 RunAllPendingInMessageLoop(); |
| 58 EXPECT_FALSE(DisplayErrorDialog::GetInstanceForTest()); | 108 EXPECT_FALSE(observer()->dialog()); |
| 59 } | 109 } |
| 60 | 110 |
| 61 } // namespace internal | 111 } // namespace internal |
| 62 } // namespace ash | 112 } // namespace ash |
| OLD | NEW |