OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <atlbase.h> | 5 #include <atlbase.h> |
6 #include <atlcom.h> | 6 #include <atlcom.h> |
7 | 7 |
8 #include "app/win/scoped_com_initializer.h" | 8 #include "base/win/scoped_com_initializer.h" |
9 #include "chrome/common/automation_messages.h" | 9 #include "chrome/common/automation_messages.h" |
10 #include "chrome_frame/test/chrome_frame_test_utils.h" | 10 #include "chrome_frame/test/chrome_frame_test_utils.h" |
11 #include "chrome_frame/test/test_server.h" | 11 #include "chrome_frame/test/test_server.h" |
12 #include "chrome_frame/test/test_with_web_server.h" | 12 #include "chrome_frame/test/test_with_web_server.h" |
13 #include "chrome_frame/urlmon_url_request.h" | 13 #include "chrome_frame/urlmon_url_request.h" |
14 #include "chrome_frame/urlmon_url_request_private.h" | 14 #include "chrome_frame/urlmon_url_request_private.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gmock_mutant.h" | 16 #include "testing/gmock_mutant.h" |
16 #include "testing/gmock/include/gmock/gmock.h" | |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
19 using testing::CreateFunctor; | 19 using testing::CreateFunctor; |
20 | 20 |
21 const int kChromeFrameLongNavigationTimeoutInSeconds = 10; | 21 const int kChromeFrameLongNavigationTimeoutInSeconds = 10; |
22 | 22 |
23 static void AppendToStream(IStream* s, void* buffer, ULONG cb) { | 23 static void AppendToStream(IStream* s, void* buffer, ULONG cb) { |
24 ULONG bytes_written; | 24 ULONG bytes_written; |
25 LARGE_INTEGER current_pos; | 25 LARGE_INTEGER current_pos; |
26 LARGE_INTEGER zero = {0}; | 26 LARGE_INTEGER zero = {0}; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 67 |
68 // Simplest UrlmonUrlRequest. Retrieve a file from local web server. | 68 // Simplest UrlmonUrlRequest. Retrieve a file from local web server. |
69 TEST(UrlmonUrlRequestTest, Simple1) { | 69 TEST(UrlmonUrlRequestTest, Simple1) { |
70 MockUrlDelegate mock; | 70 MockUrlDelegate mock; |
71 chrome_frame_test::TimedMsgLoop loop; | 71 chrome_frame_test::TimedMsgLoop loop; |
72 | 72 |
73 testing::StrictMock<MockWebServer> mock_server(1337, L"127.0.0.1", | 73 testing::StrictMock<MockWebServer> mock_server(1337, L"127.0.0.1", |
74 chrome_frame_test::GetTestDataFolder()); | 74 chrome_frame_test::GetTestDataFolder()); |
75 mock_server.ExpectAndServeAnyRequests(CFInvocation(CFInvocation::NONE)); | 75 mock_server.ExpectAndServeAnyRequests(CFInvocation(CFInvocation::NONE)); |
76 | 76 |
77 app::win::ScopedCOMInitializer init_com; | 77 base::win::ScopedCOMInitializer init_com; |
78 CComObjectStackEx<UrlmonUrlRequest> request; | 78 CComObjectStackEx<UrlmonUrlRequest> request; |
79 | 79 |
80 request.AddRef(); | 80 request.AddRef(); |
81 request.Initialize(&mock, 1, // request_id | 81 request.Initialize(&mock, 1, // request_id |
82 WideToUTF8(mock_server.Resolve(L"chrome_frame_window_open.html")), | 82 WideToUTF8(mock_server.Resolve(L"chrome_frame_window_open.html")), |
83 "get", | 83 "get", |
84 "", // referrer | 84 "", // referrer |
85 "", // extra request | 85 "", // extra request |
86 NULL, // upload data | 86 NULL, // upload data |
87 ResourceType::MAIN_FRAME, // resource type | 87 ResourceType::MAIN_FRAME, // resource type |
(...skipping 28 matching lines...) Expand all Loading... |
116 // from the server. | 116 // from the server. |
117 TEST(UrlmonUrlRequestTest, Head) { | 117 TEST(UrlmonUrlRequestTest, Head) { |
118 MockUrlDelegate mock; | 118 MockUrlDelegate mock; |
119 chrome_frame_test::TimedMsgLoop loop; | 119 chrome_frame_test::TimedMsgLoop loop; |
120 // Use SimpleWebServer instead of the python server to support HEAD | 120 // Use SimpleWebServer instead of the python server to support HEAD |
121 // requests. | 121 // requests. |
122 test_server::SimpleWebServer server(13337); | 122 test_server::SimpleWebServer server(13337); |
123 test_server::SimpleResponse head_response("/head", ""); | 123 test_server::SimpleResponse head_response("/head", ""); |
124 server.AddResponse(&head_response); | 124 server.AddResponse(&head_response); |
125 | 125 |
126 app::win::ScopedCOMInitializer init_com; | 126 base::win::ScopedCOMInitializer init_com; |
127 CComObjectStackEx<UrlmonUrlRequest> request; | 127 CComObjectStackEx<UrlmonUrlRequest> request; |
128 | 128 |
129 request.AddRef(); | 129 request.AddRef(); |
130 request.Initialize(&mock, 1, // request_id | 130 request.Initialize(&mock, 1, // request_id |
131 "http://localhost:13337/head", | 131 "http://localhost:13337/head", |
132 "head", | 132 "head", |
133 "", // referrer | 133 "", // referrer |
134 "", // extra request | 134 "", // extra request |
135 NULL, // upload data | 135 NULL, // upload data |
136 ResourceType::MAIN_FRAME, // resource type | 136 ResourceType::MAIN_FRAME, // resource type |
(...skipping 16 matching lines...) Expand all Loading... |
153 .WillOnce(QUIT_LOOP_SOON(loop, 2)); | 153 .WillOnce(QUIT_LOOP_SOON(loop, 2)); |
154 | 154 |
155 request.Start(); | 155 request.Start(); |
156 loop.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); | 156 loop.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); |
157 request.Release(); | 157 request.Release(); |
158 } | 158 } |
159 | 159 |
160 TEST(UrlmonUrlRequestTest, UnreachableUrl) { | 160 TEST(UrlmonUrlRequestTest, UnreachableUrl) { |
161 MockUrlDelegate mock; | 161 MockUrlDelegate mock; |
162 chrome_frame_test::TimedMsgLoop loop; | 162 chrome_frame_test::TimedMsgLoop loop; |
163 app::win::ScopedCOMInitializer init_com; | 163 base::win::ScopedCOMInitializer init_com; |
164 CComObjectStackEx<UrlmonUrlRequest> request; | 164 CComObjectStackEx<UrlmonUrlRequest> request; |
165 | 165 |
166 testing::StrictMock<MockWebServer> mock_server(1337, L"127.0.0.1", | 166 testing::StrictMock<MockWebServer> mock_server(1337, L"127.0.0.1", |
167 chrome_frame_test::GetTestDataFolder()); | 167 chrome_frame_test::GetTestDataFolder()); |
168 mock_server.ExpectAndServeAnyRequests(CFInvocation(CFInvocation::NONE)); | 168 mock_server.ExpectAndServeAnyRequests(CFInvocation(CFInvocation::NONE)); |
169 | 169 |
170 GURL unreachable(WideToUTF8(mock_server.Resolve( | 170 GURL unreachable(WideToUTF8(mock_server.Resolve( |
171 L"non_existing.html"))); | 171 L"non_existing.html"))); |
172 | 172 |
173 request.AddRef(); | 173 request.AddRef(); |
(...skipping 25 matching lines...) Expand all Loading... |
199 } | 199 } |
200 | 200 |
201 TEST(UrlmonUrlRequestTest, ZeroLengthResponse) { | 201 TEST(UrlmonUrlRequestTest, ZeroLengthResponse) { |
202 MockUrlDelegate mock; | 202 MockUrlDelegate mock; |
203 chrome_frame_test::TimedMsgLoop loop; | 203 chrome_frame_test::TimedMsgLoop loop; |
204 | 204 |
205 testing::StrictMock<MockWebServer> mock_server(1337, L"127.0.0.1", | 205 testing::StrictMock<MockWebServer> mock_server(1337, L"127.0.0.1", |
206 chrome_frame_test::GetTestDataFolder()); | 206 chrome_frame_test::GetTestDataFolder()); |
207 mock_server.ExpectAndServeAnyRequests(CFInvocation(CFInvocation::NONE)); | 207 mock_server.ExpectAndServeAnyRequests(CFInvocation(CFInvocation::NONE)); |
208 | 208 |
209 app::win::ScopedCOMInitializer init_com; | 209 base::win::ScopedCOMInitializer init_com; |
210 CComObjectStackEx<UrlmonUrlRequest> request; | 210 CComObjectStackEx<UrlmonUrlRequest> request; |
211 | 211 |
212 request.AddRef(); | 212 request.AddRef(); |
213 request.Initialize(&mock, 1, // request_id | 213 request.Initialize(&mock, 1, // request_id |
214 WideToUTF8(mock_server.Resolve(L"empty.html")), "get", | 214 WideToUTF8(mock_server.Resolve(L"empty.html")), "get", |
215 "", // referrer | 215 "", // referrer |
216 "", // extra request | 216 "", // extra request |
217 NULL, // upload data | 217 NULL, // upload data |
218 ResourceType::MAIN_FRAME, // resource type | 218 ResourceType::MAIN_FRAME, // resource type |
219 true, | 219 true, |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 EXPECT_CALL(mock, OnReadComplete(1, testing::_)) | 311 EXPECT_CALL(mock, OnReadComplete(1, testing::_)) |
312 .Times(0); | 312 .Times(0); |
313 | 313 |
314 EXPECT_CALL(mock, OnResponseEnd(1, testing::_)) | 314 EXPECT_CALL(mock, OnResponseEnd(1, testing::_)) |
315 .Times(0); | 315 .Times(0); |
316 | 316 |
317 mgr->StartUrlRequest(1, r1); | 317 mgr->StartUrlRequest(1, r1); |
318 loop.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); | 318 loop.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); |
319 mgr.reset(); | 319 mgr.reset(); |
320 } | 320 } |
OLD | NEW |