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 <list> | 5 #include <list> |
6 #include <set> | 6 #include <set> |
7 | 7 |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 112 |
113 // Stores a throttle per URL request that we have delayed. | 113 // Stores a throttle per URL request that we have delayed. |
114 class Throttle : public content::ResourceThrottle, | 114 class Throttle : public content::ResourceThrottle, |
115 public base::SupportsWeakPtr<Throttle> { | 115 public base::SupportsWeakPtr<Throttle> { |
116 public: | 116 public: |
117 void Resume() { | 117 void Resume() { |
118 controller()->Resume(); | 118 controller()->Resume(); |
119 } | 119 } |
120 | 120 |
121 // content::ResourceThrottle implementation. | 121 // content::ResourceThrottle implementation. |
122 virtual void WillStartRequest(bool* defer) override { | 122 void WillStartRequest(bool* defer) override { *defer = true; } |
123 *defer = true; | |
124 } | |
125 | 123 |
126 virtual const char* GetNameForLogging() const override { | 124 const char* GetNameForLogging() const override { |
127 return "TestNavigationListener::Throttle"; | 125 return "TestNavigationListener::Throttle"; |
128 } | 126 } |
129 }; | 127 }; |
130 typedef base::WeakPtr<Throttle> WeakThrottle; | 128 typedef base::WeakPtr<Throttle> WeakThrottle; |
131 typedef std::list<WeakThrottle> WeakThrottleList; | 129 typedef std::list<WeakThrottle> WeakThrottleList; |
132 WeakThrottleList throttles_; | 130 WeakThrottleList throttles_; |
133 | 131 |
134 // The set of URLs to be delayed. | 132 // The set of URLs to be delayed. |
135 std::set<GURL> urls_to_delay_; | 133 std::set<GURL> urls_to_delay_; |
136 | 134 |
(...skipping 19 matching lines...) Expand all Loading... |
156 delay_url_(delay_url), | 154 delay_url_(delay_url), |
157 until_url_suffix_(until_url_suffix), | 155 until_url_suffix_(until_url_suffix), |
158 script_(script), | 156 script_(script), |
159 script_was_executed_(false), | 157 script_was_executed_(false), |
160 rvh_(NULL) { | 158 rvh_(NULL) { |
161 registrar_.Add(this, | 159 registrar_.Add(this, |
162 chrome::NOTIFICATION_TAB_ADDED, | 160 chrome::NOTIFICATION_TAB_ADDED, |
163 content::NotificationService::AllSources()); | 161 content::NotificationService::AllSources()); |
164 test_navigation_listener_->DelayRequestsForURL(delay_url_); | 162 test_navigation_listener_->DelayRequestsForURL(delay_url_); |
165 } | 163 } |
166 virtual ~DelayLoadStartAndExecuteJavascript() {} | 164 ~DelayLoadStartAndExecuteJavascript() override {} |
167 | 165 |
168 virtual void Observe(int type, | 166 void Observe(int type, |
169 const content::NotificationSource& source, | 167 const content::NotificationSource& source, |
170 const content::NotificationDetails& details) override { | 168 const content::NotificationDetails& details) override { |
171 if (type != chrome::NOTIFICATION_TAB_ADDED) { | 169 if (type != chrome::NOTIFICATION_TAB_ADDED) { |
172 NOTREACHED(); | 170 NOTREACHED(); |
173 return; | 171 return; |
174 } | 172 } |
175 content::WebContentsObserver::Observe( | 173 content::WebContentsObserver::Observe( |
176 content::Details<content::WebContents>(details).ptr()); | 174 content::Details<content::WebContents>(details).ptr()); |
177 registrar_.RemoveAll(); | 175 registrar_.RemoveAll(); |
178 } | 176 } |
179 | 177 |
180 virtual void DidStartProvisionalLoadForFrame( | 178 void DidStartProvisionalLoadForFrame( |
181 content::RenderFrameHost* render_frame_host, | 179 content::RenderFrameHost* render_frame_host, |
182 const GURL& validated_url, | 180 const GURL& validated_url, |
183 bool is_error_page, | 181 bool is_error_page, |
184 bool is_iframe_srcdoc) override { | 182 bool is_iframe_srcdoc) override { |
185 if (validated_url != delay_url_ || !rvh_) | 183 if (validated_url != delay_url_ || !rvh_) |
186 return; | 184 return; |
187 | 185 |
188 rvh_->GetMainFrame()->ExecuteJavaScript(base::UTF8ToUTF16(script_)); | 186 rvh_->GetMainFrame()->ExecuteJavaScript(base::UTF8ToUTF16(script_)); |
189 script_was_executed_ = true; | 187 script_was_executed_ = true; |
190 } | 188 } |
191 | 189 |
192 virtual void DidCommitProvisionalLoadForFrame( | 190 void DidCommitProvisionalLoadForFrame( |
193 content::RenderFrameHost* render_frame_host, | 191 content::RenderFrameHost* render_frame_host, |
194 const GURL& url, | 192 const GURL& url, |
195 ui::PageTransition transition_type) override { | 193 ui::PageTransition transition_type) override { |
196 if (script_was_executed_ && EndsWith(url.spec(), until_url_suffix_, true)) { | 194 if (script_was_executed_ && EndsWith(url.spec(), until_url_suffix_, true)) { |
197 content::WebContentsObserver::Observe(NULL); | 195 content::WebContentsObserver::Observe(NULL); |
198 test_navigation_listener_->ResumeAll(); | 196 test_navigation_listener_->ResumeAll(); |
199 } | 197 } |
200 rvh_ = render_frame_host->GetRenderViewHost(); | 198 rvh_ = render_frame_host->GetRenderViewHost(); |
201 } | 199 } |
202 | 200 |
(...skipping 14 matching lines...) Expand all Loading... |
217 // A ResourceDispatcherHostDelegate that adds a TestNavigationObserver. | 215 // A ResourceDispatcherHostDelegate that adds a TestNavigationObserver. |
218 class TestResourceDispatcherHostDelegate | 216 class TestResourceDispatcherHostDelegate |
219 : public ChromeResourceDispatcherHostDelegate { | 217 : public ChromeResourceDispatcherHostDelegate { |
220 public: | 218 public: |
221 TestResourceDispatcherHostDelegate( | 219 TestResourceDispatcherHostDelegate( |
222 prerender::PrerenderTracker* prerender_tracker, | 220 prerender::PrerenderTracker* prerender_tracker, |
223 TestNavigationListener* test_navigation_listener) | 221 TestNavigationListener* test_navigation_listener) |
224 : ChromeResourceDispatcherHostDelegate(prerender_tracker), | 222 : ChromeResourceDispatcherHostDelegate(prerender_tracker), |
225 test_navigation_listener_(test_navigation_listener) { | 223 test_navigation_listener_(test_navigation_listener) { |
226 } | 224 } |
227 virtual ~TestResourceDispatcherHostDelegate() {} | 225 ~TestResourceDispatcherHostDelegate() override {} |
228 | 226 |
229 virtual void RequestBeginning( | 227 void RequestBeginning( |
230 net::URLRequest* request, | 228 net::URLRequest* request, |
231 content::ResourceContext* resource_context, | 229 content::ResourceContext* resource_context, |
232 content::AppCacheService* appcache_service, | 230 content::AppCacheService* appcache_service, |
233 ResourceType resource_type, | 231 ResourceType resource_type, |
234 ScopedVector<content::ResourceThrottle>* throttles) override { | 232 ScopedVector<content::ResourceThrottle>* throttles) override { |
235 ChromeResourceDispatcherHostDelegate::RequestBeginning( | 233 ChromeResourceDispatcherHostDelegate::RequestBeginning( |
236 request, | 234 request, |
237 resource_context, | 235 resource_context, |
238 appcache_service, | 236 appcache_service, |
239 resource_type, | 237 resource_type, |
(...skipping 11 matching lines...) Expand all Loading... |
251 DISALLOW_COPY_AND_ASSIGN(TestResourceDispatcherHostDelegate); | 249 DISALLOW_COPY_AND_ASSIGN(TestResourceDispatcherHostDelegate); |
252 }; | 250 }; |
253 | 251 |
254 } // namespace | 252 } // namespace |
255 | 253 |
256 class WebNavigationApiTest : public ExtensionApiTest { | 254 class WebNavigationApiTest : public ExtensionApiTest { |
257 public: | 255 public: |
258 WebNavigationApiTest() {} | 256 WebNavigationApiTest() {} |
259 virtual ~WebNavigationApiTest() {} | 257 virtual ~WebNavigationApiTest() {} |
260 | 258 |
261 virtual void SetUpInProcessBrowserTestFixture() override { | 259 void SetUpInProcessBrowserTestFixture() override { |
262 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | 260 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
263 | 261 |
264 FrameNavigationState::set_allow_extension_scheme(true); | 262 FrameNavigationState::set_allow_extension_scheme(true); |
265 | 263 |
266 CommandLine::ForCurrentProcess()->AppendSwitch( | 264 CommandLine::ForCurrentProcess()->AppendSwitch( |
267 switches::kAllowLegacyExtensionManifests); | 265 switches::kAllowLegacyExtensionManifests); |
268 | 266 |
269 host_resolver()->AddRule("*", "127.0.0.1"); | 267 host_resolver()->AddRule("*", "127.0.0.1"); |
270 } | 268 } |
271 | 269 |
272 virtual void SetUpOnMainThread() override { | 270 void SetUpOnMainThread() override { |
273 ExtensionApiTest::SetUpOnMainThread(); | 271 ExtensionApiTest::SetUpOnMainThread(); |
274 test_navigation_listener_ = new TestNavigationListener(); | 272 test_navigation_listener_ = new TestNavigationListener(); |
275 resource_dispatcher_host_delegate_.reset( | 273 resource_dispatcher_host_delegate_.reset( |
276 new TestResourceDispatcherHostDelegate( | 274 new TestResourceDispatcherHostDelegate( |
277 g_browser_process->prerender_tracker(), | 275 g_browser_process->prerender_tracker(), |
278 test_navigation_listener_.get())); | 276 test_navigation_listener_.get())); |
279 content::ResourceDispatcherHost::Get()->SetDelegate( | 277 content::ResourceDispatcherHost::Get()->SetDelegate( |
280 resource_dispatcher_host_delegate_.get()); | 278 resource_dispatcher_host_delegate_.get()); |
281 } | 279 } |
282 | 280 |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 "extensions/api_test/webnavigation/crash/b.html", | 626 "extensions/api_test/webnavigation/crash/b.html", |
629 embedded_test_server()->port())); | 627 embedded_test_server()->port())); |
630 ui_test_utils::NavigateToURL(browser(), url); | 628 ui_test_utils::NavigateToURL(browser(), url); |
631 | 629 |
632 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 630 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
633 } | 631 } |
634 | 632 |
635 #endif | 633 #endif |
636 | 634 |
637 } // namespace extensions | 635 } // namespace extensions |
OLD | NEW |