Chromium Code Reviews| Index: chrome/test/perf/mach_ports_test.cc |
| diff --git a/chrome/test/perf/mach_ports_test.cc b/chrome/test/perf/mach_ports_test.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9aebcd2afd3d7e6ac97f23eb9ed9f9855d427045 |
| --- /dev/null |
| +++ b/chrome/test/perf/mach_ports_test.cc |
| @@ -0,0 +1,105 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include <vector> |
| + |
| +#include "base/memory/ref_counted.h" |
| +#include "base/string_util.h" |
| +#include "chrome/common/automation_constants.h" |
| +#include "chrome/common/automation_messages.h" |
| +#include "chrome/test/automation/automation_proxy.h" |
| +#include "chrome/test/automation/browser_proxy.h" |
| +#include "chrome/test/automation/tab_proxy.h" |
| +#include "chrome/test/automation/window_proxy.h" |
| +#include "chrome/test/perf/perf_test.h" |
| +#include "chrome/test/ui/ui_perf_test.h" |
| +#include "net/test/test_server.h" |
| + |
| +namespace { |
| + |
| +// This test spawns a new browser and counts the number of open Mach ports in |
| +// the browser process. It navigates tabs and closes them, repeatedly measuring |
| +// the number of open ports. This is used to protect against leaking Mach ports, |
| +// which was the source of <http://crbug.com/105513>. |
| +class MachPortsTest : public UIPerfTest { |
| + public: |
| + MachPortsTest() |
| + : server_(net::TestServer::TYPE_HTTP, |
| + FilePath(FILE_PATH_LITERAL("data/page_cycler/moz"))) { |
|
cmp
2012/01/23 21:20:51
Please create a new data set that's named to match
Robert Sesek
2012/01/23 21:58:41
Really? Why do I need a separate data set if this
cmp
2012/01/23 22:20:56
Sure, it would technically be a separate data set,
Robert Sesek
2012/01/27 19:10:41
Added a new data set per internal CL.
|
| + } |
| + |
| + virtual void SetUp() OVERRIDE { |
|
cmp
2012/01/23 21:20:51
I believe SetUp and TearDown can both be defined a
Robert Sesek
2012/01/23 21:58:41
In UITest, they're defined as OVERRIDE.
cmp
2012/01/23 22:20:56
cmp@terakrom:/work/chrome/trunk/src/chrome/test/pe
Robert Sesek
2012/01/27 19:10:41
The modifier is rather new, so old code may not ha
|
| + UIPerfTest::SetUp(); |
| + |
| + ASSERT_TRUE(server_.Start()); |
| + } |
| + |
| + virtual void TearDown() OVERRIDE { |
| + std::string ports; |
| + for (std::vector<int>::iterator it = port_counts_.begin(); |
| + it != port_counts_.end(); ++it) { |
| + base::StringAppendF(&ports, "%d,", *it); |
| + } |
| + perf_test::PrintResultList("mach_ports", "", "", ports, "ports", true); |
| + |
| + UIPerfTest::TearDown(); |
| + } |
| + |
| + // Gets the browser's current number of Mach ports and records it. |
| + void RecordPortCount() { |
| + int port_count = 0; |
| + ASSERT_TRUE(automation()->Send( |
| + new AutomationMsg_GetMachPortCount(&port_count))); |
| + port_counts_.push_back(port_count); |
| + } |
| + |
| + // Adds a tab from the page cycler data at the specified domain. |
| + bool AddTab(scoped_refptr<BrowserProxy> browser, const std::string& domain) { |
| + GURL url = server_.GetURL("files/" + domain + "/").Resolve("?skip"); |
| + return browser->AppendTab(url); |
| + } |
| + |
| + private: |
| + net::TestServer server_; |
| + std::vector<int> port_counts_; |
| +}; |
| + |
| +TEST_F(MachPortsTest, GetCounts) { |
| + ASSERT_EQ(AUTOMATION_SUCCESS, automation()->WaitForAppLaunch()); |
| + |
| + // Record startup number. |
| + RecordPortCount(); |
| + |
| + // Create a browser and open a few tabs. |
| + scoped_refptr<WindowProxy> window(automation()->GetActiveWindow()); |
| + ASSERT_TRUE(window.get()); |
| + |
| + scoped_refptr<BrowserProxy> browser(automation()->FindTabbedBrowserWindow()); |
| + ASSERT_TRUE(browser.get()); |
| + |
| + EXPECT_TRUE(AddTab(browser, "www.google.com")); |
| + RecordPortCount(); |
| + |
| + EXPECT_TRUE(AddTab(browser, "www.cnn.com")); |
| + RecordPortCount(); |
| + |
| + EXPECT_TRUE(AddTab(browser, "www.nytimes.com")); |
| + RecordPortCount(); |
| + |
| + int tab_count = 0; |
| + ASSERT_TRUE(browser->GetTabCount(&tab_count)); |
| + EXPECT_EQ(4, tab_count); // Also count about:blank. |
| + |
| + // Close each tab, recording the number of ports after each. Do not close the |
| + // last tab, which is about:blank because it will be closed by the proxy. |
| + for (int i = 0; i < tab_count - 1; ++i) { |
| + scoped_refptr<TabProxy> tab(browser->GetActiveTab()); |
| + ASSERT_TRUE(tab.get()); |
| + |
| + EXPECT_TRUE(tab->Close(true)); |
| + RecordPortCount(); |
| + } |
|
cmp
2012/01/23 21:20:51
Can the values returned by this test vary across t
Robert Sesek
2012/01/23 21:58:41
The values will vary slightly, but the mean (what
cmp
2012/01/23 22:20:56
Based on this, I will assume you won't need any re
Robert Sesek
2012/01/27 19:10:41
I think that's correct, yes.
|
| +} |
| + |
| +} // namespace |