OLD | NEW |
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/spawned_test_server/spawned_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_(net::SpawnedTestServer::TYPE_HTTP, | 28 server_.ServeFilesFromSourceDirectory("data/mach_ports/moz"); |
29 net::SpawnedTestServer::kLocalhost, | |
30 base::FilePath(FILE_PATH_LITERAL("data/mach_ports/moz"))) { | |
31 } | 29 } |
32 | 30 |
33 void SetUp() override { | 31 void SetUp() override { |
34 InProcessBrowserTest::SetUp(); | 32 InProcessBrowserTest::SetUp(); |
35 | 33 |
36 ASSERT_TRUE(server_.Start()); | 34 ASSERT_TRUE(server_.Start()); |
37 } | 35 } |
38 | 36 |
39 void TearDown() override { | 37 void TearDown() override { |
40 std::string ports; | 38 std::string ports; |
(...skipping 26 matching lines...) Expand all Loading... |
67 port_counts_.push_back(names_count); | 65 port_counts_.push_back(names_count); |
68 | 66 |
69 vm_deallocate(self, reinterpret_cast<vm_address_t>(names), | 67 vm_deallocate(self, reinterpret_cast<vm_address_t>(names), |
70 names_count * sizeof(mach_port_name_array_t)); | 68 names_count * sizeof(mach_port_name_array_t)); |
71 vm_deallocate(self, reinterpret_cast<vm_address_t>(types), | 69 vm_deallocate(self, reinterpret_cast<vm_address_t>(types), |
72 types_count * sizeof(mach_port_type_array_t)); | 70 types_count * sizeof(mach_port_type_array_t)); |
73 } | 71 } |
74 | 72 |
75 // 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. |
76 void AddTab(const std::string& domain) { | 74 void AddTab(const std::string& domain) { |
77 GURL url = server_.GetURL("files/" + domain + "/").Resolve("?skip"); | 75 GURL url = server_.GetURL("/" + domain + "/").Resolve("?skip"); |
78 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED); | 76 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED); |
79 } | 77 } |
80 | 78 |
81 private: | 79 private: |
82 net::SpawnedTestServer server_; | 80 net::EmbeddedTestServer server_; |
83 std::vector<int> port_counts_; | 81 std::vector<int> port_counts_; |
84 }; | 82 }; |
85 | 83 |
86 IN_PROC_BROWSER_TEST_F(MachPortsTest, GetCounts) { | 84 IN_PROC_BROWSER_TEST_F(MachPortsTest, GetCounts) { |
87 browser()->window()->Show(); | 85 browser()->window()->Show(); |
88 | 86 |
89 // Record startup number. | 87 // Record startup number. |
90 RecordPortCount(); | 88 RecordPortCount(); |
91 | 89 |
92 // Create a browser and open a few tabs. | 90 // Create a browser and open a few tabs. |
(...skipping 13 matching lines...) Expand all Loading... |
106 // 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 |
107 // last tab, which is about:blank. | 105 // last tab, which is about:blank. |
108 for (int i = 0; i < tab_count - 1; ++i) { | 106 for (int i = 0; i < tab_count - 1; ++i) { |
109 EXPECT_TRUE( | 107 EXPECT_TRUE( |
110 tab_strip_model->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE)); | 108 tab_strip_model->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE)); |
111 RecordPortCount(); | 109 RecordPortCount(); |
112 } | 110 } |
113 } | 111 } |
114 | 112 |
115 } // namespace | 113 } // namespace |
OLD | NEW |