| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/presentation/PresentationRequest.h" | 5 #include "modules/presentation/PresentationRequest.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/V8BindingForTesting.h" | 7 #include "bindings/core/v8/V8BindingForTesting.h" |
| 8 #include "core/dom/ExceptionCode.h" | 8 #include "core/dom/ExceptionCode.h" |
| 9 #include "platform/weborigin/KURL.h" | 9 #include "platform/weborigin/KURL.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 WTF::Vector<KURL> requestUrls = request->urls(); | 22 WTF::Vector<KURL> requestUrls = request->urls(); |
| 23 EXPECT_EQ(static_cast<size_t>(1), requestUrls.size()); | 23 EXPECT_EQ(static_cast<size_t>(1), requestUrls.size()); |
| 24 EXPECT_TRUE(requestUrls[0].isValid()); | 24 EXPECT_TRUE(requestUrls[0].isValid()); |
| 25 EXPECT_EQ("https://example.com/", requestUrls[0].getString()); | 25 EXPECT_EQ("https://example.com/", requestUrls[0].getString()); |
| 26 } | 26 } |
| 27 | 27 |
| 28 TEST(PresentationRequestTest, TestMultipleUrlConstructor) { | 28 TEST(PresentationRequestTest, TestMultipleUrlConstructor) { |
| 29 V8TestingScope scope; | 29 V8TestingScope scope; |
| 30 WTF::Vector<String> urls; | 30 WTF::Vector<String> urls; |
| 31 urls.append("https://example.com"); | 31 urls.push_back("https://example.com"); |
| 32 urls.append("cast://deadbeef?param=foo"); | 32 urls.push_back("cast://deadbeef?param=foo"); |
| 33 | 33 |
| 34 PresentationRequest* request = PresentationRequest::create( | 34 PresentationRequest* request = PresentationRequest::create( |
| 35 scope.getExecutionContext(), urls, scope.getExceptionState()); | 35 scope.getExecutionContext(), urls, scope.getExceptionState()); |
| 36 ASSERT_FALSE(scope.getExceptionState().hadException()); | 36 ASSERT_FALSE(scope.getExceptionState().hadException()); |
| 37 | 37 |
| 38 WTF::Vector<KURL> requestUrls = request->urls(); | 38 WTF::Vector<KURL> requestUrls = request->urls(); |
| 39 EXPECT_EQ(static_cast<size_t>(2), requestUrls.size()); | 39 EXPECT_EQ(static_cast<size_t>(2), requestUrls.size()); |
| 40 EXPECT_TRUE(requestUrls[0].isValid()); | 40 EXPECT_TRUE(requestUrls[0].isValid()); |
| 41 EXPECT_EQ("https://example.com/", requestUrls[0].getString()); | 41 EXPECT_EQ("https://example.com/", requestUrls[0].getString()); |
| 42 EXPECT_TRUE(requestUrls[1].isValid()); | 42 EXPECT_TRUE(requestUrls[1].isValid()); |
| 43 EXPECT_EQ("cast://deadbeef?param=foo", requestUrls[1].getString()); | 43 EXPECT_EQ("cast://deadbeef?param=foo", requestUrls[1].getString()); |
| 44 } | 44 } |
| 45 | 45 |
| 46 TEST(PresentationRequestTest, TestMultipleUrlConstructorInvalidURLFamily) { | 46 TEST(PresentationRequestTest, TestMultipleUrlConstructorInvalidURLFamily) { |
| 47 V8TestingScope scope; | 47 V8TestingScope scope; |
| 48 WTF::Vector<String> urls; | 48 WTF::Vector<String> urls; |
| 49 urls.append("https://example.com"); | 49 urls.push_back("https://example.com"); |
| 50 urls.append("about://deadbeef?param=foo"); | 50 urls.push_back("about://deadbeef?param=foo"); |
| 51 | 51 |
| 52 PresentationRequest::create(scope.getExecutionContext(), urls, | 52 PresentationRequest::create(scope.getExecutionContext(), urls, |
| 53 scope.getExceptionState()); | 53 scope.getExceptionState()); |
| 54 ASSERT_TRUE(scope.getExceptionState().hadException()); | 54 ASSERT_TRUE(scope.getExceptionState().hadException()); |
| 55 | 55 |
| 56 EXPECT_EQ(SyntaxError, scope.getExceptionState().code()); | 56 EXPECT_EQ(SyntaxError, scope.getExceptionState().code()); |
| 57 } | 57 } |
| 58 | 58 |
| 59 TEST(PresentationRequestTest, TestMultipleUrlConstructorInvalidUrl) { | 59 TEST(PresentationRequestTest, TestMultipleUrlConstructorInvalidUrl) { |
| 60 V8TestingScope scope; | 60 V8TestingScope scope; |
| 61 WTF::Vector<String> urls; | 61 WTF::Vector<String> urls; |
| 62 urls.append("https://example.com"); | 62 urls.push_back("https://example.com"); |
| 63 urls.append(""); | 63 urls.push_back(""); |
| 64 | 64 |
| 65 PresentationRequest::create(scope.getExecutionContext(), urls, | 65 PresentationRequest::create(scope.getExecutionContext(), urls, |
| 66 scope.getExceptionState()); | 66 scope.getExceptionState()); |
| 67 EXPECT_TRUE(scope.getExceptionState().hadException()); | 67 EXPECT_TRUE(scope.getExceptionState().hadException()); |
| 68 EXPECT_EQ(SyntaxError, scope.getExceptionState().code()); | 68 EXPECT_EQ(SyntaxError, scope.getExceptionState().code()); |
| 69 } | 69 } |
| 70 | 70 |
| 71 TEST(PresentationRequestTest, TestSingleUrlConstructorMixedContent) { | 71 TEST(PresentationRequestTest, TestSingleUrlConstructorMixedContent) { |
| 72 V8TestingScope scope; | 72 V8TestingScope scope; |
| 73 scope.getExecutionContext()->securityContext().setSecurityOrigin( | 73 scope.getExecutionContext()->securityContext().setSecurityOrigin( |
| 74 SecurityOrigin::createFromString("https://example.test")); | 74 SecurityOrigin::createFromString("https://example.test")); |
| 75 | 75 |
| 76 PresentationRequest::create(scope.getExecutionContext(), "http://example.com", | 76 PresentationRequest::create(scope.getExecutionContext(), "http://example.com", |
| 77 scope.getExceptionState()); | 77 scope.getExceptionState()); |
| 78 EXPECT_TRUE(scope.getExceptionState().hadException()); | 78 EXPECT_TRUE(scope.getExceptionState().hadException()); |
| 79 EXPECT_EQ(SecurityError, scope.getExceptionState().code()); | 79 EXPECT_EQ(SecurityError, scope.getExceptionState().code()); |
| 80 } | 80 } |
| 81 | 81 |
| 82 TEST(PresentationRequestTest, TestMultipleUrlConstructorMixedContent) { | 82 TEST(PresentationRequestTest, TestMultipleUrlConstructorMixedContent) { |
| 83 V8TestingScope scope; | 83 V8TestingScope scope; |
| 84 scope.getExecutionContext()->securityContext().setSecurityOrigin( | 84 scope.getExecutionContext()->securityContext().setSecurityOrigin( |
| 85 SecurityOrigin::createFromString("https://example.test")); | 85 SecurityOrigin::createFromString("https://example.test")); |
| 86 | 86 |
| 87 WTF::Vector<String> urls; | 87 WTF::Vector<String> urls; |
| 88 urls.append("http://example.com"); | 88 urls.push_back("http://example.com"); |
| 89 urls.append("https://example1.com"); | 89 urls.push_back("https://example1.com"); |
| 90 | 90 |
| 91 PresentationRequest::create(scope.getExecutionContext(), urls, | 91 PresentationRequest::create(scope.getExecutionContext(), urls, |
| 92 scope.getExceptionState()); | 92 scope.getExceptionState()); |
| 93 EXPECT_TRUE(scope.getExceptionState().hadException()); | 93 EXPECT_TRUE(scope.getExceptionState().hadException()); |
| 94 EXPECT_EQ(SecurityError, scope.getExceptionState().code()); | 94 EXPECT_EQ(SecurityError, scope.getExceptionState().code()); |
| 95 } | 95 } |
| 96 | 96 |
| 97 TEST(PresentationRequestTest, TestMultipleUrlConstructorEmptySequence) { | 97 TEST(PresentationRequestTest, TestMultipleUrlConstructorEmptySequence) { |
| 98 V8TestingScope scope; | 98 V8TestingScope scope; |
| 99 WTF::Vector<String> urls; | 99 WTF::Vector<String> urls; |
| 100 | 100 |
| 101 PresentationRequest::create(scope.getExecutionContext(), urls, | 101 PresentationRequest::create(scope.getExecutionContext(), urls, |
| 102 scope.getExceptionState()); | 102 scope.getExceptionState()); |
| 103 EXPECT_TRUE(scope.getExceptionState().hadException()); | 103 EXPECT_TRUE(scope.getExceptionState().hadException()); |
| 104 EXPECT_EQ(NotSupportedError, scope.getExceptionState().code()); | 104 EXPECT_EQ(NotSupportedError, scope.getExceptionState().code()); |
| 105 } | 105 } |
| 106 | 106 |
| 107 } // anonymous namespace | 107 } // anonymous namespace |
| 108 } // namespace blink | 108 } // namespace blink |
| OLD | NEW |