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

Side by Side Diff: Source/modules/fetch/RequestTest.cpp

Issue 1060033002: Implement Request.context for Fetch API (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 8 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 unified diff | Download patch
OLDNEW
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 "config.h" 5 #include "config.h"
6 #include "modules/fetch/Request.h" 6 #include "modules/fetch/Request.h"
7 7
8 #include "bindings/core/v8/ExceptionState.h" 8 #include "bindings/core/v8/ExceptionState.h"
9 #include "bindings/core/v8/ScriptState.h" 9 #include "bindings/core/v8/ScriptState.h"
10 #include "core/dom/Document.h" 10 #include "core/dom/Document.h"
11 #include "core/frame/Frame.h" 11 #include "core/frame/Frame.h"
12 #include "core/testing/DummyPageHolder.h" 12 #include "core/testing/DummyPageHolder.h"
13 #include "public/platform/WebServiceWorkerRequest.h" 13 #include "public/platform/WebServiceWorkerRequest.h"
14 #include "public/platform/WebURLRequest.h"
14 #include "wtf/HashMap.h" 15 #include "wtf/HashMap.h"
15 #include "wtf/text/WTFString.h" 16 #include "wtf/text/WTFString.h"
16 #include <gtest/gtest.h> 17 #include <gtest/gtest.h>
17 18
18 namespace blink { 19 namespace blink {
19 namespace { 20 namespace {
20 21
21 class ServiceWorkerRequestTest : public ::testing::Test { 22 class ServiceWorkerRequestTest : public ::testing::Test {
22 public: 23 public:
23 ServiceWorkerRequestTest() 24 ServiceWorkerRequestTest()
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 WebServiceWorkerRequest webRequest; 61 WebServiceWorkerRequest webRequest;
61 62
62 const KURL url(ParsedURLString, "http://www.example.com/"); 63 const KURL url(ParsedURLString, "http://www.example.com/");
63 const String method = "GET"; 64 const String method = "GET";
64 struct { 65 struct {
65 const char* key; 66 const char* key;
66 const char* value; 67 const char* value;
67 } headers[] = { {"X-Foo", "bar"}, {"X-Quux", "foop"}, {0, 0} }; 68 } headers[] = { {"X-Foo", "bar"}, {"X-Quux", "foop"}, {0, 0} };
68 const String referrer = "http://www.referrer.com/"; 69 const String referrer = "http://www.referrer.com/";
69 const WebReferrerPolicy referrerPolicy = WebReferrerPolicyAlways; 70 const WebReferrerPolicy referrerPolicy = WebReferrerPolicyAlways;
71 const WebURLRequest::RequestContext context = WebURLRequest::RequestContextA udio;
70 72
71 webRequest.setURL(url); 73 webRequest.setURL(url);
72 webRequest.setMethod(method); 74 webRequest.setMethod(method);
75 webRequest.setRequestContext(context);
73 for (int i = 0; headers[i].key; ++i) 76 for (int i = 0; headers[i].key; ++i)
74 webRequest.setHeader(WebString::fromUTF8(headers[i].key), WebString::fro mUTF8(headers[i].value)); 77 webRequest.setHeader(WebString::fromUTF8(headers[i].key), WebString::fro mUTF8(headers[i].value));
75 webRequest.setReferrer(referrer, referrerPolicy); 78 webRequest.setReferrer(referrer, referrerPolicy);
76 79
77 Request* request = Request::create(executionContext(), webRequest); 80 Request* request = Request::create(executionContext(), webRequest);
78 ASSERT(request); 81 ASSERT(request);
79 EXPECT_EQ(url, request->url()); 82 EXPECT_EQ(url, request->url());
80 EXPECT_EQ(method, request->method()); 83 EXPECT_EQ(method, request->method());
84 EXPECT_EQ("audio", request->context());
81 EXPECT_EQ(referrer, request->referrer()); 85 EXPECT_EQ(referrer, request->referrer());
82 86
83 Headers* requestHeaders = request->headers(); 87 Headers* requestHeaders = request->headers();
84 88
85 WTF::HashMap<String, String> headersMap; 89 WTF::HashMap<String, String> headersMap;
86 for (int i = 0; headers[i].key; ++i) 90 for (int i = 0; headers[i].key; ++i)
87 headersMap.add(headers[i].key, headers[i].value); 91 headersMap.add(headers[i].key, headers[i].value);
88 EXPECT_EQ(headersMap.size(), requestHeaders->headerList()->size()); 92 EXPECT_EQ(headersMap.size(), requestHeaders->headerList()->size());
89 for (WTF::HashMap<String, String>::iterator iter = headersMap.begin(); iter != headersMap.end(); ++iter) { 93 for (WTF::HashMap<String, String>::iterator iter = headersMap.begin(); iter != headersMap.end(); ++iter) {
90 TrackExceptionState exceptionState; 94 TrackExceptionState exceptionState;
91 EXPECT_EQ(iter->value, requestHeaders->get(iter->key, exceptionState)); 95 EXPECT_EQ(iter->value, requestHeaders->get(iter->key, exceptionState));
92 EXPECT_FALSE(exceptionState.hadException()); 96 EXPECT_FALSE(exceptionState.hadException());
93 } 97 }
94 98
95 WebServiceWorkerRequest secondWebRequest; 99 WebServiceWorkerRequest secondWebRequest;
96 request->populateWebServiceWorkerRequest(secondWebRequest); 100 request->populateWebServiceWorkerRequest(secondWebRequest);
97 EXPECT_EQ(url, KURL(secondWebRequest.url())); 101 EXPECT_EQ(url, KURL(secondWebRequest.url()));
98 EXPECT_EQ(method, String(secondWebRequest.method())); 102 EXPECT_EQ(method, String(secondWebRequest.method()));
103 EXPECT_EQ(context, secondWebRequest.requestContext());
99 EXPECT_EQ(referrer, KURL(secondWebRequest.referrerUrl())); 104 EXPECT_EQ(referrer, KURL(secondWebRequest.referrerUrl()));
100 EXPECT_EQ(referrerPolicy, secondWebRequest.referrerPolicy()); 105 EXPECT_EQ(referrerPolicy, secondWebRequest.referrerPolicy());
101 EXPECT_EQ(webRequest.headers(), secondWebRequest.headers()); 106 EXPECT_EQ(webRequest.headers(), secondWebRequest.headers());
102 } 107 }
103 108
104 TEST_F(ServiceWorkerRequestTest, ToWebRequestStripsURLFragment) 109 TEST_F(ServiceWorkerRequestTest, ToWebRequestStripsURLFragment)
105 { 110 {
106 TrackExceptionState exceptionState; 111 TrackExceptionState exceptionState;
107 String urlWithoutFragment = "http://www.example.com/"; 112 String urlWithoutFragment = "http://www.example.com/";
108 String url = urlWithoutFragment + "#fragment"; 113 String url = urlWithoutFragment + "#fragment";
109 Request* request = Request::create(executionContext(), url, exceptionState); 114 Request* request = Request::create(executionContext(), url, exceptionState);
110 ASSERT(request); 115 ASSERT(request);
111 116
112 WebServiceWorkerRequest webRequest; 117 WebServiceWorkerRequest webRequest;
113 request->populateWebServiceWorkerRequest(webRequest); 118 request->populateWebServiceWorkerRequest(webRequest);
114 EXPECT_EQ(urlWithoutFragment, KURL(webRequest.url())); 119 EXPECT_EQ(urlWithoutFragment, KURL(webRequest.url()));
115 } 120 }
116 121
117 } // namespace 122 } // namespace
118 } // namespace blink 123 } // namespace blink
OLDNEW
« Source/modules/fetch/Request.cpp ('K') | « Source/modules/fetch/Request.idl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698