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

Unified Diff: third_party/WebKit/Source/modules/presentation/PresentationRequestTest.cpp

Issue 2552343009: [Presentation API] Adds DOMString[] constructor to PresentationRequest. (Closed)
Patch Set: resolve code review comments from foolip Created 3 years, 11 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/modules/presentation/PresentationRequestTest.cpp
diff --git a/third_party/WebKit/Source/modules/presentation/PresentationRequestTest.cpp b/third_party/WebKit/Source/modules/presentation/PresentationRequestTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..f76d06334b6c63a755957b2edcc4bc7020afeb6e
--- /dev/null
+++ b/third_party/WebKit/Source/modules/presentation/PresentationRequestTest.cpp
@@ -0,0 +1,95 @@
+// 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 "modules/presentation/PresentationRequest.h"
+
+#include "bindings/core/v8/V8BindingForTesting.h"
+#include "core/dom/ExceptionCode.h"
+#include "platform/weborigin/KURL.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blink {
+namespace {
+
+TEST(PresentationRequestTest, TestSingleUrlConstructor) {
+ V8TestingScope scope;
+ PresentationRequest* request = PresentationRequest::create(
+ scope.getExecutionContext(), "https://example.com",
+ scope.getExceptionState());
+ ASSERT_FALSE(scope.getExceptionState().hadException());
+
+ WTF::Vector<KURL> requestUrls = request->urls();
+ EXPECT_EQ(static_cast<size_t>(1), requestUrls.size());
+ EXPECT_TRUE(requestUrls[0].isValid());
+ EXPECT_EQ("https://example.com/", requestUrls[0].getString());
+}
+
+TEST(PresentationRequestTest, TestMultipleUrlConstructor) {
+ V8TestingScope scope;
+ WTF::Vector<String> urls;
+ urls.append("https://example.com");
+ urls.append("cast://deadbeef?param=foo");
+
+ PresentationRequest* request = PresentationRequest::create(
+ scope.getExecutionContext(), urls, scope.getExceptionState());
+ ASSERT_FALSE(scope.getExceptionState().hadException());
+
+ WTF::Vector<KURL> requestUrls = request->urls();
+ EXPECT_EQ(static_cast<size_t>(2), requestUrls.size());
+ EXPECT_TRUE(requestUrls[0].isValid());
+ EXPECT_EQ("https://example.com/", requestUrls[0].getString());
+ EXPECT_TRUE(requestUrls[1].isValid());
+ EXPECT_EQ("cast://deadbeef?param=foo", requestUrls[1].getString());
+}
+
+TEST(PresentationRequestTest, TestMultipleUrlConstructorInvalidUrl) {
+ V8TestingScope scope;
+ WTF::Vector<String> urls;
+ urls.append("https://example.com");
+ urls.append("");
+
+ PresentationRequest::create(scope.getExecutionContext(), urls,
+ scope.getExceptionState());
+ EXPECT_TRUE(scope.getExceptionState().hadException());
+ EXPECT_EQ(SyntaxError, scope.getExceptionState().code());
+}
+
+TEST(PresentationRequestTest, TestSingleUrlConstructorMixedContent) {
+ V8TestingScope scope;
+ scope.getExecutionContext()->securityContext().setSecurityOrigin(
+ SecurityOrigin::createFromString("https://example.test"));
+
+ PresentationRequest::create(scope.getExecutionContext(), "http://example.com",
+ scope.getExceptionState());
+ EXPECT_TRUE(scope.getExceptionState().hadException());
+ EXPECT_EQ(SecurityError, scope.getExceptionState().code());
+}
+
+TEST(PresentationRequestTest, TestMultipleUrlConstructorMixedContent) {
+ V8TestingScope scope;
+ scope.getExecutionContext()->securityContext().setSecurityOrigin(
+ SecurityOrigin::createFromString("https://example.test"));
+
+ WTF::Vector<String> urls;
+ urls.append("http://example.com");
+ urls.append("https://example1.com");
+
+ PresentationRequest::create(scope.getExecutionContext(), urls,
+ scope.getExceptionState());
+ EXPECT_TRUE(scope.getExceptionState().hadException());
+ EXPECT_EQ(SecurityError, scope.getExceptionState().code());
+}
+
+TEST(PresentationRequestTest, TestMultipleUrlConstructorEmptySequence) {
+ V8TestingScope scope;
+ WTF::Vector<String> urls;
+
+ PresentationRequest::create(scope.getExecutionContext(), urls,
+ scope.getExceptionState());
+ EXPECT_TRUE(scope.getExceptionState().hadException());
+ EXPECT_EQ(NotSupportedError, scope.getExceptionState().code());
+}
+
+} // anonymous namespace
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698