OLD | NEW |
---|---|
(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 "chrome/browser/domain_reliability/service_factory.h" | |
8 #include "chrome/browser/profiles/profile.h" | |
9 #include "chrome/browser/ui/browser.h" | |
10 #include "chrome/common/chrome_switches.h" | |
11 #include "chrome/test/base/in_process_browser_test.h" | |
12 #include "chrome/test/base/ui_test_utils.h" | |
13 #include "components/domain_reliability/service.h" | |
14 #include "net/test/url_request/url_request_hanging_read_job.h" | |
15 | |
16 namespace domain_reliability { | |
17 | |
18 class DomainReliabilityBrowserTest : public InProcessBrowserTest { | |
mmenke
2016/12/14 19:12:17
Should probably call this file domain_reliability_
Julia Tuttle
2016/12/15 21:52:59
It's not a test of *just* the service, and Domain
| |
19 protected: | |
mmenke
2016/12/14 19:12:17
optional: Suggest just making these public, as pr
Julia Tuttle
2016/12/15 21:52:59
Done.
| |
20 DomainReliabilityBrowserTest() { | |
21 // Note: This test's use of URLRequestHangingReadJob only works because the | |
22 // Uploader currently uses a URLFetcher, and therefore doesn't return from | |
23 // uploads until the body is completely downloaded. | |
24 // | |
25 // If some day it switches to returning after the headers and canceling the | |
26 // request after it has a response code, this test will need to use the | |
27 // (non-existent) URLRequestHangingStartJob. | |
28 net::URLRequestHangingReadJob::AddUrlHandler(); | |
mmenke
2016/12/14 19:12:17
See URLRequestFailedJob::GetMockHttp[s]Url(net::ER
Julia Tuttle
2016/12/15 21:53:00
Oh! Good call. Done.
| |
29 } | |
30 | |
31 ~DomainReliabilityBrowserTest() override {} | |
32 | |
33 // Note: In an ideal world, instead of appending the command-line switch and | |
34 // manually setting discard_uploads to false, Domain Reliability would | |
35 // continuously monitor the metrics reporting pref, and the test could just | |
36 // set the pref. | |
37 | |
38 void SetUpCommandLine(base::CommandLine* command_line) override { | |
39 command_line->AppendSwitch(switches::kEnableDomainReliability); | |
40 } | |
41 | |
42 void SetUpOnMainThread() override { | |
43 InProcessBrowserTest::SetUpOnMainThread(); | |
44 | |
45 DomainReliabilityService* service = GetService(); | |
46 if (service) | |
47 service->SetDiscardUploadsForTesting(false); | |
48 } | |
49 | |
50 DomainReliabilityService* GetService() { | |
51 return DomainReliabilityServiceFactory::GetForBrowserContext( | |
52 browser()->profile()); | |
53 } | |
54 | |
55 private: | |
56 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityBrowserTest); | |
57 }; | |
58 | |
59 class DomainReliabilityDisabledBrowserTest | |
60 : public DomainReliabilityBrowserTest { | |
61 protected: | |
62 DomainReliabilityDisabledBrowserTest() {} | |
63 | |
64 ~DomainReliabilityDisabledBrowserTest() override {} | |
65 | |
66 void SetUpCommandLine(base::CommandLine* command_line) override { | |
67 command_line->AppendSwitch(switches::kDisableDomainReliability); | |
68 } | |
69 | |
70 private: | |
71 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityDisabledBrowserTest); | |
72 }; | |
73 | |
74 IN_PROC_BROWSER_TEST_F(DomainReliabilityDisabledBrowserTest, | |
75 ServiceNotCreated) { | |
76 EXPECT_FALSE(GetService()); | |
77 } | |
78 | |
79 IN_PROC_BROWSER_TEST_F(DomainReliabilityBrowserTest, ServiceCreated) { | |
80 EXPECT_TRUE(GetService()); | |
81 } | |
82 | |
83 IN_PROC_BROWSER_TEST_F(DomainReliabilityBrowserTest, UploadAtShutdown) { | |
84 DomainReliabilityService* service = GetService(); | |
85 | |
86 auto config = base::MakeUnique<DomainReliabilityConfig>(); | |
mmenke
2016/12/14 19:12:17
include base/memory/ptr_util.h
Julia Tuttle
2016/12/15 21:52:59
Done.
| |
87 config->origin = GURL("https://localhost/"); | |
mmenke
2016/12/14 19:12:17
include gurl.h
Julia Tuttle
2016/12/15 21:53:00
Done.
| |
88 config->include_subdomains = false; | |
89 config->collectors.push_back( | |
90 new GURL(net::URLRequestHangingReadJob::GetMockHttpsUrl())); | |
91 config->success_sample_rate = 1.0; | |
92 config->failure_sample_rate = 1.0; | |
93 service->AddContextForTesting(std::move(config)); | |
94 | |
95 ui_test_utils::NavigateToURL(browser(), GURL("https://localhost/")); | |
96 | |
97 service->ForceUploadsForTesting(); | |
mmenke
2016/12/14 19:12:17
Think you need a comment about what this actually
Julia Tuttle
2016/12/15 21:52:59
Done.
| |
98 } | |
99 | |
100 } // namespace domain_reliability | |
OLD | NEW |