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

Side by Side Diff: ui/aura/window_unittest.cc

Issue 558203002: Propagate window transformed notification to child hierarchy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renamed/re-ordered arguments Created 6 years, 3 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
« no previous file with comments | « ui/aura/window_observer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/aura/window.h" 5 #include "ui/aura/window.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 1689 matching lines...) Expand 10 before | Expand all | Expand 10 after
1700 } 1700 }
1701 1701
1702 // Return a tuple of the arguments passed in OnPropertyChanged callback. 1702 // Return a tuple of the arguments passed in OnPropertyChanged callback.
1703 PropertyChangeInfo PropertyChangeInfoAndClear() { 1703 PropertyChangeInfo PropertyChangeInfoAndClear() {
1704 PropertyChangeInfo result(property_key_, old_property_value_); 1704 PropertyChangeInfo result(property_key_, old_property_value_);
1705 property_key_ = NULL; 1705 property_key_ = NULL;
1706 old_property_value_ = -3; 1706 old_property_value_ = -3;
1707 return result; 1707 return result;
1708 } 1708 }
1709 1709
1710 std::string TransformNotificationsAndClear() {
1711 std::string result;
1712 for (std::vector<std::pair<int, int> >::iterator it =
1713 transform_notifications_.begin();
1714 it != transform_notifications_.end();
1715 ++it) {
1716 base::StringAppendF(&result, "(%d,%d)", it->first, it->second);
1717 }
1718 transform_notifications_.clear();
1719 return result;
1720 }
1721
1710 private: 1722 private:
1711 virtual void OnWindowAdded(Window* new_window) OVERRIDE { 1723 virtual void OnWindowAdded(Window* new_window) OVERRIDE {
1712 added_count_++; 1724 added_count_++;
1713 } 1725 }
1714 1726
1715 virtual void OnWillRemoveWindow(Window* window) OVERRIDE { 1727 virtual void OnWillRemoveWindow(Window* window) OVERRIDE {
1716 removed_count_++; 1728 removed_count_++;
1717 } 1729 }
1718 1730
1719 virtual void OnWindowVisibilityChanged(Window* window, 1731 virtual void OnWindowVisibilityChanged(Window* window,
1720 bool visible) OVERRIDE { 1732 bool visible) OVERRIDE {
1721 visibility_info_.reset(new VisibilityInfo); 1733 visibility_info_.reset(new VisibilityInfo);
1722 visibility_info_->window_visible = window->IsVisible(); 1734 visibility_info_->window_visible = window->IsVisible();
1723 visibility_info_->visible_param = visible; 1735 visibility_info_->visible_param = visible;
1724 } 1736 }
1725 1737
1726 virtual void OnWindowDestroyed(Window* window) OVERRIDE { 1738 virtual void OnWindowDestroyed(Window* window) OVERRIDE {
1727 EXPECT_FALSE(window->parent()); 1739 EXPECT_FALSE(window->parent());
1728 destroyed_count_++; 1740 destroyed_count_++;
1729 } 1741 }
1730 1742
1731 virtual void OnWindowPropertyChanged(Window* window, 1743 virtual void OnWindowPropertyChanged(Window* window,
1732 const void* key, 1744 const void* key,
1733 intptr_t old) OVERRIDE { 1745 intptr_t old) OVERRIDE {
1734 property_key_ = key; 1746 property_key_ = key;
1735 old_property_value_ = old; 1747 old_property_value_ = old;
1736 } 1748 }
1737 1749
1750 virtual void OnAncestorWindowTransformed(Window* source,
1751 Window* window) OVERRIDE {
1752 transform_notifications_.push_back(
1753 std::make_pair(source->id(), window->id()));
1754 }
1755
1738 int added_count_; 1756 int added_count_;
1739 int removed_count_; 1757 int removed_count_;
1740 int destroyed_count_; 1758 int destroyed_count_;
1741 scoped_ptr<VisibilityInfo> visibility_info_; 1759 scoped_ptr<VisibilityInfo> visibility_info_;
1742 const void* property_key_; 1760 const void* property_key_;
1743 intptr_t old_property_value_; 1761 intptr_t old_property_value_;
1762 std::vector<std::pair<int, int> > transform_notifications_;
1744 1763
1745 DISALLOW_COPY_AND_ASSIGN(WindowObserverTest); 1764 DISALLOW_COPY_AND_ASSIGN(WindowObserverTest);
1746 }; 1765 };
1747 1766
1748 // Various assertions for WindowObserver. 1767 // Various assertions for WindowObserver.
1749 TEST_F(WindowObserverTest, WindowObserver) { 1768 TEST_F(WindowObserverTest, WindowObserver) {
1750 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); 1769 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window()));
1751 w1->AddObserver(this); 1770 w1->AddObserver(this);
1752 1771
1753 // Create a new window as a child of w1, our observer should be notified. 1772 // Create a new window as a child of w1, our observer should be notified.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1850 w1->SetNativeWindowProperty(native_prop_key, NULL); 1869 w1->SetNativeWindowProperty(native_prop_key, NULL);
1851 EXPECT_EQ(PropertyChangeInfo(native_prop_key, 1870 EXPECT_EQ(PropertyChangeInfo(native_prop_key,
1852 reinterpret_cast<intptr_t>(&*w1)), 1871 reinterpret_cast<intptr_t>(&*w1)),
1853 PropertyChangeInfoAndClear()); 1872 PropertyChangeInfoAndClear());
1854 1873
1855 // Sanity check to see if |PropertyChangeInfoAndClear| really clears. 1874 // Sanity check to see if |PropertyChangeInfoAndClear| really clears.
1856 EXPECT_EQ(PropertyChangeInfo( 1875 EXPECT_EQ(PropertyChangeInfo(
1857 reinterpret_cast<const void*>(NULL), -3), PropertyChangeInfoAndClear()); 1876 reinterpret_cast<const void*>(NULL), -3), PropertyChangeInfoAndClear());
1858 } 1877 }
1859 1878
1879 TEST_F(WindowObserverTest, AncestorTransformed) {
1880 // Create following window hierarchy:
1881 // root_window
1882 // +-- w1
1883 // +-- w2
1884 // +-- w3
1885 // +-- w4
1886 // Then, apply a transform to |w1| and ensure all its descendants are
1887 // notified.
1888 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window()));
1889 w1->AddObserver(this);
1890 scoped_ptr<Window> w2(CreateTestWindowWithId(2, w1.get()));
1891 w2->AddObserver(this);
1892 scoped_ptr<Window> w3(CreateTestWindowWithId(3, w1.get()));
1893 w3->AddObserver(this);
1894 scoped_ptr<Window> w4(CreateTestWindowWithId(4, w3.get()));
1895 w4->AddObserver(this);
1896
1897 EXPECT_EQ("", TransformNotificationsAndClear());
sky 2014/09/10 16:10:47 nit: either "" -> std::string() or EXPECT_TRUE(Tra
1898
1899 gfx::Transform transform;
1900 transform.Translate(10, 10);
1901 w1->SetTransform(transform);
1902
1903 EXPECT_EQ("(1,1)(1,2)(1,3)(1,4)", TransformNotificationsAndClear());
1904 }
1905
1860 TEST_F(WindowTest, AcquireLayer) { 1906 TEST_F(WindowTest, AcquireLayer) {
1861 scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window())); 1907 scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window()));
1862 scoped_ptr<Window> window2(CreateTestWindowWithId(2, root_window())); 1908 scoped_ptr<Window> window2(CreateTestWindowWithId(2, root_window()));
1863 ui::Layer* parent = window1->parent()->layer(); 1909 ui::Layer* parent = window1->parent()->layer();
1864 EXPECT_EQ(2U, parent->children().size()); 1910 EXPECT_EQ(2U, parent->children().size());
1865 1911
1866 WindowTestApi window1_test_api(window1.get()); 1912 WindowTestApi window1_test_api(window1.get());
1867 WindowTestApi window2_test_api(window2.get()); 1913 WindowTestApi window2_test_api(window2.get());
1868 1914
1869 EXPECT_TRUE(window1_test_api.OwnsLayer()); 1915 EXPECT_TRUE(window1_test_api.OwnsLayer());
(...skipping 1558 matching lines...) Expand 10 before | Expand all | Expand 10 after
3428 3474
3429 EXPECT_TRUE(animator.get()); 3475 EXPECT_TRUE(animator.get());
3430 EXPECT_FALSE(animator->is_animating()); 3476 EXPECT_FALSE(animator->is_animating());
3431 EXPECT_TRUE(observer.animation_completed()); 3477 EXPECT_TRUE(observer.animation_completed());
3432 EXPECT_FALSE(observer.animation_aborted()); 3478 EXPECT_FALSE(observer.animation_aborted());
3433 animator->RemoveObserver(&observer); 3479 animator->RemoveObserver(&observer);
3434 } 3480 }
3435 3481
3436 } // namespace test 3482 } // namespace test
3437 } // namespace aura 3483 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/window_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698