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

Side by Side Diff: chrome/browser/printing/cloud_print/privet_notifications_unittest.cc

Issue 2027883002: Fix PrivetNotificationService::PrivetNotify() silliness. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix crazy formatting in unit test Created 4 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
« 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/printing/cloud_print/privet_notifications.h" 5 #include "chrome/browser/printing/cloud_print/privet_notifications.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 62 }
63 63
64 const std::string& GetName() override { return name_; } 64 const std::string& GetName() override { return name_; }
65 65
66 private: 66 private:
67 std::string name_; 67 std::string name_;
68 scoped_refptr<net::URLRequestContextGetter> request_context_; 68 scoped_refptr<net::URLRequestContextGetter> request_context_;
69 }; 69 };
70 70
71 explicit MockPrivetHttpFactory(net::URLRequestContextGetter* request_context) 71 explicit MockPrivetHttpFactory(net::URLRequestContextGetter* request_context)
72 : request_context_(request_context) { 72 : request_context_(request_context) {}
Lei Zhang 2016/06/01 02:15:17 I let "git cl format" reformat the file.
73 }
74 73
75 std::unique_ptr<PrivetHTTPResolution> CreatePrivetHTTP( 74 std::unique_ptr<PrivetHTTPResolution> CreatePrivetHTTP(
76 const std::string& name) override { 75 const std::string& name) override {
77 return base::WrapUnique(new MockResolution(name, request_context_.get())); 76 return base::WrapUnique(new MockResolution(name, request_context_.get()));
78 } 77 }
79 78
80 private: 79 private:
81 scoped_refptr<net::URLRequestContextGetter> request_context_; 80 scoped_refptr<net::URLRequestContextGetter> request_context_;
82 }; 81 };
83 82
84 class PrivetNotificationsListenerTest : public ::testing::Test { 83 class PrivetNotificationsListenerTest : public ::testing::Test {
85 public: 84 public:
86 PrivetNotificationsListenerTest() 85 PrivetNotificationsListenerTest()
87 : request_context_(new net::TestURLRequestContextGetter( 86 : request_context_(new net::TestURLRequestContextGetter(
88 base::ThreadTaskRunnerHandle::Get())) { 87 base::ThreadTaskRunnerHandle::Get())) {
89 notification_listener_.reset(new PrivetNotificationsListener( 88 notification_listener_.reset(new PrivetNotificationsListener(
90 std::unique_ptr<PrivetHTTPAsynchronousFactory>( 89 std::unique_ptr<PrivetHTTPAsynchronousFactory>(
91 new MockPrivetHttpFactory(request_context_.get())), 90 new MockPrivetHttpFactory(request_context_.get())),
92 &mock_delegate_)); 91 &mock_delegate_));
93 92
94 description_.name = kExampleDeviceHumanName; 93 description_.name = kExampleDeviceHumanName;
95 description_.description = kExampleDeviceDescription; 94 description_.description = kExampleDeviceDescription;
96 } 95 }
97 96
98 virtual ~PrivetNotificationsListenerTest() { 97 virtual ~PrivetNotificationsListenerTest() {}
99 }
100 98
101 bool SuccessfulResponseToInfo(const std::string& response) { 99 bool SuccessfulResponseToInfo(const std::string& response) {
102 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0); 100 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0);
103 EXPECT_TRUE(fetcher); 101 EXPECT_TRUE(fetcher);
104 EXPECT_EQ(GURL(kDeviceInfoURL), fetcher->GetOriginalURL()); 102 EXPECT_EQ(GURL(kDeviceInfoURL), fetcher->GetOriginalURL());
105 103
106 if (!fetcher || GURL(kDeviceInfoURL) != fetcher->GetOriginalURL()) 104 if (!fetcher || GURL(kDeviceInfoURL) != fetcher->GetOriginalURL())
107 return false; 105 return false;
108 106
109 fetcher->SetResponseString(response); 107 fetcher->SetResponseString(response);
110 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 108 fetcher->set_status(
111 net::OK)); 109 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, net::OK));
112 fetcher->set_response_code(200); 110 fetcher->set_response_code(200);
113 fetcher->delegate()->OnURLFetchComplete(fetcher); 111 fetcher->delegate()->OnURLFetchComplete(fetcher);
114 return true; 112 return true;
115 } 113 }
116 114
117 protected: 115 protected:
118 StrictMock<MockPrivetNotificationsListenerDeleagate> mock_delegate_; 116 StrictMock<MockPrivetNotificationsListenerDeleagate> mock_delegate_;
119 std::unique_ptr<PrivetNotificationsListener> notification_listener_; 117 std::unique_ptr<PrivetNotificationsListener> notification_listener_;
120 base::MessageLoop message_loop_; 118 base::MessageLoop message_loop_;
121 scoped_refptr<net::TestURLRequestContextGetter> request_context_; 119 scoped_refptr<net::TestURLRequestContextGetter> request_context_;
122 net::TestURLFetcherFactory fetcher_factory_; 120 net::TestURLFetcherFactory fetcher_factory_;
123 DeviceDescription description_; 121 DeviceDescription description_;
124 }; 122 };
125 123
126 TEST_F(PrivetNotificationsListenerTest, DisappearReappearTest) { 124 TEST_F(PrivetNotificationsListenerTest, DisappearReappearTest) {
127 EXPECT_CALL(mock_delegate_, PrivetNotify( 125 EXPECT_CALL(mock_delegate_, PrivetNotify(1, true));
128 1,
129 true));
130 126
131 notification_listener_->DeviceChanged( 127 notification_listener_->DeviceChanged(kExampleDeviceName, description_);
132 kExampleDeviceName,
133 description_);
134 128
135 SuccessfulResponseToInfo(kInfoResponseUptime20); 129 SuccessfulResponseToInfo(kInfoResponseUptime20);
136 130
137 EXPECT_CALL(mock_delegate_, PrivetRemoveNotification()); 131 EXPECT_CALL(mock_delegate_, PrivetRemoveNotification());
138 132
139 notification_listener_->DeviceRemoved( 133 notification_listener_->DeviceRemoved(kExampleDeviceName);
140 kExampleDeviceName);
141 134
142 notification_listener_->DeviceChanged( 135 notification_listener_->DeviceChanged(kExampleDeviceName, description_);
143 kExampleDeviceName,
144 description_);
145 136
146 description_.id = kExampleDeviceID; 137 description_.id = kExampleDeviceID;
147 138
148 notification_listener_->DeviceChanged( 139 notification_listener_->DeviceChanged(kExampleDeviceName, description_);
149 kExampleDeviceName,
150 description_);
151 } 140 }
152 141
153 TEST_F(PrivetNotificationsListenerTest, RegisterTest) { 142 TEST_F(PrivetNotificationsListenerTest, RegisterTest) {
154 EXPECT_CALL(mock_delegate_, PrivetNotify( 143 EXPECT_CALL(mock_delegate_, PrivetNotify(1, true));
155 1,
156 true));
157 144
158 notification_listener_->DeviceChanged( 145 notification_listener_->DeviceChanged(kExampleDeviceName, description_);
159 kExampleDeviceName,
160 description_);
161 146
162 SuccessfulResponseToInfo(kInfoResponseUptime20); 147 SuccessfulResponseToInfo(kInfoResponseUptime20);
163 148
164 EXPECT_CALL(mock_delegate_, PrivetRemoveNotification()); 149 EXPECT_CALL(mock_delegate_, PrivetRemoveNotification());
165 150
166 description_.id = kExampleDeviceID; 151 description_.id = kExampleDeviceID;
167 152
168 notification_listener_->DeviceChanged( 153 notification_listener_->DeviceChanged(kExampleDeviceName, description_);
169 kExampleDeviceName,
170 description_);
171 } 154 }
172 155
173 TEST_F(PrivetNotificationsListenerTest, HighUptimeTest) { 156 TEST_F(PrivetNotificationsListenerTest, HighUptimeTest) {
174 notification_listener_->DeviceChanged( 157 notification_listener_->DeviceChanged(kExampleDeviceName, description_);
175 kExampleDeviceName,
176 description_);
177 158
178 SuccessfulResponseToInfo(kInfoResponseUptime3600); 159 SuccessfulResponseToInfo(kInfoResponseUptime3600);
179 160
180 description_.id = kExampleDeviceID; 161 description_.id = kExampleDeviceID;
181 162
182 notification_listener_->DeviceChanged( 163 notification_listener_->DeviceChanged(kExampleDeviceName, description_);
183 kExampleDeviceName,
184 description_);
185 } 164 }
186 165
187 TEST_F(PrivetNotificationsListenerTest, HTTPErrorTest) { 166 TEST_F(PrivetNotificationsListenerTest, HTTPErrorTest) {
188 notification_listener_->DeviceChanged( 167 notification_listener_->DeviceChanged(kExampleDeviceName, description_);
189 kExampleDeviceName,
190 description_);
191 168
192 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0); 169 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0);
193 170
194 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 171 fetcher->set_status(
195 net::OK)); 172 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, net::OK));
196 fetcher->set_response_code(200); 173 fetcher->set_response_code(200);
197 fetcher->delegate()->OnURLFetchComplete(fetcher); 174 fetcher->delegate()->OnURLFetchComplete(fetcher);
198 } 175 }
199 176
200 TEST_F(PrivetNotificationsListenerTest, DictionaryErrorTest) { 177 TEST_F(PrivetNotificationsListenerTest, DictionaryErrorTest) {
201 notification_listener_->DeviceChanged( 178 notification_listener_->DeviceChanged(kExampleDeviceName, description_);
202 kExampleDeviceName,
203 description_);
204 179
205 SuccessfulResponseToInfo(kInfoResponseNoUptime); 180 SuccessfulResponseToInfo(kInfoResponseNoUptime);
206 } 181 }
207 182
208 } // namespace 183 } // namespace
209 184
210 } // namespace cloud_print 185 } // namespace cloud_print
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