OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/test/base/uma_histogram_helper.h" | 5 #include "base/test/histogram_tester.h" |
6 #include "chrome/test/nacl/nacl_browsertest_util.h" | 6 #include "chrome/test/nacl/nacl_browsertest_util.h" |
7 #include "components/nacl/browser/nacl_browser.h" | 7 #include "components/nacl/browser/nacl_browser.h" |
| 8 #include "content/public/test/browser_test_utils.h" |
8 #include "native_client/src/trusted/service_runtime/nacl_error_code.h" | 9 #include "native_client/src/trusted/service_runtime/nacl_error_code.h" |
9 #include "ppapi/c/private/ppb_nacl_private.h" | 10 #include "ppapi/c/private/ppb_nacl_private.h" |
10 | 11 |
11 namespace { | 12 namespace { |
12 | 13 |
13 NACL_BROWSER_TEST_F(NaClBrowserTest, SuccessfulLoadUMA, { | 14 NACL_BROWSER_TEST_F(NaClBrowserTest, SuccessfulLoadUMA, { |
| 15 base::HistogramTester histograms; |
14 // Load a NaCl module to generate UMA data. | 16 // Load a NaCl module to generate UMA data. |
15 RunLoadTest(FILE_PATH_LITERAL("nacl_load_test.html")); | 17 RunLoadTest(FILE_PATH_LITERAL("nacl_load_test.html")); |
16 | 18 |
17 // Make sure histograms from child processes have been accumulated in the | 19 // Make sure histograms from child processes have been accumulated in the |
18 // browser brocess. | 20 // browser brocess. |
19 UMAHistogramHelper histograms; | 21 content::FetchHistogramsData(); |
20 histograms.Fetch(); | |
21 | 22 |
22 // Did the plugin report success? | 23 // Did the plugin report success? |
23 histograms.ExpectUniqueSample("NaCl.LoadStatus.Plugin", | 24 histograms.ExpectUniqueSample("NaCl.LoadStatus.Plugin", |
24 PP_NACL_ERROR_LOAD_SUCCESS, 1); | 25 PP_NACL_ERROR_LOAD_SUCCESS, 1); |
25 | 26 |
26 // Did the sel_ldr report success? | 27 // Did the sel_ldr report success? |
27 histograms.ExpectUniqueSample("NaCl.LoadStatus.SelLdr", | 28 histograms.ExpectUniqueSample("NaCl.LoadStatus.SelLdr", |
28 LOAD_OK, 1); | 29 LOAD_OK, 1); |
29 | 30 |
30 // Check validation cache usage: | 31 // Check validation cache usage: |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 class NaClBrowserTestVcacheExtension: | 82 class NaClBrowserTestVcacheExtension: |
82 public NaClBrowserTestNewlibExtension { | 83 public NaClBrowserTestNewlibExtension { |
83 public: | 84 public: |
84 virtual base::FilePath::StringType Variant() OVERRIDE { | 85 virtual base::FilePath::StringType Variant() OVERRIDE { |
85 return FILE_PATH_LITERAL("extension_vcache_test/newlib"); | 86 return FILE_PATH_LITERAL("extension_vcache_test/newlib"); |
86 } | 87 } |
87 }; | 88 }; |
88 | 89 |
89 IN_PROC_BROWSER_TEST_F(NaClBrowserTestVcacheExtension, | 90 IN_PROC_BROWSER_TEST_F(NaClBrowserTestVcacheExtension, |
90 ValidationCacheOfMainNexe) { | 91 ValidationCacheOfMainNexe) { |
| 92 base::HistogramTester histograms; |
91 // Hardcoded extension AppID that corresponds to the hardcoded | 93 // Hardcoded extension AppID that corresponds to the hardcoded |
92 // public key in the manifest.json file. We need to load the extension | 94 // public key in the manifest.json file. We need to load the extension |
93 // nexe from the same origin, so we can't just try to load the extension | 95 // nexe from the same origin, so we can't just try to load the extension |
94 // nexe as a mime-type handler from a non-extension URL. | 96 // nexe as a mime-type handler from a non-extension URL. |
95 base::FilePath::StringType full_url = | 97 base::FilePath::StringType full_url = |
96 FILE_PATH_LITERAL("chrome-extension://cbcdidchbppangcjoddlpdjlenngjldk/") | 98 FILE_PATH_LITERAL("chrome-extension://cbcdidchbppangcjoddlpdjlenngjldk/") |
97 FILE_PATH_LITERAL("extension_validation_cache.html"); | 99 FILE_PATH_LITERAL("extension_validation_cache.html"); |
98 RunNaClIntegrationTest(full_url, true); | 100 RunNaClIntegrationTest(full_url, true); |
99 | 101 |
100 // Make sure histograms from child processes have been accumulated in the | 102 // Make sure histograms from child processes have been accumulated in the |
101 // browser brocess. | 103 // browser brocess. |
102 UMAHistogramHelper histograms; | 104 content::FetchHistogramsData(); |
103 histograms.Fetch(); | |
104 // Should have received 2 validation queries (one for IRT and one for NEXE), | 105 // Should have received 2 validation queries (one for IRT and one for NEXE), |
105 // and responded with a miss. | 106 // and responded with a miss. |
106 histograms.ExpectBucketCount("NaCl.ValidationCache.Query", | 107 histograms.ExpectBucketCount("NaCl.ValidationCache.Query", |
107 nacl::NaClBrowser::CACHE_MISS, 2); | 108 nacl::NaClBrowser::CACHE_MISS, 2); |
108 // TOTAL should then be 2 queries so far. | 109 // TOTAL should then be 2 queries so far. |
109 histograms.ExpectTotalCount("NaCl.ValidationCache.Query", 2); | 110 histograms.ExpectTotalCount("NaCl.ValidationCache.Query", 2); |
110 // Should have received a cache setting afterwards for IRT and nexe. | 111 // Should have received a cache setting afterwards for IRT and nexe. |
111 histograms.ExpectBucketCount("NaCl.ValidationCache.Set", | 112 histograms.ExpectBucketCount("NaCl.ValidationCache.Set", |
112 nacl::NaClBrowser::CACHE_HIT, 2); | 113 nacl::NaClBrowser::CACHE_HIT, 2); |
113 | 114 |
114 // Load it again to hit the cache. | 115 // Load it again to hit the cache. |
115 RunNaClIntegrationTest(full_url, true); | 116 RunNaClIntegrationTest(full_url, true); |
116 histograms.Fetch(); | 117 content::FetchHistogramsData(); |
117 // Should have received 2 more validation queries later (IRT and NEXE), | 118 // Should have received 2 more validation queries later (IRT and NEXE), |
118 // and responded with a hit. | 119 // and responded with a hit. |
119 histograms.ExpectBucketCount("NaCl.ValidationCache.Query", | 120 histograms.ExpectBucketCount("NaCl.ValidationCache.Query", |
120 nacl::NaClBrowser::CACHE_HIT, 2); | 121 nacl::NaClBrowser::CACHE_HIT, 2); |
121 // TOTAL should then be 4 queries now. | 122 // TOTAL should then be 4 queries now. |
122 histograms.ExpectTotalCount("NaCl.ValidationCache.Query", 4); | 123 histograms.ExpectTotalCount("NaCl.ValidationCache.Query", 4); |
123 // Still only 2 settings. | 124 // Still only 2 settings. |
124 histograms.ExpectTotalCount("NaCl.ValidationCache.Set", 2); | 125 histograms.ExpectTotalCount("NaCl.ValidationCache.Set", 2); |
125 } | 126 } |
126 | 127 |
127 // Test that validation for the 2 PNaCl translator nexes can be cached. | 128 // Test that validation for the 2 PNaCl translator nexes can be cached. |
128 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl, | 129 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl, |
129 ValidationCacheOfTranslatorNexes) { | 130 ValidationCacheOfTranslatorNexes) { |
| 131 base::HistogramTester histograms; |
130 // Run a load test w/ one pexe cache identity. | 132 // Run a load test w/ one pexe cache identity. |
131 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_0")); | 133 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_0")); |
132 | 134 |
133 UMAHistogramHelper histograms; | 135 content::FetchHistogramsData(); |
134 histograms.Fetch(); | |
135 // Should have received 3 validation queries: | 136 // Should have received 3 validation queries: |
136 // - One for IRT for actual application | 137 // - One for IRT for actual application |
137 // - Two for two translator nexes | 138 // - Two for two translator nexes |
138 // The translators don't currently use the IRT, so there is no IRT cache | 139 // The translators don't currently use the IRT, so there is no IRT cache |
139 // query for those two loads. The PNaCl main nexe comes from a | 140 // query for those two loads. The PNaCl main nexe comes from a |
140 // delete-on-close temp file, so it doesn't have a stable identity | 141 // delete-on-close temp file, so it doesn't have a stable identity |
141 // for validation caching. All three query results should be misses. | 142 // for validation caching. All three query results should be misses. |
142 histograms.ExpectUniqueSample("NaCl.ValidationCache.Query", | 143 histograms.ExpectUniqueSample("NaCl.ValidationCache.Query", |
143 nacl::NaClBrowser::CACHE_MISS, 3); | 144 nacl::NaClBrowser::CACHE_MISS, 3); |
144 // Should have received a cache setting afterwards for IRT and translators. | 145 // Should have received a cache setting afterwards for IRT and translators. |
(...skipping 14 matching lines...) Expand all Loading... |
159 // No extra cache settings. | 160 // No extra cache settings. |
160 histograms.ExpectUniqueSample("NaCl.ValidationCache.Set", | 161 histograms.ExpectUniqueSample("NaCl.ValidationCache.Set", |
161 nacl::NaClBrowser::CACHE_HIT, 3); | 162 nacl::NaClBrowser::CACHE_HIT, 3); |
162 } | 163 } |
163 | 164 |
164 | 165 |
165 // TODO(ncbray) convert the rest of nacl_uma.py (currently in the NaCl repo.) | 166 // TODO(ncbray) convert the rest of nacl_uma.py (currently in the NaCl repo.) |
166 // Test validation failures and crashes. | 167 // Test validation failures and crashes. |
167 | 168 |
168 } // namespace | 169 } // namespace |
OLD | NEW |