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

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

Issue 2804023004: Replace ASSERT with DCHECK in modules/fetch. (Closed)
Patch Set: Use DCHECK_EQ in all but a few instances Created 3 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 "modules/fetch/Request.h" 5 #include "modules/fetch/Request.h"
6 6
7 #include <memory> 7 #include <memory>
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 "bindings/core/v8/V8BindingForTesting.h" 10 #include "bindings/core/v8/V8BindingForTesting.h"
11 #include "core/dom/Document.h" 11 #include "core/dom/Document.h"
12 #include "platform/wtf/HashMap.h" 12 #include "platform/wtf/HashMap.h"
13 #include "platform/wtf/text/WTFString.h" 13 #include "platform/wtf/text/WTFString.h"
14 #include "public/platform/WebURLRequest.h" 14 #include "public/platform/WebURLRequest.h"
15 #include "public/platform/modules/serviceworker/WebServiceWorkerRequest.h" 15 #include "public/platform/modules/serviceworker/WebServiceWorkerRequest.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
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 exception_state; 23 DummyExceptionStateForTesting exception_state;
24 24
25 KURL url(kParsedURLString, "http://www.example.com/"); 25 KURL url(kParsedURLString, "http://www.example.com/");
26 Request* request = 26 Request* request =
27 Request::Create(scope.GetScriptState(), url, exception_state); 27 Request::Create(scope.GetScriptState(), url, exception_state);
28 ASSERT_FALSE(exception_state.HadException()); 28 ASSERT_FALSE(exception_state.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 exception_state; 35 DummyExceptionStateForTesting exception_state;
36 36
37 KURL url(kParsedURLString, "http://www.example.com/"); 37 KURL url(kParsedURLString, "http://www.example.com/");
38 Request* request1 = 38 Request* request1 =
39 Request::Create(scope.GetScriptState(), url, exception_state); 39 Request::Create(scope.GetScriptState(), url, exception_state);
40 ASSERT(request1); 40 DCHECK(request1);
41 41
42 Request* request2 = 42 Request* request2 =
43 Request::Create(scope.GetScriptState(), request1, exception_state); 43 Request::Create(scope.GetScriptState(), request1, exception_state);
44 ASSERT_FALSE(exception_state.HadException()); 44 ASSERT_FALSE(exception_state.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 web_request; 51 WebServiceWorkerRequest web_request;
52 52
53 const KURL url(kParsedURLString, "http://www.example.com/"); 53 const KURL url(kParsedURLString, "http://www.example.com/");
54 const String method = "GET"; 54 const String method = "GET";
55 struct { 55 struct {
(...skipping 10 matching lines...) Expand all
66 web_request.SetURL(url); 66 web_request.SetURL(url);
67 web_request.SetMethod(method); 67 web_request.SetMethod(method);
68 web_request.SetRequestContext(kContext); 68 web_request.SetRequestContext(kContext);
69 web_request.SetMode(kMode); 69 web_request.SetMode(kMode);
70 for (int i = 0; headers[i].key; ++i) 70 for (int i = 0; headers[i].key; ++i)
71 web_request.SetHeader(WebString::FromUTF8(headers[i].key), 71 web_request.SetHeader(WebString::FromUTF8(headers[i].key),
72 WebString::FromUTF8(headers[i].value)); 72 WebString::FromUTF8(headers[i].value));
73 web_request.SetReferrer(referrer, kReferrerPolicy); 73 web_request.SetReferrer(referrer, kReferrerPolicy);
74 74
75 Request* request = Request::Create(scope.GetScriptState(), web_request); 75 Request* request = Request::Create(scope.GetScriptState(), web_request);
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* request_headers = request->getHeaders(); 83 Headers* request_headers = request->getHeaders();
84 84
85 WTF::HashMap<String, String> headers_map; 85 WTF::HashMap<String, String> headers_map;
86 for (int i = 0; headers[i].key; ++i) 86 for (int i = 0; headers[i].key; ++i)
(...skipping 17 matching lines...) Expand all
104 EXPECT_EQ(WebURLRequest::kFetchRequestModeNoCORS, second_web_request.Mode()); 104 EXPECT_EQ(WebURLRequest::kFetchRequestModeNoCORS, second_web_request.Mode());
105 } 105 }
106 106
107 TEST(ServiceWorkerRequestTest, ToWebRequestStripsURLFragment) { 107 TEST(ServiceWorkerRequestTest, ToWebRequestStripsURLFragment) {
108 V8TestingScope scope; 108 V8TestingScope scope;
109 DummyExceptionStateForTesting exception_state; 109 DummyExceptionStateForTesting exception_state;
110 String url_without_fragment = "http://www.example.com/"; 110 String url_without_fragment = "http://www.example.com/";
111 String url = url_without_fragment + "#fragment"; 111 String url = url_without_fragment + "#fragment";
112 Request* request = 112 Request* request =
113 Request::Create(scope.GetScriptState(), url, exception_state); 113 Request::Create(scope.GetScriptState(), url, exception_state);
114 ASSERT(request); 114 DCHECK(request);
115 115
116 WebServiceWorkerRequest web_request; 116 WebServiceWorkerRequest web_request;
117 request->PopulateWebServiceWorkerRequest(web_request); 117 request->PopulateWebServiceWorkerRequest(web_request);
118 EXPECT_EQ(url_without_fragment, KURL(web_request.Url())); 118 EXPECT_EQ(url_without_fragment, KURL(web_request.Url()));
119 } 119 }
120 120
121 } // namespace 121 } // namespace
122 } // namespace blink 122 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/fetch/Request.cpp ('k') | third_party/WebKit/Source/modules/fetch/Response.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698