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

Side by Side Diff: remoting/test/app_remoting_report_issue_request_unittest.cc

Issue 1357973002: Removing Test and Staging environments from App Remoting Test Driver tool. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing unittest Created 5 years, 3 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 | remoting/test/app_remoting_service_urls.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "remoting/test/app_remoting_report_issue_request.h" 5 #include "remoting/test/app_remoting_report_issue_request.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/timer/timer.h" 10 #include "base/timer/timer.h"
(...skipping 25 matching lines...) Expand all
36 void SetUp() override; 36 void SetUp() override;
37 37
38 // Sets the HTTP status and data returned for a specified URL. 38 // Sets the HTTP status and data returned for a specified URL.
39 void SetFakeResponse(const GURL& url, 39 void SetFakeResponse(const GURL& url,
40 const std::string& data, 40 const std::string& data,
41 net::HttpStatusCode code, 41 net::HttpStatusCode code,
42 net::URLRequestStatus::Status status); 42 net::URLRequestStatus::Status status);
43 43
44 // Used for result verification. 44 // Used for result verification.
45 std::string dev_service_environment_url_; 45 std::string dev_service_environment_url_;
46 std::string test_service_environment_url_;
47 std::string staging_service_environment_url_;
48 46
49 scoped_ptr<base::RunLoop> run_loop_; 47 scoped_ptr<base::RunLoop> run_loop_;
50 scoped_ptr<base::Timer> timer_; 48 scoped_ptr<base::Timer> timer_;
51 49
52 AppRemotingReportIssueRequest app_remoting_report_issue_request_; 50 AppRemotingReportIssueRequest app_remoting_report_issue_request_;
53 51
54 private: 52 private:
55 net::FakeURLFetcherFactory url_fetcher_factory_; 53 net::FakeURLFetcherFactory url_fetcher_factory_;
56 scoped_ptr<base::MessageLoopForIO> message_loop_; 54 scoped_ptr<base::MessageLoopForIO> message_loop_;
57 55
58 DISALLOW_COPY_AND_ASSIGN(AppRemotingReportIssueRequestTest); 56 DISALLOW_COPY_AND_ASSIGN(AppRemotingReportIssueRequestTest);
59 }; 57 };
60 58
61 AppRemotingReportIssueRequestTest::AppRemotingReportIssueRequestTest() 59 AppRemotingReportIssueRequestTest::AppRemotingReportIssueRequestTest()
62 : url_fetcher_factory_(nullptr), message_loop_(new base::MessageLoopForIO) { 60 : url_fetcher_factory_(nullptr), message_loop_(new base::MessageLoopForIO) {
63 } 61 }
64 62
65 AppRemotingReportIssueRequestTest::~AppRemotingReportIssueRequestTest() { 63 AppRemotingReportIssueRequestTest::~AppRemotingReportIssueRequestTest() {
66 } 64 }
67 65
68 void AppRemotingReportIssueRequestTest::SetUp() { 66 void AppRemotingReportIssueRequestTest::SetUp() {
69 run_loop_.reset(new base::RunLoop()); 67 run_loop_.reset(new base::RunLoop());
70 timer_.reset(new base::Timer(true, false)); 68 timer_.reset(new base::Timer(true, false));
71 69
72 dev_service_environment_url_ = 70 dev_service_environment_url_ =
73 GetReportIssueUrl(kTestApplicationId, kTestHostId, kDeveloperEnvironment); 71 GetReportIssueUrl(kTestApplicationId, kTestHostId, kDeveloperEnvironment);
74 SetFakeResponse(GURL(dev_service_environment_url_), kReportIssueResponse, 72 SetFakeResponse(GURL(dev_service_environment_url_), kReportIssueResponse,
75 net::HTTP_NOT_FOUND, net::URLRequestStatus::FAILED); 73 net::HTTP_NOT_FOUND, net::URLRequestStatus::FAILED);
76
77 test_service_environment_url_ =
78 GetReportIssueUrl(kTestApplicationId, kTestHostId, kTestingEnvironment);
79 SetFakeResponse(GURL(test_service_environment_url_), kReportIssueResponse,
80 net::HTTP_NOT_FOUND, net::URLRequestStatus::FAILED);
81
82 staging_service_environment_url_ =
83 GetReportIssueUrl(kTestApplicationId, kTestHostId, kStagingEnvironment);
84 SetFakeResponse(GURL(staging_service_environment_url_), kReportIssueResponse,
85 net::HTTP_NOT_FOUND, net::URLRequestStatus::FAILED);
86 } 74 }
87 75
88 void AppRemotingReportIssueRequestTest::SetFakeResponse( 76 void AppRemotingReportIssueRequestTest::SetFakeResponse(
89 const GURL& url, 77 const GURL& url,
90 const std::string& data, 78 const std::string& data,
91 net::HttpStatusCode code, 79 net::HttpStatusCode code,
92 net::URLRequestStatus::Status status) { 80 net::URLRequestStatus::Status status) {
93 url_fetcher_factory_.SetFakeResponse(url, data, code, status); 81 url_fetcher_factory_.SetFakeResponse(url, data, code, status);
94 } 82 }
95 83
96 TEST_F(AppRemotingReportIssueRequestTest, ReportIssueFromDev) { 84 TEST_F(AppRemotingReportIssueRequestTest, ReportIssueFromDev) {
97 SetFakeResponse(GURL(dev_service_environment_url_), kReportIssueResponse, 85 SetFakeResponse(GURL(dev_service_environment_url_), kReportIssueResponse,
98 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 86 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
99 87
100 timer_->Start(FROM_HERE, base::TimeDelta::FromSeconds(1), 88 timer_->Start(FROM_HERE, base::TimeDelta::FromSeconds(1),
101 run_loop_->QuitClosure()); 89 run_loop_->QuitClosure());
102 90
103 bool request_started = app_remoting_report_issue_request_.Start( 91 bool request_started = app_remoting_report_issue_request_.Start(
104 kTestApplicationId, kTestHostId, kAccessTokenValue, kDeveloperEnvironment, 92 kTestApplicationId, kTestHostId, kAccessTokenValue, kDeveloperEnvironment,
105 true, run_loop_->QuitClosure()); 93 true, run_loop_->QuitClosure());
106 EXPECT_TRUE(request_started); 94 EXPECT_TRUE(request_started);
107 95
108 run_loop_->Run(); 96 run_loop_->Run();
109 97
110 // Verify we stopped because of the request completing and not the timer. 98 // Verify we stopped because of the request completing and not the timer.
111 EXPECT_TRUE(timer_->IsRunning()); 99 EXPECT_TRUE(timer_->IsRunning());
112 timer_->Stop(); 100 timer_->Stop();
113 } 101 }
114 102
115 TEST_F(AppRemotingReportIssueRequestTest, ReportIssueFromTest) {
116 SetFakeResponse(GURL(test_service_environment_url_), kReportIssueResponse,
117 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
118
119 timer_->Start(FROM_HERE, base::TimeDelta::FromSeconds(1),
120 run_loop_->QuitClosure());
121
122 bool request_started = app_remoting_report_issue_request_.Start(
123 kTestApplicationId, kTestHostId, kAccessTokenValue, kTestingEnvironment,
124 true, run_loop_->QuitClosure());
125 EXPECT_TRUE(request_started);
126
127 run_loop_->Run();
128
129 // Verify we stopped because of the request completing and not the timer.
130 EXPECT_TRUE(timer_->IsRunning());
131 timer_->Stop();
132 }
133
134 TEST_F(AppRemotingReportIssueRequestTest, ReportIssueFromStaging) {
135 SetFakeResponse(GURL(staging_service_environment_url_), kReportIssueResponse,
136 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
137
138 timer_->Start(FROM_HERE, base::TimeDelta::FromSeconds(1),
139 run_loop_->QuitClosure());
140
141 bool request_started = app_remoting_report_issue_request_.Start(
142 kTestApplicationId, kTestHostId, kAccessTokenValue, kStagingEnvironment,
143 true, run_loop_->QuitClosure());
144 EXPECT_TRUE(request_started);
145
146 run_loop_->Run();
147
148 // Verify we stopped because of the request completing and not the timer.
149 EXPECT_TRUE(timer_->IsRunning());
150 timer_->Stop();
151 }
152
153 TEST_F(AppRemotingReportIssueRequestTest, ReportIssueFromInvalidEnvironment) { 103 TEST_F(AppRemotingReportIssueRequestTest, ReportIssueFromInvalidEnvironment) {
154 bool request_started = app_remoting_report_issue_request_.Start( 104 bool request_started = app_remoting_report_issue_request_.Start(
155 kTestApplicationId, kTestHostId, kAccessTokenValue, kUnknownEnvironment, 105 kTestApplicationId, kTestHostId, kAccessTokenValue, kUnknownEnvironment,
156 true, run_loop_->QuitClosure()); 106 true, run_loop_->QuitClosure());
157 107
158 EXPECT_FALSE(request_started); 108 EXPECT_FALSE(request_started);
159 } 109 }
160 110
161 TEST_F(AppRemotingReportIssueRequestTest, ReportIssueNetworkError) { 111 TEST_F(AppRemotingReportIssueRequestTest, ReportIssueNetworkError) {
162 timer_->Start(FROM_HERE, base::TimeDelta::FromSeconds(1), 112 timer_->Start(FROM_HERE, base::TimeDelta::FromSeconds(1),
163 run_loop_->QuitClosure()); 113 run_loop_->QuitClosure());
164 114
165 bool request_started = app_remoting_report_issue_request_.Start( 115 bool request_started = app_remoting_report_issue_request_.Start(
166 kTestApplicationId, kTestHostId, kAccessTokenValue, kStagingEnvironment, 116 kTestApplicationId, kTestHostId, kAccessTokenValue, kDeveloperEnvironment,
167 true, run_loop_->QuitClosure()); 117 true, run_loop_->QuitClosure());
168 EXPECT_TRUE(request_started); 118 EXPECT_TRUE(request_started);
169 119
170 run_loop_->Run(); 120 run_loop_->Run();
171 121
172 // Verify we stopped because of the request completing and not the timer. 122 // Verify we stopped because of the request completing and not the timer.
173 EXPECT_TRUE(timer_->IsRunning()); 123 EXPECT_TRUE(timer_->IsRunning());
174 timer_->Stop(); 124 timer_->Stop();
175 } 125 }
176 126
177 TEST_F(AppRemotingReportIssueRequestTest, MultipleRequestsCanBeIssued) { 127 TEST_F(AppRemotingReportIssueRequestTest, MultipleRequestsCanBeIssued) {
178 SetFakeResponse(GURL(staging_service_environment_url_), kReportIssueResponse, 128 SetFakeResponse(GURL(dev_service_environment_url_), kReportIssueResponse,
179 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 129 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
180 130
181 timer_->Start(FROM_HERE, base::TimeDelta::FromSeconds(1), 131 timer_->Start(FROM_HERE, base::TimeDelta::FromSeconds(1),
182 run_loop_->QuitClosure()); 132 run_loop_->QuitClosure());
183 133
184 bool request_started = app_remoting_report_issue_request_.Start( 134 bool request_started = app_remoting_report_issue_request_.Start(
185 kTestApplicationId, kTestHostId, kAccessTokenValue, kStagingEnvironment, 135 kTestApplicationId, kTestHostId, kAccessTokenValue, kDeveloperEnvironment,
186 true, run_loop_->QuitClosure()); 136 true, run_loop_->QuitClosure());
187 EXPECT_TRUE(request_started); 137 EXPECT_TRUE(request_started);
188 138
189 run_loop_->Run(); 139 run_loop_->Run();
190 140
191 // Verify we stopped because of the request completing and not the timer. 141 // Verify we stopped because of the request completing and not the timer.
192 EXPECT_TRUE(timer_->IsRunning()); 142 EXPECT_TRUE(timer_->IsRunning());
193 timer_->Stop(); 143 timer_->Stop();
194 144
195 run_loop_.reset(new base::RunLoop()); 145 run_loop_.reset(new base::RunLoop());
196 timer_->Start(FROM_HERE, base::TimeDelta::FromSeconds(1), 146 timer_->Start(FROM_HERE, base::TimeDelta::FromSeconds(1),
197 run_loop_->QuitClosure()); 147 run_loop_->QuitClosure());
198 148
199 request_started = app_remoting_report_issue_request_.Start( 149 request_started = app_remoting_report_issue_request_.Start(
200 kTestApplicationId, kTestHostId, kAccessTokenValue, kStagingEnvironment, 150 kTestApplicationId, kTestHostId, kAccessTokenValue, kDeveloperEnvironment,
201 true, run_loop_->QuitClosure()); 151 true, run_loop_->QuitClosure());
202 EXPECT_TRUE(request_started); 152 EXPECT_TRUE(request_started);
203 153
204 run_loop_->Run(); 154 run_loop_->Run();
205 155
206 // Verify we stopped because of the request completing and not the timer. 156 // Verify we stopped because of the request completing and not the timer.
207 EXPECT_TRUE(timer_->IsRunning()); 157 EXPECT_TRUE(timer_->IsRunning());
208 timer_->Stop(); 158 timer_->Stop();
209 159
210 run_loop_.reset(new base::RunLoop()); 160 run_loop_.reset(new base::RunLoop());
211 timer_->Start(FROM_HERE, base::TimeDelta::FromSeconds(1), 161 timer_->Start(FROM_HERE, base::TimeDelta::FromSeconds(1),
212 run_loop_->QuitClosure()); 162 run_loop_->QuitClosure());
213 163
214 request_started = app_remoting_report_issue_request_.Start( 164 request_started = app_remoting_report_issue_request_.Start(
215 kTestApplicationId, kTestHostId, kAccessTokenValue, kStagingEnvironment, 165 kTestApplicationId, kTestHostId, kAccessTokenValue, kDeveloperEnvironment,
216 true, run_loop_->QuitClosure()); 166 true, run_loop_->QuitClosure());
217 EXPECT_TRUE(request_started); 167 EXPECT_TRUE(request_started);
218 168
219 run_loop_->Run(); 169 run_loop_->Run();
220 170
221 // Verify we stopped because of the request completing and not the timer. 171 // Verify we stopped because of the request completing and not the timer.
222 EXPECT_TRUE(timer_->IsRunning()); 172 EXPECT_TRUE(timer_->IsRunning());
223 timer_->Stop(); 173 timer_->Stop();
224 } 174 }
225 175
226 } // namespace test 176 } // namespace test
227 } // namespace remoting 177 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | remoting/test/app_remoting_service_urls.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698