| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "chrome/browser/chrome_browser_main.h" | 10 #include "chrome/browser/chrome_browser_main.h" |
| 11 #include "chrome/browser/chrome_content_browser_client.h" | 11 #include "chrome/browser/chrome_content_browser_client.h" |
| 12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/test/base/testing_pref_service.h" | 13 #include "chrome/test/base/testing_pref_service.h" |
| 14 #include "content/common/main_function_params.h" | 14 #include "content/common/main_function_params.h" |
| 15 #include "content/common/sandbox_init_wrapper.h" | |
| 16 #include "content/public/browser/content_browser_client.h" | 15 #include "content/public/browser/content_browser_client.h" |
| 17 #include "net/socket/client_socket_pool_base.h" | 16 #include "net/socket/client_socket_pool_base.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 18 |
| 20 class BrowserMainTest : public testing::Test { | 19 class BrowserMainTest : public testing::Test { |
| 21 public: | 20 public: |
| 22 BrowserMainTest() : command_line_(CommandLine::NO_PROGRAM) {} | 21 BrowserMainTest() : command_line_(CommandLine::NO_PROGRAM) {} |
| 22 |
| 23 protected: | 23 protected: |
| 24 virtual void SetUp() { | |
| 25 sandbox_init_wrapper_.reset(new SandboxInitWrapper()); | |
| 26 } | |
| 27 | |
| 28 scoped_ptr<SandboxInitWrapper> sandbox_init_wrapper_; | |
| 29 TestingPrefService pref_service_; | 24 TestingPrefService pref_service_; |
| 30 CommandLine command_line_; | 25 CommandLine command_line_; |
| 31 }; | 26 }; |
| 32 | 27 |
| 33 TEST_F(BrowserMainTest, WarmConnectionFieldTrial_WarmestSocket) { | 28 TEST_F(BrowserMainTest, WarmConnectionFieldTrial_WarmestSocket) { |
| 34 command_line_.AppendSwitchASCII(switches::kSocketReusePolicy, "0"); | 29 command_line_.AppendSwitchASCII(switches::kSocketReusePolicy, "0"); |
| 35 | 30 |
| 36 scoped_ptr<MainFunctionParams> params( | 31 scoped_ptr<MainFunctionParams> params(new MainFunctionParams(command_line_)); |
| 37 new MainFunctionParams(command_line_, *sandbox_init_wrapper_, NULL)); | |
| 38 ScopedVector<content::BrowserMainParts> bwv; | 32 ScopedVector<content::BrowserMainParts> bwv; |
| 39 content::GetContentClient()->browser()->CreateBrowserMainParts( | 33 content::GetContentClient()->browser()->CreateBrowserMainParts( |
| 40 *params, &(bwv.get())); | 34 *params, &(bwv.get())); |
| 41 ChromeBrowserMainParts* cbw = NULL; | 35 ChromeBrowserMainParts* cbw = NULL; |
| 42 if (bwv.size() >= 1) | 36 if (bwv.size() >= 1) |
| 43 cbw = static_cast<ChromeBrowserMainParts*>(bwv[0]); | 37 cbw = static_cast<ChromeBrowserMainParts*>(bwv[0]); |
| 44 EXPECT_TRUE(cbw); | 38 EXPECT_TRUE(cbw); |
| 45 if (cbw) { | 39 if (cbw) { |
| 46 cbw->WarmConnectionFieldTrial(); | 40 cbw->WarmConnectionFieldTrial(); |
| 47 EXPECT_EQ(0, net::GetSocketReusePolicy()); | 41 EXPECT_EQ(0, net::GetSocketReusePolicy()); |
| 48 } | 42 } |
| 49 } | 43 } |
| 50 | 44 |
| 51 TEST_F(BrowserMainTest, WarmConnectionFieldTrial_Random) { | 45 TEST_F(BrowserMainTest, WarmConnectionFieldTrial_Random) { |
| 52 scoped_ptr<MainFunctionParams> params( | 46 scoped_ptr<MainFunctionParams> params(new MainFunctionParams(command_line_)); |
| 53 new MainFunctionParams(command_line_, *sandbox_init_wrapper_, NULL)); | |
| 54 ScopedVector<content::BrowserMainParts> bwv; | 47 ScopedVector<content::BrowserMainParts> bwv; |
| 55 content::GetContentClient()->browser()->CreateBrowserMainParts( | 48 content::GetContentClient()->browser()->CreateBrowserMainParts( |
| 56 *params, &(bwv.get())); | 49 *params, &(bwv.get())); |
| 57 ChromeBrowserMainParts* cbw = NULL; | 50 ChromeBrowserMainParts* cbw = NULL; |
| 58 if (bwv.size() >= 1) | 51 if (bwv.size() >= 1) |
| 59 cbw = static_cast<ChromeBrowserMainParts*>(bwv[0]); | 52 cbw = static_cast<ChromeBrowserMainParts*>(bwv[0]); |
| 60 EXPECT_TRUE(cbw); | 53 EXPECT_TRUE(cbw); |
| 61 if (cbw) { | 54 if (cbw) { |
| 62 const int kNumRuns = 1000; | 55 const int kNumRuns = 1000; |
| 63 for (int i = 0; i < kNumRuns; i++) { | 56 for (int i = 0; i < kNumRuns; i++) { |
| 64 cbw->WarmConnectionFieldTrial(); | 57 cbw->WarmConnectionFieldTrial(); |
| 65 int val = net::GetSocketReusePolicy(); | 58 int val = net::GetSocketReusePolicy(); |
| 66 EXPECT_LE(val, 2); | 59 EXPECT_LE(val, 2); |
| 67 EXPECT_GE(val, 0); | 60 EXPECT_GE(val, 0); |
| 68 } | 61 } |
| 69 } | 62 } |
| 70 } | 63 } |
| 71 | 64 |
| 72 TEST_F(BrowserMainTest, WarmConnectionFieldTrial_Invalid) { | 65 TEST_F(BrowserMainTest, WarmConnectionFieldTrial_Invalid) { |
| 73 command_line_.AppendSwitchASCII(switches::kSocketReusePolicy, "100"); | 66 command_line_.AppendSwitchASCII(switches::kSocketReusePolicy, "100"); |
| 74 | 67 |
| 75 scoped_ptr<MainFunctionParams> params( | 68 scoped_ptr<MainFunctionParams> params(new MainFunctionParams(command_line_)); |
| 76 new MainFunctionParams(command_line_, *sandbox_init_wrapper_, NULL)); | |
| 77 // This test ends up launching a new process, and that doesn't initialize the | 69 // This test ends up launching a new process, and that doesn't initialize the |
| 78 // ContentClient interfaces. | 70 // ContentClient interfaces. |
| 79 ScopedVector<content::BrowserMainParts> bwv; | 71 ScopedVector<content::BrowserMainParts> bwv; |
| 80 if (content::GetContentClient()) { | 72 if (content::GetContentClient()) { |
| 81 content::GetContentClient()->browser()->CreateBrowserMainParts( | 73 content::GetContentClient()->browser()->CreateBrowserMainParts( |
| 82 *params, &(bwv.get())); | 74 *params, &(bwv.get())); |
| 83 } else { | 75 } else { |
| 84 chrome::ChromeContentBrowserClient ccbc; | 76 chrome::ChromeContentBrowserClient ccbc; |
| 85 ccbc.CreateBrowserMainParts(*params, &(bwv.get())); | 77 ccbc.CreateBrowserMainParts(*params, &(bwv.get())); |
| 86 } | 78 } |
| 87 ChromeBrowserMainParts* cbw = NULL; | 79 ChromeBrowserMainParts* cbw = NULL; |
| 88 if (bwv.size() >= 1) | 80 if (bwv.size() >= 1) |
| 89 cbw = static_cast<ChromeBrowserMainParts*>(bwv[0]); | 81 cbw = static_cast<ChromeBrowserMainParts*>(bwv[0]); |
| 90 EXPECT_TRUE(cbw); | 82 EXPECT_TRUE(cbw); |
| 91 if (cbw) { | 83 if (cbw) { |
| 92 #if defined(NDEBUG) && defined(DCHECK_ALWAYS_ON) | 84 #if defined(NDEBUG) && defined(DCHECK_ALWAYS_ON) |
| 93 EXPECT_DEATH(cbw->WarmConnectionFieldTrial(), | 85 EXPECT_DEATH(cbw->WarmConnectionFieldTrial(), |
| 94 "Not a valid socket reuse policy group"); | 86 "Not a valid socket reuse policy group"); |
| 95 #else | 87 #else |
| 96 EXPECT_DEBUG_DEATH(cbw->WarmConnectionFieldTrial(), | 88 EXPECT_DEBUG_DEATH(cbw->WarmConnectionFieldTrial(), |
| 97 "Not a valid socket reuse policy group"); | 89 "Not a valid socket reuse policy group"); |
| 98 #endif | 90 #endif |
| 99 } | 91 } |
| 100 } | 92 } |
| OLD | NEW |