OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/chromeos/proxy_config_service_impl.h" | 5 #include "chrome/browser/chromeos/proxy_config_service_impl.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 class ProxyChangedObserver : public net::ProxyConfigService::Observer { | 540 class ProxyChangedObserver : public net::ProxyConfigService::Observer { |
541 public: | 541 public: |
542 explicit ProxyChangedObserver( | 542 explicit ProxyChangedObserver( |
543 const scoped_refptr<ProxyConfigServiceImpl>& config_service) | 543 const scoped_refptr<ProxyConfigServiceImpl>& config_service) |
544 : config_service_(config_service) { | 544 : config_service_(config_service) { |
545 config_service_->AddObserver(this); | 545 config_service_->AddObserver(this); |
546 } | 546 } |
547 virtual ~ProxyChangedObserver() { | 547 virtual ~ProxyChangedObserver() { |
548 config_service_->RemoveObserver(this); | 548 config_service_->RemoveObserver(this); |
549 } | 549 } |
| 550 net::ProxyConfigService::ConfigAvailability availability() const { |
| 551 return availability_; |
| 552 } |
550 const net::ProxyConfig& config() const { | 553 const net::ProxyConfig& config() const { |
551 return config_; | 554 return config_; |
552 } | 555 } |
553 | 556 |
554 private: | 557 private: |
555 virtual void OnProxyConfigChanged(const net::ProxyConfig& config) { | 558 virtual void OnProxyConfigChanged( |
| 559 const net::ProxyConfig& config, |
| 560 net::ProxyConfigService::ConfigAvailability availability) { |
556 config_ = config; | 561 config_ = config; |
| 562 availability_ = availability; |
557 } | 563 } |
558 | 564 |
559 scoped_refptr<ProxyConfigServiceImpl> config_service_; | 565 scoped_refptr<ProxyConfigServiceImpl> config_service_; |
| 566 net::ProxyConfigService::ConfigAvailability availability_; |
560 net::ProxyConfig config_; | 567 net::ProxyConfig config_; |
561 }; | 568 }; |
562 | 569 |
563 // Init with direct. | 570 // Init with direct. |
564 ProxyConfigServiceImpl::ProxyConfig init_config; | 571 ProxyConfigServiceImpl::ProxyConfig init_config; |
565 SetAutomaticProxy(MK_MODE(DIRECT), MK_SRC(OWNER), NULL, &init_config, | 572 SetAutomaticProxy(MK_MODE(DIRECT), MK_SRC(OWNER), NULL, &init_config, |
566 &init_config.automatic_proxy); | 573 &init_config.automatic_proxy); |
567 CreateConfigService(init_config); | 574 CreateConfigService(init_config); |
568 | 575 |
569 ProxyChangedObserver observer(config_service()); | 576 ProxyChangedObserver observer(config_service()); |
570 | 577 |
571 // Set to pac script from UI. | 578 // Set to pac script from UI. |
572 EXPECT_TRUE(config_service()->UISetProxyConfigToPACScript( | 579 EXPECT_TRUE(config_service()->UISetProxyConfigToPACScript( |
573 GURL("http://wpad.dat"))); | 580 GURL("http://wpad.dat"))); |
574 // Retrieve config from IO thread. | 581 // Retrieve config from IO thread. |
575 net::ProxyConfig io_config; | 582 net::ProxyConfig io_config; |
576 SyncGetLatestProxyConfig(&io_config); | 583 SyncGetLatestProxyConfig(&io_config); |
577 | 584 |
578 // Observer should have gotten the same new proxy config. | 585 // Observer should have gotten the same new proxy config. |
| 586 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID, observer.availability()); |
579 EXPECT_TRUE(io_config.Equals(observer.config())); | 587 EXPECT_TRUE(io_config.Equals(observer.config())); |
580 } | 588 } |
581 | 589 |
582 TEST_F(ProxyConfigServiceImplTest, SerializeAndDeserialize) { | 590 TEST_F(ProxyConfigServiceImplTest, SerializeAndDeserialize) { |
583 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 591 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
584 if (!tests[i].is_valid) | 592 if (!tests[i].is_valid) |
585 continue; | 593 continue; |
586 | 594 |
587 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i, | 595 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i, |
588 tests[i].description.c_str())); | 596 tests[i].description.c_str())); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 TestReadWriteAccessForScheme(MK_SRC(POLICY), socks_uri, "socks"); | 659 TestReadWriteAccessForScheme(MK_SRC(POLICY), socks_uri, "socks"); |
652 | 660 |
653 // Init with owner source. | 661 // Init with owner source. |
654 TestReadWriteAccessForScheme(MK_SRC(OWNER), http_uri, "http"); | 662 TestReadWriteAccessForScheme(MK_SRC(OWNER), http_uri, "http"); |
655 TestReadWriteAccessForScheme(MK_SRC(OWNER), https_uri, "https"); | 663 TestReadWriteAccessForScheme(MK_SRC(OWNER), https_uri, "https"); |
656 TestReadWriteAccessForScheme(MK_SRC(OWNER), ftp_uri, "ftp"); | 664 TestReadWriteAccessForScheme(MK_SRC(OWNER), ftp_uri, "ftp"); |
657 TestReadWriteAccessForScheme(MK_SRC(OWNER), socks_uri, "socks"); | 665 TestReadWriteAccessForScheme(MK_SRC(OWNER), socks_uri, "socks"); |
658 } | 666 } |
659 | 667 |
660 } // namespace chromeos | 668 } // namespace chromeos |
OLD | NEW |