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

Side by Side Diff: ash/display/display_error_dialog_unittest.cc

Issue 12212171: Provides more types of errors for output status. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 7 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 observer_.reset();
29 test::AshTestBase::TearDown();
30 }
31
32 DisplayErrorObserver* observer() { return observer_.get(); }
33
34 const string16& GetMessageContents(const DisplayErrorDialog* dialog) {
35 const views::Label* label = static_cast<const views::Label*>(
36 static_cast<const views::View*>(dialog)->child_at(0));
37 return label->text();
38 }
39
40 private:
41 scoped_ptr<DisplayErrorObserver> observer_;
42 };
43
44 }
16 45
17 // The test cases in this file usually check if the showing dialog doesn't 46 // 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. 47 // cause any crashes, and the code doesn't cause any memory leaks.
19 TEST_F(DisplayErrorDialogTest, Normal) { 48 TEST_F(DisplayErrorDialogTest, Normal) {
20 UpdateDisplay("200x200,300x300"); 49 UpdateDisplay("200x200,300x300");
21 DisplayErrorDialog::ShowDialog(); 50 DisplayErrorDialog* dialog =
22 DisplayErrorDialog* dialog = DisplayErrorDialog::GetInstanceForTest(); 51 DisplayErrorDialog::ShowDialog(chromeos::STATE_DUAL_MIRROR);
23 EXPECT_TRUE(dialog); 52 EXPECT_TRUE(dialog);
24 EXPECT_TRUE(dialog->GetWidget()->IsVisible()); 53 EXPECT_TRUE(dialog->GetWidget()->IsVisible());
54 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_FAILURE_ON_MIRRORING),
55 GetMessageContents(dialog));
25 EXPECT_EQ(Shell::GetAllRootWindows()[1], 56 EXPECT_EQ(Shell::GetAllRootWindows()[1],
26 dialog->GetWidget()->GetNativeView()->GetRootWindow()); 57 dialog->GetWidget()->GetNativeView()->GetRootWindow());
27 } 58 }
28 59
29 TEST_F(DisplayErrorDialogTest, CallTwice) { 60 TEST_F(DisplayErrorDialogTest, CallTwice) {
30 UpdateDisplay("200x200,300x300"); 61 UpdateDisplay("200x200,300x300");
31 DisplayErrorDialog::ShowDialog(); 62 observer()->OnDisplayModeChangeFailed(chromeos::STATE_DUAL_MIRROR);
32 DisplayErrorDialog* dialog = DisplayErrorDialog::GetInstanceForTest(); 63 const DisplayErrorDialog* dialog = observer()->dialog();
33 EXPECT_TRUE(dialog); 64 EXPECT_TRUE(dialog);
34 DisplayErrorDialog::ShowDialog(); 65
35 EXPECT_EQ(dialog, DisplayErrorDialog::GetInstanceForTest()); 66 observer()->OnDisplayModeChangeFailed(chromeos::STATE_DUAL_MIRROR);
67 EXPECT_EQ(dialog, observer()->dialog());
68 }
69
70 TEST_F(DisplayErrorDialogTest, CallWithDifferentState) {
71 UpdateDisplay("200x200,300x300");
72 observer()->OnDisplayModeChangeFailed(chromeos::STATE_DUAL_MIRROR);
73 const DisplayErrorDialog* dialog = observer()->dialog();
74 EXPECT_TRUE(dialog);
75 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_FAILURE_ON_MIRRORING),
76 GetMessageContents(dialog));
77
78 observer()->OnDisplayModeChangeFailed(chromeos::STATE_DUAL_PRIMARY_ONLY);
79 EXPECT_EQ(dialog, observer()->dialog());
80 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_FAILURE_ON_EXTENDED),
81 GetMessageContents(dialog));
36 } 82 }
37 83
38 TEST_F(DisplayErrorDialogTest, SingleDisplay) { 84 TEST_F(DisplayErrorDialogTest, SingleDisplay) {
39 UpdateDisplay("200x200"); 85 UpdateDisplay("200x200");
40 DisplayErrorDialog::ShowDialog(); 86 DisplayErrorDialog* dialog =
41 DisplayErrorDialog* dialog = DisplayErrorDialog::GetInstanceForTest(); 87 DisplayErrorDialog::ShowDialog(chromeos::STATE_DUAL_MIRROR);
42 EXPECT_TRUE(dialog); 88 EXPECT_TRUE(dialog);
43 EXPECT_TRUE(dialog->GetWidget()->IsVisible()); 89 EXPECT_TRUE(dialog->GetWidget()->IsVisible());
44 EXPECT_EQ(Shell::GetInstance()->GetPrimaryRootWindow(), 90 EXPECT_EQ(Shell::GetInstance()->GetPrimaryRootWindow(),
45 dialog->GetWidget()->GetNativeView()->GetRootWindow()); 91 dialog->GetWidget()->GetNativeView()->GetRootWindow());
46 } 92 }
47 93
48 TEST_F(DisplayErrorDialogTest, DisplayDisconnected) { 94 TEST_F(DisplayErrorDialogTest, DisplayDisconnected) {
49 UpdateDisplay("200x200,300x300"); 95 UpdateDisplay("200x200,300x300");
50 DisplayErrorDialog::ShowDialog(); 96 observer()->OnDisplayModeChangeFailed(chromeos::STATE_DUAL_MIRROR);
51 DisplayErrorDialog* dialog = DisplayErrorDialog::GetInstanceForTest(); 97 EXPECT_TRUE(observer()->dialog());
52 EXPECT_TRUE(dialog);
53 98
54 UpdateDisplay("200x200"); 99 UpdateDisplay("200x200");
55 // Disconnection will close the dialog but we have to run all pending tasks 100 // Disconnection will close the dialog but we have to run all pending tasks
56 // to make the effect of the close. 101 // to make the effect of the close.
57 RunAllPendingInMessageLoop(); 102 RunAllPendingInMessageLoop();
58 EXPECT_FALSE(DisplayErrorDialog::GetInstanceForTest()); 103 EXPECT_TRUE(observer()->dialog());
59 } 104 }
60 105
61 } // namespace internal 106 } // namespace internal
62 } // namespace ash 107 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698