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

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

Issue 2528503002: [WebPayments] Implement state transitions in desktop WebPayments dialog. (Closed)
Patch Set: Address comments Created 4 years 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') | chrome/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/observer_list.h"
6 #include "base/run_loop.h"
7 #include "chrome/browser/ui/views/payments/view_stack.h"
8 #include "ui/gfx/animation/test_animation_delegate.h"
9 #include "ui/views/test/views_test_base.h"
10
11 class TestStackView : public views::View {
12 public:
13 class Observer {
14 public:
15 Observer() : view_deleted_(false) {}
16
17 void OnViewBeingDeleted() {
18 view_deleted_ = true;
19 }
20
21 bool view_deleted() { return view_deleted_; }
22
23 private:
24 bool view_deleted_;
25 };
26
27 TestStackView() {}
28 ~TestStackView() override {
29 for (auto& observer: observers_) {
30 observer.OnViewBeingDeleted();
31 }
32 }
33
34 void AddObserver(Observer* observer) {
35 observers_.AddObserver(observer);
36 }
37
38 private:
39 base::ObserverList<Observer> observers_;
40
41 DISALLOW_COPY_AND_ASSIGN(TestStackView);
42 };
43
44 class ViewStackTest : public views::ViewsTestBase {
45 public:
46 ViewStackTest() {
47 view_stack_.reset(new ViewStack());
sky 2016/12/12 20:30:56 Use MakeUnique, or just make ViewStack a value mam
anthonyvd 2016/12/12 22:20:48 Used MakeUnique here to be able to delete the view
48 view_stack_->Push(base::MakeUnique<TestStackView>(), false);
49 }
50
51 std::unique_ptr<ViewStack> view_stack_;
52
53 DISALLOW_COPY_AND_ASSIGN(ViewStackTest);
54 };
55
56 TEST_F(ViewStackTest, TestInitialStateAddedAsChildView) {
57 EXPECT_EQ(1, view_stack_->child_count());
58 }
59
60 TEST_F(ViewStackTest, TestPushStateAddsViewToChildren) {
61 view_stack_->Push(base::MakeUnique<TestStackView>(), true);
62 EXPECT_EQ(2, view_stack_->child_count());
63 }
sky 2016/12/12 20:30:56 Please add assertions around bounds and visibility
anthonyvd 2016/12/12 22:20:48 Added some around bounds, let me know if you had a
64
65 TEST_F(ViewStackTest, TestPopStateRemovesChildViewAndCleansUpState) {
66 view_stack_->SetBounds(0, 0, 10, 10);
67
68 TestStackView::Observer observer;
69 std::unique_ptr<TestStackView> view = base::MakeUnique<TestStackView>();
70 view->AddObserver(&observer);
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,
77 std::unique_ptr<gfx::AnimationDelegate>(
78 new gfx::TestAnimationDelegate()));
79
80 base::RunLoop().Run();
sky 2016/12/12 20:30:56 Do these tests set the animation time to 0? If the
anthonyvd 2016/12/12 22:20:48 It looks like this makes the base::RunLoop().Run()
sky 2016/12/12 23:57:00 That would seem to indicate your delegate isn't be
81 EXPECT_FALSE(view_stack_->slide_in_animator_->IsAnimating());
82 view_stack_->Pop();
83
84 EXPECT_TRUE(view_stack_->slide_out_animator_->IsAnimating());
85 view_stack_->slide_out_animator_->SetAnimationDelegate(
86 view_ptr,
87 std::unique_ptr<gfx::AnimationDelegate>(
88 new gfx::TestAnimationDelegate()));
89
90 base::RunLoop().Run();
91 EXPECT_FALSE(view_stack_->slide_out_animator_->IsAnimating());
92
93 ASSERT_TRUE(observer.view_deleted());
94 }
95
96 TEST_F(ViewStackTest, TestDeletingViewCleansUpState) {
97 view_stack_->SetBounds(0, 0, 10, 10);
98
99 TestStackView::Observer observer;
100 std::unique_ptr<TestStackView> view = base::MakeUnique<TestStackView>();
101 view->AddObserver(&observer);
102 views::View* view_ptr = view.get();
103
104 view_stack_->Push(std::move(view), true);
105 EXPECT_TRUE(view_stack_->slide_in_animator_->IsAnimating());
106 view_stack_->slide_in_animator_->SetAnimationDelegate(
107 view_ptr,
108 std::unique_ptr<gfx::AnimationDelegate>(
109 new gfx::TestAnimationDelegate()));
110
111 base::RunLoop().Run();
112 EXPECT_FALSE(view_stack_->slide_in_animator_->IsAnimating());
113 view_stack_->Pop();
114
115 EXPECT_TRUE(view_stack_->slide_out_animator_->IsAnimating());
116 view_stack_.reset();
117
118 ASSERT_TRUE(observer.view_deleted());
119 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/payments/view_stack.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698