| OLD | NEW |
| 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 <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 const char kRandomPageContent[] = | 511 const char kRandomPageContent[] = |
| 512 "<html><title>SomthingElse</title><body>I am SomethingElse</body></html>"; | 512 "<html><title>SomthingElse</title><body>I am SomethingElse</body></html>"; |
| 513 const char kHelloPagePath[] = "/hello_google"; | 513 const char kHelloPagePath[] = "/hello_google"; |
| 514 const char kRandomPagePath[] = "/non_google_page"; | 514 const char kRandomPagePath[] = "/non_google_page"; |
| 515 | 515 |
| 516 | 516 |
| 517 // FakeGoogle serves content of http://www.google.com/hello_google page for | 517 // FakeGoogle serves content of http://www.google.com/hello_google page for |
| 518 // merge session tests. | 518 // merge session tests. |
| 519 class FakeGoogle { | 519 class FakeGoogle { |
| 520 public: | 520 public: |
| 521 FakeGoogle() : start_event_(true, false) { | 521 FakeGoogle() |
| 522 } | 522 : start_event_(base::WaitableEvent::ResetPolicy::MANUAL, |
| 523 base::WaitableEvent::InitialState::NOT_SIGNALED) {} |
| 523 | 524 |
| 524 ~FakeGoogle() {} | 525 ~FakeGoogle() {} |
| 525 | 526 |
| 526 std::unique_ptr<HttpResponse> HandleRequest(const HttpRequest& request) { | 527 std::unique_ptr<HttpResponse> HandleRequest(const HttpRequest& request) { |
| 527 // The scheme and host of the URL is actually not important but required to | 528 // The scheme and host of the URL is actually not important but required to |
| 528 // get a valid GURL in order to parse |request.relative_url|. | 529 // get a valid GURL in order to parse |request.relative_url|. |
| 529 GURL request_url = GURL("http://localhost").Resolve(request.relative_url); | 530 GURL request_url = GURL("http://localhost").Resolve(request.relative_url); |
| 530 LOG(WARNING) << "Requesting page " << request.relative_url; | 531 LOG(WARNING) << "Requesting page " << request.relative_url; |
| 531 std::string request_path = request_url.path(); | 532 std::string request_path = request_url.path(); |
| 532 std::unique_ptr<BasicHttpResponse> http_response(new BasicHttpResponse()); | 533 std::unique_ptr<BasicHttpResponse> http_response(new BasicHttpResponse()); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 scoped_refptr<content::MessageLoopRunner> runner_; | 577 scoped_refptr<content::MessageLoopRunner> runner_; |
| 577 | 578 |
| 578 DISALLOW_COPY_AND_ASSIGN(FakeGoogle); | 579 DISALLOW_COPY_AND_ASSIGN(FakeGoogle); |
| 579 }; | 580 }; |
| 580 | 581 |
| 581 // FakeGaia specialization that can delay /MergeSession handler until | 582 // FakeGaia specialization that can delay /MergeSession handler until |
| 582 // we explicitly call DelayedFakeGaia::UnblockMergeSession(). | 583 // we explicitly call DelayedFakeGaia::UnblockMergeSession(). |
| 583 class DelayedFakeGaia : public FakeGaia { | 584 class DelayedFakeGaia : public FakeGaia { |
| 584 public: | 585 public: |
| 585 DelayedFakeGaia() | 586 DelayedFakeGaia() |
| 586 : blocking_event_(true, false), | 587 : blocking_event_(base::WaitableEvent::ResetPolicy::MANUAL, |
| 587 start_event_(true, false) { | 588 base::WaitableEvent::InitialState::NOT_SIGNALED), |
| 588 } | 589 start_event_(base::WaitableEvent::ResetPolicy::MANUAL, |
| 590 base::WaitableEvent::InitialState::NOT_SIGNALED) {} |
| 589 | 591 |
| 590 void UnblockMergeSession() { | 592 void UnblockMergeSession() { |
| 591 blocking_event_.Signal(); | 593 blocking_event_.Signal(); |
| 592 } | 594 } |
| 593 | 595 |
| 594 void WaitForMergeSessionToStart() { | 596 void WaitForMergeSessionToStart() { |
| 595 // If we have already served the request, bail out. | 597 // If we have already served the request, bail out. |
| 596 if (start_event_.IsSignaled()) | 598 if (start_event_.IsSignaled()) |
| 597 return; | 599 return; |
| 598 | 600 |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 | 806 |
| 805 if (!catcher.GetNextResult()) { | 807 if (!catcher.GetNextResult()) { |
| 806 std::string message = catcher.message(); | 808 std::string message = catcher.message(); |
| 807 ADD_FAILURE() << "Tests failed: " << message; | 809 ADD_FAILURE() << "Tests failed: " << message; |
| 808 } | 810 } |
| 809 | 811 |
| 810 EXPECT_TRUE(fake_google_.IsPageRequested()); | 812 EXPECT_TRUE(fake_google_.IsPageRequested()); |
| 811 } | 813 } |
| 812 | 814 |
| 813 } // namespace chromeos | 815 } // namespace chromeos |
| OLD | NEW |