Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: chrome/browser/extensions/api/web_navigation/web_navigation_apitest.cc

Issue 190663012: Run ContentMain in a browser_test's browser process. This removes duplication of code in the browse… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: try to fix android by restoring old path just for it Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 if (throttle) 250 if (throttle)
251 throttles->push_back(throttle); 251 throttles->push_back(throttle);
252 } 252 }
253 253
254 private: 254 private:
255 scoped_refptr<TestNavigationListener> test_navigation_listener_; 255 scoped_refptr<TestNavigationListener> test_navigation_listener_;
256 256
257 DISALLOW_COPY_AND_ASSIGN(TestResourceDispatcherHostDelegate); 257 DISALLOW_COPY_AND_ASSIGN(TestResourceDispatcherHostDelegate);
258 }; 258 };
259 259
260 // Used to manage the lifetime of the TestResourceDispatcherHostDelegate which
261 // needs to be deleted before the threads are stopped.
262 class TestBrowserMainExtraParts : public ChromeBrowserMainExtraParts {
263 public:
264 explicit TestBrowserMainExtraParts(
265 TestNavigationListener* test_navigation_listener)
266 : test_navigation_listener_(test_navigation_listener) {
267 }
268 virtual ~TestBrowserMainExtraParts() {}
269
270 TestResourceDispatcherHostDelegate* resource_dispatcher_host_delegate() {
271 if (!resource_dispatcher_host_delegate_.get()) {
272 resource_dispatcher_host_delegate_.reset(
273 new TestResourceDispatcherHostDelegate(
274 g_browser_process->prerender_tracker(),
275 test_navigation_listener_.get()));
276 }
277 return resource_dispatcher_host_delegate_.get();
278 }
279
280 // ChromeBrowserMainExtraParts implementation.
281 virtual void PostMainMessageLoopRun() OVERRIDE {
282 resource_dispatcher_host_delegate_.reset();
283 }
284
285 private:
286 scoped_refptr<TestNavigationListener> test_navigation_listener_;
287 scoped_ptr<TestResourceDispatcherHostDelegate>
288 resource_dispatcher_host_delegate_;
289
290 DISALLOW_COPY_AND_ASSIGN(TestBrowserMainExtraParts);
291 };
292
293 // A ContentBrowserClient that doesn't forward the RDH created signal.
294 class TestContentBrowserClient : public chrome::ChromeContentBrowserClient {
295 public:
296 explicit TestContentBrowserClient(
297 TestNavigationListener* test_navigation_listener)
298 : test_navigation_listener_(test_navigation_listener) {
299 }
300 virtual ~TestContentBrowserClient() {}
301
302 virtual void ResourceDispatcherHostCreated() OVERRIDE {
303 // Don't invoke ChromeContentBrowserClient::ResourceDispatcherHostCreated.
304 // It would notify BrowserProcessImpl which would create a
305 // ChromeResourceDispatcherHostDelegate and other objects. Not creating
306 // other objects might turn out to be a problem in the future.
307 content::ResourceDispatcherHost::Get()->SetDelegate(
308 browser_main_extra_parts_->resource_dispatcher_host_delegate());
309 }
310
311 virtual content::BrowserMainParts* CreateBrowserMainParts(
312 const content::MainFunctionParams& parameters) OVERRIDE {
313 ChromeBrowserMainParts* main_parts = static_cast<ChromeBrowserMainParts*>(
314 ChromeContentBrowserClient::CreateBrowserMainParts(parameters));
315
316 browser_main_extra_parts_ =
317 new TestBrowserMainExtraParts(test_navigation_listener_.get());
318 main_parts->AddParts(browser_main_extra_parts_);
319 return main_parts;
320 }
321
322 private:
323 scoped_refptr<TestNavigationListener> test_navigation_listener_;
324 TestBrowserMainExtraParts* browser_main_extra_parts_;
325
326 DISALLOW_COPY_AND_ASSIGN(TestContentBrowserClient);
327 };
328
329 } // namespace 260 } // namespace
330 261
331 class WebNavigationApiTest : public ExtensionApiTest { 262 class WebNavigationApiTest : public ExtensionApiTest {
332 public: 263 public:
333 WebNavigationApiTest() {} 264 WebNavigationApiTest() {}
334 virtual ~WebNavigationApiTest() {} 265 virtual ~WebNavigationApiTest() {}
335 266
336 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 267 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
337 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); 268 ExtensionApiTest::SetUpInProcessBrowserTestFixture();
338 269
339 test_navigation_listener_ = new TestNavigationListener();
340 content_browser_client_.reset(
341 new TestContentBrowserClient(test_navigation_listener_.get()));
342 original_content_browser_client_ = content::SetBrowserClientForTesting(
343 content_browser_client_.get());
344
345 FrameNavigationState::set_allow_extension_scheme(true); 270 FrameNavigationState::set_allow_extension_scheme(true);
346 271
347 CommandLine::ForCurrentProcess()->AppendSwitch( 272 CommandLine::ForCurrentProcess()->AppendSwitch(
348 switches::kAllowLegacyExtensionManifests); 273 switches::kAllowLegacyExtensionManifests);
349 274
350 host_resolver()->AddRule("*", "127.0.0.1"); 275 host_resolver()->AddRule("*", "127.0.0.1");
351 } 276 }
352 277
353 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { 278 virtual void SetUpOnMainThread() OVERRIDE {
354 ExtensionApiTest::TearDownInProcessBrowserTestFixture(); 279 ExtensionApiTest::SetUpOnMainThread();
355 content::SetBrowserClientForTesting(original_content_browser_client_); 280 test_navigation_listener_ = new TestNavigationListener();
281 resource_dispatcher_host_delegate_.reset(
282 new TestResourceDispatcherHostDelegate(
283 g_browser_process->prerender_tracker(),
284 test_navigation_listener_.get()));
285 content::ResourceDispatcherHost::Get()->SetDelegate(
286 resource_dispatcher_host_delegate_.get());
356 } 287 }
357 288
358 TestNavigationListener* test_navigation_listener() { 289 TestNavigationListener* test_navigation_listener() {
359 return test_navigation_listener_.get(); 290 return test_navigation_listener_.get();
360 } 291 }
361 292
362 private: 293 private:
363 scoped_refptr<TestNavigationListener> test_navigation_listener_; 294 scoped_refptr<TestNavigationListener> test_navigation_listener_;
364 scoped_ptr<TestContentBrowserClient> content_browser_client_; 295 scoped_ptr<TestResourceDispatcherHostDelegate>
365 content::ContentBrowserClient* original_content_browser_client_; 296 resource_dispatcher_host_delegate_;
366 297
367 DISALLOW_COPY_AND_ASSIGN(WebNavigationApiTest); 298 DISALLOW_COPY_AND_ASSIGN(WebNavigationApiTest);
368 }; 299 };
369 300
370 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, Api) { 301 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, Api) {
371 ASSERT_TRUE(StartEmbeddedTestServer()); 302 ASSERT_TRUE(StartEmbeddedTestServer());
372 ASSERT_TRUE(RunExtensionTest("webnavigation/api")) << message_; 303 ASSERT_TRUE(RunExtensionTest("webnavigation/api")) << message_;
373 } 304 }
374 305
375 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, GetFrame) { 306 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, GetFrame) {
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 url = GURL(base::StringPrintf( 626 url = GURL(base::StringPrintf(
696 "http://www.a.com:%d/" 627 "http://www.a.com:%d/"
697 "extensions/api_test/webnavigation/crash/b.html", 628 "extensions/api_test/webnavigation/crash/b.html",
698 embedded_test_server()->port())); 629 embedded_test_server()->port()));
699 ui_test_utils::NavigateToURL(browser(), url); 630 ui_test_utils::NavigateToURL(browser(), url);
700 631
701 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 632 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
702 } 633 }
703 634
704 } // namespace extensions 635 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698