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" |
(...skipping 25 matching lines...) Expand all Loading... |
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 did_clear_data_(false) { |
47 } | 48 } |
48 | 49 |
49 void RequestBeginning(net::URLRequest* request, | 50 void RequestBeginning(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 { |
54 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 55 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
55 ShellResourceDispatcherHostDelegate::RequestBeginning(request, | 56 ShellResourceDispatcherHostDelegate::RequestBeginning(request, |
56 resource_context, | 57 resource_context, |
(...skipping 15 matching lines...) Expand all Loading... |
72 void OnResponseStarted(net::URLRequest* request, | 73 void OnResponseStarted(net::URLRequest* request, |
73 ResourceContext* resource_context, | 74 ResourceContext* resource_context, |
74 ResourceResponse* response, | 75 ResourceResponse* response, |
75 IPC::Sender* sender) override { | 76 IPC::Sender* sender) override { |
76 ResourceRequestInfoImpl* info = | 77 ResourceRequestInfoImpl* info = |
77 ResourceRequestInfoImpl::ForRequest(request_); | 78 ResourceRequestInfoImpl::ForRequest(request_); |
78 | 79 |
79 did_defer_response_ = info->cross_site_handler()->did_defer_for_testing(); | 80 did_defer_response_ = info->cross_site_handler()->did_defer_for_testing(); |
80 } | 81 } |
81 | 82 |
| 83 void RequestComplete(net::URLRequest* url_request) override { |
| 84 if (is_transition_request_) { |
| 85 ResourceRequestInfoImpl* info = |
| 86 ResourceRequestInfoImpl::ForRequest(request_); |
| 87 TransitionLayerData transition_data; |
| 88 did_clear_data_ = !TransitionRequestManager::GetInstance( |
| 89 )->HasPendingTransitionRequest(info->GetChildID(), |
| 90 info->GetRenderFrameID(), |
| 91 request_->url(), |
| 92 &transition_data); |
| 93 } |
| 94 } |
| 95 |
82 void set_pending_transition_request(bool is_transition_request) { | 96 void set_pending_transition_request(bool is_transition_request) { |
83 is_transition_request_ = is_transition_request; | 97 is_transition_request_ = is_transition_request; |
84 } | 98 } |
85 | 99 |
86 bool did_defer_response() const { return did_defer_response_; } | 100 bool did_defer_response() const { return did_defer_response_; } |
| 101 bool did_clear_data() const { return did_clear_data_; } |
87 | 102 |
88 private: | 103 private: |
89 net::URLRequest* request_; | 104 net::URLRequest* request_; |
90 bool did_defer_response_; | 105 bool did_defer_response_; |
91 bool is_transition_request_; | 106 bool is_transition_request_; |
| 107 bool did_clear_data_; |
92 }; | 108 }; |
93 | 109 |
94 // This tests that normal navigations don't defer at first response. | 110 // This tests that normal navigations don't defer at first response. |
95 IN_PROC_BROWSER_TEST_F(TransitionBrowserTest, | 111 IN_PROC_BROWSER_TEST_F(TransitionBrowserTest, |
96 NormalNavigationNotDeferred) { | 112 NormalNavigationNotDeferred) { |
97 // This test shouldn't run in --site-per-process mode, where normal | 113 // This test shouldn't run in --site-per-process mode, where normal |
98 // navigations are also deferred. | 114 // navigations are also deferred. |
99 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 115 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
100 switches::kSitePerProcess)) | 116 switches::kSitePerProcess)) |
101 return; | 117 return; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 transition_web_contents->Focus(); | 165 transition_web_contents->Focus(); |
150 | 166 |
151 WaitForLoadStop(transition_web_contents.get()); | 167 WaitForLoadStop(transition_web_contents.get()); |
152 | 168 |
153 int transition_process_id = | 169 int transition_process_id = |
154 transition_web_contents->GetRenderProcessHost()->GetID(); | 170 transition_web_contents->GetRenderProcessHost()->GetID(); |
155 | 171 |
156 EXPECT_EQ(outgoing_process_id, transition_process_id); | 172 EXPECT_EQ(outgoing_process_id, transition_process_id); |
157 } | 173 } |
158 | 174 |
| 175 // This tests that the transition data is cleared after the transition. |
| 176 IN_PROC_BROWSER_TEST_F(TransitionBrowserTest, |
| 177 TransitionNavigationDataIsCleared) { |
| 178 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 179 scoped_ptr<TransitionBrowserTestObserver> observer( |
| 180 new TransitionBrowserTestObserver(shell()->web_contents())); |
| 181 |
| 182 ResourceDispatcherHost::Get()->SetDelegate(observer.get()); |
| 183 observer->set_pending_transition_request(true); |
| 184 |
| 185 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")); |
| 186 WaitForLoadStop(shell()->web_contents()); |
| 187 |
| 188 EXPECT_TRUE(observer->did_clear_data()); |
| 189 } |
| 190 |
159 } // namespace content | 191 } // namespace content |
OLD | NEW |