[M120][Tizen][Onscreen] Fix build errors for TV profile
[platform/framework/web/chromium-efl.git] / chrome / browser / chrome_data_use_measurement_browsertest.cc
1 // Copyright 2022 The Chromium Authors
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 "base/run_loop.h"
6 #include "base/task/thread_pool/thread_pool_instance.h"
7 #include "build/build_config.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/test/base/in_process_browser_test.h"
11 #include "chrome/test/base/ui_test_utils.h"
12 #include "components/metrics/content/subprocess_metrics_provider.h"
13 #include "content/public/test/browser_test.h"
14 #include "content/public/test/browser_test_utils.h"
15 #include "content/public/test/content_browser_test.h"
16 #include "services/network/public/cpp/features.h"
17 #include "testing/gmock/include/gmock/gmock.h"
18
19 class ChromeDataUseMeasurementBrowserTest : public InProcessBrowserTest {
20  protected:
21   void SetUpOnMainThread() override {
22     embedded_test_server()->ServeFilesFromSourceDirectory(
23         GetChromeTestDataDir());
24     ASSERT_TRUE(embedded_test_server()->Start());
25   }
26
27   size_t GetTotalDataUse() const {
28     return histogram_tester_.GetTotalSum("DataUse.BytesReceived3.Delegate") +
29            histogram_tester_.GetTotalSum("DataUse.BytesSent3.Delegate");
30   }
31
32   void RetryUntilUserInitiatedDataUsePrefHasEntry() {
33     do {
34       base::ThreadPoolInstance::Get()->FlushForTesting();
35       base::RunLoop().RunUntilIdle();
36       content::FetchHistogramsFromChildProcesses();
37       metrics::SubprocessMetricsProvider::MergeHistogramDeltasForTesting();
38     } while (GetTotalDataUse() == 0);
39   }
40
41  private:
42   base::HistogramTester histogram_tester_;
43 };
44
45 IN_PROC_BROWSER_TEST_F(ChromeDataUseMeasurementBrowserTest, DataUseRecorded) {
46   ASSERT_TRUE(ui_test_utils::NavigateToURL(
47       browser(), embedded_test_server()->GetURL("/title1.html")));
48   RetryUntilUserInitiatedDataUsePrefHasEntry();
49
50   EXPECT_GT(GetTotalDataUse(), 0u);
51 }