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 virtual void WillStartRequest(bool* defer) override { |
123 *defer = true; | 123 *defer = true; |
124 } | 124 } |
125 | 125 |
126 virtual const char* GetNameForLogging() const OVERRIDE { | 126 virtual const char* GetNameForLogging() const override { |
127 return "TestNavigationListener::Throttle"; | 127 return "TestNavigationListener::Throttle"; |
128 } | 128 } |
129 }; | 129 }; |
130 typedef base::WeakPtr<Throttle> WeakThrottle; | 130 typedef base::WeakPtr<Throttle> WeakThrottle; |
131 typedef std::list<WeakThrottle> WeakThrottleList; | 131 typedef std::list<WeakThrottle> WeakThrottleList; |
132 WeakThrottleList throttles_; | 132 WeakThrottleList throttles_; |
133 | 133 |
134 // The set of URLs to be delayed. | 134 // The set of URLs to be delayed. |
135 std::set<GURL> urls_to_delay_; | 135 std::set<GURL> urls_to_delay_; |
136 | 136 |
(...skipping 23 matching lines...) Expand all Loading... |
160 rvh_(NULL) { | 160 rvh_(NULL) { |
161 registrar_.Add(this, | 161 registrar_.Add(this, |
162 chrome::NOTIFICATION_TAB_ADDED, | 162 chrome::NOTIFICATION_TAB_ADDED, |
163 content::NotificationService::AllSources()); | 163 content::NotificationService::AllSources()); |
164 test_navigation_listener_->DelayRequestsForURL(delay_url_); | 164 test_navigation_listener_->DelayRequestsForURL(delay_url_); |
165 } | 165 } |
166 virtual ~DelayLoadStartAndExecuteJavascript() {} | 166 virtual ~DelayLoadStartAndExecuteJavascript() {} |
167 | 167 |
168 virtual void Observe(int type, | 168 virtual void Observe(int type, |
169 const content::NotificationSource& source, | 169 const content::NotificationSource& source, |
170 const content::NotificationDetails& details) OVERRIDE { | 170 const content::NotificationDetails& details) override { |
171 if (type != chrome::NOTIFICATION_TAB_ADDED) { | 171 if (type != chrome::NOTIFICATION_TAB_ADDED) { |
172 NOTREACHED(); | 172 NOTREACHED(); |
173 return; | 173 return; |
174 } | 174 } |
175 content::WebContentsObserver::Observe( | 175 content::WebContentsObserver::Observe( |
176 content::Details<content::WebContents>(details).ptr()); | 176 content::Details<content::WebContents>(details).ptr()); |
177 registrar_.RemoveAll(); | 177 registrar_.RemoveAll(); |
178 } | 178 } |
179 | 179 |
180 virtual void DidStartProvisionalLoadForFrame( | 180 virtual void DidStartProvisionalLoadForFrame( |
181 content::RenderFrameHost* render_frame_host, | 181 content::RenderFrameHost* render_frame_host, |
182 const GURL& validated_url, | 182 const GURL& validated_url, |
183 bool is_error_page, | 183 bool is_error_page, |
184 bool is_iframe_srcdoc) OVERRIDE { | 184 bool is_iframe_srcdoc) override { |
185 if (validated_url != delay_url_ || !rvh_) | 185 if (validated_url != delay_url_ || !rvh_) |
186 return; | 186 return; |
187 | 187 |
188 rvh_->GetMainFrame()->ExecuteJavaScript(base::UTF8ToUTF16(script_)); | 188 rvh_->GetMainFrame()->ExecuteJavaScript(base::UTF8ToUTF16(script_)); |
189 script_was_executed_ = true; | 189 script_was_executed_ = true; |
190 } | 190 } |
191 | 191 |
192 virtual void DidCommitProvisionalLoadForFrame( | 192 virtual void DidCommitProvisionalLoadForFrame( |
193 content::RenderFrameHost* render_frame_host, | 193 content::RenderFrameHost* render_frame_host, |
194 const GURL& url, | 194 const GURL& url, |
195 ui::PageTransition transition_type) OVERRIDE { | 195 ui::PageTransition transition_type) override { |
196 if (script_was_executed_ && EndsWith(url.spec(), until_url_suffix_, true)) { | 196 if (script_was_executed_ && EndsWith(url.spec(), until_url_suffix_, true)) { |
197 content::WebContentsObserver::Observe(NULL); | 197 content::WebContentsObserver::Observe(NULL); |
198 test_navigation_listener_->ResumeAll(); | 198 test_navigation_listener_->ResumeAll(); |
199 } | 199 } |
200 rvh_ = render_frame_host->GetRenderViewHost(); | 200 rvh_ = render_frame_host->GetRenderViewHost(); |
201 } | 201 } |
202 | 202 |
203 private: | 203 private: |
204 content::NotificationRegistrar registrar_; | 204 content::NotificationRegistrar registrar_; |
205 | 205 |
(...skipping 18 matching lines...) Expand all Loading... |
224 : ChromeResourceDispatcherHostDelegate(prerender_tracker), | 224 : ChromeResourceDispatcherHostDelegate(prerender_tracker), |
225 test_navigation_listener_(test_navigation_listener) { | 225 test_navigation_listener_(test_navigation_listener) { |
226 } | 226 } |
227 virtual ~TestResourceDispatcherHostDelegate() {} | 227 virtual ~TestResourceDispatcherHostDelegate() {} |
228 | 228 |
229 virtual void RequestBeginning( | 229 virtual void RequestBeginning( |
230 net::URLRequest* request, | 230 net::URLRequest* request, |
231 content::ResourceContext* resource_context, | 231 content::ResourceContext* resource_context, |
232 content::AppCacheService* appcache_service, | 232 content::AppCacheService* appcache_service, |
233 ResourceType resource_type, | 233 ResourceType resource_type, |
234 ScopedVector<content::ResourceThrottle>* throttles) OVERRIDE { | 234 ScopedVector<content::ResourceThrottle>* throttles) override { |
235 ChromeResourceDispatcherHostDelegate::RequestBeginning( | 235 ChromeResourceDispatcherHostDelegate::RequestBeginning( |
236 request, | 236 request, |
237 resource_context, | 237 resource_context, |
238 appcache_service, | 238 appcache_service, |
239 resource_type, | 239 resource_type, |
240 throttles); | 240 throttles); |
241 content::ResourceThrottle* throttle = | 241 content::ResourceThrottle* throttle = |
242 test_navigation_listener_->CreateResourceThrottle(request->url(), | 242 test_navigation_listener_->CreateResourceThrottle(request->url(), |
243 resource_type); | 243 resource_type); |
244 if (throttle) | 244 if (throttle) |
245 throttles->push_back(throttle); | 245 throttles->push_back(throttle); |
246 } | 246 } |
247 | 247 |
248 private: | 248 private: |
249 scoped_refptr<TestNavigationListener> test_navigation_listener_; | 249 scoped_refptr<TestNavigationListener> test_navigation_listener_; |
250 | 250 |
251 DISALLOW_COPY_AND_ASSIGN(TestResourceDispatcherHostDelegate); | 251 DISALLOW_COPY_AND_ASSIGN(TestResourceDispatcherHostDelegate); |
252 }; | 252 }; |
253 | 253 |
254 } // namespace | 254 } // namespace |
255 | 255 |
256 class WebNavigationApiTest : public ExtensionApiTest { | 256 class WebNavigationApiTest : public ExtensionApiTest { |
257 public: | 257 public: |
258 WebNavigationApiTest() {} | 258 WebNavigationApiTest() {} |
259 virtual ~WebNavigationApiTest() {} | 259 virtual ~WebNavigationApiTest() {} |
260 | 260 |
261 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 261 virtual void SetUpInProcessBrowserTestFixture() override { |
262 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | 262 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
263 | 263 |
264 FrameNavigationState::set_allow_extension_scheme(true); | 264 FrameNavigationState::set_allow_extension_scheme(true); |
265 | 265 |
266 CommandLine::ForCurrentProcess()->AppendSwitch( | 266 CommandLine::ForCurrentProcess()->AppendSwitch( |
267 switches::kAllowLegacyExtensionManifests); | 267 switches::kAllowLegacyExtensionManifests); |
268 | 268 |
269 host_resolver()->AddRule("*", "127.0.0.1"); | 269 host_resolver()->AddRule("*", "127.0.0.1"); |
270 } | 270 } |
271 | 271 |
272 virtual void SetUpOnMainThread() OVERRIDE { | 272 virtual void SetUpOnMainThread() override { |
273 ExtensionApiTest::SetUpOnMainThread(); | 273 ExtensionApiTest::SetUpOnMainThread(); |
274 test_navigation_listener_ = new TestNavigationListener(); | 274 test_navigation_listener_ = new TestNavigationListener(); |
275 resource_dispatcher_host_delegate_.reset( | 275 resource_dispatcher_host_delegate_.reset( |
276 new TestResourceDispatcherHostDelegate( | 276 new TestResourceDispatcherHostDelegate( |
277 g_browser_process->prerender_tracker(), | 277 g_browser_process->prerender_tracker(), |
278 test_navigation_listener_.get())); | 278 test_navigation_listener_.get())); |
279 content::ResourceDispatcherHost::Get()->SetDelegate( | 279 content::ResourceDispatcherHost::Get()->SetDelegate( |
280 resource_dispatcher_host_delegate_.get()); | 280 resource_dispatcher_host_delegate_.get()); |
281 } | 281 } |
282 | 282 |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 "extensions/api_test/webnavigation/crash/b.html", | 628 "extensions/api_test/webnavigation/crash/b.html", |
629 embedded_test_server()->port())); | 629 embedded_test_server()->port())); |
630 ui_test_utils::NavigateToURL(browser(), url); | 630 ui_test_utils::NavigateToURL(browser(), url); |
631 | 631 |
632 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 632 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
633 } | 633 } |
634 | 634 |
635 #endif | 635 #endif |
636 | 636 |
637 } // namespace extensions | 637 } // namespace extensions |
OLD | NEW |