Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: chrome/test/perf/mach_ports_performancetest.cc

Issue 2901113003: Fix breakages while performance_browser_tests was not running on Mac. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/test/BUILD.gn ('k') | media/cast/test/utility/standalone_cast_environment.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <mach/mach.h> 5 #include <mach/mach.h>
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_window.h" 13 #include "chrome/browser/ui/browser_window.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" 14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "chrome/test/base/in_process_browser_test.h" 15 #include "chrome/test/base/in_process_browser_test.h"
16 #include "net/test/embedded_test_server/embedded_test_server.h" 16 #include "net/test/embedded_test_server/embedded_test_server.h"
17 #include "testing/perf/perf_test.h" 17 #include "testing/perf/perf_test.h"
18 18
19 namespace { 19 namespace {
20 20
21 // This test spawns a new browser and counts the number of open Mach ports in 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 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, 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>. 24 // which was the source of <http://crbug.com/105513>.
25 class MachPortsTest : public InProcessBrowserTest { 25 class MachPortsTest : public InProcessBrowserTest {
26 public: 26 public:
27 MachPortsTest() { 27 MachPortsTest() {
28 server_.ServeFilesFromSourceDirectory("data/mach_ports/moz"); 28 embedded_test_server()->ServeFilesFromSourceDirectory(
29 "data/mach_ports/moz");
29 } 30 }
30 31
31 void SetUp() override { 32 void SetUpOnMainThread() override {
32 InProcessBrowserTest::SetUp(); 33 InProcessBrowserTest::SetUpOnMainThread();
33 34 ASSERT_TRUE(embedded_test_server()->Start());
34 ASSERT_TRUE(server_.Start());
35 } 35 }
36 36
37 void TearDown() override { 37 void TearDown() override {
38 std::string ports; 38 std::string ports;
39 for (std::vector<int>::iterator it = port_counts_.begin(); 39 for (std::vector<int>::iterator it = port_counts_.begin();
40 it != port_counts_.end(); ++it) { 40 it != port_counts_.end(); ++it) {
41 base::StringAppendF(&ports, "%d,", *it); 41 base::StringAppendF(&ports, "%d,", *it);
42 } 42 }
43 perf_test::PrintResultList("mach_ports", "", "", ports, "ports", true); 43 perf_test::PrintResultList("mach_ports", "", "", ports, "ports", true);
44 44
(...skipping 20 matching lines...) Expand all
65 port_counts_.push_back(names_count); 65 port_counts_.push_back(names_count);
66 66
67 vm_deallocate(self, reinterpret_cast<vm_address_t>(names), 67 vm_deallocate(self, reinterpret_cast<vm_address_t>(names),
68 names_count * sizeof(mach_port_name_array_t)); 68 names_count * sizeof(mach_port_name_array_t));
69 vm_deallocate(self, reinterpret_cast<vm_address_t>(types), 69 vm_deallocate(self, reinterpret_cast<vm_address_t>(types),
70 types_count * sizeof(mach_port_type_array_t)); 70 types_count * sizeof(mach_port_type_array_t));
71 } 71 }
72 72
73 // Adds a tab from the page cycler data at the specified domain. 73 // Adds a tab from the page cycler data at the specified domain.
74 void AddTab(const std::string& domain) { 74 void AddTab(const std::string& domain) {
75 GURL url = server_.GetURL("/" + domain + "/").Resolve("?skip"); 75 AddTabAtIndex(
76 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED); 76 0, embedded_test_server()->GetURL("/" + domain + "/").Resolve("?skip"),
77 ui::PAGE_TRANSITION_TYPED);
77 } 78 }
78 79
79 private: 80 private:
80 net::EmbeddedTestServer server_;
81 std::vector<int> port_counts_; 81 std::vector<int> port_counts_;
82 }; 82 };
83 83
84 IN_PROC_BROWSER_TEST_F(MachPortsTest, GetCounts) { 84 IN_PROC_BROWSER_TEST_F(MachPortsTest, GetCounts) {
85 browser()->window()->Show(); 85 browser()->window()->Show();
86 86
87 // Record startup number. 87 // Record startup number.
88 RecordPortCount(); 88 RecordPortCount();
89 89
90 // Create a browser and open a few tabs. 90 // Create a browser and open a few tabs.
(...skipping 13 matching lines...) Expand all
104 // Close each tab, recording the number of ports after each. Do not close the 104 // Close each tab, recording the number of ports after each. Do not close the
105 // last tab, which is about:blank. 105 // last tab, which is about:blank.
106 for (int i = 0; i < tab_count - 1; ++i) { 106 for (int i = 0; i < tab_count - 1; ++i) {
107 EXPECT_TRUE( 107 EXPECT_TRUE(
108 tab_strip_model->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE)); 108 tab_strip_model->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE));
109 RecordPortCount(); 109 RecordPortCount();
110 } 110 }
111 } 111 }
112 112
113 } // namespace 113 } // namespace
OLDNEW
« no previous file with comments | « chrome/test/BUILD.gn ('k') | media/cast/test/utility/standalone_cast_environment.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698