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

Side by Side Diff: chrome/browser/chromeos/file_system_provider/request_manager_unittest.cc

Issue 304533003: [fsp] Rename has_next to has_more. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/files/file.h" 10 #include "base/files/file.h"
(...skipping 20 matching lines...) Expand all
31 virtual ~ExecuteEvent() {} 31 virtual ~ExecuteEvent() {}
32 32
33 int request_id() { return request_id_; } 33 int request_id() { return request_id_; }
34 34
35 private: 35 private:
36 int request_id_; 36 int request_id_;
37 }; 37 };
38 38
39 class SuccessEvent { 39 class SuccessEvent {
40 public: 40 public:
41 SuccessEvent(int request_id, scoped_ptr<RequestValue> result, bool has_next) 41 SuccessEvent(int request_id, scoped_ptr<RequestValue> result, bool has_more)
42 : request_id_(request_id), 42 : request_id_(request_id),
43 result_(result.Pass()), 43 result_(result.Pass()),
44 has_next_(has_next) {} 44 has_more_(has_more) {}
45 virtual ~SuccessEvent() {} 45 virtual ~SuccessEvent() {}
46 46
47 int request_id() { return request_id_; } 47 int request_id() { return request_id_; }
48 RequestValue* result() { return result_.get(); } 48 RequestValue* result() { return result_.get(); }
49 bool has_next() { return has_next_; } 49 bool has_more() { return has_more_; }
50 50
51 private: 51 private:
52 int request_id_; 52 int request_id_;
53 scoped_ptr<RequestValue> result_; 53 scoped_ptr<RequestValue> result_;
54 bool has_next_; 54 bool has_more_;
55 }; 55 };
56 56
57 class ErrorEvent { 57 class ErrorEvent {
58 public: 58 public:
59 ErrorEvent(int request_id, base::File::Error error) 59 ErrorEvent(int request_id, base::File::Error error)
60 : request_id_(request_id), error_(error) {} 60 : request_id_(request_id), error_(error) {}
61 virtual ~ErrorEvent() {} 61 virtual ~ErrorEvent() {}
62 62
63 int request_id() { return request_id_; } 63 int request_id() { return request_id_; }
64 base::File::Error error() { return error_; } 64 base::File::Error error() { return error_; }
65 65
66 private: 66 private:
67 int request_id_; 67 int request_id_;
68 base::File::Error error_; 68 base::File::Error error_;
69 }; 69 };
70 70
71 EventLogger() : weak_ptr_factory_(this) {} 71 EventLogger() : weak_ptr_factory_(this) {}
72 virtual ~EventLogger() {} 72 virtual ~EventLogger() {}
73 73
74 void OnExecute(int request_id) { 74 void OnExecute(int request_id) {
75 execute_events_.push_back(new ExecuteEvent(request_id)); 75 execute_events_.push_back(new ExecuteEvent(request_id));
76 } 76 }
77 77
78 void OnSuccess(int request_id, 78 void OnSuccess(int request_id,
79 scoped_ptr<RequestValue> result, 79 scoped_ptr<RequestValue> result,
80 bool has_next) { 80 bool has_more) {
81 success_events_.push_back( 81 success_events_.push_back(
82 new SuccessEvent(request_id, result.Pass(), has_next)); 82 new SuccessEvent(request_id, result.Pass(), has_more));
83 } 83 }
84 84
85 void OnError(int request_id, base::File::Error error) { 85 void OnError(int request_id, base::File::Error error) {
86 error_events_.push_back(new ErrorEvent(request_id, error)); 86 error_events_.push_back(new ErrorEvent(request_id, error));
87 } 87 }
88 88
89 ScopedVector<ExecuteEvent>& execute_events() { return execute_events_; } 89 ScopedVector<ExecuteEvent>& execute_events() { return execute_events_; }
90 ScopedVector<SuccessEvent>& success_events() { return success_events_; } 90 ScopedVector<SuccessEvent>& success_events() { return success_events_; }
91 ScopedVector<ErrorEvent>& error_events() { return error_events_; } 91 ScopedVector<ErrorEvent>& error_events() { return error_events_; }
92 92
(...skipping 23 matching lines...) Expand all
116 virtual bool Execute(int request_id) OVERRIDE { 116 virtual bool Execute(int request_id) OVERRIDE {
117 if (logger_.get()) 117 if (logger_.get())
118 logger_->OnExecute(request_id); 118 logger_->OnExecute(request_id);
119 119
120 return execute_reply_; 120 return execute_reply_;
121 } 121 }
122 122
123 // RequestManager::Handler overrides. 123 // RequestManager::Handler overrides.
124 virtual void OnSuccess(int request_id, 124 virtual void OnSuccess(int request_id,
125 scoped_ptr<RequestValue> result, 125 scoped_ptr<RequestValue> result,
126 bool has_next) OVERRIDE { 126 bool has_more) OVERRIDE {
127 if (logger_.get()) 127 if (logger_.get())
128 logger_->OnSuccess(request_id, result.Pass(), has_next); 128 logger_->OnSuccess(request_id, result.Pass(), has_more);
129 } 129 }
130 130
131 // RequestManager::Handler overrides. 131 // RequestManager::Handler overrides.
132 virtual void OnError(int request_id, base::File::Error error) OVERRIDE { 132 virtual void OnError(int request_id, base::File::Error error) OVERRIDE {
133 if (logger_.get()) 133 if (logger_.get())
134 logger_->OnError(request_id, error); 134 logger_->OnError(request_id, error);
135 } 135 }
136 136
137 virtual ~FakeHandler() {} 137 virtual ~FakeHandler() {}
138 138
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 297
298 ASSERT_EQ(1u, observer.created().size()); 298 ASSERT_EQ(1u, observer.created().size());
299 EXPECT_EQ(request_id, observer.created()[0].request_id()); 299 EXPECT_EQ(request_id, observer.created()[0].request_id());
300 EXPECT_EQ(RequestManager::TESTING, observer.created()[0].type()); 300 EXPECT_EQ(RequestManager::TESTING, observer.created()[0].type());
301 301
302 ASSERT_EQ(1u, observer.executed().size()); 302 ASSERT_EQ(1u, observer.executed().size());
303 EXPECT_EQ(request_id, observer.executed()[0].request_id()); 303 EXPECT_EQ(request_id, observer.executed()[0].request_id());
304 304
305 scoped_ptr<RequestValue> response( 305 scoped_ptr<RequestValue> response(
306 RequestValue::CreateForTesting("i-like-vanilla")); 306 RequestValue::CreateForTesting("i-like-vanilla"));
307 const bool has_next = false; 307 const bool has_more = false;
308 308
309 bool result = 309 bool result =
310 request_manager_->FulfillRequest(request_id, response.Pass(), has_next); 310 request_manager_->FulfillRequest(request_id, response.Pass(), has_more);
311 EXPECT_TRUE(result); 311 EXPECT_TRUE(result);
312 312
313 ASSERT_EQ(1u, observer.fulfilled().size()); 313 ASSERT_EQ(1u, observer.fulfilled().size());
314 EXPECT_EQ(request_id, observer.fulfilled()[0].request_id()); 314 EXPECT_EQ(request_id, observer.fulfilled()[0].request_id());
315 EXPECT_FALSE(observer.fulfilled()[0].has_more()); 315 EXPECT_FALSE(observer.fulfilled()[0].has_more());
316 316
317 // Validate if the callback has correct arguments. 317 // Validate if the callback has correct arguments.
318 ASSERT_EQ(1u, logger.success_events().size()); 318 ASSERT_EQ(1u, logger.success_events().size());
319 EXPECT_EQ(0u, logger.error_events().size()); 319 EXPECT_EQ(0u, logger.error_events().size());
320 EventLogger::SuccessEvent* event = logger.success_events()[0]; 320 EventLogger::SuccessEvent* event = logger.success_events()[0];
321 ASSERT_TRUE(event->result()); 321 ASSERT_TRUE(event->result());
322 const std::string* response_test_string = event->result()->testing_params(); 322 const std::string* response_test_string = event->result()->testing_params();
323 ASSERT_TRUE(response_test_string); 323 ASSERT_TRUE(response_test_string);
324 EXPECT_EQ("i-like-vanilla", *response_test_string); 324 EXPECT_EQ("i-like-vanilla", *response_test_string);
325 EXPECT_FALSE(event->has_next()); 325 EXPECT_FALSE(event->has_more());
326 326
327 // Confirm, that the request is removed. Basically, fulfilling again for the 327 // Confirm, that the request is removed. Basically, fulfilling again for the
328 // same request, should fail. 328 // same request, should fail.
329 { 329 {
330 scoped_ptr<RequestValue> response; 330 scoped_ptr<RequestValue> response;
331 bool retry = 331 bool retry =
332 request_manager_->FulfillRequest(request_id, response.Pass(), has_next); 332 request_manager_->FulfillRequest(request_id, response.Pass(), has_more);
333 EXPECT_FALSE(retry); 333 EXPECT_FALSE(retry);
334 EXPECT_EQ(1u, observer.fulfilled().size()); 334 EXPECT_EQ(1u, observer.fulfilled().size());
335 } 335 }
336 336
337 // Rejecting should also fail. 337 // Rejecting should also fail.
338 { 338 {
339 bool retry = request_manager_->RejectRequest(request_id, 339 bool retry = request_manager_->RejectRequest(request_id,
340 base::File::FILE_ERROR_FAILED); 340 base::File::FILE_ERROR_FAILED);
341 EXPECT_FALSE(retry); 341 EXPECT_FALSE(retry);
342 EXPECT_EQ(0u, observer.rejected().size()); 342 EXPECT_EQ(0u, observer.rejected().size());
(...skipping 21 matching lines...) Expand all
364 EXPECT_EQ(0u, logger.error_events().size()); 364 EXPECT_EQ(0u, logger.error_events().size());
365 365
366 ASSERT_EQ(1u, observer.created().size()); 366 ASSERT_EQ(1u, observer.created().size());
367 EXPECT_EQ(request_id, observer.created()[0].request_id()); 367 EXPECT_EQ(request_id, observer.created()[0].request_id());
368 EXPECT_EQ(RequestManager::TESTING, observer.created()[0].type()); 368 EXPECT_EQ(RequestManager::TESTING, observer.created()[0].type());
369 369
370 ASSERT_EQ(1u, observer.executed().size()); 370 ASSERT_EQ(1u, observer.executed().size());
371 EXPECT_EQ(request_id, observer.executed()[0].request_id()); 371 EXPECT_EQ(request_id, observer.executed()[0].request_id());
372 372
373 scoped_ptr<RequestValue> response; 373 scoped_ptr<RequestValue> response;
374 const bool has_next = true; 374 const bool has_more = true;
375 375
376 bool result = 376 bool result =
377 request_manager_->FulfillRequest(request_id, response.Pass(), has_next); 377 request_manager_->FulfillRequest(request_id, response.Pass(), has_more);
378 EXPECT_TRUE(result); 378 EXPECT_TRUE(result);
379 379
380 // Validate if the callback has correct arguments. 380 // Validate if the callback has correct arguments.
381 ASSERT_EQ(1u, logger.success_events().size()); 381 ASSERT_EQ(1u, logger.success_events().size());
382 EXPECT_EQ(0u, logger.error_events().size()); 382 EXPECT_EQ(0u, logger.error_events().size());
383 EventLogger::SuccessEvent* event = logger.success_events()[0]; 383 EventLogger::SuccessEvent* event = logger.success_events()[0];
384 EXPECT_FALSE(event->result()); 384 EXPECT_FALSE(event->result());
385 EXPECT_TRUE(event->has_next()); 385 EXPECT_TRUE(event->has_more());
386 386
387 ASSERT_EQ(1u, observer.fulfilled().size()); 387 ASSERT_EQ(1u, observer.fulfilled().size());
388 EXPECT_EQ(request_id, observer.fulfilled()[0].request_id()); 388 EXPECT_EQ(request_id, observer.fulfilled()[0].request_id());
389 EXPECT_TRUE(observer.fulfilled()[0].has_more()); 389 EXPECT_TRUE(observer.fulfilled()[0].has_more());
390 390
391 // Confirm, that the request is not removed (since it has has_next == true). 391 // Confirm, that the request is not removed (since it has has_more == true).
392 // Basically, fulfilling again for the same request, should not fail. 392 // Basically, fulfilling again for the same request, should not fail.
393 { 393 {
394 bool new_has_next = false; 394 bool new_has_more = false;
395 bool retry = request_manager_->FulfillRequest( 395 bool retry = request_manager_->FulfillRequest(
396 request_id, response.Pass(), new_has_next); 396 request_id, response.Pass(), new_has_more);
397 EXPECT_TRUE(retry); 397 EXPECT_TRUE(retry);
398 398
399 ASSERT_EQ(2u, observer.fulfilled().size()); 399 ASSERT_EQ(2u, observer.fulfilled().size());
400 EXPECT_EQ(request_id, observer.fulfilled()[1].request_id()); 400 EXPECT_EQ(request_id, observer.fulfilled()[1].request_id());
401 EXPECT_FALSE(observer.fulfilled()[1].has_more()); 401 EXPECT_FALSE(observer.fulfilled()[1].has_more());
402 } 402 }
403 403
404 // Since |new_has_next| is false, then the request should be removed. To check 404 // Since |new_has_more| is false, then the request should be removed. To check
405 // it, try to fulfill again, what should fail. 405 // it, try to fulfill again, what should fail.
406 { 406 {
407 bool new_has_next = false; 407 bool new_has_more = false;
408 bool retry = request_manager_->FulfillRequest( 408 bool retry = request_manager_->FulfillRequest(
409 request_id, response.Pass(), new_has_next); 409 request_id, response.Pass(), new_has_more);
410 EXPECT_FALSE(retry); 410 EXPECT_FALSE(retry);
411 EXPECT_EQ(0u, observer.rejected().size()); 411 EXPECT_EQ(0u, observer.rejected().size());
412 } 412 }
413 413
414 ASSERT_EQ(1u, observer.destroyed().size()); 414 ASSERT_EQ(1u, observer.destroyed().size());
415 EXPECT_EQ(request_id, observer.destroyed()[0].request_id()); 415 EXPECT_EQ(request_id, observer.destroyed()[0].request_id());
416 EXPECT_EQ(0u, observer.timeouted().size()); 416 EXPECT_EQ(0u, observer.timeouted().size());
417 417
418 request_manager_->RemoveObserver(&observer); 418 request_manager_->RemoveObserver(&observer);
419 } 419 }
(...skipping 30 matching lines...) Expand all
450 EXPECT_EQ(error, event->error()); 450 EXPECT_EQ(error, event->error());
451 451
452 ASSERT_EQ(1u, observer.rejected().size()); 452 ASSERT_EQ(1u, observer.rejected().size());
453 EXPECT_EQ(request_id, observer.rejected()[0].request_id()); 453 EXPECT_EQ(request_id, observer.rejected()[0].request_id());
454 EXPECT_EQ(error, observer.rejected()[0].error()); 454 EXPECT_EQ(error, observer.rejected()[0].error());
455 455
456 // Confirm, that the request is removed. Basically, fulfilling again for the 456 // Confirm, that the request is removed. Basically, fulfilling again for the
457 // same request, should fail. 457 // same request, should fail.
458 { 458 {
459 scoped_ptr<RequestValue> response; 459 scoped_ptr<RequestValue> response;
460 bool has_next = false; 460 bool has_more = false;
461 bool retry = 461 bool retry =
462 request_manager_->FulfillRequest(request_id, response.Pass(), has_next); 462 request_manager_->FulfillRequest(request_id, response.Pass(), has_more);
463 EXPECT_FALSE(retry); 463 EXPECT_FALSE(retry);
464 EXPECT_EQ(0u, observer.fulfilled().size()); 464 EXPECT_EQ(0u, observer.fulfilled().size());
465 } 465 }
466 466
467 // Rejecting should also fail. 467 // Rejecting should also fail.
468 { 468 {
469 bool retry = request_manager_->RejectRequest(request_id, error); 469 bool retry = request_manager_->RejectRequest(request_id, error);
470 EXPECT_FALSE(retry); 470 EXPECT_FALSE(retry);
471 EXPECT_EQ(1u, observer.rejected().size()); 471 EXPECT_EQ(1u, observer.rejected().size());
472 } 472 }
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 ASSERT_EQ(1u, observer.timeouted().size()); 666 ASSERT_EQ(1u, observer.timeouted().size());
667 EXPECT_EQ(request_id, observer.timeouted()[0].request_id()); 667 EXPECT_EQ(request_id, observer.timeouted()[0].request_id());
668 ASSERT_EQ(1u, observer.destroyed().size()); 668 ASSERT_EQ(1u, observer.destroyed().size());
669 EXPECT_EQ(request_id, observer.destroyed()[0].request_id()); 669 EXPECT_EQ(request_id, observer.destroyed()[0].request_id());
670 670
671 request_manager_->RemoveObserver(&observer); 671 request_manager_->RemoveObserver(&observer);
672 } 672 }
673 673
674 } // namespace file_system_provider 674 } // namespace file_system_provider
675 } // namespace chromeos 675 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/file_system_provider/request_manager.cc ('k') | chrome/common/extensions/api/file_system_provider.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698