OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
824 w121->Focus(); | 824 w121->Focus(); |
825 EXPECT_EQ(w121.get(), w1->GetFocusManager()->GetFocusedWindow()); | 825 EXPECT_EQ(w121.get(), w1->GetFocusManager()->GetFocusedWindow()); |
826 | 826 |
827 // An attempt to focus 111 should be ignored and w121 should retain focus, | 827 // An attempt to focus 111 should be ignored and w121 should retain focus, |
828 // since a consumes_events_ window with a child is in the z-index above w111. | 828 // since a consumes_events_ window with a child is in the z-index above w111. |
829 EXPECT_FALSE(w111->CanFocus()); | 829 EXPECT_FALSE(w111->CanFocus()); |
830 w111->Focus(); | 830 w111->Focus(); |
831 EXPECT_EQ(w121.get(), w1->GetFocusManager()->GetFocusedWindow()); | 831 EXPECT_EQ(w121.get(), w1->GetFocusManager()->GetFocusedWindow()); |
832 } | 832 } |
833 | 833 |
834 TEST_F(WindowTest, Fullscreen) { | |
835 gfx::Rect original_bounds = gfx::Rect(100, 100, 100, 100); | |
836 gfx::Rect desktop_bounds(Desktop::GetInstance()->GetHostSize()); | |
837 scoped_ptr<Window> w(CreateTestWindowWithDelegate( | |
838 NULL, 1, original_bounds, NULL)); | |
839 EXPECT_EQ(original_bounds, w->bounds()); | |
840 | |
841 // Restoreing the restored window. | |
842 w->Restore(); | |
843 EXPECT_EQ(ui::SHOW_STATE_NORMAL, w->show_state()); | |
844 EXPECT_EQ(original_bounds, w->bounds()); | |
845 | |
846 // Fullscreen | |
847 w->Fullscreen(); | |
848 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, w->show_state()); | |
849 EXPECT_EQ(desktop_bounds, w->bounds()); | |
850 w->Restore(); | |
851 EXPECT_EQ(ui::SHOW_STATE_NORMAL, w->show_state()); | |
852 EXPECT_EQ(original_bounds, w->bounds()); | |
853 | |
854 // Calling Fullscreen() twice should have no additional effect. | |
855 w->Fullscreen(); | |
856 w->Fullscreen(); | |
857 EXPECT_EQ(desktop_bounds, w->bounds()); | |
858 w->Restore(); | |
859 EXPECT_EQ(ui::SHOW_STATE_NORMAL, w->show_state()); | |
860 EXPECT_EQ(original_bounds, w->bounds()); | |
861 | |
862 // Calling SetBounds() in fullscreen mode should only update the | |
863 // restore bounds not change the bounds of the window. | |
864 gfx::Rect new_bounds(50, 50, 50, 50); | |
865 w->Fullscreen(); | |
866 w->SetBounds(new_bounds); | |
867 EXPECT_EQ(desktop_bounds, w->bounds()); | |
868 w->Restore(); | |
869 EXPECT_EQ(new_bounds, w->bounds()); | |
870 } | |
871 | |
872 TEST_F(WindowTest, Maximized) { | |
873 gfx::Rect original_bounds = gfx::Rect(100, 100, 100, 100); | |
874 gfx::Rect desktop_bounds( | |
875 gfx::Screen::GetMonitorWorkAreaNearestPoint(gfx::Point())); | |
876 scoped_ptr<Window> w(CreateTestWindowWithDelegate( | |
877 NULL, 1, original_bounds, NULL)); | |
878 EXPECT_EQ(original_bounds, w->bounds()); | |
879 | |
880 // Maximized | |
881 w->Maximize(); | |
882 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, w->show_state()); | |
883 gfx::Rect max_bounds(desktop_bounds); | |
884 EXPECT_EQ(max_bounds, w->bounds()); | |
885 w->Restore(); | |
886 EXPECT_EQ(ui::SHOW_STATE_NORMAL, w->show_state()); | |
887 EXPECT_EQ(original_bounds, w->bounds()); | |
888 | |
889 // Maximize twice | |
890 w->Maximize(); | |
891 w->Maximize(); | |
892 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, w->show_state()); | |
893 EXPECT_EQ(max_bounds, w->bounds()); | |
894 w->Restore(); | |
895 EXPECT_EQ(ui::SHOW_STATE_NORMAL, w->show_state()); | |
896 EXPECT_EQ(original_bounds, w->bounds()); | |
897 | |
898 // Maximized -> Fullscreen -> Maximized -> Normal | |
899 w->Maximize(); | |
900 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, w->show_state()); | |
901 EXPECT_EQ(max_bounds, w->bounds()); | |
902 w->Fullscreen(); | |
903 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, w->show_state()); | |
904 EXPECT_EQ(desktop_bounds, w->bounds()); | |
905 w->Maximize(); | |
906 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, w->show_state()); | |
907 EXPECT_EQ(max_bounds, w->bounds()); | |
908 w->Restore(); | |
909 EXPECT_EQ(ui::SHOW_STATE_NORMAL, w->show_state()); | |
910 EXPECT_EQ(original_bounds, w->bounds()); | |
911 | |
912 // Calling SetBounds() in maximized mode mode should only update the | |
913 // restore bounds not change the bounds of the window. | |
914 gfx::Rect new_bounds(50, 50, 50, 50); | |
915 w->Maximize(); | |
916 w->SetBounds(new_bounds); | |
917 EXPECT_EQ(max_bounds, w->bounds()); | |
918 w->Restore(); | |
919 EXPECT_EQ(new_bounds, w->bounds()); | |
920 } | |
921 | |
922 // Various assertions for activating/deactivating. | 834 // Various assertions for activating/deactivating. |
923 TEST_F(WindowTest, Deactivate) { | 835 TEST_F(WindowTest, Deactivate) { |
924 TestWindowDelegate d1; | 836 TestWindowDelegate d1; |
925 TestWindowDelegate d2; | 837 TestWindowDelegate d2; |
926 scoped_ptr<Window> w1( | 838 scoped_ptr<Window> w1( |
927 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(), NULL)); | 839 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(), NULL)); |
928 scoped_ptr<Window> w2( | 840 scoped_ptr<Window> w2( |
929 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(), NULL)); | 841 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(), NULL)); |
930 Window* parent = w1->parent(); | 842 Window* parent = w1->parent(); |
931 parent->Show(); | 843 parent->Show(); |
(...skipping 11 matching lines...) Expand all Loading... | |
943 EXPECT_FALSE(w2->IsActive()); | 855 EXPECT_FALSE(w2->IsActive()); |
944 EXPECT_EQ(w1.get(), parent->children()[1]); | 856 EXPECT_EQ(w1.get(), parent->children()[1]); |
945 | 857 |
946 // Deactivate w1 and make sure w2 becomes active and frontmost. | 858 // Deactivate w1 and make sure w2 becomes active and frontmost. |
947 w1->Deactivate(); | 859 w1->Deactivate(); |
948 EXPECT_FALSE(w1->IsActive()); | 860 EXPECT_FALSE(w1->IsActive()); |
949 EXPECT_TRUE(w2->IsActive()); | 861 EXPECT_TRUE(w2->IsActive()); |
950 EXPECT_EQ(w2.get(), parent->children()[1]); | 862 EXPECT_EQ(w2.get(), parent->children()[1]); |
951 } | 863 } |
952 | 864 |
953 TEST_F(WindowTest, IsOrContainsFullscreenWindow) { | |
954 scoped_ptr<Window> w1( | |
955 CreateTestWindowWithDelegate(NULL, 1, gfx::Rect(0, 0, 100, 100), NULL)); | |
956 scoped_ptr<Window> w11( | |
957 CreateTestWindow(SK_ColorWHITE, 11, gfx::Rect(0, 0, 10, 10), w1.get())); | |
958 | |
959 Window* root = Desktop::GetInstance(); | |
960 EXPECT_FALSE(root->IsOrContainsFullscreenWindow()); | |
961 | |
962 w11->Fullscreen(); | |
963 EXPECT_TRUE(root->IsOrContainsFullscreenWindow()); | |
964 | |
965 w11->Hide(); | |
966 EXPECT_FALSE(root->IsOrContainsFullscreenWindow()); | |
967 } | |
968 | |
969 #if !defined(OS_WIN) | 865 #if !defined(OS_WIN) |
970 // Tests transformation on the desktop. | 866 // Tests transformation on the desktop. |
971 TEST_F(WindowTest, Transform) { | 867 TEST_F(WindowTest, Transform) { |
972 Desktop* desktop = Desktop::GetInstance(); | 868 Desktop* desktop = Desktop::GetInstance(); |
973 desktop->ShowDesktop(); | 869 desktop->ShowDesktop(); |
974 gfx::Size size = desktop->GetHostSize(); | 870 gfx::Size size = desktop->GetHostSize(); |
975 EXPECT_EQ(gfx::Rect(size), | 871 EXPECT_EQ(gfx::Rect(size), |
976 gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point())); | 872 gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point())); |
977 | 873 |
978 // Rotate it clock-wise 90 degrees. | 874 // Rotate it clock-wise 90 degrees. |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1082 TEST_F(ToplevelWindowTest, TopMostActivate) { | 978 TEST_F(ToplevelWindowTest, TopMostActivate) { |
1083 ActivateWindowDelegate activate; | 979 ActivateWindowDelegate activate; |
1084 ActivateWindowDelegate non_activate(false); | 980 ActivateWindowDelegate non_activate(false); |
1085 | 981 |
1086 scoped_ptr<Window> w1(CreateTestToplevelWindow(&non_activate, gfx::Rect())); | 982 scoped_ptr<Window> w1(CreateTestToplevelWindow(&non_activate, gfx::Rect())); |
1087 scoped_ptr<Window> w2(CreateTestToplevelWindow(&activate, gfx::Rect())); | 983 scoped_ptr<Window> w2(CreateTestToplevelWindow(&activate, gfx::Rect())); |
1088 scoped_ptr<Window> w3(CreateTestToplevelWindow(&non_activate, gfx::Rect())); | 984 scoped_ptr<Window> w3(CreateTestToplevelWindow(&non_activate, gfx::Rect())); |
1089 EXPECT_EQ(w2.get(), toplevel_container_.GetTopmostWindowToActivate(NULL)); | 985 EXPECT_EQ(w2.get(), toplevel_container_.GetTopmostWindowToActivate(NULL)); |
1090 } | 986 } |
1091 | 987 |
1092 // Tests that maximized windows get resized after desktop is resized. | |
1093 TEST_F(ToplevelWindowTest, MaximizeAfterDesktopResize) { | |
1094 gfx::Rect window_bounds(10, 10, 300, 400); | |
1095 scoped_ptr<Window> w1(CreateTestToplevelWindow(NULL, window_bounds)); | |
1096 | |
1097 w1->Show(); | |
1098 EXPECT_EQ(window_bounds, w1->bounds()); | |
1099 | |
1100 w1->Maximize(); | |
1101 EXPECT_EQ(gfx::Screen::GetMonitorWorkAreaNearestWindow(w1.get()), | |
1102 w1->bounds()); | |
1103 | |
1104 // Resize the desktop. | |
1105 Desktop* desktop = Desktop::GetInstance(); | |
1106 gfx::Size desktop_size = desktop->GetHostSize(); | |
1107 desktop->SetBounds(gfx::Rect(0, 0, desktop_size.width() + 100, | |
1108 desktop_size.height() + 200)); | |
1109 | |
1110 EXPECT_EQ(gfx::Screen::GetMonitorWorkAreaNearestWindow(w1.get()), | |
1111 w1->bounds()); | |
1112 | |
1113 w1->Restore(); | |
1114 EXPECT_EQ(window_bounds, w1->bounds()); | |
1115 } | |
1116 | |
1117 // Tests that fullscreen windows get resized after desktop is resized. | |
1118 TEST_F(ToplevelWindowTest, FullscreenAfterDesktopResize) { | |
1119 gfx::Rect window_bounds(10, 10, 300, 400); | |
1120 scoped_ptr<Window> w1(CreateTestToplevelWindow(NULL, window_bounds)); | |
1121 | |
1122 w1->Show(); | |
1123 EXPECT_EQ(window_bounds, w1->bounds()); | |
1124 | |
1125 w1->Fullscreen(); | |
1126 EXPECT_EQ(gfx::Screen::GetMonitorAreaNearestWindow(w1.get()), w1->bounds()); | |
1127 | |
1128 // Resize the desktop. | |
1129 Desktop* desktop = Desktop::GetInstance(); | |
1130 gfx::Size desktop_size = desktop->GetHostSize(); | |
1131 desktop->SetBounds(gfx::Rect(0, 0, desktop_size.width() + 100, | |
1132 desktop_size.height() + 200)); | |
1133 | |
1134 EXPECT_EQ(gfx::Screen::GetMonitorAreaNearestWindow(w1.get()), w1->bounds()); | |
1135 | |
1136 w1->Restore(); | |
1137 EXPECT_EQ(window_bounds, w1->bounds()); | |
1138 } | |
1139 | |
1140 TEST_F(WindowTest, Property) { | 988 TEST_F(WindowTest, Property) { |
1141 scoped_ptr<Window> w(CreateTestWindowWithId(0, NULL)); | 989 scoped_ptr<Window> w(CreateTestWindowWithId(0, NULL)); |
1142 const gfx::NativeView target = const_cast<const gfx::NativeView>(w.get()); | 990 const gfx::NativeView target = const_cast<const gfx::NativeView>(w.get()); |
1143 const char* key = "test"; | 991 const char* key = "test"; |
1144 EXPECT_EQ(NULL, w->GetProperty(key)); | 992 EXPECT_EQ(NULL, w->GetProperty(key)); |
993 EXPECT_EQ(0, w->GetIntProperty(key)); | |
1145 EXPECT_EQ(NULL, ui::ViewProp::GetValue(target, key)); | 994 EXPECT_EQ(NULL, ui::ViewProp::GetValue(target, key)); |
1146 | 995 |
996 w->SetIntProperty(key, 1); | |
997 EXPECT_EQ(1, w->GetIntProperty(key)); | |
1147 void* value = reinterpret_cast<void*>(static_cast<intptr_t>(1)); | 998 void* value = reinterpret_cast<void*>(static_cast<intptr_t>(1)); |
1148 w->SetProperty(key, value); | |
1149 EXPECT_EQ(value, w->GetProperty(key)); | |
1150 EXPECT_EQ(value, ui::ViewProp::GetValue(target, key)); | 999 EXPECT_EQ(value, ui::ViewProp::GetValue(target, key)); |
1151 | 1000 |
1152 // Overwrite the property with different value type. | 1001 // Overwrite the property with different value type. |
1153 w->SetProperty(key, static_cast<void*>(const_cast<char*>("string"))); | 1002 w->SetProperty(key, static_cast<void*>(const_cast<char*>("string"))); |
1154 std::string expected("string"); | 1003 std::string expected("string"); |
1155 EXPECT_EQ(expected, | 1004 EXPECT_EQ(expected, static_cast<const char*>(w->GetProperty(key))); |
1156 static_cast<const char*>(w->GetProperty(key))); | |
1157 EXPECT_EQ(expected, | 1005 EXPECT_EQ(expected, |
1158 static_cast<const char*>(ui::ViewProp::GetValue(target, key))); | 1006 static_cast<const char*>(ui::ViewProp::GetValue(target, key))); |
1159 | 1007 |
1160 // Non-existent property. | 1008 // Non-existent property. |
1161 EXPECT_EQ(NULL, w->GetProperty("foo")); | 1009 EXPECT_EQ(NULL, w->GetProperty("foo")); |
1010 EXPECT_EQ(0, w->GetIntProperty("foo")); | |
1162 EXPECT_EQ(NULL, ui::ViewProp::GetValue(target, "foo")); | 1011 EXPECT_EQ(NULL, ui::ViewProp::GetValue(target, "foo")); |
1163 | 1012 |
1164 // Set NULL and make sure the property is gone. | 1013 // Set NULL and make sure the property is gone. |
1165 w->SetProperty(key, NULL); | 1014 w->SetProperty(key, NULL); |
1166 EXPECT_EQ(NULL, w->GetProperty(key)); | 1015 EXPECT_EQ(NULL, w->GetProperty(key)); |
1016 EXPECT_EQ(0, w->GetIntProperty(key)); | |
1167 EXPECT_EQ(NULL, ui::ViewProp::GetValue(target, key)); | 1017 EXPECT_EQ(NULL, ui::ViewProp::GetValue(target, key)); |
1168 } | 1018 } |
1169 | 1019 |
1170 class WindowObserverTest : public WindowTest, | 1020 class WindowObserverTest : public WindowTest, |
1171 public WindowObserver { | 1021 public WindowObserver { |
1172 public: | 1022 public: |
1173 struct VisibilityInfo { | 1023 struct VisibilityInfo { |
1174 bool window_visible; | 1024 bool window_visible; |
1175 bool visible_param; | 1025 bool visible_param; |
1176 }; | 1026 }; |
1177 | 1027 |
1178 WindowObserverTest() | 1028 WindowObserverTest() |
1179 : added_count_(0), | 1029 : added_count_(0), |
1180 removed_count_(0), | 1030 removed_count_(0), |
1181 destroyed_count_(0) { | 1031 destroyed_count_(0), |
1032 old_property_value_(NULL), | |
1033 new_property_value_(NULL) { | |
1182 } | 1034 } |
1183 | 1035 |
1184 virtual ~WindowObserverTest() {} | 1036 virtual ~WindowObserverTest() {} |
1185 | 1037 |
1186 const VisibilityInfo* GetVisibilityInfo() const { | 1038 const VisibilityInfo* GetVisibilityInfo() const { |
1187 return visibility_info_.get(); | 1039 return visibility_info_.get(); |
1188 } | 1040 } |
1189 | 1041 |
1190 void ResetVisibilityInfo() { | 1042 void ResetVisibilityInfo() { |
1191 visibility_info_.reset(); | 1043 visibility_info_.reset(); |
1192 } | 1044 } |
1193 | 1045 |
1194 // Returns a description of the WindowObserver methods that have been invoked. | 1046 // Returns a description of the WindowObserver methods that have been invoked. |
1195 std::string WindowObserverCountStateAndClear() { | 1047 std::string WindowObserverCountStateAndClear() { |
1196 std::string result( | 1048 std::string result( |
1197 base::StringPrintf("added=%d removed=%d", | 1049 base::StringPrintf("added=%d removed=%d", |
1198 added_count_, removed_count_)); | 1050 added_count_, removed_count_)); |
1199 added_count_ = removed_count_ = 0; | 1051 added_count_ = removed_count_ = 0; |
1200 return result; | 1052 return result; |
1201 } | 1053 } |
1202 | 1054 |
1203 int DestroyedCountAndClear() { | 1055 int DestroyedCountAndClear() { |
1204 int result = destroyed_count_; | 1056 int result = destroyed_count_; |
1205 destroyed_count_ = 0; | 1057 destroyed_count_ = 0; |
1206 return result; | 1058 return result; |
1207 } | 1059 } |
1208 | 1060 |
1061 std::string PropertyChangeInfoAndClear() { | |
sky
2011/10/31 23:17:34
Add a description of what this does.
oshima
2011/11/01 00:40:33
Done.
| |
1062 std::string result( | |
1063 base::StringPrintf("name=%s old=%p new=%p", | |
1064 property_name_.c_str(), | |
1065 old_property_value_, | |
1066 new_property_value_)); | |
1067 property_name_.clear(); | |
1068 old_property_value_ = NULL; | |
1069 new_property_value_ = NULL; | |
1070 return result; | |
1071 } | |
1072 | |
1209 private: | 1073 private: |
1210 virtual void OnWindowAdded(Window* new_window) OVERRIDE { | 1074 virtual void OnWindowAdded(Window* new_window) OVERRIDE { |
1211 added_count_++; | 1075 added_count_++; |
1212 } | 1076 } |
1213 | 1077 |
1214 virtual void OnWillRemoveWindow(Window* window) OVERRIDE { | 1078 virtual void OnWillRemoveWindow(Window* window) OVERRIDE { |
1215 removed_count_++; | 1079 removed_count_++; |
1216 } | 1080 } |
1217 | 1081 |
1218 virtual void OnWindowVisibilityChanged(Window* window, | 1082 virtual void OnWindowVisibilityChanged(Window* window, |
1219 bool visible) OVERRIDE { | 1083 bool visible) OVERRIDE { |
1220 visibility_info_.reset(new VisibilityInfo); | 1084 visibility_info_.reset(new VisibilityInfo); |
1221 visibility_info_->window_visible = window->IsVisible(); | 1085 visibility_info_->window_visible = window->IsVisible(); |
1222 visibility_info_->visible_param = visible; | 1086 visibility_info_->visible_param = visible; |
1223 } | 1087 } |
1224 | 1088 |
1225 virtual void OnWindowDestroyed(Window* window) OVERRIDE { | 1089 virtual void OnWindowDestroyed(Window* window) OVERRIDE { |
1226 destroyed_count_++; | 1090 destroyed_count_++; |
1227 } | 1091 } |
1228 | 1092 |
1093 virtual void OnPropertyChanged(Window* window, | |
1094 const char* name, | |
1095 void* old) OVERRIDE { | |
1096 property_name_ = std::string(name); | |
1097 old_property_value_ = old; | |
1098 new_property_value_ = window->GetProperty(name); | |
1099 } | |
1100 | |
1229 int added_count_; | 1101 int added_count_; |
1230 int removed_count_; | 1102 int removed_count_; |
1231 int destroyed_count_; | 1103 int destroyed_count_; |
1232 scoped_ptr<VisibilityInfo> visibility_info_; | 1104 scoped_ptr<VisibilityInfo> visibility_info_; |
1105 std::string property_name_; | |
1106 void* old_property_value_; | |
1107 void* new_property_value_; | |
1233 | 1108 |
1234 DISALLOW_COPY_AND_ASSIGN(WindowObserverTest); | 1109 DISALLOW_COPY_AND_ASSIGN(WindowObserverTest); |
1235 }; | 1110 }; |
1236 | 1111 |
1237 // Various assertions for WindowObserver. | 1112 // Various assertions for WindowObserver. |
1238 TEST_F(WindowObserverTest, WindowObserver) { | 1113 TEST_F(WindowObserverTest, WindowObserver) { |
1239 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); | 1114 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); |
1240 w1->AddObserver(this); | 1115 w1->AddObserver(this); |
1241 | 1116 |
1242 // Create a new window as a child of w1, our observer should be notified. | 1117 // Create a new window as a child of w1, our observer should be notified. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1309 EXPECT_EQ(1, DestroyedCountAndClear()); | 1184 EXPECT_EQ(1, DestroyedCountAndClear()); |
1310 | 1185 |
1311 // Observe on child and delete parent window should fire a notification. | 1186 // Observe on child and delete parent window should fire a notification. |
1312 scoped_ptr<Window> parent(CreateTestWindowWithId(1, NULL)); | 1187 scoped_ptr<Window> parent(CreateTestWindowWithId(1, NULL)); |
1313 Window* child = CreateTestWindowWithId(1, parent.get()); // owned by parent | 1188 Window* child = CreateTestWindowWithId(1, parent.get()); // owned by parent |
1314 child->AddObserver(this); | 1189 child->AddObserver(this); |
1315 parent.reset(); | 1190 parent.reset(); |
1316 EXPECT_EQ(1, DestroyedCountAndClear()); | 1191 EXPECT_EQ(1, DestroyedCountAndClear()); |
1317 } | 1192 } |
1318 | 1193 |
1194 TEST_F(WindowObserverTest, PropertyChanged) { | |
1195 // Setting property should fire a property change notification. | |
1196 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); | |
1197 w1->AddObserver(this); | |
1198 w1->SetIntProperty("test", 1); | |
1199 EXPECT_EQ("name=test old=(nil) new=0x1", PropertyChangeInfoAndClear()); | |
1200 w1->SetIntProperty("test", 2); | |
1201 EXPECT_EQ("name=test old=0x1 new=0x2", PropertyChangeInfoAndClear()); | |
1202 w1->SetProperty("test", NULL); | |
1203 EXPECT_EQ("name=test old=0x2 new=(nil)", PropertyChangeInfoAndClear()); | |
1204 | |
1205 // Sanity check to see if |PropertyChangeInfoAndClear| really clears. | |
1206 EXPECT_EQ("name= old=(nil) new=(nil)", PropertyChangeInfoAndClear()); | |
1207 } | |
1208 | |
1319 class DesktopObserverTest : public WindowTest, | 1209 class DesktopObserverTest : public WindowTest, |
1320 public DesktopObserver { | 1210 public DesktopObserver { |
1321 public: | 1211 public: |
1322 DesktopObserverTest() : active_(NULL) { | 1212 DesktopObserverTest() : active_(NULL) { |
1323 } | 1213 } |
1324 | 1214 |
1325 virtual ~DesktopObserverTest() {} | 1215 virtual ~DesktopObserverTest() {} |
1326 | 1216 |
1327 Window* active() const { return active_; } | 1217 Window* active() const { return active_; } |
1328 | 1218 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1362 | 1252 |
1363 w3->Activate(); | 1253 w3->Activate(); |
1364 EXPECT_EQ(w2.get(), active()); | 1254 EXPECT_EQ(w2.get(), active()); |
1365 | 1255 |
1366 w1->Activate(); | 1256 w1->Activate(); |
1367 EXPECT_EQ(w1.get(), active()); | 1257 EXPECT_EQ(w1.get(), active()); |
1368 } | 1258 } |
1369 | 1259 |
1370 } // namespace test | 1260 } // namespace test |
1371 } // namespace aura | 1261 } // namespace aura |
OLD | NEW |