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

Side by Side Diff: chrome/browser/ui/views/payments/view_stack_unittest.cc

Issue 2817533006: [Web Payments] Add PopMany and Size functions to ViewStack (Closed)
Patch Set: Remove unused Observer that caused use-after-free in tests. Created 3 years, 8 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 | « chrome/browser/ui/views/payments/view_stack.cc ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/memory/ptr_util.h" 5 #include "base/memory/ptr_util.h"
6 #include "base/observer_list.h" 6 #include "base/observer_list.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "chrome/browser/ui/views/payments/view_stack.h" 8 #include "chrome/browser/ui/views/payments/view_stack.h"
9 #include "ui/gfx/animation/test_animation_delegate.h" 9 #include "ui/gfx/animation/test_animation_delegate.h"
10 #include "ui/views/test/views_test_base.h" 10 #include "ui/views/test/views_test_base.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 target.set_origin(gfx::Point(0, 0)); 57 target.set_origin(gfx::Point(0, 0));
58 EXPECT_EQ(target, view->bounds()); 58 EXPECT_EQ(target, view->bounds());
59 } 59 }
60 60
61 void AssertViewCompletelyNextToStack(views::View* view) { 61 void AssertViewCompletelyNextToStack(views::View* view) {
62 gfx::Rect target = view_stack_->bounds(); 62 gfx::Rect target = view_stack_->bounds();
63 target.set_origin(gfx::Point(view_stack_->width(), 0)); 63 target.set_origin(gfx::Point(view_stack_->width(), 0));
64 EXPECT_EQ(target, view->bounds()); 64 EXPECT_EQ(target, view->bounds());
65 } 65 }
66 66
67 // Pushes a view on the stack, waits for its animation to be over, then
68 // returns a pointer to the pushed view.
69 views::View* PushViewOnStackAndWait() {
70 std::unique_ptr<TestStackView> view = base::MakeUnique<TestStackView>();
71 views::View* view_ptr = view.get();
72
73 view_stack_->Push(std::move(view), true);
74 EXPECT_TRUE(view_stack_->slide_in_animator_->IsAnimating());
75 view_stack_->slide_in_animator_->SetAnimationDelegate(
76 view_ptr, std::unique_ptr<gfx::AnimationDelegate>(
77 new gfx::TestAnimationDelegate()));
78
79 base::RunLoop().Run();
80 EXPECT_FALSE(view_stack_->slide_in_animator_->IsAnimating());
81 return view_ptr;
82 }
83
84 // Pops |n| views from the stack, then waits for |top_view_ptr|'s animation to
85 // be over.
86 void PopManyAndWait(int n, views::View* top_view_ptr) {
87 view_stack_->PopMany(n);
88
89 EXPECT_TRUE(view_stack_->slide_out_animator_->IsAnimating());
90 view_stack_->slide_out_animator_->SetAnimationDelegate(
91 top_view_ptr, std::unique_ptr<gfx::AnimationDelegate>(
92 new gfx::TestAnimationDelegate()));
93
94 base::RunLoop().Run();
95 EXPECT_FALSE(view_stack_->slide_out_animator_->IsAnimating());
96 }
97
67 std::unique_ptr<ViewStack> view_stack_; 98 std::unique_ptr<ViewStack> view_stack_;
68 99
69 DISALLOW_COPY_AND_ASSIGN(ViewStackTest); 100 DISALLOW_COPY_AND_ASSIGN(ViewStackTest);
70 }; 101 };
71 102
72 TEST_F(ViewStackTest, TestInitialStateAddedAsChildView) { 103 TEST_F(ViewStackTest, TestInitialStateAddedAsChildView) {
73 EXPECT_EQ(1, view_stack_->child_count()); 104 EXPECT_EQ(1, view_stack_->child_count());
74 // This child was added without any animation so it's on top of its parent 105 // This child was added without any animation so it's on top of its parent
75 // already. 106 // already.
76 AssertViewOnTopOfStack(view_stack_->top()); 107 AssertViewOnTopOfStack(view_stack_->top());
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 view_stack_->slide_out_animator_->SetAnimationDelegate( 197 view_stack_->slide_out_animator_->SetAnimationDelegate(
167 view_ptr, 198 view_ptr,
168 std::unique_ptr<gfx::AnimationDelegate>( 199 std::unique_ptr<gfx::AnimationDelegate>(
169 new gfx::TestAnimationDelegate())); 200 new gfx::TestAnimationDelegate()));
170 201
171 base::RunLoop().Run(); 202 base::RunLoop().Run();
172 EXPECT_FALSE(view_stack_->slide_out_animator_->IsAnimating()); 203 EXPECT_FALSE(view_stack_->slide_out_animator_->IsAnimating());
173 204
174 ASSERT_TRUE(observer.view_deleted()); 205 ASSERT_TRUE(observer.view_deleted());
175 } 206 }
207
208 TEST_F(ViewStackTest, TestPopMany) {
209 views::View* top = PushViewOnStackAndWait();
210 EXPECT_EQ(2U, view_stack_->size());
211
212 PopManyAndWait(1, top);
213 EXPECT_EQ(1U, view_stack_->size());
214
215 top = PushViewOnStackAndWait();
216 top = PushViewOnStackAndWait();
217 top = PushViewOnStackAndWait();
218 EXPECT_EQ(4U, view_stack_->size());
219
220 PopManyAndWait(3, top);
221 EXPECT_EQ(1U, view_stack_->size());
222
223 top = PushViewOnStackAndWait();
224 top = PushViewOnStackAndWait();
225 EXPECT_EQ(3U, view_stack_->size());
226 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/payments/view_stack.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698