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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "content/browser/loader/cross_site_resource_handler.h" | 7 #include "content/browser/loader/cross_site_resource_handler.h" |
8 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 8 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
9 #include "content/browser/loader/resource_request_info_impl.h" | 9 #include "content/browser/loader/resource_request_info_impl.h" |
10 #include "content/browser/transition_request_manager.h" | 10 #include "content/browser/transition_request_manager.h" |
11 #include "content/browser/web_contents/web_contents_impl.h" | 11 #include "content/browser/web_contents/web_contents_impl.h" |
12 #include "content/public/browser/web_contents_observer.h" | 12 #include "content/public/browser/web_contents_observer.h" |
13 #include "content/public/common/content_switches.h" | 13 #include "content/public/common/content_switches.h" |
14 #include "content/public/test/browser_test_utils.h" | 14 #include "content/public/test/browser_test_utils.h" |
15 #include "content/public/test/content_browser_test.h" | 15 #include "content/public/test/content_browser_test.h" |
16 #include "content/public/test/content_browser_test_utils.h" | 16 #include "content/public/test/content_browser_test_utils.h" |
17 #include "content/public/test/test_utils.h" | 17 #include "content/public/test/test_utils.h" |
18 #include "content/shell/browser/shell.h" | 18 #include "content/shell/browser/shell.h" |
19 #include "content/shell/browser/shell_resource_dispatcher_host_delegate.h" | 19 #include "content/shell/browser/shell_resource_dispatcher_host_delegate.h" |
20 #include "net/test/embedded_test_server/embedded_test_server.h" | 20 #include "net/test/embedded_test_server/embedded_test_server.h" |
21 #include "net/url_request/url_request.h" | 21 #include "net/url_request/url_request.h" |
22 | 22 |
23 namespace content { | 23 namespace content { |
24 | 24 |
25 class TransitionBrowserTest : public ContentBrowserTest { | 25 class TransitionBrowserTest : public ContentBrowserTest { |
26 public: | 26 public: |
27 TransitionBrowserTest() {} | 27 TransitionBrowserTest() {} |
28 | 28 |
29 virtual void SetUpCommandLine(CommandLine* command_line) override { | 29 void SetUpCommandLine(CommandLine* command_line) override { |
30 command_line->AppendSwitch( | 30 command_line->AppendSwitch( |
31 switches::kEnableExperimentalWebPlatformFeatures); | 31 switches::kEnableExperimentalWebPlatformFeatures); |
32 } | 32 } |
33 | 33 |
34 private: | 34 private: |
35 DISALLOW_COPY_AND_ASSIGN(TransitionBrowserTest); | 35 DISALLOW_COPY_AND_ASSIGN(TransitionBrowserTest); |
36 }; | 36 }; |
37 | 37 |
38 class TransitionBrowserTestObserver | 38 class TransitionBrowserTestObserver |
39 : public WebContentsObserver, | 39 : public WebContentsObserver, |
40 public ShellResourceDispatcherHostDelegate { | 40 public ShellResourceDispatcherHostDelegate { |
41 public: | 41 public: |
42 TransitionBrowserTestObserver(WebContents* web_contents) | 42 TransitionBrowserTestObserver(WebContents* web_contents) |
43 : WebContentsObserver(web_contents), | 43 : WebContentsObserver(web_contents), |
44 request_(NULL), | 44 request_(NULL), |
45 did_defer_response_(false), | 45 did_defer_response_(false), |
46 is_transition_request_(false) { | 46 is_transition_request_(false) { |
47 } | 47 } |
48 | 48 |
49 virtual void RequestBeginning( | 49 void RequestBeginning(net::URLRequest* request, |
50 net::URLRequest* request, | 50 ResourceContext* resource_context, |
51 ResourceContext* resource_context, | 51 AppCacheService* appcache_service, |
52 AppCacheService* appcache_service, | 52 ResourceType resource_type, |
53 ResourceType resource_type, | 53 ScopedVector<ResourceThrottle>* throttles) override { |
54 ScopedVector<ResourceThrottle>* throttles) override { | |
55 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 54 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
56 ShellResourceDispatcherHostDelegate::RequestBeginning(request, | 55 ShellResourceDispatcherHostDelegate::RequestBeginning(request, |
57 resource_context, | 56 resource_context, |
58 appcache_service, | 57 appcache_service, |
59 resource_type, | 58 resource_type, |
60 throttles); | 59 throttles); |
61 request_ = request; | 60 request_ = request; |
62 | 61 |
63 ResourceRequestInfoImpl* info = | 62 ResourceRequestInfoImpl* info = |
64 ResourceRequestInfoImpl::ForRequest(request_); | 63 ResourceRequestInfoImpl::ForRequest(request_); |
65 | 64 |
66 if (is_transition_request_) { | 65 if (is_transition_request_) { |
67 TransitionRequestManager::GetInstance( | 66 TransitionRequestManager::GetInstance( |
68 )->AddPendingTransitionRequestDataForTesting( | 67 )->AddPendingTransitionRequestDataForTesting( |
69 info->GetChildID(), info->GetRenderFrameID()); | 68 info->GetChildID(), info->GetRenderFrameID()); |
70 } | 69 } |
71 } | 70 } |
72 | 71 |
73 virtual void OnResponseStarted( | 72 void OnResponseStarted(net::URLRequest* request, |
74 net::URLRequest* request, | 73 ResourceContext* resource_context, |
75 ResourceContext* resource_context, | 74 ResourceResponse* response, |
76 ResourceResponse* response, | 75 IPC::Sender* sender) override { |
77 IPC::Sender* sender) override { | |
78 ResourceRequestInfoImpl* info = | 76 ResourceRequestInfoImpl* info = |
79 ResourceRequestInfoImpl::ForRequest(request_); | 77 ResourceRequestInfoImpl::ForRequest(request_); |
80 | 78 |
81 did_defer_response_ = info->cross_site_handler()->did_defer_for_testing(); | 79 did_defer_response_ = info->cross_site_handler()->did_defer_for_testing(); |
82 } | 80 } |
83 | 81 |
84 void set_pending_transition_request(bool is_transition_request) { | 82 void set_pending_transition_request(bool is_transition_request) { |
85 is_transition_request_ = is_transition_request; | 83 is_transition_request_ = is_transition_request; |
86 } | 84 } |
87 | 85 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 150 |
153 WaitForLoadStop(transition_web_contents.get()); | 151 WaitForLoadStop(transition_web_contents.get()); |
154 | 152 |
155 int transition_process_id = | 153 int transition_process_id = |
156 transition_web_contents->GetRenderProcessHost()->GetID(); | 154 transition_web_contents->GetRenderProcessHost()->GetID(); |
157 | 155 |
158 EXPECT_EQ(outgoing_process_id, transition_process_id); | 156 EXPECT_EQ(outgoing_process_id, transition_process_id); |
159 } | 157 } |
160 | 158 |
161 } // namespace content | 159 } // namespace content |
OLD | NEW |