OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/display/chromeos/display_configurator.h" | 5 #include "ui/display/chromeos/display_configurator.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/run_loop.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "ui/display/chromeos/test/action_logger_util.h" | 16 #include "ui/display/chromeos/test/action_logger_util.h" |
16 #include "ui/display/chromeos/test/test_display_snapshot.h" | 17 #include "ui/display/chromeos/test/test_display_snapshot.h" |
17 #include "ui/display/chromeos/test/test_native_display_delegate.h" | 18 #include "ui/display/chromeos/test/test_native_display_delegate.h" |
18 #include "ui/display/util/display_util.h" | 19 #include "ui/display/util/display_util.h" |
19 | 20 |
20 namespace ui { | 21 namespace ui { |
21 namespace test { | 22 namespace test { |
22 | 23 |
23 namespace { | 24 namespace { |
(...skipping 1644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1668 EXPECT_EQ(CALLBACK_SUCCESS, PopDisplayControlResult()); | 1669 EXPECT_EQ(CALLBACK_SUCCESS, PopDisplayControlResult()); |
1669 EXPECT_EQ(JoinActions(kTakeDisplayControl, kGrab, | 1670 EXPECT_EQ(JoinActions(kTakeDisplayControl, kGrab, |
1670 GetFramebufferAction(small_mode_.size(), &outputs_[0], | 1671 GetFramebufferAction(small_mode_.size(), &outputs_[0], |
1671 nullptr).c_str(), | 1672 nullptr).c_str(), |
1672 GetCrtcAction(outputs_[0], &small_mode_, | 1673 GetCrtcAction(outputs_[0], &small_mode_, |
1673 gfx::Point(0, 0)).c_str(), | 1674 gfx::Point(0, 0)).c_str(), |
1674 kUngrab, NULL), | 1675 kUngrab, NULL), |
1675 log_->GetActionsAndClear()); | 1676 log_->GetActionsAndClear()); |
1676 } | 1677 } |
1677 | 1678 |
| 1679 TEST_F(DisplayConfiguratorTest, |
| 1680 SetDisplayPowerWhilePendingConfigurationTaskRunning) { |
| 1681 // Start out with two displays in extended mode. |
| 1682 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED); |
| 1683 Init(false); |
| 1684 configurator_.ForceInitialConfigure(0); |
| 1685 log_->GetActionsAndClear(); |
| 1686 observer_.Reset(); |
| 1687 |
| 1688 native_display_delegate_->set_run_async(true); |
| 1689 |
| 1690 configurator_.SetDisplayPower( |
| 1691 chromeos::DISPLAY_POWER_ALL_OFF, |
| 1692 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 1693 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, |
| 1694 base::Unretained(this))); |
| 1695 |
| 1696 configurator_.SetDisplayPower( |
| 1697 chromeos::DISPLAY_POWER_ALL_ON, |
| 1698 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 1699 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, |
| 1700 base::Unretained(this))); |
| 1701 |
| 1702 EXPECT_EQ(CALLBACK_NOT_CALLED, PopCallbackResult()); |
| 1703 base::RunLoop().RunUntilIdle(); |
| 1704 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); |
| 1705 EXPECT_EQ(1, observer_.num_changes()); |
| 1706 EXPECT_EQ(0, observer_.num_failures()); |
| 1707 |
| 1708 const int kDualHeight = small_mode_.size().height() + |
| 1709 DisplayConfigurator::kVerticalGap + |
| 1710 big_mode_.size().height(); |
| 1711 EXPECT_EQ( |
| 1712 JoinActions( |
| 1713 kGrab, |
| 1714 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), |
| 1715 &outputs_[0], &outputs_[1]) |
| 1716 .c_str(), |
| 1717 GetCrtcAction(outputs_[0], nullptr, gfx::Point(0, 0)).c_str(), |
| 1718 GetCrtcAction(outputs_[1], nullptr, |
| 1719 gfx::Point(0, small_mode_.size().height() + |
| 1720 DisplayConfigurator::kVerticalGap)) |
| 1721 .c_str(), |
| 1722 kUngrab, NULL), |
| 1723 log_->GetActionsAndClear()); |
| 1724 |
| 1725 EXPECT_TRUE(test_api_.TriggerConfigureTimeout()); |
| 1726 base::RunLoop().RunUntilIdle(); |
| 1727 EXPECT_EQ(CALLBACK_SUCCESS, PopCallbackResult()); |
| 1728 EXPECT_EQ(2, observer_.num_changes()); |
| 1729 EXPECT_EQ(0, observer_.num_failures()); |
| 1730 |
| 1731 EXPECT_EQ( |
| 1732 JoinActions( |
| 1733 kGrab, |
| 1734 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), |
| 1735 &outputs_[0], &outputs_[1]) |
| 1736 .c_str(), |
| 1737 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 1738 GetCrtcAction(outputs_[1], &big_mode_, |
| 1739 gfx::Point(0, small_mode_.size().height() + |
| 1740 DisplayConfigurator::kVerticalGap)) |
| 1741 .c_str(), |
| 1742 kForceDPMS, kUngrab, NULL), |
| 1743 log_->GetActionsAndClear()); |
| 1744 } |
| 1745 |
| 1746 TEST_F(DisplayConfiguratorTest, |
| 1747 SetDisplayPowerAfterFailedDisplayConfiguration) { |
| 1748 // Start out with two displays in extended mode. |
| 1749 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED); |
| 1750 Init(false); |
| 1751 configurator_.ForceInitialConfigure(0); |
| 1752 log_->GetActionsAndClear(); |
| 1753 observer_.Reset(); |
| 1754 |
| 1755 // Fail display configuration. |
| 1756 native_display_delegate_->set_max_configurable_pixels(-1); |
| 1757 |
| 1758 configurator_.SetDisplayPower( |
| 1759 chromeos::DISPLAY_POWER_ALL_OFF, |
| 1760 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 1761 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, |
| 1762 base::Unretained(this))); |
| 1763 |
| 1764 EXPECT_EQ(CALLBACK_FAILURE, PopCallbackResult()); |
| 1765 EXPECT_EQ(0, observer_.num_changes()); |
| 1766 EXPECT_EQ(1, observer_.num_failures()); |
| 1767 |
| 1768 const int kDualHeight = small_mode_.size().height() + |
| 1769 DisplayConfigurator::kVerticalGap + |
| 1770 big_mode_.size().height(); |
| 1771 |
| 1772 EXPECT_EQ( |
| 1773 JoinActions( |
| 1774 kGrab, |
| 1775 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), |
| 1776 &outputs_[0], &outputs_[1]) |
| 1777 .c_str(), |
| 1778 GetCrtcAction(outputs_[0], nullptr, gfx::Point(0, 0)).c_str(), |
| 1779 GetCrtcAction(outputs_[1], nullptr, |
| 1780 gfx::Point(0, small_mode_.size().height() + |
| 1781 DisplayConfigurator::kVerticalGap)) |
| 1782 .c_str(), |
| 1783 kUngrab, NULL), |
| 1784 log_->GetActionsAndClear()); |
| 1785 |
| 1786 // This configuration should trigger a display configuration since the |
| 1787 // previous configuration failed. |
| 1788 configurator_.SetDisplayPower( |
| 1789 chromeos::DISPLAY_POWER_ALL_ON, |
| 1790 DisplayConfigurator::kSetDisplayPowerNoFlags, |
| 1791 base::Bind(&DisplayConfiguratorTest::OnConfiguredCallback, |
| 1792 base::Unretained(this))); |
| 1793 |
| 1794 EXPECT_EQ(0, observer_.num_changes()); |
| 1795 EXPECT_EQ(2, observer_.num_failures()); |
| 1796 EXPECT_EQ( |
| 1797 JoinActions( |
| 1798 kGrab, |
| 1799 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), |
| 1800 &outputs_[0], &outputs_[1]) |
| 1801 .c_str(), |
| 1802 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 1803 GetCrtcAction(outputs_[1], &big_mode_, |
| 1804 gfx::Point(0, small_mode_.size().height() + |
| 1805 DisplayConfigurator::kVerticalGap)) |
| 1806 .c_str(), |
| 1807 GetCrtcAction(outputs_[1], &small_mode_, |
| 1808 gfx::Point(0, small_mode_.size().height() + |
| 1809 DisplayConfigurator::kVerticalGap)) |
| 1810 .c_str(), |
| 1811 kUngrab, NULL), |
| 1812 log_->GetActionsAndClear()); |
| 1813 |
| 1814 // Allow configuration to succeed. |
| 1815 native_display_delegate_->set_max_configurable_pixels(0); |
| 1816 |
| 1817 // Validate that a configuration event has the proper power state (displays |
| 1818 // should be on). |
| 1819 configurator_.OnConfigurationChanged(); |
| 1820 EXPECT_TRUE(test_api_.TriggerConfigureTimeout()); |
| 1821 |
| 1822 EXPECT_EQ(1, observer_.num_changes()); |
| 1823 EXPECT_EQ(2, observer_.num_failures()); |
| 1824 |
| 1825 EXPECT_EQ( |
| 1826 JoinActions( |
| 1827 kGrab, |
| 1828 GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), |
| 1829 &outputs_[0], &outputs_[1]) |
| 1830 .c_str(), |
| 1831 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 1832 GetCrtcAction(outputs_[1], &big_mode_, |
| 1833 gfx::Point(0, small_mode_.size().height() + |
| 1834 DisplayConfigurator::kVerticalGap)) |
| 1835 .c_str(), |
| 1836 kUngrab, NULL), |
| 1837 log_->GetActionsAndClear()); |
| 1838 } |
| 1839 |
1678 } // namespace test | 1840 } // namespace test |
1679 } // namespace ui | 1841 } // namespace ui |
OLD | NEW |