Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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 <vector> | |
| 6 | |
| 7 #include "base/memory/ref_counted.h" | |
| 8 #include "base/string_util.h" | |
| 9 #include "chrome/common/automation_constants.h" | |
| 10 #include "chrome/common/automation_messages.h" | |
| 11 #include "chrome/test/automation/automation_proxy.h" | |
| 12 #include "chrome/test/automation/browser_proxy.h" | |
| 13 #include "chrome/test/automation/tab_proxy.h" | |
| 14 #include "chrome/test/automation/window_proxy.h" | |
| 15 #include "chrome/test/perf/perf_test.h" | |
| 16 #include "chrome/test/ui/ui_perf_test.h" | |
| 17 #include "net/test/test_server.h" | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 // This test spawns a new browser and counts the number of open Mach ports in | |
| 22 // the browser process. It navigates tabs and closes them, repeatedly measuring | |
| 23 // the number of open ports. This is used to protect against leaking Mach ports, | |
| 24 // which was the source of <http://crbug.com/105513>. | |
| 25 class MachPortsTest : public UIPerfTest { | |
| 26 public: | |
| 27 MachPortsTest() | |
| 28 : server_(net::TestServer::TYPE_HTTP, | |
| 29 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.
| |
| 30 } | |
| 31 | |
| 32 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
| |
| 33 UIPerfTest::SetUp(); | |
| 34 | |
| 35 ASSERT_TRUE(server_.Start()); | |
| 36 } | |
| 37 | |
| 38 virtual void TearDown() OVERRIDE { | |
| 39 std::string ports; | |
| 40 for (std::vector<int>::iterator it = port_counts_.begin(); | |
| 41 it != port_counts_.end(); ++it) { | |
| 42 base::StringAppendF(&ports, "%d,", *it); | |
| 43 } | |
| 44 perf_test::PrintResultList("mach_ports", "", "", ports, "ports", true); | |
| 45 | |
| 46 UIPerfTest::TearDown(); | |
| 47 } | |
| 48 | |
| 49 // Gets the browser's current number of Mach ports and records it. | |
| 50 void RecordPortCount() { | |
| 51 int port_count = 0; | |
| 52 ASSERT_TRUE(automation()->Send( | |
| 53 new AutomationMsg_GetMachPortCount(&port_count))); | |
| 54 port_counts_.push_back(port_count); | |
| 55 } | |
| 56 | |
| 57 // Adds a tab from the page cycler data at the specified domain. | |
| 58 bool AddTab(scoped_refptr<BrowserProxy> browser, const std::string& domain) { | |
| 59 GURL url = server_.GetURL("files/" + domain + "/").Resolve("?skip"); | |
| 60 return browser->AppendTab(url); | |
| 61 } | |
| 62 | |
| 63 private: | |
| 64 net::TestServer server_; | |
| 65 std::vector<int> port_counts_; | |
| 66 }; | |
| 67 | |
| 68 TEST_F(MachPortsTest, GetCounts) { | |
| 69 ASSERT_EQ(AUTOMATION_SUCCESS, automation()->WaitForAppLaunch()); | |
| 70 | |
| 71 // Record startup number. | |
| 72 RecordPortCount(); | |
| 73 | |
| 74 // Create a browser and open a few tabs. | |
| 75 scoped_refptr<WindowProxy> window(automation()->GetActiveWindow()); | |
| 76 ASSERT_TRUE(window.get()); | |
| 77 | |
| 78 scoped_refptr<BrowserProxy> browser(automation()->FindTabbedBrowserWindow()); | |
| 79 ASSERT_TRUE(browser.get()); | |
| 80 | |
| 81 EXPECT_TRUE(AddTab(browser, "www.google.com")); | |
| 82 RecordPortCount(); | |
| 83 | |
| 84 EXPECT_TRUE(AddTab(browser, "www.cnn.com")); | |
| 85 RecordPortCount(); | |
| 86 | |
| 87 EXPECT_TRUE(AddTab(browser, "www.nytimes.com")); | |
| 88 RecordPortCount(); | |
| 89 | |
| 90 int tab_count = 0; | |
| 91 ASSERT_TRUE(browser->GetTabCount(&tab_count)); | |
| 92 EXPECT_EQ(4, tab_count); // Also count about:blank. | |
| 93 | |
| 94 // Close each tab, recording the number of ports after each. Do not close the | |
| 95 // last tab, which is about:blank because it will be closed by the proxy. | |
| 96 for (int i = 0; i < tab_count - 1; ++i) { | |
| 97 scoped_refptr<TabProxy> tab(browser->GetActiveTab()); | |
| 98 ASSERT_TRUE(tab.get()); | |
| 99 | |
| 100 EXPECT_TRUE(tab->Close(true)); | |
| 101 RecordPortCount(); | |
| 102 } | |
|
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.
| |
| 103 } | |
| 104 | |
| 105 } // namespace | |
| OLD | NEW |