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

Side by Side Diff: chrome/browser/domain_reliability/browsertest.cc

Issue 2336043007: Domain Reliability: Don't crash on shutdown with uploads pending (Closed)
Patch Set: Remove outdated comment. Created 4 years 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
OLDNEW
(Empty)
1 // Copyright 2016 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 "base/command_line.h"
6 #include "base/macros.h"
7 #include "base/memory/ptr_util.h"
8 #include "chrome/browser/domain_reliability/service_factory.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "chrome/test/base/in_process_browser_test.h"
13 #include "chrome/test/base/ui_test_utils.h"
14 #include "components/domain_reliability/service.h"
15 #include "net/base/net_errors.h"
16 #include "net/test/url_request/url_request_failed_job.h"
17 #include "url/gurl.h"
18
19 namespace domain_reliability {
20
21 class DomainReliabilityBrowserTest : public InProcessBrowserTest {
22 public:
23 DomainReliabilityBrowserTest() {
24 net::URLRequestFailedJob::AddUrlHandler();
25 }
26
27 ~DomainReliabilityBrowserTest() override {}
28
29 // Note: In an ideal world, instead of appending the command-line switch and
30 // manually setting discard_uploads to false, Domain Reliability would
31 // continuously monitor the metrics reporting pref, and the test could just
32 // set the pref.
33
34 void SetUpCommandLine(base::CommandLine* command_line) override {
35 command_line->AppendSwitch(switches::kEnableDomainReliability);
36 }
37
38 void SetUpOnMainThread() override {
39 InProcessBrowserTest::SetUpOnMainThread();
40
41 DomainReliabilityService* service = GetService();
42 if (service)
43 service->SetDiscardUploadsForTesting(false);
44 }
45
46 DomainReliabilityService* GetService() {
47 return DomainReliabilityServiceFactory::GetForBrowserContext(
48 browser()->profile());
49 }
50
51 private:
52 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityBrowserTest);
53 };
54
55 class DomainReliabilityDisabledBrowserTest
56 : public DomainReliabilityBrowserTest {
57 protected:
58 DomainReliabilityDisabledBrowserTest() {}
59
60 ~DomainReliabilityDisabledBrowserTest() override {}
61
62 void SetUpCommandLine(base::CommandLine* command_line) override {
63 command_line->AppendSwitch(switches::kDisableDomainReliability);
64 }
65
66 private:
67 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityDisabledBrowserTest);
68 };
69
70 IN_PROC_BROWSER_TEST_F(DomainReliabilityDisabledBrowserTest,
71 ServiceNotCreated) {
72 EXPECT_FALSE(GetService());
73 }
74
75 IN_PROC_BROWSER_TEST_F(DomainReliabilityBrowserTest, ServiceCreated) {
76 EXPECT_TRUE(GetService());
77 }
78
79 IN_PROC_BROWSER_TEST_F(DomainReliabilityBrowserTest, UploadAtShutdown) {
80 DomainReliabilityService* service = GetService();
81
82 auto config = base::MakeUnique<DomainReliabilityConfig>();
83 config->origin = GURL("https://localhost/");
84 config->include_subdomains = false;
85 config->collectors.push_back(new GURL(
86 net::URLRequestFailedJob::GetMockHttpsUrl(net::ERR_IO_PENDING)));
87 config->success_sample_rate = 1.0;
88 config->failure_sample_rate = 1.0;
89 service->AddContextForTesting(std::move(config));
90
91 ui_test_utils::NavigateToURL(browser(), GURL("https://localhost/"));
92
93 service->ForceUploadsForTesting();
94
95 // At this point, there is an upload pending. If everything goes well, the
96 // test will finish, destroy the profile, and Domain Reliability will shut
97 // down properly. If things go awry, it may crash as terminating the pending
98 // upload calls into already-destroyed parts of the component.
99 }
100
101 } // namespace domain_reliability
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data/browsing_data_remover_unittest.cc ('k') | chrome/browser/net/chrome_network_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698