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 "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
10 #include "core/frame/Frame.h" | 10 #include "core/frame/Frame.h" |
11 #include "core/testing/DummyPageHolder.h" | 11 #include "core/testing/DummyPageHolder.h" |
12 #include "public/platform/WebURLRequest.h" | 12 #include "public/platform/WebURLRequest.h" |
13 #include "public/platform/modules/serviceworker/WebServiceWorkerRequest.h" | 13 #include "public/platform/modules/serviceworker/WebServiceWorkerRequest.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "wtf/HashMap.h" | 15 #include "wtf/HashMap.h" |
16 #include "wtf/text/WTFString.h" | 16 #include "wtf/text/WTFString.h" |
17 #include <memory> | 17 #include <memory> |
18 | 18 |
19 namespace blink { | 19 namespace blink { |
20 namespace { | 20 namespace { |
21 | 21 |
22 class ServiceWorkerRequestTest : public ::testing::Test { | 22 class ServiceWorkerRequestTest : public ::testing::Test { |
23 public: | 23 public: |
24 ServiceWorkerRequestTest() | 24 ServiceWorkerRequestTest() |
25 : m_page(DummyPageHolder::create(IntSize(1, 1))) { } | 25 : m_page(DummyPageHolder::create(IntSize(1, 1))) { } |
haraken
2016/07/14 02:26:08
Nit: It would be better to use V8TestingScope. (Yo
yhirano
2016/07/14 04:45:32
Done.
| |
26 | 26 |
27 ScriptState* getScriptState() { return ScriptState::forMainWorld(m_page->doc ument().frame()); } | 27 ScriptState* getScriptState() { return ScriptState::forMainWorld(m_page->doc ument().frame()); } |
28 ExecutionContext* getExecutionContext() { return getScriptState()->getExecut ionContext(); } | 28 ExecutionContext* getExecutionContext() { return getScriptState()->getExecut ionContext(); } |
29 | 29 |
30 private: | 30 private: |
31 std::unique_ptr<DummyPageHolder> m_page; | 31 std::unique_ptr<DummyPageHolder> m_page; |
32 }; | 32 }; |
33 | 33 |
34 TEST_F(ServiceWorkerRequestTest, FromString) | 34 TEST_F(ServiceWorkerRequestTest, FromString) |
35 { | 35 { |
36 ScriptState::Scope scope(getScriptState()); | |
36 TrackExceptionState exceptionState; | 37 TrackExceptionState exceptionState; |
37 | 38 |
38 KURL url(ParsedURLString, "http://www.example.com/"); | 39 KURL url(ParsedURLString, "http://www.example.com/"); |
39 Request* request = Request::create(getScriptState(), url, exceptionState); | 40 Request* request = Request::create(getScriptState(), url, exceptionState); |
40 ASSERT_FALSE(exceptionState.hadException()); | 41 ASSERT_FALSE(exceptionState.hadException()); |
41 ASSERT(request); | 42 ASSERT(request); |
42 EXPECT_EQ(url, request->url()); | 43 EXPECT_EQ(url, request->url()); |
43 } | 44 } |
44 | 45 |
45 TEST_F(ServiceWorkerRequestTest, FromRequest) | 46 TEST_F(ServiceWorkerRequestTest, FromRequest) |
46 { | 47 { |
48 ScriptState::Scope scope(getScriptState()); | |
47 TrackExceptionState exceptionState; | 49 TrackExceptionState exceptionState; |
48 | 50 |
49 KURL url(ParsedURLString, "http://www.example.com/"); | 51 KURL url(ParsedURLString, "http://www.example.com/"); |
50 Request* request1 = Request::create(getScriptState(), url, exceptionState); | 52 Request* request1 = Request::create(getScriptState(), url, exceptionState); |
51 ASSERT(request1); | 53 ASSERT(request1); |
52 | 54 |
53 Request* request2 = Request::create(getScriptState(), request1, exceptionSta te); | 55 Request* request2 = Request::create(getScriptState(), request1, exceptionSta te); |
54 ASSERT_FALSE(exceptionState.hadException()); | 56 ASSERT_FALSE(exceptionState.hadException()); |
55 ASSERT(request2); | 57 ASSERT(request2); |
56 EXPECT_EQ(url, request2->url()); | 58 EXPECT_EQ(url, request2->url()); |
57 } | 59 } |
58 | 60 |
59 TEST_F(ServiceWorkerRequestTest, FromAndToWebRequest) | 61 TEST_F(ServiceWorkerRequestTest, FromAndToWebRequest) |
60 { | 62 { |
63 ScriptState::Scope scope(getScriptState()); | |
61 WebServiceWorkerRequest webRequest; | 64 WebServiceWorkerRequest webRequest; |
62 | 65 |
63 const KURL url(ParsedURLString, "http://www.example.com/"); | 66 const KURL url(ParsedURLString, "http://www.example.com/"); |
64 const String method = "GET"; | 67 const String method = "GET"; |
65 struct { | 68 struct { |
66 const char* key; | 69 const char* key; |
67 const char* value; | 70 const char* value; |
68 } headers[] = { {"X-Foo", "bar"}, {"X-Quux", "foop"}, {0, 0} }; | 71 } headers[] = { {"X-Foo", "bar"}, {"X-Quux", "foop"}, {0, 0} }; |
69 const String referrer = "http://www.referrer.com/"; | 72 const String referrer = "http://www.referrer.com/"; |
70 const WebReferrerPolicy referrerPolicy = WebReferrerPolicyAlways; | 73 const WebReferrerPolicy referrerPolicy = WebReferrerPolicyAlways; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 EXPECT_EQ(method, String(secondWebRequest.method())); | 108 EXPECT_EQ(method, String(secondWebRequest.method())); |
106 EXPECT_EQ(context, secondWebRequest.requestContext()); | 109 EXPECT_EQ(context, secondWebRequest.requestContext()); |
107 EXPECT_EQ(referrer, KURL(secondWebRequest.referrerUrl())); | 110 EXPECT_EQ(referrer, KURL(secondWebRequest.referrerUrl())); |
108 EXPECT_EQ(WebReferrerPolicyAlways, secondWebRequest.referrerPolicy()); | 111 EXPECT_EQ(WebReferrerPolicyAlways, secondWebRequest.referrerPolicy()); |
109 EXPECT_EQ(webRequest.headers(), secondWebRequest.headers()); | 112 EXPECT_EQ(webRequest.headers(), secondWebRequest.headers()); |
110 EXPECT_EQ(WebURLRequest::FetchRequestModeNoCORS, secondWebRequest.mode()); | 113 EXPECT_EQ(WebURLRequest::FetchRequestModeNoCORS, secondWebRequest.mode()); |
111 } | 114 } |
112 | 115 |
113 TEST_F(ServiceWorkerRequestTest, ToWebRequestStripsURLFragment) | 116 TEST_F(ServiceWorkerRequestTest, ToWebRequestStripsURLFragment) |
114 { | 117 { |
118 ScriptState::Scope scope(getScriptState()); | |
115 TrackExceptionState exceptionState; | 119 TrackExceptionState exceptionState; |
116 String urlWithoutFragment = "http://www.example.com/"; | 120 String urlWithoutFragment = "http://www.example.com/"; |
117 String url = urlWithoutFragment + "#fragment"; | 121 String url = urlWithoutFragment + "#fragment"; |
118 Request* request = Request::create(getScriptState(), url, exceptionState); | 122 Request* request = Request::create(getScriptState(), url, exceptionState); |
119 ASSERT(request); | 123 ASSERT(request); |
120 | 124 |
121 WebServiceWorkerRequest webRequest; | 125 WebServiceWorkerRequest webRequest; |
122 request->populateWebServiceWorkerRequest(webRequest); | 126 request->populateWebServiceWorkerRequest(webRequest); |
123 EXPECT_EQ(urlWithoutFragment, KURL(webRequest.url())); | 127 EXPECT_EQ(urlWithoutFragment, KURL(webRequest.url())); |
124 } | 128 } |
125 | 129 |
126 } // namespace | 130 } // namespace |
127 } // namespace blink | 131 } // namespace blink |
OLD | NEW |