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 "content/public/renderer/resource_fetcher.h" | 5 #include "content/public/renderer/resource_fetcher.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
13 #include "content/public/common/content_switches.h" | 13 #include "content/public/common/content_switches.h" |
14 #include "content/public/common/url_constants.h" | 14 #include "content/public/common/url_constants.h" |
15 #include "content/public/renderer/render_view.h" | 15 #include "content/public/renderer/render_view.h" |
16 #include "content/public/test/test_utils.h" | 16 #include "content/public/test/test_utils.h" |
17 #include "content/shell/browser/shell.h" | 17 #include "content/shell/browser/shell.h" |
18 #include "content/test/content_browser_test.h" | 18 #include "content/test/content_browser_test.h" |
19 #include "content/test/content_browser_test_utils.h" | 19 #include "content/test/content_browser_test_utils.h" |
20 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 20 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
21 #include "third_party/WebKit/public/web/WebFrame.h" | 21 #include "third_party/WebKit/public/web/WebFrame.h" |
22 #include "third_party/WebKit/public/web/WebView.h" | 22 #include "third_party/WebKit/public/web/WebView.h" |
23 | 23 |
24 using blink::WebFrame; | 24 using blink::WebFrame; |
25 using blink::WebURLRequest; | 25 using blink::WebURLRequest; |
26 using blink::WebURLResponse; | 26 using blink::WebURLResponse; |
27 | 27 |
28 namespace { | |
29 | |
30 // The first RenderFrame is routing ID 1, and the first RenderView is 2. | |
31 const int kRenderViewRoutingId = 2; | |
32 | |
33 } | |
34 | |
35 namespace content { | 28 namespace content { |
36 | 29 |
37 static const int kMaxWaitTimeMs = 5000; | 30 static const int kMaxWaitTimeMs = 5000; |
38 | 31 |
39 class FetcherDelegate { | 32 class FetcherDelegate { |
40 public: | 33 public: |
41 FetcherDelegate() | 34 FetcherDelegate() |
42 : completed_(false), | 35 : completed_(false), |
43 timed_out_(false) { | 36 timed_out_(false) { |
44 // Start a repeating timer waiting for the download to complete. The | 37 // Start a repeating timer waiting for the download to complete. The |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 command_line->AppendSwitch(switches::kSingleProcess); | 128 command_line->AppendSwitch(switches::kSingleProcess); |
136 #if defined(OS_WIN) && defined(USE_AURA) | 129 #if defined(OS_WIN) && defined(USE_AURA) |
137 // Don't want to try to create a GPU process. | 130 // Don't want to try to create a GPU process. |
138 command_line->AppendSwitch(switches::kDisableAcceleratedCompositing); | 131 command_line->AppendSwitch(switches::kDisableAcceleratedCompositing); |
139 #endif | 132 #endif |
140 } | 133 } |
141 | 134 |
142 RenderView* GetRenderView() { | 135 RenderView* GetRenderView() { |
143 // We could have the test on the UI thread get the WebContent's routing ID, | 136 // We could have the test on the UI thread get the WebContent's routing ID, |
144 // but we know this will be the first RV so skip that and just hardcode it. | 137 // but we know this will be the first RV so skip that and just hardcode it. |
145 return RenderView::FromRoutingID(kRenderViewRoutingId); | 138 return RenderView::FromRoutingID(1); |
146 } | 139 } |
147 | 140 |
148 void ResourceFetcherDownloadOnRenderer(const GURL& url) { | 141 void ResourceFetcherDownloadOnRenderer(const GURL& url) { |
149 WebFrame* frame = GetRenderView()->GetWebView()->mainFrame(); | 142 WebFrame* frame = GetRenderView()->GetWebView()->mainFrame(); |
150 | 143 |
151 scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate); | 144 scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate); |
152 scoped_ptr<ResourceFetcher> fetcher(ResourceFetcher::Create( | 145 scoped_ptr<ResourceFetcher> fetcher(ResourceFetcher::Create( |
153 url, frame, WebURLRequest::TargetIsMainFrame, delegate->NewCallback())); | 146 url, frame, WebURLRequest::TargetIsMainFrame, delegate->NewCallback())); |
154 | 147 |
155 delegate->WaitForResponse(); | 148 delegate->WaitForResponse(); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 ASSERT_TRUE(test_server()->Start()); | 280 ASSERT_TRUE(test_server()->Start()); |
288 GURL url(test_server()->GetURL("slow?1")); | 281 GURL url(test_server()->GetURL("slow?1")); |
289 | 282 |
290 PostTaskToInProcessRendererAndWait( | 283 PostTaskToInProcessRendererAndWait( |
291 base::Bind( | 284 base::Bind( |
292 &ResourceFetcherTests::ResourceFetcherDeletedInCallbackOnRenderer, | 285 &ResourceFetcherTests::ResourceFetcherDeletedInCallbackOnRenderer, |
293 base::Unretained(this), url)); | 286 base::Unretained(this), url)); |
294 } | 287 } |
295 | 288 |
296 } // namespace content | 289 } // namespace content |
OLD | NEW |