OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/test/base/browser_with_content_test.h" |
| 6 |
| 7 #include "base/base_paths.h" |
| 8 #include "base/command_line.h" |
| 9 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" |
| 11 #include "base/path_service.h" |
| 12 #include "base/run_loop.h" |
| 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/common/chrome_constants.h" |
| 15 #include "chrome/common/chrome_paths.h" |
| 16 #include "chrome/test/base/chrome_unit_test_suite.h" |
| 17 #include "chrome/test/base/testing_browser_process.h" |
| 18 #include "chrome/test/base/testing_profile.h" |
| 19 #include "content/public/common/content_switches.h" |
| 20 |
| 21 #if defined(OS_MACOSX) |
| 22 #include "base/mac/scoped_nsautorelease_pool.h" |
| 23 #include "chrome/test/base/scoped_bundle_swizzler_mac.h" |
| 24 #endif |
| 25 |
| 26 BrowserWithContentTest::BrowserWithContentTest() { |
| 27 #if defined(OS_MACOSX) |
| 28 // TODO(phajdan.jr): Make browser_tests self-contained on Mac, remove this. |
| 29 // Before we run the browser, we have to hack the path to the exe to match |
| 30 // what it would be if Chrome was running, because it is used to fork renderer |
| 31 // processes, on Linux at least (failure to do so will cause a browser_test to |
| 32 // be run instead of a renderer). |
| 33 base::FilePath chrome_path; |
| 34 CHECK(PathService::Get(base::FILE_EXE, &chrome_path)); |
| 35 chrome_path = chrome_path.DirName(); |
| 36 chrome_path = chrome_path.Append(chrome::kBrowserProcessExecutablePath); |
| 37 CHECK(PathService::Override(base::FILE_EXE, chrome_path)); |
| 38 #endif // defined(OS_MACOSX) |
| 39 |
| 40 base::FilePath src_dir; |
| 41 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)); |
| 42 base::FilePath test_data_dir = src_dir.AppendASCII("chrome/test/data"); |
| 43 |
| 44 #if 0 |
| 45 CreateTestServer(base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
| 46 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); |
| 47 #endif |
| 48 |
| 49 ChromeUnitTestSuite::InitializeProviders(); |
| 50 ChromeUnitTestSuite::InitializeResourceBundle(); |
| 51 |
| 52 #if defined(OS_MACOSX) |
| 53 bundle_swizzler_.reset(new ScopedBundleSwizzlerMac); |
| 54 #endif |
| 55 } |
| 56 |
| 57 BrowserWithContentTest::~BrowserWithContentTest() {} |
| 58 |
| 59 void BrowserWithContentTest::SetUp() { |
| 60 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 61 command_line->AppendSwitchASCII(switches::kTestType, "browser_with_content"); |
| 62 SetUpCommandLine(command_line); |
| 63 |
| 64 // Create the first Browser here rather than in SetUpOnMainThread() since the |
| 65 // initialization uses banned IO tasks. |
| 66 TestingBrowserProcess::CreateInstance(); |
| 67 profile_.reset(new TestingProfile); |
| 68 browser_ = new Browser( |
| 69 Browser::CreateParams(profile_.get(), chrome::GetActiveDesktop())); |
| 70 |
| 71 content::BrowserTestBase::SetUp(); |
| 72 } |
| 73 |
| 74 void BrowserWithContentTest::SetUpOnMainThread() {} |
| 75 |
| 76 void BrowserWithContentTest::TearDownOnMainThread() { |
| 77 profile_.reset(); |
| 78 /* close browser */ |
| 79 TestingBrowserProcess::DeleteInstance(); |
| 80 } |
| 81 |
| 82 void BrowserWithContentTest::RunTestOnMainThreadLoop() { |
| 83 base::RunLoop().RunUntilIdle(); |
| 84 |
| 85 SetUpOnMainThread(); |
| 86 RunTestOnMainThread(); |
| 87 TearDownOnMainThread(); |
| 88 } |
OLD | NEW |