| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #ifndef CHROME_TEST_UNIT_CHROME_TEST_SUITE_H_ | 5 #ifndef CHROME_TEST_UNIT_CHROME_TEST_SUITE_H_ |
| 6 #define CHROME_TEST_UNIT_CHROME_TEST_SUITE_H_ | 6 #define CHROME_TEST_UNIT_CHROME_TEST_SUITE_H_ |
| 7 | 7 |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 | 9 |
| 10 #include "base/stats_table.h" | 10 #include "base/stats_table.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #if defined(OS_MACOSX) | 12 #if defined(OS_MACOSX) |
| 13 #include "base/mac_util.h" | 13 #include "base/mac_util.h" |
| 14 #endif | 14 #endif |
| 15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/ref_counted.h" |
| 16 #include "base/scoped_nsautorelease_pool.h" | 17 #include "base/scoped_nsautorelease_pool.h" |
| 17 #include "base/test_suite.h" | 18 #include "base/test_suite.h" |
| 18 #include "chrome/app/scoped_ole_initializer.h" | 19 #include "chrome/app/scoped_ole_initializer.h" |
| 19 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
| 21 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/common/resource_bundle.h" | 23 #include "chrome/common/resource_bundle.h" |
| 23 #include "chrome/test/testing_browser_process.h" | 24 #include "chrome/test/testing_browser_process.h" |
| 25 #include "net/base/host_resolver_unittest.h" |
| 26 |
| 27 // In many cases it may be not obvious that a test makes a real DNS lookup. |
| 28 // We generally don't want to rely on external DNS servers for our tests, |
| 29 // so this mapper catches external queries. |
| 30 class WarningHostMapper : public net::HostMapper { |
| 31 public: |
| 32 virtual std::string Map(const std::string& host) { |
| 33 const char* kLocalHostNames[] = {"localhost", "127.0.0.1"}; |
| 34 bool local = false; |
| 35 for (size_t i = 0; i < arraysize(kLocalHostNames); i++) |
| 36 if (host == kLocalHostNames[i]) { |
| 37 local = true; |
| 38 break; |
| 39 } |
| 40 |
| 41 // Make the test fail so it's harder to ignore. |
| 42 // If you really need to make real DNS query, use net::RuleBasedHostMapper |
| 43 // and its AllowDirectLookup method. |
| 44 EXPECT_TRUE(local) << "Making external DNS lookup of " << host; |
| 45 |
| 46 return MapUsingPrevious(host); |
| 47 } |
| 48 }; |
| 24 | 49 |
| 25 class ChromeTestSuite : public TestSuite { | 50 class ChromeTestSuite : public TestSuite { |
| 26 public: | 51 public: |
| 27 ChromeTestSuite(int argc, char** argv) : TestSuite(argc, argv) { | 52 ChromeTestSuite(int argc, char** argv) : TestSuite(argc, argv) { |
| 28 } | 53 } |
| 29 | 54 |
| 30 protected: | 55 protected: |
| 31 | 56 |
| 32 virtual void Initialize() { | 57 virtual void Initialize() { |
| 33 base::ScopedNSAutoreleasePool autorelease_pool; | 58 base::ScopedNSAutoreleasePool autorelease_pool; |
| 34 | 59 |
| 35 TestSuite::Initialize(); | 60 TestSuite::Initialize(); |
| 36 | 61 |
| 62 host_mapper_ = new WarningHostMapper(); |
| 63 scoped_host_mapper_.Init(host_mapper_.get()); |
| 64 |
| 37 chrome::RegisterPathProvider(); | 65 chrome::RegisterPathProvider(); |
| 38 g_browser_process = new TestingBrowserProcess; | 66 g_browser_process = new TestingBrowserProcess; |
| 39 | 67 |
| 40 // Notice a user data override, and otherwise default to using a custom | 68 // Notice a user data override, and otherwise default to using a custom |
| 41 // user data directory that lives alongside the current app. | 69 // user data directory that lives alongside the current app. |
| 42 // NOTE: The user data directory will be erased before each UI test that | 70 // NOTE: The user data directory will be erased before each UI test that |
| 43 // uses it, in order to ensure consistency. | 71 // uses it, in order to ensure consistency. |
| 44 std::wstring user_data_dir = | 72 std::wstring user_data_dir = |
| 45 CommandLine::ForCurrentProcess()->GetSwitchValue( | 73 CommandLine::ForCurrentProcess()->GetSwitchValue( |
| 46 switches::kUserDataDir); | 74 switches::kUserDataDir); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 111 |
| 84 // Tear down shared StatsTable; prevents unit_tests from leaking it. | 112 // Tear down shared StatsTable; prevents unit_tests from leaking it. |
| 85 StatsTable::set_current(NULL); | 113 StatsTable::set_current(NULL); |
| 86 delete stats_table_; | 114 delete stats_table_; |
| 87 | 115 |
| 88 TestSuite::Shutdown(); | 116 TestSuite::Shutdown(); |
| 89 } | 117 } |
| 90 | 118 |
| 91 StatsTable* stats_table_; | 119 StatsTable* stats_table_; |
| 92 ScopedOleInitializer ole_initializer_; | 120 ScopedOleInitializer ole_initializer_; |
| 121 scoped_refptr<WarningHostMapper> host_mapper_; |
| 122 net::ScopedHostMapper scoped_host_mapper_; |
| 93 }; | 123 }; |
| 94 | 124 |
| 95 #endif // CHROME_TEST_UNIT_CHROME_TEST_SUITE_H_ | 125 #endif // CHROME_TEST_UNIT_CHROME_TEST_SUITE_H_ |
| OLD | NEW |