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 } | |
|
oshima
2013/02/14 00:01:50
It's probably better to keep the order of setup/te
Jun Mukai
2013/02/14 00:54:03
Done.
| |
| 26 | |
| 27 DisplayErrorObserver* observer() { return observer_.get(); } | |
| 28 | |
| 29 string16 GetMessageContents(DisplayErrorDialog* dialog) { | |
| 30 views::Label* label = static_cast<views::Label*>( | |
| 31 static_cast<views::View*>(dialog)->child_at(0)); | |
| 32 return label->text(); | |
| 33 } | |
| 34 | |
| 35 private: | |
| 36 scoped_ptr<DisplayErrorObserver> observer_; | |
| 37 }; | |
| 38 | |
| 39 } | |
| 16 | 40 |
| 17 // The test cases in this file usually check if the showing dialog doesn't | 41 // 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. | 42 // cause any crashes, and the code doesn't cause any memory leaks. |
| 19 TEST_F(DisplayErrorDialogTest, Normal) { | 43 TEST_F(DisplayErrorDialogTest, Normal) { |
| 20 UpdateDisplay("200x200,300x300"); | 44 UpdateDisplay("200x200,300x300"); |
| 21 DisplayErrorDialog::ShowDialog(); | 45 DisplayErrorDialog* dialog = |
| 22 DisplayErrorDialog* dialog = DisplayErrorDialog::GetInstanceForTest(); | 46 DisplayErrorDialog::ShowDialog(chromeos::STATE_DUAL_MIRROR); |
| 23 EXPECT_TRUE(dialog); | 47 EXPECT_TRUE(dialog); |
| 24 EXPECT_TRUE(dialog->GetWidget()->IsVisible()); | 48 EXPECT_TRUE(dialog->GetWidget()->IsVisible()); |
| 49 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_FAILURE_ON_MIRRORING), | |
| 50 GetMessageContents(dialog)); | |
| 25 EXPECT_EQ(Shell::GetAllRootWindows()[1], | 51 EXPECT_EQ(Shell::GetAllRootWindows()[1], |
| 26 dialog->GetWidget()->GetNativeView()->GetRootWindow()); | 52 dialog->GetWidget()->GetNativeView()->GetRootWindow()); |
| 27 } | 53 } |
| 28 | 54 |
| 29 TEST_F(DisplayErrorDialogTest, CallTwice) { | 55 TEST_F(DisplayErrorDialogTest, CallTwice) { |
| 30 UpdateDisplay("200x200,300x300"); | 56 UpdateDisplay("200x200,300x300"); |
| 31 DisplayErrorDialog::ShowDialog(); | 57 observer()->OnDisplayModeChangeFailed(chromeos::STATE_DUAL_MIRROR); |
| 32 DisplayErrorDialog* dialog = DisplayErrorDialog::GetInstanceForTest(); | 58 DisplayErrorDialog* dialog = observer()->dialog(); |
| 33 EXPECT_TRUE(dialog); | 59 EXPECT_TRUE(dialog); |
| 34 DisplayErrorDialog::ShowDialog(); | 60 |
| 35 EXPECT_EQ(dialog, DisplayErrorDialog::GetInstanceForTest()); | 61 observer()->OnDisplayModeChangeFailed(chromeos::STATE_DUAL_MIRROR); |
| 62 EXPECT_EQ(dialog, observer()->dialog()); | |
| 63 } | |
| 64 | |
| 65 TEST_F(DisplayErrorDialogTest, CallWithDifferentState) { | |
| 66 UpdateDisplay("200x200,300x300"); | |
| 67 observer()->OnDisplayModeChangeFailed(chromeos::STATE_DUAL_MIRROR); | |
| 68 DisplayErrorDialog* dialog = observer()->dialog(); | |
| 69 EXPECT_TRUE(dialog); | |
| 70 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_FAILURE_ON_MIRRORING), | |
| 71 GetMessageContents(dialog)); | |
| 72 | |
| 73 observer()->OnDisplayModeChangeFailed(chromeos::STATE_DUAL_PRIMARY_ONLY); | |
| 74 EXPECT_EQ(dialog, observer()->dialog()); | |
| 75 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_FAILURE_ON_EXTENDED), | |
| 76 GetMessageContents(dialog)); | |
| 36 } | 77 } |
| 37 | 78 |
| 38 TEST_F(DisplayErrorDialogTest, SingleDisplay) { | 79 TEST_F(DisplayErrorDialogTest, SingleDisplay) { |
| 39 UpdateDisplay("200x200"); | 80 UpdateDisplay("200x200"); |
| 40 DisplayErrorDialog::ShowDialog(); | 81 DisplayErrorDialog* dialog = |
| 41 DisplayErrorDialog* dialog = DisplayErrorDialog::GetInstanceForTest(); | 82 DisplayErrorDialog::ShowDialog(chromeos::STATE_DUAL_MIRROR); |
| 42 EXPECT_TRUE(dialog); | 83 EXPECT_TRUE(dialog); |
| 43 EXPECT_TRUE(dialog->GetWidget()->IsVisible()); | 84 EXPECT_TRUE(dialog->GetWidget()->IsVisible()); |
| 44 EXPECT_EQ(Shell::GetInstance()->GetPrimaryRootWindow(), | 85 EXPECT_EQ(Shell::GetInstance()->GetPrimaryRootWindow(), |
| 45 dialog->GetWidget()->GetNativeView()->GetRootWindow()); | 86 dialog->GetWidget()->GetNativeView()->GetRootWindow()); |
| 46 } | 87 } |
| 47 | 88 |
| 48 TEST_F(DisplayErrorDialogTest, DisplayDisconnected) { | 89 TEST_F(DisplayErrorDialogTest, DisplayDisconnected) { |
| 49 UpdateDisplay("200x200,300x300"); | 90 UpdateDisplay("200x200,300x300"); |
| 50 DisplayErrorDialog::ShowDialog(); | 91 observer()->OnDisplayModeChangeFailed(chromeos::STATE_DUAL_MIRROR); |
| 51 DisplayErrorDialog* dialog = DisplayErrorDialog::GetInstanceForTest(); | 92 EXPECT_TRUE(observer()->dialog()); |
| 52 EXPECT_TRUE(dialog); | |
| 53 | 93 |
| 54 UpdateDisplay("200x200"); | 94 UpdateDisplay("200x200"); |
| 55 // Disconnection will close the dialog but we have to run all pending tasks | 95 // Disconnection will close the dialog but we have to run all pending tasks |
| 56 // to make the effect of the close. | 96 // to make the effect of the close. |
| 57 RunAllPendingInMessageLoop(); | 97 RunAllPendingInMessageLoop(); |
| 58 EXPECT_FALSE(DisplayErrorDialog::GetInstanceForTest()); | 98 EXPECT_TRUE(observer()->dialog()); |
| 59 } | 99 } |
| 60 | 100 |
| 61 } // namespace internal | 101 } // namespace internal |
| 62 } // namespace ash | 102 } // namespace ash |
| OLD | NEW |