| 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 "modules/presentation/PresentationRequest.h" |
| 6 |
| 7 #include "bindings/core/v8/V8BindingForTesting.h" |
| 8 #include "core/dom/ExceptionCode.h" |
| 9 #include "platform/weborigin/KURL.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace blink { |
| 13 namespace { |
| 14 |
| 15 TEST(PresentationRequestTest, TestSingleUrlConstructor) { |
| 16 V8TestingScope scope; |
| 17 PresentationRequest* request = PresentationRequest::create( |
| 18 scope.getExecutionContext(), "https://example.com", |
| 19 scope.getExceptionState()); |
| 20 ASSERT_FALSE(scope.getExceptionState().hadException()); |
| 21 |
| 22 WTF::Vector<KURL> requestUrls = request->urls(); |
| 23 EXPECT_EQ(static_cast<size_t>(1), requestUrls.size()); |
| 24 EXPECT_TRUE(requestUrls[0].isValid()); |
| 25 EXPECT_EQ("https://example.com/", requestUrls[0].getString()); |
| 26 } |
| 27 |
| 28 TEST(PresentationRequestTest, TestMultipleUrlConstructor) { |
| 29 V8TestingScope scope; |
| 30 WTF::Vector<String> urls; |
| 31 urls.append("https://example.com"); |
| 32 urls.append("cast://deadbeef?param=foo"); |
| 33 |
| 34 PresentationRequest* request = PresentationRequest::create( |
| 35 scope.getExecutionContext(), urls, scope.getExceptionState()); |
| 36 ASSERT_FALSE(scope.getExceptionState().hadException()); |
| 37 |
| 38 WTF::Vector<KURL> requestUrls = request->urls(); |
| 39 EXPECT_EQ(static_cast<size_t>(2), requestUrls.size()); |
| 40 EXPECT_TRUE(requestUrls[0].isValid()); |
| 41 EXPECT_EQ("https://example.com/", requestUrls[0].getString()); |
| 42 EXPECT_TRUE(requestUrls[1].isValid()); |
| 43 EXPECT_EQ("cast://deadbeef?param=foo", requestUrls[1].getString()); |
| 44 } |
| 45 |
| 46 TEST(PresentationRequestTest, TestMultipleUrlConstructorInvalidUrl) { |
| 47 V8TestingScope scope; |
| 48 WTF::Vector<String> urls; |
| 49 urls.append("https://example.com"); |
| 50 urls.append(""); |
| 51 |
| 52 PresentationRequest::create(scope.getExecutionContext(), urls, |
| 53 scope.getExceptionState()); |
| 54 EXPECT_TRUE(scope.getExceptionState().hadException()); |
| 55 EXPECT_EQ(SyntaxError, scope.getExceptionState().code()); |
| 56 } |
| 57 |
| 58 TEST(PresentationRequestTest, TestSingleUrlConstructorMixedContent) { |
| 59 V8TestingScope scope; |
| 60 scope.getExecutionContext()->securityContext().setSecurityOrigin( |
| 61 SecurityOrigin::createFromString("https://example.test")); |
| 62 |
| 63 PresentationRequest::create(scope.getExecutionContext(), "http://example.com", |
| 64 scope.getExceptionState()); |
| 65 EXPECT_TRUE(scope.getExceptionState().hadException()); |
| 66 EXPECT_EQ(SecurityError, scope.getExceptionState().code()); |
| 67 } |
| 68 |
| 69 TEST(PresentationRequestTest, TestMultipleUrlConstructorMixedContent) { |
| 70 V8TestingScope scope; |
| 71 scope.getExecutionContext()->securityContext().setSecurityOrigin( |
| 72 SecurityOrigin::createFromString("https://example.test")); |
| 73 |
| 74 WTF::Vector<String> urls; |
| 75 urls.append("http://example.com"); |
| 76 urls.append("https://example1.com"); |
| 77 |
| 78 PresentationRequest::create(scope.getExecutionContext(), urls, |
| 79 scope.getExceptionState()); |
| 80 EXPECT_TRUE(scope.getExceptionState().hadException()); |
| 81 EXPECT_EQ(SecurityError, scope.getExceptionState().code()); |
| 82 } |
| 83 |
| 84 TEST(PresentationRequestTest, TestMultipleUrlConstructorEmptySequence) { |
| 85 V8TestingScope scope; |
| 86 WTF::Vector<String> urls; |
| 87 |
| 88 PresentationRequest::create(scope.getExecutionContext(), urls, |
| 89 scope.getExceptionState()); |
| 90 EXPECT_TRUE(scope.getExceptionState().hadException()); |
| 91 EXPECT_EQ(NotSupportedError, scope.getExceptionState().code()); |
| 92 } |
| 93 |
| 94 } // anonymous namespace |
| 95 } // namespace blink |
| OLD | NEW |