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/macros.h" | |
| 6 #include "base/message_loop/message_loop.h" | |
| 7 #include "mojo/public/cpp/bindings/binding.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 #include "url/mojo/url_test.mojom-blink.h" | |
| 10 #include "url/url_constants.h" | |
| 11 | |
| 12 namespace blink { | |
| 13 namespace { | |
| 14 | |
| 15 class UrlTestImpl : public url::mojom::blink::UrlTest { | |
| 16 public: | |
| 17 explicit UrlTestImpl(url::mojom::blink::UrlTestRequest request) | |
| 18 : m_binding(this, std::move(request)) | |
| 19 { | |
| 20 } | |
| 21 | |
| 22 // UrlTest: | |
| 23 void BounceUrl(const KURL& in, const BounceUrlCallback& callback) override | |
| 24 { | |
| 25 callback.Run(in); | |
| 26 } | |
| 27 | |
| 28 void BounceOrigin(const RefPtr<SecurityOrigin>& in, | |
| 29 const BounceOriginCallback& callback) override | |
| 30 { | |
| 31 callback.Run(in); | |
| 32 } | |
| 33 | |
| 34 private: | |
| 35 mojo::Binding<UrlTest> m_binding; | |
| 36 }; | |
| 37 | |
| 38 } // namespace | |
| 39 | |
| 40 // Mojo version of chrome IPC test in url/ipc/url_param_traits_unittest.cc. | |
| 41 TEST(KURLSecurityOriginStructTraitsTest, Basic) | |
| 42 { | |
| 43 base::MessageLoop messageLoop; | |
| 44 | |
| 45 url::mojom::blink::UrlTestPtr proxy; | |
| 46 UrlTestImpl impl(GetProxy(&proxy)); | |
| 47 | |
| 48 const char* serializeCases[] = { | |
| 49 "http://www.google.com/", | |
| 50 "http://user:pass@host.com:888/foo;bar?baz#nop", | |
| 51 }; | |
| 52 | |
| 53 for (size_t i = 0; i < arraysize(serializeCases); i++) { | |
|
dcheng
2016/05/26 20:15:15
Thanks to the magic of C++11, you can just write:
Marijn Kruisselbrink
2016/05/26 20:52:42
Good point, not sure why the non-blink version of
| |
| 54 KURL input(KURL(), serializeCases[i]); | |
| 55 KURL output; | |
| 56 EXPECT_TRUE(proxy->BounceUrl(input, &output)); | |
| 57 | |
| 58 // We want to test each component individually to make sure its range wa s | |
| 59 // correctly serialized and deserialized, not just the spec. | |
| 60 EXPECT_EQ(input.getString(), output.getString()); | |
| 61 EXPECT_EQ(input.isValid(), output.isValid()); | |
| 62 EXPECT_EQ(input.protocol(), output.protocol()); | |
| 63 EXPECT_EQ(input.user(), output.user()); | |
| 64 EXPECT_EQ(input.pass(), output.pass()); | |
| 65 EXPECT_EQ(input.host(), output.host()); | |
| 66 EXPECT_EQ(input.port(), output.port()); | |
| 67 EXPECT_EQ(input.path(), output.path()); | |
| 68 EXPECT_EQ(input.query(), output.query()); | |
| 69 EXPECT_EQ(input.fragmentIdentifier(), output.fragmentIdentifier()); | |
| 70 } | |
| 71 | |
| 72 // Test an excessively long GURL. | |
| 73 { | |
| 74 const std::string url = std::string("http://example.org/").append(url::k MaxURLChars + 1, 'a'); | |
| 75 KURL input(KURL(), url.c_str()); | |
| 76 KURL output; | |
| 77 EXPECT_TRUE(proxy->BounceUrl(input, &output)); | |
| 78 EXPECT_TRUE(output.isEmpty()); | |
| 79 } | |
| 80 | |
| 81 // Test basic Origin serialization. | |
| 82 RefPtr<SecurityOrigin> nonUnique = SecurityOrigin::create("http", "www.googl e.com", 80); | |
| 83 RefPtr<SecurityOrigin> output; | |
| 84 EXPECT_TRUE(proxy->BounceOrigin(nonUnique, &output)); | |
| 85 EXPECT_TRUE(nonUnique->isSameSchemeHostPort(output.get())); | |
| 86 EXPECT_FALSE(nonUnique->isUnique()); | |
| 87 | |
| 88 RefPtr<SecurityOrigin> unique = SecurityOrigin::createUnique(); | |
| 89 EXPECT_TRUE(proxy->BounceOrigin(unique, &output)); | |
| 90 EXPECT_TRUE(output->isUnique()); | |
| 91 } | |
| 92 | |
| 93 } // namespace url | |
| OLD | NEW |