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

Unified Diff: third_party/WebKit/Source/platform/mojo/KURLSecurityOriginTest.cpp

Issue 2000253006: Implement URL and Origin typemaps/struct traits for blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/mojo/KURLSecurityOriginTest.cpp
diff --git a/third_party/WebKit/Source/platform/mojo/KURLSecurityOriginTest.cpp b/third_party/WebKit/Source/platform/mojo/KURLSecurityOriginTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..111e6f1b07268405543ce60ee4db3127c77dbaac
--- /dev/null
+++ b/third_party/WebKit/Source/platform/mojo/KURLSecurityOriginTest.cpp
@@ -0,0 +1,93 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/macros.h"
+#include "base/message_loop/message_loop.h"
+#include "mojo/public/cpp/bindings/binding.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "url/mojo/url_test.mojom-blink.h"
+#include "url/url_constants.h"
+
+namespace blink {
+namespace {
+
+ class UrlTestImpl : public url::mojom::blink::UrlTest {
esprehn 2016/05/25 17:06:27 don't indent nested namespace functions
Marijn Kruisselbrink 2016/05/25 17:35:08 I never quite understood what "nested namespaces w
dcheng 2016/05/26 20:15:15 Basically, just think of it as namespaces never in
Marijn Kruisselbrink 2016/05/26 20:52:42 Yes, that's the chromium styleguide. The blink/web
+ public:
+ explicit UrlTestImpl(url::mojom::blink::UrlTestRequest request)
esprehn 2016/05/25 17:06:27 Where are things like the generated TestRequest st
Marijn Kruisselbrink 2016/05/25 17:35:08 https://www.chromium.org/developers/design-documen
+ : m_binding(this, std::move(request))
+ {
+ }
+
+ // UrlTest:
+ void BounceUrl(const KURL& in, const BounceUrlCallback& callback) override
+ {
+ callback.Run(in);
+ }
+
+ void BounceOrigin(const RefPtr<SecurityOrigin>& in,
+ const BounceOriginCallback& callback) override
+ {
+ callback.Run(in);
+ }
+
+ private:
+ mojo::Binding<UrlTest> m_binding;
+ };
+
+} // namespace
+
+// Mojo version of chrome IPC test in url/ipc/url_param_traits_unittest.cc.
+TEST(KURLSecurityOriginStructTraitsTest, Basic)
+{
+ base::MessageLoop messageLoop;
+
+ url::mojom::blink::UrlTestPtr proxy;
+ UrlTestImpl impl(GetProxy(&proxy));
+
+ const char* serializeCases[] = {
+ "http://www.google.com/",
+ "http://user:pass@host.com:888/foo;bar?baz#nop",
+ };
+
+ for (size_t i = 0; i < arraysize(serializeCases); i++) {
+ KURL input(KURL(), serializeCases[i]);
+ KURL output;
+ EXPECT_TRUE(proxy->BounceUrl(input, &output));
+
+ // We want to test each component individually to make sure its range was
+ // correctly serialized and deserialized, not just the spec.
+ EXPECT_EQ(input.getString(), output.getString());
+ EXPECT_EQ(input.isValid(), output.isValid());
+ EXPECT_EQ(input.protocol(), output.protocol());
+ EXPECT_EQ(input.user(), output.user());
+ EXPECT_EQ(input.pass(), output.pass());
+ EXPECT_EQ(input.host(), output.host());
+ EXPECT_EQ(input.port(), output.port());
+ EXPECT_EQ(input.path(), output.path());
+ EXPECT_EQ(input.query(), output.query());
+ EXPECT_EQ(input.fragmentIdentifier(), output.fragmentIdentifier());
+ }
+
+ // Test an excessively long GURL.
+ {
+ const std::string url = std::string("http://example.org/").append(url::kMaxURLChars + 1, 'a');
+ KURL input(KURL(), url.c_str());
+ KURL output;
+ EXPECT_TRUE(proxy->BounceUrl(input, &output));
+ EXPECT_TRUE(output.isEmpty());
+ }
+
+ // Test basic Origin serialization.
+ RefPtr<SecurityOrigin> nonUnique = SecurityOrigin::create("http", "www.google.com", 80);
+ RefPtr<SecurityOrigin> output;
+ EXPECT_TRUE(proxy->BounceOrigin(nonUnique, &output));
+ EXPECT_TRUE(nonUnique->isSameSchemeHostPort(output.get()));
+ EXPECT_FALSE(nonUnique->isUnique());
+
+ RefPtr<SecurityOrigin> unique = SecurityOrigin::createUnique();
+ EXPECT_TRUE(proxy->BounceOrigin(unique, &output));
+ EXPECT_TRUE(output->isUnique());
+}
+
+} // namespace url

Powered by Google App Engine
This is Rietveld 408576698