Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/logging.h" | |
| 6 #include "base/macros.h" | |
| 7 #include "mojo/public/cpp/bindings/binding.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 #include "url/mojo/url_test.mojom.h" | |
| 10 | |
| 11 namespace url { | |
| 12 | |
| 13 class UrlTestImpl : public mojom::UrlTest { | |
| 14 public: | |
| 15 explicit UrlTestImpl(mojo::InterfaceRequest<url::mojom::UrlTest> request) | |
| 16 : binding_(this, std::move(request)) { | |
|
dcheng
2016/03/03 21:37:36
Nit: #include <utility> for std::move
jam
2016/03/03 21:49:47
Done.
| |
| 17 } | |
| 18 | |
| 19 // UrlTest: | |
| 20 void Bounce(const GURL& in, const BounceCallback& callback) override { | |
| 21 callback.Run(in); | |
| 22 } | |
| 23 | |
| 24 private: | |
| 25 mojo::Binding<UrlTest> binding_; | |
| 26 }; | |
| 27 | |
| 28 // Mojo version of chrome IPC test in | |
| 29 // content/common/common_param_traits_unittest.cc | |
| 30 TEST(MojoUrlGURLStructTraitsTest, Basic) { | |
| 31 base::MessageLoop message_loop; | |
| 32 | |
| 33 mojom::UrlTestPtr proxy; | |
| 34 UrlTestImpl impl(GetProxy(&proxy)); | |
| 35 | |
| 36 const char* serialize_cases[] = { | |
| 37 "http://www.google.com/", | |
| 38 "http://user:pass@host.com:888/foo;bar?baz#nop", | |
| 39 }; | |
| 40 | |
| 41 for (size_t i = 0; i < arraysize(serialize_cases); i++) { | |
| 42 GURL input(serialize_cases[i]); | |
| 43 GURL output; | |
| 44 EXPECT_TRUE(proxy->Bounce(input, &output)); | |
| 45 | |
| 46 // We want to test each component individually to make sure its range was | |
| 47 // correctly serialized and deserialized, not just the spec. | |
| 48 EXPECT_EQ(input.possibly_invalid_spec(), output.possibly_invalid_spec()); | |
| 49 EXPECT_EQ(input.is_valid(), output.is_valid()); | |
| 50 EXPECT_EQ(input.scheme(), output.scheme()); | |
| 51 EXPECT_EQ(input.username(), output.username()); | |
| 52 EXPECT_EQ(input.password(), output.password()); | |
| 53 EXPECT_EQ(input.host(), output.host()); | |
| 54 EXPECT_EQ(input.port(), output.port()); | |
| 55 EXPECT_EQ(input.path(), output.path()); | |
| 56 EXPECT_EQ(input.query(), output.query()); | |
| 57 EXPECT_EQ(input.ref(), output.ref()); | |
| 58 } | |
| 59 | |
| 60 // Test an excessively long GURL. | |
| 61 { | |
| 62 const std::string url = std::string("http://example.org/").append( | |
| 63 mojo::kMaxUrlChars + 1, 'a'); | |
| 64 GURL input(url.c_str()); | |
| 65 GURL output; | |
| 66 EXPECT_TRUE(proxy->Bounce(input, &output)); | |
| 67 EXPECT_TRUE(output.is_empty()); | |
| 68 } | |
| 69 } | |
| 70 | |
| 71 } // namespace url | |
| OLD | NEW |