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

Side by Side Diff: views/view_unittest.cc

Issue 7046074: views: Add unittests for View::RemoveAllChildViews() method. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 6 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
« no previous file with comments | « no previous file | 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) 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 <map> 5 #include <map>
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "ui/base/clipboard/clipboard.h" 10 #include "ui/base/clipboard/clipboard.h"
(...skipping 1984 matching lines...) Expand 10 before | Expand all | Expand 10 after
1995 // Conversions from top_view to child with a value that should be negative. 1995 // Conversions from top_view to child with a value that should be negative.
1996 // This ensures we don't round up with negative numbers. 1996 // This ensures we don't round up with negative numbers.
1997 { 1997 {
1998 gfx::Point point(6, 18); 1998 gfx::Point point(6, 18);
1999 View::ConvertPointToView(&top_view, child, &point); 1999 View::ConvertPointToView(&top_view, child, &point);
2000 EXPECT_EQ(-1, point.x()); 2000 EXPECT_EQ(-1, point.x());
2001 EXPECT_EQ(-1, point.y()); 2001 EXPECT_EQ(-1, point.y());
2002 } 2002 }
2003 } 2003 }
2004 2004
2005 // Verify if the child views added under the root are all deleted when
2006 // calling RemoveAllChildViews.
2007 // The tree looks like this:
2008 // root
2009 // |-- child
2010 // | |-- foo
2011 // | |-- bar0
2012 // | |-- bar1
2013 // +-------|-- bar2
2014 TEST_F(ViewTest, RemoveAllChildViews) {
2015 View root;
2016
2017 View* child = new View();
2018 root.AddChildView(child);
2019
2020 View* foo = new View();
2021 child->AddChildView(foo);
2022
2023 // Add some nodes to |foo|.
2024 for (int i = 0; i < 3; ++i)
2025 foo->AddChildView(new View());
2026
2027 ASSERT_EQ(1, root.child_count());
2028 ASSERT_EQ(1, child->child_count());
2029 ASSERT_EQ(3, foo->child_count());
2030
2031 // Now remove all child views from root.
2032 root.RemoveAllChildViews(true);
2033
2034 ASSERT_EQ(0, root.child_count());
2035 ASSERT_FALSE(root.has_children());
2036 }
2037
2005 TEST_F(ViewTest, Contains) { 2038 TEST_F(ViewTest, Contains) {
2006 View v1; 2039 View v1;
2007 View* v2 = new View(); 2040 View* v2 = new View();
2008 View* v3 = new View(); 2041 View* v3 = new View();
2009 2042
2010 v1.AddChildView(v2); 2043 v1.AddChildView(v2);
2011 v2->AddChildView(v3); 2044 v2->AddChildView(v3);
2012 2045
2013 EXPECT_FALSE(v1.Contains(NULL)); 2046 EXPECT_FALSE(v1.Contains(NULL));
2014 EXPECT_TRUE(v1.Contains(&v1)); 2047 EXPECT_TRUE(v1.Contains(&v1));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2058 ASSERT_EQ(0, child1->GetIndexOf(foo1)); 2091 ASSERT_EQ(0, child1->GetIndexOf(foo1));
2059 2092
2060 ASSERT_EQ(-1, child2->GetIndexOf(NULL)); 2093 ASSERT_EQ(-1, child2->GetIndexOf(NULL));
2061 ASSERT_EQ(-1, child2->GetIndexOf(&root)); 2094 ASSERT_EQ(-1, child2->GetIndexOf(&root));
2062 ASSERT_EQ(-1, child2->GetIndexOf(child2)); 2095 ASSERT_EQ(-1, child2->GetIndexOf(child2));
2063 ASSERT_EQ(-1, child2->GetIndexOf(child1)); 2096 ASSERT_EQ(-1, child2->GetIndexOf(child1));
2064 ASSERT_EQ(-1, child2->GetIndexOf(foo1)); 2097 ASSERT_EQ(-1, child2->GetIndexOf(foo1));
2065 } 2098 }
2066 2099
2067 } // namespace views 2100 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698