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