Home | History | Annotate | Download | only in display
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "ash/display/display_error_observer_chromeos.h"
      6 
      7 #include "ash/shell.h"
      8 #include "ash/test/ash_test_base.h"
      9 #include "grit/ash_strings.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"
     14 #include "ui/views/widget/widget.h"
     15 
     16 namespace ash {
     17 
     18 class DisplayErrorObserverTest : public test::AshTestBase {
     19  protected:
     20   DisplayErrorObserverTest() {
     21   }
     22 
     23   virtual ~DisplayErrorObserverTest() {
     24   }
     25 
     26   virtual void SetUp() OVERRIDE {
     27     test::AshTestBase::SetUp();
     28     observer_.reset(new DisplayErrorObserver());
     29   }
     30 
     31  protected:
     32   DisplayErrorObserver* observer() { return observer_.get(); }
     33 
     34   base::string16 GetMessageContents() {
     35     return observer_->GetTitleOfDisplayErrorNotificationForTest();
     36   }
     37 
     38  private:
     39   scoped_ptr<DisplayErrorObserver> observer_;
     40 
     41   DISALLOW_COPY_AND_ASSIGN(DisplayErrorObserverTest);
     42 };
     43 
     44 TEST_F(DisplayErrorObserverTest, Normal) {
     45   if (!SupportsMultipleDisplays())
     46     return;
     47 
     48   UpdateDisplay("200x200,300x300");
     49   observer()->OnDisplayModeChangeFailed(ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR);
     50   EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_FAILURE_ON_MIRRORING),
     51             GetMessageContents());
     52 }
     53 
     54 TEST_F(DisplayErrorObserverTest, CallTwice) {
     55   if (!SupportsMultipleDisplays())
     56     return;
     57 
     58   UpdateDisplay("200x200,300x300");
     59   observer()->OnDisplayModeChangeFailed(ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR);
     60   base::string16 message = GetMessageContents();
     61   EXPECT_FALSE(message.empty());
     62 
     63   observer()->OnDisplayModeChangeFailed(ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR);
     64   base::string16 message2 = GetMessageContents();
     65   EXPECT_FALSE(message2.empty());
     66   EXPECT_EQ(message, message2);
     67 }
     68 
     69 TEST_F(DisplayErrorObserverTest, CallWithDifferentState) {
     70   if (!SupportsMultipleDisplays())
     71     return;
     72 
     73   UpdateDisplay("200x200,300x300");
     74   observer()->OnDisplayModeChangeFailed(ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR);
     75   EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_FAILURE_ON_MIRRORING),
     76             GetMessageContents());
     77 
     78   observer()->OnDisplayModeChangeFailed(
     79       ui::MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED);
     80   EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_FAILURE_ON_NON_MIRRORING),
     81             GetMessageContents());
     82 }
     83 
     84 }  // namespace ash
     85