OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/compiler_specific.h" | 5 #include "base/compiler_specific.h" |
6 #include "content/public/test/render_view_test.h" | 6 #include "content/public/test/render_view_test.h" |
7 #include "content/renderer/pepper/url_request_info_util.h" | 7 #include "content/renderer/pepper/url_request_info_util.h" |
8 #include "ppapi/proxy/connection.h" | 8 #include "ppapi/proxy/connection.h" |
9 #include "ppapi/proxy/url_request_info_resource.h" | 9 #include "ppapi/proxy/url_request_info_resource.h" |
10 #include "ppapi/shared_impl/test_globals.h" | 10 #include "ppapi/shared_impl/test_globals.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 URLRequestInfoData()); | 69 URLRequestInfoData()); |
70 } | 70 } |
71 | 71 |
72 virtual void TearDown() OVERRIDE { | 72 virtual void TearDown() OVERRIDE { |
73 test_globals_.GetResourceTracker()->DidDeleteInstance(pp_instance_); | 73 test_globals_.GetResourceTracker()->DidDeleteInstance(pp_instance_); |
74 RenderViewTest::TearDown(); | 74 RenderViewTest::TearDown(); |
75 } | 75 } |
76 | 76 |
77 bool GetDownloadToFile() { | 77 bool GetDownloadToFile() { |
78 WebURLRequest web_request; | 78 WebURLRequest web_request; |
79 URLRequestInfoData data = info_->GetData(); | 79 if (!CreateWebURLRequestInternal(&web_request)) |
80 if (!CreateWebURLRequest(&data, GetMainFrame(), &web_request)) | |
81 return false; | 80 return false; |
| 81 |
82 return web_request.downloadToFile(); | 82 return web_request.downloadToFile(); |
83 } | 83 } |
84 | 84 |
85 WebCString GetURL() { | 85 WebCString GetURL() { |
86 WebURLRequest web_request; | 86 WebURLRequest web_request; |
87 URLRequestInfoData data = info_->GetData(); | 87 if (!CreateWebURLRequestInternal(&web_request)) |
88 if (!CreateWebURLRequest(&data, GetMainFrame(), &web_request)) | |
89 return WebCString(); | 88 return WebCString(); |
| 89 |
90 return web_request.url().spec(); | 90 return web_request.url().spec(); |
91 } | 91 } |
92 | 92 |
93 WebString GetMethod() { | 93 WebString GetMethod() { |
94 WebURLRequest web_request; | 94 WebURLRequest web_request; |
95 URLRequestInfoData data = info_->GetData(); | 95 if (!CreateWebURLRequestInternal(&web_request)) |
96 if (!CreateWebURLRequest(&data, GetMainFrame(), &web_request)) | |
97 return WebString(); | 96 return WebString(); |
| 97 |
98 return web_request.httpMethod(); | 98 return web_request.httpMethod(); |
99 } | 99 } |
100 | 100 |
101 WebString GetHeaderValue(const char* field) { | 101 WebString GetHeaderValue(const char* field) { |
102 WebURLRequest web_request; | 102 WebURLRequest web_request; |
103 URLRequestInfoData data = info_->GetData(); | 103 if (!CreateWebURLRequestInternal(&web_request)) |
104 if (!CreateWebURLRequest(&data, GetMainFrame(), &web_request)) | |
105 return WebString(); | 104 return WebString(); |
| 105 |
106 return web_request.httpHeaderField(WebString::fromUTF8(field)); | 106 return web_request.httpHeaderField(WebString::fromUTF8(field)); |
107 } | 107 } |
108 | 108 |
109 bool SetBooleanProperty(PP_URLRequestProperty prop, bool b) { | 109 bool SetBooleanProperty(PP_URLRequestProperty prop, bool b) { |
110 return info_->SetBooleanProperty(prop, b); | 110 return info_->SetBooleanProperty(prop, b); |
111 } | 111 } |
| 112 |
112 bool SetStringProperty(PP_URLRequestProperty prop, const std::string& s) { | 113 bool SetStringProperty(PP_URLRequestProperty prop, const std::string& s) { |
113 return info_->SetStringProperty(prop, s); | 114 return info_->SetStringProperty(prop, s); |
114 } | 115 } |
115 | 116 |
| 117 protected: |
| 118 bool CreateWebURLRequestInternal(WebURLRequest* web_request) { |
| 119 URLRequestInfoData data = info_->GetData(); |
| 120 return CreateWebURLRequest( |
| 121 &data, WebURLRequest::TargetIsUnspecified, GetMainFrame(), web_request); |
| 122 } |
| 123 |
116 PP_Instance pp_instance_; | 124 PP_Instance pp_instance_; |
117 | 125 |
118 // Needs to be alive for resource tracking to work. | 126 // Needs to be alive for resource tracking to work. |
119 ppapi::TestGlobals test_globals_; | 127 ppapi::TestGlobals test_globals_; |
120 | 128 |
121 scoped_refptr<URLRequestInfoResource> info_; | 129 scoped_refptr<URLRequestInfoResource> info_; |
122 }; | 130 }; |
123 | 131 |
124 TEST_F(URLRequestInfoTest, GetInterface) { | 132 TEST_F(URLRequestInfoTest, GetInterface) { |
125 const PPB_URLRequestInfo* request_info = | 133 const PPB_URLRequestInfo* request_info = |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 PP_URLREQUESTPROPERTY_HEADERS, "foo: bar\nbar: baz")); | 254 PP_URLREQUESTPROPERTY_HEADERS, "foo: bar\nbar: baz")); |
247 EXPECT_TRUE(IsExpected( | 255 EXPECT_TRUE(IsExpected( |
248 GetHeaderValue("foo"), "bar")); | 256 GetHeaderValue("foo"), "bar")); |
249 EXPECT_TRUE(IsExpected( | 257 EXPECT_TRUE(IsExpected( |
250 GetHeaderValue("bar"), "baz")); | 258 GetHeaderValue("bar"), "baz")); |
251 } | 259 } |
252 | 260 |
253 // TODO(bbudge) Unit tests for AppendDataToBody, AppendFileToBody. | 261 // TODO(bbudge) Unit tests for AppendDataToBody, AppendFileToBody. |
254 | 262 |
255 } // namespace content | 263 } // namespace content |
OLD | NEW |