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

Side by Side Diff: chrome/browser/download/download_request_infobar_delegate_unittest.cc

Issue 1392023004: Rename android only infobars (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: try again Created 5 years, 2 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
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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/memory/weak_ptr.h" 6 #include "base/memory/weak_ptr.h"
7 #include "chrome/browser/download/download_request_infobar_delegate.h" 7 #include "chrome/browser/download/download_request_infobar_delegate_android.h"
8 #include "chrome/browser/download/download_request_limiter.h" 8 #include "chrome/browser/download/download_request_limiter.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 // MockTabDownloadState ------------------------------------------------------- 11 // MockTabDownloadState -------------------------------------------------------
12 12
13 class MockTabDownloadState : public DownloadRequestLimiter::TabDownloadState { 13 class MockTabDownloadState : public DownloadRequestLimiter::TabDownloadState {
14 public: 14 public:
15 MockTabDownloadState(); 15 MockTabDownloadState();
16 ~MockTabDownloadState() override; 16 ~MockTabDownloadState() override;
17 17
18 // DownloadRequestLimiter::TabDownloadState: 18 // DownloadRequestLimiter::TabDownloadState:
19 void Cancel() override; 19 void Cancel() override;
20 void Accept() override; 20 void Accept() override;
21 void CancelOnce() override; 21 void CancelOnce() override;
22 22
23 ConfirmInfoBarDelegate* infobar_delegate() { return infobar_delegate_.get(); } 23 ConfirmInfoBarDelegate* infobar_delegate() { return infobar_delegate_.get(); }
24 void delete_infobar_delegate() { infobar_delegate_.reset(); } 24 void delete_infobar_delegate() { infobar_delegate_.reset(); }
25 bool responded() const { return responded_; } 25 bool responded() const { return responded_; }
26 bool accepted() const { return accepted_; } 26 bool accepted() const { return accepted_; }
27 27
28 private: 28 private:
29 // The actual infobar delegate we're listening to. 29 // The actual infobar delegate we're listening to.
30 scoped_ptr<DownloadRequestInfoBarDelegate> infobar_delegate_; 30 scoped_ptr<DownloadRequestInfoBarDelegateAndroid> infobar_delegate_;
31 31
32 // True if we have gotten some sort of response. 32 // True if we have gotten some sort of response.
33 bool responded_; 33 bool responded_;
34 34
35 // True if we have gotten a Accept response. Meaningless if |responded_| is 35 // True if we have gotten a Accept response. Meaningless if |responded_| is
36 // not true. 36 // not true.
37 bool accepted_; 37 bool accepted_;
38 38
39 // To produce weak pointers for infobar_ construction. 39 // To produce weak pointers for infobar_ construction.
40 base::WeakPtrFactory<MockTabDownloadState> weak_ptr_factory_; 40 base::WeakPtrFactory<MockTabDownloadState> weak_ptr_factory_;
41 41
42 DISALLOW_COPY_AND_ASSIGN(MockTabDownloadState); 42 DISALLOW_COPY_AND_ASSIGN(MockTabDownloadState);
43 }; 43 };
44 44
45 MockTabDownloadState::MockTabDownloadState() 45 MockTabDownloadState::MockTabDownloadState()
46 : responded_(false), 46 : responded_(false),
47 accepted_(false), 47 accepted_(false),
48 weak_ptr_factory_(this) { 48 weak_ptr_factory_(this) {
49 infobar_delegate_ = 49 infobar_delegate_ = DownloadRequestInfoBarDelegateAndroid::Create(
50 DownloadRequestInfoBarDelegate::Create(weak_ptr_factory_.GetWeakPtr()); 50 weak_ptr_factory_.GetWeakPtr());
51 } 51 }
52 52
53 MockTabDownloadState::~MockTabDownloadState() { 53 MockTabDownloadState::~MockTabDownloadState() {
54 EXPECT_TRUE(responded_); 54 EXPECT_TRUE(responded_);
55 } 55 }
56 56
57 void MockTabDownloadState::Cancel() { 57 void MockTabDownloadState::Cancel() {
58 EXPECT_FALSE(responded_); 58 EXPECT_FALSE(responded_);
59 responded_ = true; 59 responded_ = true;
60 accepted_ = false; 60 accepted_ = false;
61 } 61 }
62 62
63 void MockTabDownloadState::Accept() { 63 void MockTabDownloadState::Accept() {
64 EXPECT_FALSE(responded_); 64 EXPECT_FALSE(responded_);
65 responded_ = true; 65 responded_ = true;
66 accepted_ = true; 66 accepted_ = true;
67 weak_ptr_factory_.InvalidateWeakPtrs(); 67 weak_ptr_factory_.InvalidateWeakPtrs();
68 } 68 }
69 69
70 void MockTabDownloadState::CancelOnce() { 70 void MockTabDownloadState::CancelOnce() {
71 Cancel(); 71 Cancel();
72 } 72 }
73 73
74 74
75 // Tests ---------------------------------------------------------------------- 75 // Tests ----------------------------------------------------------------------
76 76
77 TEST(DownloadRequestInfoBarDelegate, AcceptTest) { 77 TEST(DownloadRequestInfoBarDelegateAndroid, AcceptTest) {
78 MockTabDownloadState state; 78 MockTabDownloadState state;
79 if (state.infobar_delegate()->Accept()) 79 if (state.infobar_delegate()->Accept())
80 state.delete_infobar_delegate(); 80 state.delete_infobar_delegate();
81 EXPECT_TRUE(state.accepted()); 81 EXPECT_TRUE(state.accepted());
82 } 82 }
83 83
84 TEST(DownloadRequestInfoBarDelegate, CancelTest) { 84 TEST(DownloadRequestInfoBarDelegateAndroid, CancelTest) {
85 MockTabDownloadState state; 85 MockTabDownloadState state;
86 if (state.infobar_delegate()->Cancel()) 86 if (state.infobar_delegate()->Cancel())
87 state.delete_infobar_delegate(); 87 state.delete_infobar_delegate();
88 EXPECT_FALSE(state.accepted()); 88 EXPECT_FALSE(state.accepted());
89 } 89 }
90 90
91 TEST(DownloadRequestInfoBarDelegate, CloseTest) { 91 TEST(DownloadRequestInfoBarDelegateAndroid, CloseTest) {
92 MockTabDownloadState state; 92 MockTabDownloadState state;
93 state.delete_infobar_delegate(); 93 state.delete_infobar_delegate();
94 EXPECT_FALSE(state.accepted()); 94 EXPECT_FALSE(state.accepted());
95 } 95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698