| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/fetch/Request.h" | 5 #include "modules/fetch/Request.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "bindings/core/v8/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
| 9 #include "bindings/core/v8/V8BindingForTesting.h" | 9 #include "bindings/core/v8/V8BindingForTesting.h" |
| 10 #include "core/dom/Document.h" | 10 #include "core/dom/Document.h" |
| 11 #include "public/platform/WebURLRequest.h" | 11 #include "public/platform/WebURLRequest.h" |
| 12 #include "public/platform/modules/serviceworker/WebServiceWorkerRequest.h" | 12 #include "public/platform/modules/serviceworker/WebServiceWorkerRequest.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "wtf/HashMap.h" | 14 #include "wtf/HashMap.h" |
| 15 #include "wtf/text/WTFString.h" | 15 #include "wtf/text/WTFString.h" |
| 16 #include <memory> | 16 #include <memory> |
| 17 | 17 |
| 18 namespace blink { | 18 namespace blink { |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 TEST(ServiceWorkerRequestTest, FromString) { | 21 TEST(ServiceWorkerRequestTest, FromString) { |
| 22 V8TestingScope scope; | 22 V8TestingScope scope; |
| 23 DummyExceptionStateForTesting exceptionState; | 23 DummyExceptionStateForTesting exceptionState; |
| 24 | 24 |
| 25 KURL url(ParsedURLString, "http://www.example.com/"); | 25 KURL url(ParsedURLString, "http://www.example.com/"); |
| 26 Request* request = | 26 Request* request = |
| 27 Request::create(scope.getScriptState(), url, exceptionState); | 27 Request::create(scope.getScriptState(), url, exceptionState); |
| 28 ASSERT_FALSE(exceptionState.hadException()); | 28 ASSERT_FALSE(exceptionState.hadException()); |
| 29 ASSERT(request); | 29 DCHECK(request); |
| 30 EXPECT_EQ(url, request->url()); | 30 EXPECT_EQ(url, request->url()); |
| 31 } | 31 } |
| 32 | 32 |
| 33 TEST(ServiceWorkerRequestTest, FromRequest) { | 33 TEST(ServiceWorkerRequestTest, FromRequest) { |
| 34 V8TestingScope scope; | 34 V8TestingScope scope; |
| 35 DummyExceptionStateForTesting exceptionState; | 35 DummyExceptionStateForTesting exceptionState; |
| 36 | 36 |
| 37 KURL url(ParsedURLString, "http://www.example.com/"); | 37 KURL url(ParsedURLString, "http://www.example.com/"); |
| 38 Request* request1 = | 38 Request* request1 = |
| 39 Request::create(scope.getScriptState(), url, exceptionState); | 39 Request::create(scope.getScriptState(), url, exceptionState); |
| 40 ASSERT(request1); | 40 DCHECK(request1); |
| 41 | 41 |
| 42 Request* request2 = | 42 Request* request2 = |
| 43 Request::create(scope.getScriptState(), request1, exceptionState); | 43 Request::create(scope.getScriptState(), request1, exceptionState); |
| 44 ASSERT_FALSE(exceptionState.hadException()); | 44 ASSERT_FALSE(exceptionState.hadException()); |
| 45 ASSERT(request2); | 45 DCHECK(request2); |
| 46 EXPECT_EQ(url, request2->url()); | 46 EXPECT_EQ(url, request2->url()); |
| 47 } | 47 } |
| 48 | 48 |
| 49 TEST(ServiceWorkerRequestTest, FromAndToWebRequest) { | 49 TEST(ServiceWorkerRequestTest, FromAndToWebRequest) { |
| 50 V8TestingScope scope; | 50 V8TestingScope scope; |
| 51 WebServiceWorkerRequest webRequest; | 51 WebServiceWorkerRequest webRequest; |
| 52 | 52 |
| 53 const KURL url(ParsedURLString, "http://www.example.com/"); | 53 const KURL url(ParsedURLString, "http://www.example.com/"); |
| 54 const String method = "GET"; | 54 const String method = "GET"; |
| 55 struct { | 55 struct { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 66 webRequest.setURL(url); | 66 webRequest.setURL(url); |
| 67 webRequest.setMethod(method); | 67 webRequest.setMethod(method); |
| 68 webRequest.setRequestContext(context); | 68 webRequest.setRequestContext(context); |
| 69 webRequest.setMode(mode); | 69 webRequest.setMode(mode); |
| 70 for (int i = 0; headers[i].key; ++i) | 70 for (int i = 0; headers[i].key; ++i) |
| 71 webRequest.setHeader(WebString::fromUTF8(headers[i].key), | 71 webRequest.setHeader(WebString::fromUTF8(headers[i].key), |
| 72 WebString::fromUTF8(headers[i].value)); | 72 WebString::fromUTF8(headers[i].value)); |
| 73 webRequest.setReferrer(referrer, referrerPolicy); | 73 webRequest.setReferrer(referrer, referrerPolicy); |
| 74 | 74 |
| 75 Request* request = Request::create(scope.getScriptState(), webRequest); | 75 Request* request = Request::create(scope.getScriptState(), webRequest); |
| 76 ASSERT(request); | 76 DCHECK(request); |
| 77 EXPECT_EQ(url, request->url()); | 77 EXPECT_EQ(url, request->url()); |
| 78 EXPECT_EQ(method, request->method()); | 78 EXPECT_EQ(method, request->method()); |
| 79 EXPECT_EQ("audio", request->context()); | 79 EXPECT_EQ("audio", request->context()); |
| 80 EXPECT_EQ(referrer, request->referrer()); | 80 EXPECT_EQ(referrer, request->referrer()); |
| 81 EXPECT_EQ("navigate", request->mode()); | 81 EXPECT_EQ("navigate", request->mode()); |
| 82 | 82 |
| 83 Headers* requestHeaders = request->getHeaders(); | 83 Headers* requestHeaders = request->getHeaders(); |
| 84 | 84 |
| 85 WTF::HashMap<String, String> headersMap; | 85 WTF::HashMap<String, String> headersMap; |
| 86 for (int i = 0; headers[i].key; ++i) | 86 for (int i = 0; headers[i].key; ++i) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 104 EXPECT_EQ(WebURLRequest::FetchRequestModeNoCORS, secondWebRequest.mode()); | 104 EXPECT_EQ(WebURLRequest::FetchRequestModeNoCORS, secondWebRequest.mode()); |
| 105 } | 105 } |
| 106 | 106 |
| 107 TEST(ServiceWorkerRequestTest, ToWebRequestStripsURLFragment) { | 107 TEST(ServiceWorkerRequestTest, ToWebRequestStripsURLFragment) { |
| 108 V8TestingScope scope; | 108 V8TestingScope scope; |
| 109 DummyExceptionStateForTesting exceptionState; | 109 DummyExceptionStateForTesting exceptionState; |
| 110 String urlWithoutFragment = "http://www.example.com/"; | 110 String urlWithoutFragment = "http://www.example.com/"; |
| 111 String url = urlWithoutFragment + "#fragment"; | 111 String url = urlWithoutFragment + "#fragment"; |
| 112 Request* request = | 112 Request* request = |
| 113 Request::create(scope.getScriptState(), url, exceptionState); | 113 Request::create(scope.getScriptState(), url, exceptionState); |
| 114 ASSERT(request); | 114 DCHECK(request); |
| 115 | 115 |
| 116 WebServiceWorkerRequest webRequest; | 116 WebServiceWorkerRequest webRequest; |
| 117 request->populateWebServiceWorkerRequest(webRequest); | 117 request->populateWebServiceWorkerRequest(webRequest); |
| 118 EXPECT_EQ(urlWithoutFragment, KURL(webRequest.url())); | 118 EXPECT_EQ(urlWithoutFragment, KURL(webRequest.url())); |
| 119 } | 119 } |
| 120 | 120 |
| 121 } // namespace | 121 } // namespace |
| 122 } // namespace blink | 122 } // namespace blink |
| OLD | NEW |