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 "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 |
OLD | NEW |