| 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 25 matching lines...) Expand all Loading... |
| 36 ASSERT_FALSE(scope.GetExceptionState().HadException()); | 36 ASSERT_FALSE(scope.GetExceptionState().HadException()); |
| 37 | 37 |
| 38 WTF::Vector<KURL> request_urls = request->Urls(); | 38 WTF::Vector<KURL> request_urls = request->Urls(); |
| 39 EXPECT_EQ(static_cast<size_t>(2), request_urls.size()); | 39 EXPECT_EQ(static_cast<size_t>(2), request_urls.size()); |
| 40 EXPECT_TRUE(request_urls[0].IsValid()); | 40 EXPECT_TRUE(request_urls[0].IsValid()); |
| 41 EXPECT_EQ("https://example.com/", request_urls[0].GetString()); | 41 EXPECT_EQ("https://example.com/", request_urls[0].GetString()); |
| 42 EXPECT_TRUE(request_urls[1].IsValid()); | 42 EXPECT_TRUE(request_urls[1].IsValid()); |
| 43 EXPECT_EQ("cast://deadbeef?param=foo", request_urls[1].GetString()); | 43 EXPECT_EQ("cast://deadbeef?param=foo", request_urls[1].GetString()); |
| 44 } | 44 } |
| 45 | 45 |
| 46 TEST(PresentationRequestTest, TestMultipleUrlConstructorInvalidURLFamily) { | |
| 47 V8TestingScope scope; | |
| 48 WTF::Vector<String> urls; | |
| 49 urls.push_back("https://example.com"); | |
| 50 urls.push_back("about://deadbeef?param=foo"); | |
| 51 | |
| 52 PresentationRequest::Create(scope.GetExecutionContext(), urls, | |
| 53 scope.GetExceptionState()); | |
| 54 ASSERT_TRUE(scope.GetExceptionState().HadException()); | |
| 55 | |
| 56 EXPECT_EQ(kSyntaxError, scope.GetExceptionState().Code()); | |
| 57 } | |
| 58 | |
| 59 TEST(PresentationRequestTest, TestMultipleUrlConstructorInvalidUrl) { | 46 TEST(PresentationRequestTest, TestMultipleUrlConstructorInvalidUrl) { |
| 60 V8TestingScope scope; | 47 V8TestingScope scope; |
| 61 WTF::Vector<String> urls; | 48 WTF::Vector<String> urls; |
| 62 urls.push_back("https://example.com"); | 49 urls.push_back("https://example.com"); |
| 63 urls.push_back(""); | 50 urls.push_back(""); |
| 64 | 51 |
| 65 PresentationRequest::Create(scope.GetExecutionContext(), urls, | 52 PresentationRequest::Create(scope.GetExecutionContext(), urls, |
| 66 scope.GetExceptionState()); | 53 scope.GetExceptionState()); |
| 67 EXPECT_TRUE(scope.GetExceptionState().HadException()); | 54 EXPECT_TRUE(scope.GetExceptionState().HadException()); |
| 68 EXPECT_EQ(kSyntaxError, scope.GetExceptionState().Code()); | 55 EXPECT_EQ(kSyntaxError, scope.GetExceptionState().Code()); |
| 69 } | 56 } |
| 70 | 57 |
| 58 TEST(PresentationRequestTest, TestMixedContentNotCheckedForNonHttpFamily) { |
| 59 V8TestingScope scope; |
| 60 scope.GetExecutionContext()->GetSecurityContext().SetSecurityOrigin( |
| 61 SecurityOrigin::CreateFromString("https://example.test")); |
| 62 |
| 63 PresentationRequest* request = PresentationRequest::Create( |
| 64 scope.GetExecutionContext(), "foo://bar", scope.GetExceptionState()); |
| 65 ASSERT_FALSE(scope.GetExceptionState().HadException()); |
| 66 |
| 67 WTF::Vector<KURL> request_urls = request->Urls(); |
| 68 EXPECT_EQ(static_cast<size_t>(1), request_urls.size()); |
| 69 EXPECT_TRUE(request_urls[0].IsValid()); |
| 70 EXPECT_EQ("foo://bar", request_urls[0].GetString()); |
| 71 } |
| 72 |
| 71 TEST(PresentationRequestTest, TestSingleUrlConstructorMixedContent) { | 73 TEST(PresentationRequestTest, TestSingleUrlConstructorMixedContent) { |
| 72 V8TestingScope scope; | 74 V8TestingScope scope; |
| 73 scope.GetExecutionContext()->GetSecurityContext().SetSecurityOrigin( | 75 scope.GetExecutionContext()->GetSecurityContext().SetSecurityOrigin( |
| 74 SecurityOrigin::CreateFromString("https://example.test")); | 76 SecurityOrigin::CreateFromString("https://example.test")); |
| 75 | 77 |
| 76 PresentationRequest::Create(scope.GetExecutionContext(), "http://example.com", | 78 PresentationRequest::Create(scope.GetExecutionContext(), "http://example.com", |
| 77 scope.GetExceptionState()); | 79 scope.GetExceptionState()); |
| 78 EXPECT_TRUE(scope.GetExceptionState().HadException()); | 80 EXPECT_TRUE(scope.GetExceptionState().HadException()); |
| 79 EXPECT_EQ(kSecurityError, scope.GetExceptionState().Code()); | 81 EXPECT_EQ(kSecurityError, scope.GetExceptionState().Code()); |
| 80 } | 82 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 99 WTF::Vector<String> urls; | 101 WTF::Vector<String> urls; |
| 100 | 102 |
| 101 PresentationRequest::Create(scope.GetExecutionContext(), urls, | 103 PresentationRequest::Create(scope.GetExecutionContext(), urls, |
| 102 scope.GetExceptionState()); | 104 scope.GetExceptionState()); |
| 103 EXPECT_TRUE(scope.GetExceptionState().HadException()); | 105 EXPECT_TRUE(scope.GetExceptionState().HadException()); |
| 104 EXPECT_EQ(kNotSupportedError, scope.GetExceptionState().Code()); | 106 EXPECT_EQ(kNotSupportedError, scope.GetExceptionState().Code()); |
| 105 } | 107 } |
| 106 | 108 |
| 107 } // anonymous namespace | 109 } // anonymous namespace |
| 108 } // namespace blink | 110 } // namespace blink |
| OLD | NEW |