OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 5 #include <algorithm> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
14 #include "base/files/scoped_temp_dir.h" | 14 #include "base/files/scoped_temp_dir.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/run_loop.h" |
17 #include "base/string16.h" | 18 #include "base/string16.h" |
18 #include "base/stringprintf.h" | 19 #include "base/stringprintf.h" |
19 #include "base/test/test_file_util.h" | 20 #include "base/test/test_file_util.h" |
20 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
21 #include "base/values.h" | 22 #include "base/values.h" |
22 #include "chrome/app/chrome_command_ids.h" | 23 #include "chrome/app/chrome_command_ids.h" |
23 #include "chrome/browser/api/infobars/infobar_service.h" | 24 #include "chrome/browser/api/infobars/infobar_service.h" |
24 #include "chrome/browser/autocomplete/autocomplete_controller.h" | 25 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
25 #include "chrome/browser/browser_process.h" | 26 #include "chrome/browser/browser_process.h" |
26 #include "chrome/browser/devtools/devtools_window.h" | 27 #include "chrome/browser/devtools/devtools_window.h" |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 | 532 |
532 void UninstallExtension(const std::string& id, bool expect_success) { | 533 void UninstallExtension(const std::string& id, bool expect_success) { |
533 content::WindowedNotificationObserver observer( | 534 content::WindowedNotificationObserver observer( |
534 expect_success ? chrome::NOTIFICATION_EXTENSION_UNINSTALLED | 535 expect_success ? chrome::NOTIFICATION_EXTENSION_UNINSTALLED |
535 : chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, | 536 : chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, |
536 content::NotificationService::AllSources()); | 537 content::NotificationService::AllSources()); |
537 extension_service()->UninstallExtension(id, false, NULL); | 538 extension_service()->UninstallExtension(id, false, NULL); |
538 observer.Wait(); | 539 observer.Wait(); |
539 } | 540 } |
540 | 541 |
| 542 void UpdateProviderPolicy(const PolicyMap& policy) { |
| 543 provider_.UpdateChromePolicy(policy); |
| 544 DCHECK(MessageLoop::current()); |
| 545 base::RunLoop loop; |
| 546 loop.RunUntilIdle(); |
| 547 } |
| 548 |
541 MockConfigurationPolicyProvider provider_; | 549 MockConfigurationPolicyProvider provider_; |
542 }; | 550 }; |
543 | 551 |
544 #if defined(OS_WIN) | 552 #if defined(OS_WIN) |
545 // This policy only exists on Windows. | 553 // This policy only exists on Windows. |
546 | 554 |
547 // Sets the locale policy before the browser is started. | 555 // Sets the locale policy before the browser is started. |
548 class LocalePolicyTest : public PolicyTest { | 556 class LocalePolicyTest : public PolicyTest { |
549 public: | 557 public: |
550 LocalePolicyTest() {} | 558 LocalePolicyTest() {} |
551 virtual ~LocalePolicyTest() {} | 559 virtual ~LocalePolicyTest() {} |
552 | 560 |
553 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 561 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
554 PolicyTest::SetUpInProcessBrowserTestFixture(); | 562 PolicyTest::SetUpInProcessBrowserTestFixture(); |
555 PolicyMap policies; | 563 PolicyMap policies; |
556 policies.Set( | 564 policies.Set( |
557 key::kApplicationLocaleValue, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 565 key::kApplicationLocaleValue, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
558 base::Value::CreateStringValue("fr")); | 566 base::Value::CreateStringValue("fr")); |
559 provider_.UpdateChromePolicy(policies); | 567 UpdateProviderPolicy(policies); |
560 // The "en-US" ResourceBundle is always loaded before this step for tests, | 568 // The "en-US" ResourceBundle is always loaded before this step for tests, |
561 // but in this test we want the browser to load the bundle as it | 569 // but in this test we want the browser to load the bundle as it |
562 // normally would. | 570 // normally would. |
563 ResourceBundle::CleanupSharedInstance(); | 571 ResourceBundle::CleanupSharedInstance(); |
564 } | 572 } |
565 }; | 573 }; |
566 | 574 |
567 IN_PROC_BROWSER_TEST_F(LocalePolicyTest, ApplicationLocaleValue) { | 575 IN_PROC_BROWSER_TEST_F(LocalePolicyTest, ApplicationLocaleValue) { |
568 // Verifies that the default locale can be overridden with policy. | 576 // Verifies that the default locale can be overridden with policy. |
569 EXPECT_EQ("fr", g_browser_process->GetApplicationLocale()); | 577 EXPECT_EQ("fr", g_browser_process->GetApplicationLocale()); |
(...skipping 17 matching lines...) Expand all Loading... |
587 | 595 |
588 // Test starts in about:blank. | 596 // Test starts in about:blank. |
589 PrefService* prefs = browser()->profile()->GetPrefs(); | 597 PrefService* prefs = browser()->profile()->GetPrefs(); |
590 EXPECT_FALSE(prefs->IsManagedPreference(prefs::kShowBookmarkBar)); | 598 EXPECT_FALSE(prefs->IsManagedPreference(prefs::kShowBookmarkBar)); |
591 EXPECT_FALSE(prefs->GetBoolean(prefs::kShowBookmarkBar)); | 599 EXPECT_FALSE(prefs->GetBoolean(prefs::kShowBookmarkBar)); |
592 EXPECT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state()); | 600 EXPECT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state()); |
593 | 601 |
594 PolicyMap policies; | 602 PolicyMap policies; |
595 policies.Set(key::kBookmarkBarEnabled, POLICY_LEVEL_MANDATORY, | 603 policies.Set(key::kBookmarkBarEnabled, POLICY_LEVEL_MANDATORY, |
596 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); | 604 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); |
597 provider_.UpdateChromePolicy(policies); | 605 UpdateProviderPolicy(policies); |
598 EXPECT_TRUE(prefs->IsManagedPreference(prefs::kShowBookmarkBar)); | 606 EXPECT_TRUE(prefs->IsManagedPreference(prefs::kShowBookmarkBar)); |
599 EXPECT_TRUE(prefs->GetBoolean(prefs::kShowBookmarkBar)); | 607 EXPECT_TRUE(prefs->GetBoolean(prefs::kShowBookmarkBar)); |
600 EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state()); | 608 EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state()); |
601 | 609 |
602 // The NTP has special handling of the bookmark bar. | 610 // The NTP has special handling of the bookmark bar. |
603 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); | 611 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); |
604 EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state()); | 612 EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state()); |
605 | 613 |
606 policies.Set(key::kBookmarkBarEnabled, POLICY_LEVEL_MANDATORY, | 614 policies.Set(key::kBookmarkBarEnabled, POLICY_LEVEL_MANDATORY, |
607 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false)); | 615 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false)); |
608 provider_.UpdateChromePolicy(policies); | 616 UpdateProviderPolicy(policies); |
609 EXPECT_TRUE(prefs->IsManagedPreference(prefs::kShowBookmarkBar)); | 617 EXPECT_TRUE(prefs->IsManagedPreference(prefs::kShowBookmarkBar)); |
610 EXPECT_FALSE(prefs->GetBoolean(prefs::kShowBookmarkBar)); | 618 EXPECT_FALSE(prefs->GetBoolean(prefs::kShowBookmarkBar)); |
611 // The bookmark bar is hidden in the NTP when disabled by policy. | 619 // The bookmark bar is hidden in the NTP when disabled by policy. |
612 EXPECT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state()); | 620 EXPECT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state()); |
613 | 621 |
614 policies.Clear(); | 622 policies.Clear(); |
615 provider_.UpdateChromePolicy(policies); | 623 UpdateProviderPolicy(policies); |
616 EXPECT_FALSE(prefs->IsManagedPreference(prefs::kShowBookmarkBar)); | 624 EXPECT_FALSE(prefs->IsManagedPreference(prefs::kShowBookmarkBar)); |
617 EXPECT_FALSE(prefs->GetBoolean(prefs::kShowBookmarkBar)); | 625 EXPECT_FALSE(prefs->GetBoolean(prefs::kShowBookmarkBar)); |
618 // The bookmark bar is shown detached in the NTP, when disabled by prefs only. | 626 // The bookmark bar is shown detached in the NTP, when disabled by prefs only. |
619 EXPECT_EQ(BookmarkBar::DETACHED, browser()->bookmark_bar_state()); | 627 EXPECT_EQ(BookmarkBar::DETACHED, browser()->bookmark_bar_state()); |
620 } | 628 } |
621 | 629 |
622 IN_PROC_BROWSER_TEST_F(PolicyTest, PRE_PRE_ClearSiteDataOnExit) { | 630 IN_PROC_BROWSER_TEST_F(PolicyTest, PRE_PRE_ClearSiteDataOnExit) { |
623 // Verifies that cookies are deleted on shutdown. This test is split in 3 | 631 // Verifies that cookies are deleted on shutdown. This test is split in 3 |
624 // parts because it spans 2 browser restarts. | 632 // parts because it spans 2 browser restarts. |
625 | 633 |
626 Profile* profile = browser()->profile(); | 634 Profile* profile = browser()->profile(); |
627 GURL url(kURL); | 635 GURL url(kURL); |
628 // No cookies at startup. | 636 // No cookies at startup. |
629 EXPECT_TRUE(content::GetCookies(profile, url).empty()); | 637 EXPECT_TRUE(content::GetCookies(profile, url).empty()); |
630 // Set a cookie now. | 638 // Set a cookie now. |
631 std::string value = std::string(kCookieValue) + std::string(kCookieOptions); | 639 std::string value = std::string(kCookieValue) + std::string(kCookieOptions); |
632 EXPECT_TRUE(content::SetCookie(profile, url, value)); | 640 EXPECT_TRUE(content::SetCookie(profile, url, value)); |
633 // Verify it was set. | 641 // Verify it was set. |
634 EXPECT_EQ(kCookieValue, GetCookies(profile, url)); | 642 EXPECT_EQ(kCookieValue, GetCookies(profile, url)); |
635 } | 643 } |
636 | 644 |
637 IN_PROC_BROWSER_TEST_F(PolicyTest, PRE_ClearSiteDataOnExit) { | 645 IN_PROC_BROWSER_TEST_F(PolicyTest, PRE_ClearSiteDataOnExit) { |
638 // Verify that the cookie persists across restarts. | 646 // Verify that the cookie persists across restarts. |
639 EXPECT_EQ(kCookieValue, GetCookies(browser()->profile(), GURL(kURL))); | 647 EXPECT_EQ(kCookieValue, GetCookies(browser()->profile(), GURL(kURL))); |
640 // Now set the policy and the cookie should be gone after another restart. | 648 // Now set the policy and the cookie should be gone after another restart. |
641 PolicyMap policies; | 649 PolicyMap policies; |
642 policies.Set(key::kClearSiteDataOnExit, POLICY_LEVEL_MANDATORY, | 650 policies.Set(key::kClearSiteDataOnExit, POLICY_LEVEL_MANDATORY, |
643 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); | 651 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); |
644 provider_.UpdateChromePolicy(policies); | 652 UpdateProviderPolicy(policies); |
645 } | 653 } |
646 | 654 |
647 IN_PROC_BROWSER_TEST_F(PolicyTest, ClearSiteDataOnExit) { | 655 IN_PROC_BROWSER_TEST_F(PolicyTest, ClearSiteDataOnExit) { |
648 // Verify that the cookie is gone. | 656 // Verify that the cookie is gone. |
649 EXPECT_TRUE(GetCookies(browser()->profile(), GURL(kURL)).empty()); | 657 EXPECT_TRUE(GetCookies(browser()->profile(), GURL(kURL)).empty()); |
650 } | 658 } |
651 | 659 |
652 IN_PROC_BROWSER_TEST_F(PolicyTest, DefaultSearchProvider) { | 660 IN_PROC_BROWSER_TEST_F(PolicyTest, DefaultSearchProvider) { |
653 MakeRequestFail make_request_fail("search.example"); | 661 MakeRequestFail make_request_fail("search.example"); |
654 | 662 |
(...skipping 29 matching lines...) Expand all Loading... |
684 policies.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, | 692 policies.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, |
685 POLICY_SCOPE_USER, base::Value::CreateStringValue(kSearchURL)); | 693 POLICY_SCOPE_USER, base::Value::CreateStringValue(kSearchURL)); |
686 base::ListValue* alternate_urls = new base::ListValue(); | 694 base::ListValue* alternate_urls = new base::ListValue(); |
687 alternate_urls->AppendString(kAlternateURL0); | 695 alternate_urls->AppendString(kAlternateURL0); |
688 alternate_urls->AppendString(kAlternateURL1); | 696 alternate_urls->AppendString(kAlternateURL1); |
689 policies.Set(key::kDefaultSearchProviderAlternateURLs, POLICY_LEVEL_MANDATORY, | 697 policies.Set(key::kDefaultSearchProviderAlternateURLs, POLICY_LEVEL_MANDATORY, |
690 POLICY_SCOPE_USER, alternate_urls); | 698 POLICY_SCOPE_USER, alternate_urls); |
691 policies.Set(key::kDefaultSearchProviderSearchTermsReplacementKey, | 699 policies.Set(key::kDefaultSearchProviderSearchTermsReplacementKey, |
692 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 700 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
693 base::Value::CreateStringValue(kSearchTermsReplacementKey)); | 701 base::Value::CreateStringValue(kSearchTermsReplacementKey)); |
694 provider_.UpdateChromePolicy(policies); | 702 UpdateProviderPolicy(policies); |
695 default_search = service->GetDefaultSearchProvider(); | 703 default_search = service->GetDefaultSearchProvider(); |
696 ASSERT_TRUE(default_search); | 704 ASSERT_TRUE(default_search); |
697 EXPECT_EQ(kKeyword, default_search->keyword()); | 705 EXPECT_EQ(kKeyword, default_search->keyword()); |
698 EXPECT_EQ(kSearchURL, default_search->url()); | 706 EXPECT_EQ(kSearchURL, default_search->url()); |
699 EXPECT_EQ(2U, default_search->alternate_urls().size()); | 707 EXPECT_EQ(2U, default_search->alternate_urls().size()); |
700 EXPECT_EQ(kAlternateURL0, default_search->alternate_urls()[0]); | 708 EXPECT_EQ(kAlternateURL0, default_search->alternate_urls()[0]); |
701 EXPECT_EQ(kAlternateURL1, default_search->alternate_urls()[1]); | 709 EXPECT_EQ(kAlternateURL1, default_search->alternate_urls()[1]); |
702 EXPECT_EQ(kSearchTermsReplacementKey, | 710 EXPECT_EQ(kSearchTermsReplacementKey, |
703 default_search->search_terms_replacement_key()); | 711 default_search->search_terms_replacement_key()); |
704 | 712 |
705 // Verify that searching from the omnibox uses kSearchURL. | 713 // Verify that searching from the omnibox uses kSearchURL. |
706 chrome::FocusLocationBar(browser()); | 714 chrome::FocusLocationBar(browser()); |
707 LocationBar* location_bar = browser()->window()->GetLocationBar(); | 715 LocationBar* location_bar = browser()->window()->GetLocationBar(); |
708 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "stuff to search for"); | 716 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "stuff to search for"); |
709 OmniboxEditModel* model = location_bar->GetLocationEntry()->model(); | 717 OmniboxEditModel* model = location_bar->GetLocationEntry()->model(); |
710 EXPECT_TRUE(model->CurrentMatch().destination_url.is_valid()); | 718 EXPECT_TRUE(model->CurrentMatch().destination_url.is_valid()); |
711 content::WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 719 content::WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
712 GURL expected("http://search.example/search?q=stuff+to+search+for"); | 720 GURL expected("http://search.example/search?q=stuff+to+search+for"); |
713 EXPECT_EQ(expected, web_contents->GetURL()); | 721 EXPECT_EQ(expected, web_contents->GetURL()); |
714 | 722 |
715 // Verify that searching from the omnibox can be disabled. | 723 // Verify that searching from the omnibox can be disabled. |
716 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); | 724 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); |
717 policies.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY, | 725 policies.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY, |
718 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false)); | 726 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false)); |
719 EXPECT_TRUE(service->GetDefaultSearchProvider()); | 727 EXPECT_TRUE(service->GetDefaultSearchProvider()); |
720 provider_.UpdateChromePolicy(policies); | 728 UpdateProviderPolicy(policies); |
721 EXPECT_FALSE(service->GetDefaultSearchProvider()); | 729 EXPECT_FALSE(service->GetDefaultSearchProvider()); |
722 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "should not work"); | 730 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "should not work"); |
723 // This means that submitting won't trigger any action. | 731 // This means that submitting won't trigger any action. |
724 EXPECT_FALSE(model->CurrentMatch().destination_url.is_valid()); | 732 EXPECT_FALSE(model->CurrentMatch().destination_url.is_valid()); |
725 EXPECT_EQ(GURL(chrome::kAboutBlankURL), web_contents->GetURL()); | 733 EXPECT_EQ(GURL(chrome::kAboutBlankURL), web_contents->GetURL()); |
726 } | 734 } |
727 | 735 |
728 IN_PROC_BROWSER_TEST_F(PolicyTest, ForceSafeSearch) { | 736 IN_PROC_BROWSER_TEST_F(PolicyTest, ForceSafeSearch) { |
729 // Makes the requests fail since all we want to check is that the redirection | 737 // Makes the requests fail since all we want to check is that the redirection |
730 // is done properly. | 738 // is done properly. |
(...skipping 19 matching lines...) Expand all Loading... |
750 EXPECT_EQ(expected_without, web_contents->GetURL()); | 758 EXPECT_EQ(expected_without, web_contents->GetURL()); |
751 | 759 |
752 PrefService* prefs = browser()->profile()->GetPrefs(); | 760 PrefService* prefs = browser()->profile()->GetPrefs(); |
753 EXPECT_FALSE(prefs->IsManagedPreference(prefs::kForceSafeSearch)); | 761 EXPECT_FALSE(prefs->IsManagedPreference(prefs::kForceSafeSearch)); |
754 EXPECT_FALSE(prefs->GetBoolean(prefs::kForceSafeSearch)); | 762 EXPECT_FALSE(prefs->GetBoolean(prefs::kForceSafeSearch)); |
755 | 763 |
756 // Override the default SafeSearch setting using policies. | 764 // Override the default SafeSearch setting using policies. |
757 PolicyMap policies; | 765 PolicyMap policies; |
758 policies.Set(key::kForceSafeSearch, POLICY_LEVEL_MANDATORY, | 766 policies.Set(key::kForceSafeSearch, POLICY_LEVEL_MANDATORY, |
759 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); | 767 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); |
760 provider_.UpdateChromePolicy(policies); | 768 UpdateProviderPolicy(policies); |
761 | 769 |
762 EXPECT_TRUE(prefs->IsManagedPreference(prefs::kForceSafeSearch)); | 770 EXPECT_TRUE(prefs->IsManagedPreference(prefs::kForceSafeSearch)); |
763 EXPECT_TRUE(prefs->GetBoolean(prefs::kForceSafeSearch)); | 771 EXPECT_TRUE(prefs->GetBoolean(prefs::kForceSafeSearch)); |
764 | 772 |
765 content::TestNavigationObserver safesearch_observer( | 773 content::TestNavigationObserver safesearch_observer( |
766 content::NotificationService::AllSources()); | 774 content::NotificationService::AllSources()); |
767 | 775 |
768 // Verify that searching from google.com works. | 776 // Verify that searching from google.com works. |
769 chrome::FocusLocationBar(browser()); | 777 chrome::FocusLocationBar(browser()); |
770 location_bar = browser()->window()->GetLocationBar(); | 778 location_bar = browser()->window()->GetLocationBar(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); | 819 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); |
812 policies.Set(key::kDefaultSearchProviderKeyword, POLICY_LEVEL_MANDATORY, | 820 policies.Set(key::kDefaultSearchProviderKeyword, POLICY_LEVEL_MANDATORY, |
813 POLICY_SCOPE_USER, base::Value::CreateStringValue(kKeyword)); | 821 POLICY_SCOPE_USER, base::Value::CreateStringValue(kKeyword)); |
814 policies.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, | 822 policies.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, |
815 POLICY_SCOPE_USER, base::Value::CreateStringValue(kSearchURL)); | 823 POLICY_SCOPE_USER, base::Value::CreateStringValue(kSearchURL)); |
816 base::ListValue* alternate_urls = new base::ListValue(); | 824 base::ListValue* alternate_urls = new base::ListValue(); |
817 alternate_urls->AppendString(kAlternateURL0); | 825 alternate_urls->AppendString(kAlternateURL0); |
818 alternate_urls->AppendString(kAlternateURL1); | 826 alternate_urls->AppendString(kAlternateURL1); |
819 policies.Set(key::kDefaultSearchProviderAlternateURLs, POLICY_LEVEL_MANDATORY, | 827 policies.Set(key::kDefaultSearchProviderAlternateURLs, POLICY_LEVEL_MANDATORY, |
820 POLICY_SCOPE_USER, alternate_urls); | 828 POLICY_SCOPE_USER, alternate_urls); |
821 provider_.UpdateChromePolicy(policies); | 829 UpdateProviderPolicy(policies); |
822 default_search = service->GetDefaultSearchProvider(); | 830 default_search = service->GetDefaultSearchProvider(); |
823 ASSERT_TRUE(default_search); | 831 ASSERT_TRUE(default_search); |
824 EXPECT_EQ(kKeyword, default_search->keyword()); | 832 EXPECT_EQ(kKeyword, default_search->keyword()); |
825 EXPECT_EQ(kSearchURL, default_search->url()); | 833 EXPECT_EQ(kSearchURL, default_search->url()); |
826 EXPECT_EQ(2U, default_search->alternate_urls().size()); | 834 EXPECT_EQ(2U, default_search->alternate_urls().size()); |
827 EXPECT_EQ(kAlternateURL0, default_search->alternate_urls()[0]); | 835 EXPECT_EQ(kAlternateURL0, default_search->alternate_urls()[0]); |
828 EXPECT_EQ(kAlternateURL1, default_search->alternate_urls()[1]); | 836 EXPECT_EQ(kAlternateURL1, default_search->alternate_urls()[1]); |
829 | 837 |
830 // Verify that searching from the omnibox does search term replacement with | 838 // Verify that searching from the omnibox does search term replacement with |
831 // first URL pattern. | 839 // first URL pattern. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 #if defined(OS_MACOSX) | 886 #if defined(OS_MACOSX) |
879 IN_PROC_BROWSER_TEST_F(PolicyTest, Disable3DAPIs) { | 887 IN_PROC_BROWSER_TEST_F(PolicyTest, Disable3DAPIs) { |
880 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); | 888 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); |
881 // WebGL is enabled by default. | 889 // WebGL is enabled by default. |
882 content::WebContents* contents = chrome::GetActiveWebContents(browser()); | 890 content::WebContents* contents = chrome::GetActiveWebContents(browser()); |
883 EXPECT_TRUE(IsWebGLEnabled(contents)); | 891 EXPECT_TRUE(IsWebGLEnabled(contents)); |
884 // Disable with a policy. | 892 // Disable with a policy. |
885 PolicyMap policies; | 893 PolicyMap policies; |
886 policies.Set(key::kDisable3DAPIs, POLICY_LEVEL_MANDATORY, | 894 policies.Set(key::kDisable3DAPIs, POLICY_LEVEL_MANDATORY, |
887 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); | 895 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); |
888 provider_.UpdateChromePolicy(policies); | 896 UpdateProviderPolicy(policies); |
889 // Crash and reload the tab to get a new renderer. | 897 // Crash and reload the tab to get a new renderer. |
890 content::CrashTab(contents); | 898 content::CrashTab(contents); |
891 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_RELOAD)); | 899 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_RELOAD)); |
892 EXPECT_FALSE(IsWebGLEnabled(contents)); | 900 EXPECT_FALSE(IsWebGLEnabled(contents)); |
893 // Enable with a policy. | 901 // Enable with a policy. |
894 policies.Set(key::kDisable3DAPIs, POLICY_LEVEL_MANDATORY, | 902 policies.Set(key::kDisable3DAPIs, POLICY_LEVEL_MANDATORY, |
895 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false)); | 903 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false)); |
896 provider_.UpdateChromePolicy(policies); | 904 UpdateProviderPolicy(policies); |
897 content::CrashTab(contents); | 905 content::CrashTab(contents); |
898 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_RELOAD)); | 906 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_RELOAD)); |
899 EXPECT_TRUE(IsWebGLEnabled(contents)); | 907 EXPECT_TRUE(IsWebGLEnabled(contents)); |
900 } | 908 } |
901 #endif | 909 #endif |
902 | 910 |
903 IN_PROC_BROWSER_TEST_F(PolicyTest, DisableSpdy) { | 911 IN_PROC_BROWSER_TEST_F(PolicyTest, DisableSpdy) { |
904 // Verifies that SPDY can be disable by policy. | 912 // Verifies that SPDY can be disable by policy. |
905 EXPECT_TRUE(net::HttpStreamFactory::spdy_enabled()); | 913 EXPECT_TRUE(net::HttpStreamFactory::spdy_enabled()); |
906 PolicyMap policies; | 914 PolicyMap policies; |
907 policies.Set(key::kDisableSpdy, POLICY_LEVEL_MANDATORY, | 915 policies.Set(key::kDisableSpdy, POLICY_LEVEL_MANDATORY, |
908 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); | 916 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); |
909 provider_.UpdateChromePolicy(policies); | 917 UpdateProviderPolicy(policies); |
910 content::RunAllPendingInMessageLoop(); | 918 content::RunAllPendingInMessageLoop(); |
911 EXPECT_FALSE(net::HttpStreamFactory::spdy_enabled()); | 919 EXPECT_FALSE(net::HttpStreamFactory::spdy_enabled()); |
912 // Verify that it can be force-enabled too. | 920 // Verify that it can be force-enabled too. |
913 browser()->profile()->GetPrefs()->SetBoolean(prefs::kDisableSpdy, true); | 921 browser()->profile()->GetPrefs()->SetBoolean(prefs::kDisableSpdy, true); |
914 policies.Set(key::kDisableSpdy, POLICY_LEVEL_MANDATORY, | 922 policies.Set(key::kDisableSpdy, POLICY_LEVEL_MANDATORY, |
915 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false)); | 923 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false)); |
916 provider_.UpdateChromePolicy(policies); | 924 UpdateProviderPolicy(policies); |
917 content::RunAllPendingInMessageLoop(); | 925 content::RunAllPendingInMessageLoop(); |
918 EXPECT_TRUE(net::HttpStreamFactory::spdy_enabled()); | 926 EXPECT_TRUE(net::HttpStreamFactory::spdy_enabled()); |
919 } | 927 } |
920 | 928 |
921 IN_PROC_BROWSER_TEST_F(PolicyTest, DisabledPlugins) { | 929 IN_PROC_BROWSER_TEST_F(PolicyTest, DisabledPlugins) { |
922 // Verifies that plugins can be forced to be disabled by policy. | 930 // Verifies that plugins can be forced to be disabled by policy. |
923 | 931 |
924 // Verify that the Flash plugin exists and that it can be enabled and disabled | 932 // Verify that the Flash plugin exists and that it can be enabled and disabled |
925 // by the user. | 933 // by the user. |
926 std::vector<webkit::WebPluginInfo> plugins; | 934 std::vector<webkit::WebPluginInfo> plugins; |
927 GetPluginList(&plugins); | 935 GetPluginList(&plugins); |
928 const webkit::WebPluginInfo* flash = GetFlashPlugin(plugins); | 936 const webkit::WebPluginInfo* flash = GetFlashPlugin(plugins); |
929 if (!flash) | 937 if (!flash) |
930 return; | 938 return; |
931 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser()->profile()); | 939 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser()->profile()); |
932 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); | 940 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); |
933 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, false)); | 941 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, false)); |
934 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); | 942 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); |
935 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, true)); | 943 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, true)); |
936 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); | 944 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); |
937 | 945 |
938 // Now disable it with a policy. | 946 // Now disable it with a policy. |
939 base::ListValue disabled_plugins; | 947 base::ListValue disabled_plugins; |
940 disabled_plugins.Append(base::Value::CreateStringValue("*Flash*")); | 948 disabled_plugins.Append(base::Value::CreateStringValue("*Flash*")); |
941 PolicyMap policies; | 949 PolicyMap policies; |
942 policies.Set(key::kDisabledPlugins, POLICY_LEVEL_MANDATORY, | 950 policies.Set(key::kDisabledPlugins, POLICY_LEVEL_MANDATORY, |
943 POLICY_SCOPE_USER, disabled_plugins.DeepCopy()); | 951 POLICY_SCOPE_USER, disabled_plugins.DeepCopy()); |
944 provider_.UpdateChromePolicy(policies); | 952 UpdateProviderPolicy(policies); |
945 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); | 953 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); |
946 // The user shouldn't be able to enable it. | 954 // The user shouldn't be able to enable it. |
947 EXPECT_FALSE(SetPluginEnabled(plugin_prefs, flash, true)); | 955 EXPECT_FALSE(SetPluginEnabled(plugin_prefs, flash, true)); |
948 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); | 956 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); |
949 } | 957 } |
950 | 958 |
951 IN_PROC_BROWSER_TEST_F(PolicyTest, DisabledPluginsExceptions) { | 959 IN_PROC_BROWSER_TEST_F(PolicyTest, DisabledPluginsExceptions) { |
952 // Verifies that plugins with an exception in the blacklist can be enabled. | 960 // Verifies that plugins with an exception in the blacklist can be enabled. |
953 | 961 |
954 // Verify that the Flash plugin exists and that it can be enabled and disabled | 962 // Verify that the Flash plugin exists and that it can be enabled and disabled |
955 // by the user. | 963 // by the user. |
956 std::vector<webkit::WebPluginInfo> plugins; | 964 std::vector<webkit::WebPluginInfo> plugins; |
957 GetPluginList(&plugins); | 965 GetPluginList(&plugins); |
958 const webkit::WebPluginInfo* flash = GetFlashPlugin(plugins); | 966 const webkit::WebPluginInfo* flash = GetFlashPlugin(plugins); |
959 if (!flash) | 967 if (!flash) |
960 return; | 968 return; |
961 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser()->profile()); | 969 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser()->profile()); |
962 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); | 970 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); |
963 | 971 |
964 // Disable all plugins. | 972 // Disable all plugins. |
965 base::ListValue disabled_plugins; | 973 base::ListValue disabled_plugins; |
966 disabled_plugins.Append(base::Value::CreateStringValue("*")); | 974 disabled_plugins.Append(base::Value::CreateStringValue("*")); |
967 PolicyMap policies; | 975 PolicyMap policies; |
968 policies.Set(key::kDisabledPlugins, POLICY_LEVEL_MANDATORY, | 976 policies.Set(key::kDisabledPlugins, POLICY_LEVEL_MANDATORY, |
969 POLICY_SCOPE_USER, disabled_plugins.DeepCopy()); | 977 POLICY_SCOPE_USER, disabled_plugins.DeepCopy()); |
970 provider_.UpdateChromePolicy(policies); | 978 UpdateProviderPolicy(policies); |
971 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); | 979 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); |
972 // The user shouldn't be able to enable it. | 980 // The user shouldn't be able to enable it. |
973 EXPECT_FALSE(SetPluginEnabled(plugin_prefs, flash, true)); | 981 EXPECT_FALSE(SetPluginEnabled(plugin_prefs, flash, true)); |
974 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); | 982 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); |
975 | 983 |
976 // Now open an exception for flash. | 984 // Now open an exception for flash. |
977 base::ListValue disabled_plugins_exceptions; | 985 base::ListValue disabled_plugins_exceptions; |
978 disabled_plugins_exceptions.Append( | 986 disabled_plugins_exceptions.Append( |
979 base::Value::CreateStringValue("*Flash*")); | 987 base::Value::CreateStringValue("*Flash*")); |
980 policies.Set(key::kDisabledPluginsExceptions, POLICY_LEVEL_MANDATORY, | 988 policies.Set(key::kDisabledPluginsExceptions, POLICY_LEVEL_MANDATORY, |
981 POLICY_SCOPE_USER, disabled_plugins_exceptions.DeepCopy()); | 989 POLICY_SCOPE_USER, disabled_plugins_exceptions.DeepCopy()); |
982 provider_.UpdateChromePolicy(policies); | 990 UpdateProviderPolicy(policies); |
983 // It should revert to the user's preference automatically. | 991 // It should revert to the user's preference automatically. |
984 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); | 992 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); |
985 // And the user should be able to disable and enable again. | 993 // And the user should be able to disable and enable again. |
986 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, false)); | 994 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, false)); |
987 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); | 995 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); |
988 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, true)); | 996 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, true)); |
989 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); | 997 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); |
990 } | 998 } |
991 | 999 |
992 IN_PROC_BROWSER_TEST_F(PolicyTest, EnabledPlugins) { | 1000 IN_PROC_BROWSER_TEST_F(PolicyTest, EnabledPlugins) { |
993 // Verifies that a plugin can be force-installed with a policy. | 1001 // Verifies that a plugin can be force-installed with a policy. |
994 std::vector<webkit::WebPluginInfo> plugins; | 1002 std::vector<webkit::WebPluginInfo> plugins; |
995 GetPluginList(&plugins); | 1003 GetPluginList(&plugins); |
996 const webkit::WebPluginInfo* flash = GetFlashPlugin(plugins); | 1004 const webkit::WebPluginInfo* flash = GetFlashPlugin(plugins); |
997 if (!flash) | 1005 if (!flash) |
998 return; | 1006 return; |
999 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser()->profile()); | 1007 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser()->profile()); |
1000 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); | 1008 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); |
1001 | 1009 |
1002 // The user disables it and then a policy forces it to be enabled. | 1010 // The user disables it and then a policy forces it to be enabled. |
1003 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, false)); | 1011 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, false)); |
1004 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); | 1012 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); |
1005 base::ListValue plugin_list; | 1013 base::ListValue plugin_list; |
1006 plugin_list.Append(base::Value::CreateStringValue(kFlashPluginName)); | 1014 plugin_list.Append(base::Value::CreateStringValue(kFlashPluginName)); |
1007 PolicyMap policies; | 1015 PolicyMap policies; |
1008 policies.Set(key::kEnabledPlugins, POLICY_LEVEL_MANDATORY, | 1016 policies.Set(key::kEnabledPlugins, POLICY_LEVEL_MANDATORY, |
1009 POLICY_SCOPE_USER, plugin_list.DeepCopy()); | 1017 POLICY_SCOPE_USER, plugin_list.DeepCopy()); |
1010 provider_.UpdateChromePolicy(policies); | 1018 UpdateProviderPolicy(policies); |
1011 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); | 1019 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); |
1012 // The user can't disable it anymore. | 1020 // The user can't disable it anymore. |
1013 EXPECT_FALSE(SetPluginEnabled(plugin_prefs, flash, false)); | 1021 EXPECT_FALSE(SetPluginEnabled(plugin_prefs, flash, false)); |
1014 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); | 1022 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); |
1015 | 1023 |
1016 // When a plugin is both enabled and disabled, the whitelist takes precedence. | 1024 // When a plugin is both enabled and disabled, the whitelist takes precedence. |
1017 policies.Set(key::kDisabledPlugins, POLICY_LEVEL_MANDATORY, | 1025 policies.Set(key::kDisabledPlugins, POLICY_LEVEL_MANDATORY, |
1018 POLICY_SCOPE_USER, plugin_list.DeepCopy()); | 1026 POLICY_SCOPE_USER, plugin_list.DeepCopy()); |
1019 provider_.UpdateChromePolicy(policies); | 1027 UpdateProviderPolicy(policies); |
1020 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); | 1028 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); |
1021 } | 1029 } |
1022 | 1030 |
1023 IN_PROC_BROWSER_TEST_F(PolicyTest, AlwaysAuthorizePlugins) { | 1031 IN_PROC_BROWSER_TEST_F(PolicyTest, AlwaysAuthorizePlugins) { |
1024 // Verifies that dangerous plugins can be always authorized to run with | 1032 // Verifies that dangerous plugins can be always authorized to run with |
1025 // a policy. | 1033 // a policy. |
1026 | 1034 |
1027 // Verify that the test page exists. It is only present in checkouts with | 1035 // Verify that the test page exists. It is only present in checkouts with |
1028 // src-internal. | 1036 // src-internal. |
1029 if (!file_util::PathExists(ui_test_utils::GetTestFilePath( | 1037 if (!file_util::PathExists(ui_test_utils::GetTestFilePath( |
(...skipping 22 matching lines...) Expand all Loading... |
1052 InfoBarDelegate* infobar_delegate = | 1060 InfoBarDelegate* infobar_delegate = |
1053 infobar_service->GetInfoBarDelegateAt(0); | 1061 infobar_service->GetInfoBarDelegateAt(0); |
1054 EXPECT_TRUE(infobar_delegate->AsConfirmInfoBarDelegate()); | 1062 EXPECT_TRUE(infobar_delegate->AsConfirmInfoBarDelegate()); |
1055 // And the plugin isn't running. | 1063 // And the plugin isn't running. |
1056 EXPECT_EQ(0, CountPlugins()); | 1064 EXPECT_EQ(0, CountPlugins()); |
1057 | 1065 |
1058 // Now set a policy to always authorize this. | 1066 // Now set a policy to always authorize this. |
1059 PolicyMap policies; | 1067 PolicyMap policies; |
1060 policies.Set(key::kAlwaysAuthorizePlugins, POLICY_LEVEL_MANDATORY, | 1068 policies.Set(key::kAlwaysAuthorizePlugins, POLICY_LEVEL_MANDATORY, |
1061 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); | 1069 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); |
1062 provider_.UpdateChromePolicy(policies); | 1070 UpdateProviderPolicy(policies); |
1063 // Reloading the page shouldn't trigger the infobar this time. | 1071 // Reloading the page shouldn't trigger the infobar this time. |
1064 ui_test_utils::NavigateToURL(browser(), url); | 1072 ui_test_utils::NavigateToURL(browser(), url); |
1065 EXPECT_EQ(0u, infobar_service->GetInfoBarCount()); | 1073 EXPECT_EQ(0u, infobar_service->GetInfoBarCount()); |
1066 // And the plugin started automatically. | 1074 // And the plugin started automatically. |
1067 EXPECT_EQ(1, CountPlugins()); | 1075 EXPECT_EQ(1, CountPlugins()); |
1068 } | 1076 } |
1069 | 1077 |
1070 IN_PROC_BROWSER_TEST_F(PolicyTest, DeveloperToolsDisabled) { | 1078 IN_PROC_BROWSER_TEST_F(PolicyTest, DeveloperToolsDisabled) { |
1071 // Verifies that access to the developer tools can be disabled. | 1079 // Verifies that access to the developer tools can be disabled. |
1072 | 1080 |
1073 // Open devtools. | 1081 // Open devtools. |
1074 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_DEV_TOOLS)); | 1082 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_DEV_TOOLS)); |
1075 content::WebContents* contents = chrome::GetActiveWebContents(browser()); | 1083 content::WebContents* contents = chrome::GetActiveWebContents(browser()); |
1076 EXPECT_TRUE(DevToolsWindow::GetDockedInstanceForInspectedTab(contents)); | 1084 EXPECT_TRUE(DevToolsWindow::GetDockedInstanceForInspectedTab(contents)); |
1077 | 1085 |
1078 // Disable devtools via policy. | 1086 // Disable devtools via policy. |
1079 PolicyMap policies; | 1087 PolicyMap policies; |
1080 policies.Set(key::kDeveloperToolsDisabled, POLICY_LEVEL_MANDATORY, | 1088 policies.Set(key::kDeveloperToolsDisabled, POLICY_LEVEL_MANDATORY, |
1081 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); | 1089 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); |
1082 provider_.UpdateChromePolicy(policies); | 1090 UpdateProviderPolicy(policies); |
1083 // The existing devtools window should have closed. | 1091 // The existing devtools window should have closed. |
1084 EXPECT_FALSE(DevToolsWindow::GetDockedInstanceForInspectedTab(contents)); | 1092 EXPECT_FALSE(DevToolsWindow::GetDockedInstanceForInspectedTab(contents)); |
1085 // And it's not possible to open it again. | 1093 // And it's not possible to open it again. |
1086 EXPECT_FALSE(chrome::ExecuteCommand(browser(), IDC_DEV_TOOLS)); | 1094 EXPECT_FALSE(chrome::ExecuteCommand(browser(), IDC_DEV_TOOLS)); |
1087 EXPECT_FALSE(DevToolsWindow::GetDockedInstanceForInspectedTab(contents)); | 1095 EXPECT_FALSE(DevToolsWindow::GetDockedInstanceForInspectedTab(contents)); |
1088 } | 1096 } |
1089 | 1097 |
1090 // This policy isn't available on Chrome OS. | 1098 // This policy isn't available on Chrome OS. |
1091 #if !defined(OS_CHROMEOS) | 1099 #if !defined(OS_CHROMEOS) |
1092 IN_PROC_BROWSER_TEST_F(PolicyTest, DownloadDirectory) { | 1100 IN_PROC_BROWSER_TEST_F(PolicyTest, DownloadDirectory) { |
(...skipping 13 matching lines...) Expand all Loading... |
1106 DownloadAndVerifyFile(browser(), initial_dir.path(), file); | 1114 DownloadAndVerifyFile(browser(), initial_dir.path(), file); |
1107 file_util::DieFileDie(initial_dir.path().Append(file), false); | 1115 file_util::DieFileDie(initial_dir.path().Append(file), false); |
1108 | 1116 |
1109 // Override the download directory with the policy and verify a download. | 1117 // Override the download directory with the policy and verify a download. |
1110 base::ScopedTempDir forced_dir; | 1118 base::ScopedTempDir forced_dir; |
1111 ASSERT_TRUE(forced_dir.CreateUniqueTempDir()); | 1119 ASSERT_TRUE(forced_dir.CreateUniqueTempDir()); |
1112 PolicyMap policies; | 1120 PolicyMap policies; |
1113 policies.Set(key::kDownloadDirectory, POLICY_LEVEL_MANDATORY, | 1121 policies.Set(key::kDownloadDirectory, POLICY_LEVEL_MANDATORY, |
1114 POLICY_SCOPE_USER, | 1122 POLICY_SCOPE_USER, |
1115 base::Value::CreateStringValue(forced_dir.path().value())); | 1123 base::Value::CreateStringValue(forced_dir.path().value())); |
1116 provider_.UpdateChromePolicy(policies); | 1124 UpdateProviderPolicy(policies); |
1117 DownloadAndVerifyFile(browser(), forced_dir.path(), file); | 1125 DownloadAndVerifyFile(browser(), forced_dir.path(), file); |
1118 // Verify that the first download location wasn't affected. | 1126 // Verify that the first download location wasn't affected. |
1119 EXPECT_FALSE(file_util::PathExists(initial_dir.path().Append(file))); | 1127 EXPECT_FALSE(file_util::PathExists(initial_dir.path().Append(file))); |
1120 } | 1128 } |
1121 #endif | 1129 #endif |
1122 | 1130 |
1123 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionInstallBlacklist) { | 1131 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionInstallBlacklist) { |
1124 // Verifies that blacklisted extensions can't be installed. | 1132 // Verifies that blacklisted extensions can't be installed. |
1125 ExtensionService* service = extension_service(); | 1133 ExtensionService* service = extension_service(); |
1126 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); | 1134 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
1127 ASSERT_FALSE(service->GetExtensionById(kAdBlockCrxId, true)); | 1135 ASSERT_FALSE(service->GetExtensionById(kAdBlockCrxId, true)); |
1128 base::ListValue blacklist; | 1136 base::ListValue blacklist; |
1129 blacklist.Append(base::Value::CreateStringValue(kGoodCrxId)); | 1137 blacklist.Append(base::Value::CreateStringValue(kGoodCrxId)); |
1130 PolicyMap policies; | 1138 PolicyMap policies; |
1131 policies.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, | 1139 policies.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, |
1132 POLICY_SCOPE_USER, blacklist.DeepCopy()); | 1140 POLICY_SCOPE_USER, blacklist.DeepCopy()); |
1133 provider_.UpdateChromePolicy(policies); | 1141 UpdateProviderPolicy(policies); |
1134 | 1142 |
1135 // "good.crx" is blacklisted. | 1143 // "good.crx" is blacklisted. |
1136 EXPECT_FALSE(InstallExtension(kGoodCrxName)); | 1144 EXPECT_FALSE(InstallExtension(kGoodCrxName)); |
1137 EXPECT_FALSE(service->GetExtensionById(kGoodCrxId, true)); | 1145 EXPECT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
1138 | 1146 |
1139 // "adblock.crx" is not. | 1147 // "adblock.crx" is not. |
1140 const extensions::Extension* adblock = InstallExtension(kAdBlockCrxName); | 1148 const extensions::Extension* adblock = InstallExtension(kAdBlockCrxName); |
1141 ASSERT_TRUE(adblock); | 1149 ASSERT_TRUE(adblock); |
1142 EXPECT_EQ(kAdBlockCrxId, adblock->id()); | 1150 EXPECT_EQ(kAdBlockCrxId, adblock->id()); |
1143 EXPECT_EQ(adblock, | 1151 EXPECT_EQ(adblock, |
1144 service->GetExtensionById(kAdBlockCrxId, true)); | 1152 service->GetExtensionById(kAdBlockCrxId, true)); |
1145 | 1153 |
1146 // Now blacklist all extensions. | 1154 // Now blacklist all extensions. |
1147 blacklist.Clear(); | 1155 blacklist.Clear(); |
1148 blacklist.Append(base::Value::CreateStringValue("*")); | 1156 blacklist.Append(base::Value::CreateStringValue("*")); |
1149 policies.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, | 1157 policies.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, |
1150 POLICY_SCOPE_USER, blacklist.DeepCopy()); | 1158 POLICY_SCOPE_USER, blacklist.DeepCopy()); |
1151 provider_.UpdateChromePolicy(policies); | 1159 UpdateProviderPolicy(policies); |
1152 // AdBlock was automatically removed. | 1160 // AdBlock was automatically removed. |
1153 ASSERT_FALSE(service->GetExtensionById(kAdBlockCrxId, true)); | 1161 ASSERT_FALSE(service->GetExtensionById(kAdBlockCrxId, true)); |
1154 // And can't be installed again, nor can good.crx. | 1162 // And can't be installed again, nor can good.crx. |
1155 EXPECT_FALSE(InstallExtension(kAdBlockCrxName)); | 1163 EXPECT_FALSE(InstallExtension(kAdBlockCrxName)); |
1156 EXPECT_FALSE(service->GetExtensionById(kAdBlockCrxId, true)); | 1164 EXPECT_FALSE(service->GetExtensionById(kAdBlockCrxId, true)); |
1157 EXPECT_FALSE(InstallExtension(kGoodCrxName)); | 1165 EXPECT_FALSE(InstallExtension(kGoodCrxName)); |
1158 EXPECT_FALSE(service->GetExtensionById(kGoodCrxId, true)); | 1166 EXPECT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
1159 } | 1167 } |
1160 | 1168 |
1161 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionInstallWhitelist) { | 1169 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionInstallWhitelist) { |
1162 // Verifies that the whitelist can open exceptions to the blacklist. | 1170 // Verifies that the whitelist can open exceptions to the blacklist. |
1163 ExtensionService* service = extension_service(); | 1171 ExtensionService* service = extension_service(); |
1164 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); | 1172 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
1165 ASSERT_FALSE(service->GetExtensionById(kAdBlockCrxId, true)); | 1173 ASSERT_FALSE(service->GetExtensionById(kAdBlockCrxId, true)); |
1166 base::ListValue blacklist; | 1174 base::ListValue blacklist; |
1167 blacklist.Append(base::Value::CreateStringValue("*")); | 1175 blacklist.Append(base::Value::CreateStringValue("*")); |
1168 base::ListValue whitelist; | 1176 base::ListValue whitelist; |
1169 whitelist.Append(base::Value::CreateStringValue(kGoodCrxId)); | 1177 whitelist.Append(base::Value::CreateStringValue(kGoodCrxId)); |
1170 PolicyMap policies; | 1178 PolicyMap policies; |
1171 policies.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, | 1179 policies.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, |
1172 POLICY_SCOPE_USER, blacklist.DeepCopy()); | 1180 POLICY_SCOPE_USER, blacklist.DeepCopy()); |
1173 policies.Set(key::kExtensionInstallWhitelist, POLICY_LEVEL_MANDATORY, | 1181 policies.Set(key::kExtensionInstallWhitelist, POLICY_LEVEL_MANDATORY, |
1174 POLICY_SCOPE_USER, whitelist.DeepCopy()); | 1182 POLICY_SCOPE_USER, whitelist.DeepCopy()); |
1175 provider_.UpdateChromePolicy(policies); | 1183 UpdateProviderPolicy(policies); |
1176 // "adblock.crx" is blacklisted. | 1184 // "adblock.crx" is blacklisted. |
1177 EXPECT_FALSE(InstallExtension(kAdBlockCrxName)); | 1185 EXPECT_FALSE(InstallExtension(kAdBlockCrxName)); |
1178 EXPECT_FALSE(service->GetExtensionById(kAdBlockCrxId, true)); | 1186 EXPECT_FALSE(service->GetExtensionById(kAdBlockCrxId, true)); |
1179 // "good.crx" has a whitelist exception. | 1187 // "good.crx" has a whitelist exception. |
1180 const extensions::Extension* good = InstallExtension(kGoodCrxName); | 1188 const extensions::Extension* good = InstallExtension(kGoodCrxName); |
1181 ASSERT_TRUE(good); | 1189 ASSERT_TRUE(good); |
1182 EXPECT_EQ(kGoodCrxId, good->id()); | 1190 EXPECT_EQ(kGoodCrxId, good->id()); |
1183 EXPECT_EQ(good, service->GetExtensionById(kGoodCrxId, true)); | 1191 EXPECT_EQ(good, service->GetExtensionById(kGoodCrxId, true)); |
1184 // The user can also remove this extension. | 1192 // The user can also remove this extension. |
1185 UninstallExtension(kGoodCrxId, true); | 1193 UninstallExtension(kGoodCrxId, true); |
(...skipping 14 matching lines...) Expand all Loading... |
1200 // Setting the forcelist extension should install "good.crx". | 1208 // Setting the forcelist extension should install "good.crx". |
1201 base::ListValue forcelist; | 1209 base::ListValue forcelist; |
1202 forcelist.Append(base::Value::CreateStringValue(StringPrintf( | 1210 forcelist.Append(base::Value::CreateStringValue(StringPrintf( |
1203 "%s;%s", kGoodCrxId, url.spec().c_str()))); | 1211 "%s;%s", kGoodCrxId, url.spec().c_str()))); |
1204 PolicyMap policies; | 1212 PolicyMap policies; |
1205 policies.Set(key::kExtensionInstallForcelist, POLICY_LEVEL_MANDATORY, | 1213 policies.Set(key::kExtensionInstallForcelist, POLICY_LEVEL_MANDATORY, |
1206 POLICY_SCOPE_USER, forcelist.DeepCopy()); | 1214 POLICY_SCOPE_USER, forcelist.DeepCopy()); |
1207 content::WindowedNotificationObserver observer( | 1215 content::WindowedNotificationObserver observer( |
1208 chrome::NOTIFICATION_EXTENSION_INSTALLED, | 1216 chrome::NOTIFICATION_EXTENSION_INSTALLED, |
1209 content::NotificationService::AllSources()); | 1217 content::NotificationService::AllSources()); |
1210 provider_.UpdateChromePolicy(policies); | 1218 UpdateProviderPolicy(policies); |
1211 observer.Wait(); | 1219 observer.Wait(); |
1212 content::Details<const extensions::Extension> details = observer.details(); | 1220 content::Details<const extensions::Extension> details = observer.details(); |
1213 EXPECT_EQ(kGoodCrxId, details->id()); | 1221 EXPECT_EQ(kGoodCrxId, details->id()); |
1214 EXPECT_EQ(details.ptr(), service->GetExtensionById(kGoodCrxId, true)); | 1222 EXPECT_EQ(details.ptr(), service->GetExtensionById(kGoodCrxId, true)); |
1215 // The user is not allowed to uninstall force-installed extensions. | 1223 // The user is not allowed to uninstall force-installed extensions. |
1216 UninstallExtension(kGoodCrxId, false); | 1224 UninstallExtension(kGoodCrxId, false); |
1217 } | 1225 } |
1218 | 1226 |
1219 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionAllowedTypes) { | 1227 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionAllowedTypes) { |
1220 // Verifies that extensions are blocked if policy specifies an allowed types | 1228 // Verifies that extensions are blocked if policy specifies an allowed types |
1221 // list and the extension's type is not on that list. | 1229 // list and the extension's type is not on that list. |
1222 ExtensionService* service = extension_service(); | 1230 ExtensionService* service = extension_service(); |
1223 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); | 1231 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
1224 ASSERT_FALSE(service->GetExtensionById(kHostedAppCrxId, true)); | 1232 ASSERT_FALSE(service->GetExtensionById(kHostedAppCrxId, true)); |
1225 | 1233 |
1226 base::ListValue allowed_types; | 1234 base::ListValue allowed_types; |
1227 allowed_types.AppendString("hosted_app"); | 1235 allowed_types.AppendString("hosted_app"); |
1228 PolicyMap policies; | 1236 PolicyMap policies; |
1229 policies.Set(key::kExtensionAllowedTypes, POLICY_LEVEL_MANDATORY, | 1237 policies.Set(key::kExtensionAllowedTypes, POLICY_LEVEL_MANDATORY, |
1230 POLICY_SCOPE_USER, allowed_types.DeepCopy()); | 1238 POLICY_SCOPE_USER, allowed_types.DeepCopy()); |
1231 provider_.UpdateChromePolicy(policies); | 1239 UpdateProviderPolicy(policies); |
1232 | 1240 |
1233 // "good.crx" is blocked. | 1241 // "good.crx" is blocked. |
1234 EXPECT_FALSE(InstallExtension(kGoodCrxName)); | 1242 EXPECT_FALSE(InstallExtension(kGoodCrxName)); |
1235 EXPECT_FALSE(service->GetExtensionById(kGoodCrxId, true)); | 1243 EXPECT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
1236 | 1244 |
1237 // "hosted_app.crx" is of a whitelisted type. | 1245 // "hosted_app.crx" is of a whitelisted type. |
1238 const extensions::Extension* hosted_app = InstallExtension(kHostedAppCrxName); | 1246 const extensions::Extension* hosted_app = InstallExtension(kHostedAppCrxName); |
1239 ASSERT_TRUE(hosted_app); | 1247 ASSERT_TRUE(hosted_app); |
1240 EXPECT_EQ(kHostedAppCrxId, hosted_app->id()); | 1248 EXPECT_EQ(kHostedAppCrxId, hosted_app->id()); |
1241 EXPECT_EQ(hosted_app, service->GetExtensionById(kHostedAppCrxId, true)); | 1249 EXPECT_EQ(hosted_app, service->GetExtensionById(kHostedAppCrxId, true)); |
(...skipping 14 matching lines...) Expand all Loading... |
1256 content::WebContents* contents = chrome::GetActiveWebContents(browser()); | 1264 content::WebContents* contents = chrome::GetActiveWebContents(browser()); |
1257 EXPECT_EQ(GURL(chrome::kAboutBlankURL), contents->GetURL()); | 1265 EXPECT_EQ(GURL(chrome::kAboutBlankURL), contents->GetURL()); |
1258 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_HOME)); | 1266 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_HOME)); |
1259 EXPECT_EQ(GURL(chrome::kChromeUIPolicyURL), contents->GetURL()); | 1267 EXPECT_EQ(GURL(chrome::kChromeUIPolicyURL), contents->GetURL()); |
1260 | 1268 |
1261 // Now override with policy. | 1269 // Now override with policy. |
1262 PolicyMap policies; | 1270 PolicyMap policies; |
1263 policies.Set(key::kHomepageLocation, POLICY_LEVEL_MANDATORY, | 1271 policies.Set(key::kHomepageLocation, POLICY_LEVEL_MANDATORY, |
1264 POLICY_SCOPE_USER, | 1272 POLICY_SCOPE_USER, |
1265 base::Value::CreateStringValue(chrome::kChromeUICreditsURL)); | 1273 base::Value::CreateStringValue(chrome::kChromeUICreditsURL)); |
1266 provider_.UpdateChromePolicy(policies); | 1274 UpdateProviderPolicy(policies); |
1267 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_HOME)); | 1275 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_HOME)); |
1268 content::WaitForLoadStop(contents); | 1276 content::WaitForLoadStop(contents); |
1269 EXPECT_EQ(GURL(chrome::kChromeUICreditsURL), contents->GetURL()); | 1277 EXPECT_EQ(GURL(chrome::kChromeUICreditsURL), contents->GetURL()); |
1270 | 1278 |
1271 policies.Set(key::kHomepageIsNewTabPage, POLICY_LEVEL_MANDATORY, | 1279 policies.Set(key::kHomepageIsNewTabPage, POLICY_LEVEL_MANDATORY, |
1272 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); | 1280 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); |
1273 provider_.UpdateChromePolicy(policies); | 1281 UpdateProviderPolicy(policies); |
1274 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_HOME)); | 1282 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_HOME)); |
1275 content::WaitForLoadStop(contents); | 1283 content::WaitForLoadStop(contents); |
1276 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), contents->GetURL()); | 1284 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), contents->GetURL()); |
1277 } | 1285 } |
1278 | 1286 |
1279 IN_PROC_BROWSER_TEST_F(PolicyTest, IncognitoEnabled) { | 1287 IN_PROC_BROWSER_TEST_F(PolicyTest, IncognitoEnabled) { |
1280 // Verifies that incognito windows can't be opened when disabled by policy. | 1288 // Verifies that incognito windows can't be opened when disabled by policy. |
1281 | 1289 |
1282 // Disable incognito via policy and verify that incognito windows can't be | 1290 // Disable incognito via policy and verify that incognito windows can't be |
1283 // opened. | 1291 // opened. |
1284 EXPECT_EQ(1u, BrowserList::size()); | 1292 EXPECT_EQ(1u, BrowserList::size()); |
1285 EXPECT_FALSE(BrowserList::IsOffTheRecordSessionActive()); | 1293 EXPECT_FALSE(BrowserList::IsOffTheRecordSessionActive()); |
1286 PolicyMap policies; | 1294 PolicyMap policies; |
1287 policies.Set(key::kIncognitoEnabled, POLICY_LEVEL_MANDATORY, | 1295 policies.Set(key::kIncognitoEnabled, POLICY_LEVEL_MANDATORY, |
1288 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false)); | 1296 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false)); |
1289 provider_.UpdateChromePolicy(policies); | 1297 UpdateProviderPolicy(policies); |
1290 EXPECT_FALSE(chrome::ExecuteCommand(browser(), IDC_NEW_INCOGNITO_WINDOW)); | 1298 EXPECT_FALSE(chrome::ExecuteCommand(browser(), IDC_NEW_INCOGNITO_WINDOW)); |
1291 EXPECT_EQ(1u, BrowserList::size()); | 1299 EXPECT_EQ(1u, BrowserList::size()); |
1292 EXPECT_FALSE(BrowserList::IsOffTheRecordSessionActive()); | 1300 EXPECT_FALSE(BrowserList::IsOffTheRecordSessionActive()); |
1293 | 1301 |
1294 // Enable via policy and verify that incognito windows can be opened. | 1302 // Enable via policy and verify that incognito windows can be opened. |
1295 policies.Set(key::kIncognitoEnabled, POLICY_LEVEL_MANDATORY, | 1303 policies.Set(key::kIncognitoEnabled, POLICY_LEVEL_MANDATORY, |
1296 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); | 1304 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); |
1297 provider_.UpdateChromePolicy(policies); | 1305 UpdateProviderPolicy(policies); |
1298 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_NEW_INCOGNITO_WINDOW)); | 1306 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_NEW_INCOGNITO_WINDOW)); |
1299 EXPECT_EQ(2u, BrowserList::size()); | 1307 EXPECT_EQ(2u, BrowserList::size()); |
1300 EXPECT_TRUE(BrowserList::IsOffTheRecordSessionActive()); | 1308 EXPECT_TRUE(BrowserList::IsOffTheRecordSessionActive()); |
1301 } | 1309 } |
1302 | 1310 |
1303 IN_PROC_BROWSER_TEST_F(PolicyTest, Javascript) { | 1311 IN_PROC_BROWSER_TEST_F(PolicyTest, Javascript) { |
1304 // Verifies that Javascript can be disabled. | 1312 // Verifies that Javascript can be disabled. |
1305 content::WebContents* contents = chrome::GetActiveWebContents(browser()); | 1313 content::WebContents* contents = chrome::GetActiveWebContents(browser()); |
1306 EXPECT_TRUE(IsJavascriptEnabled(contents)); | 1314 EXPECT_TRUE(IsJavascriptEnabled(contents)); |
1307 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS)); | 1315 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS)); |
1308 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS_CONSOLE)); | 1316 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS_CONSOLE)); |
1309 | 1317 |
1310 // Disable Javascript via policy. | 1318 // Disable Javascript via policy. |
1311 PolicyMap policies; | 1319 PolicyMap policies; |
1312 policies.Set(key::kJavascriptEnabled, POLICY_LEVEL_MANDATORY, | 1320 policies.Set(key::kJavascriptEnabled, POLICY_LEVEL_MANDATORY, |
1313 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false)); | 1321 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false)); |
1314 provider_.UpdateChromePolicy(policies); | 1322 UpdateProviderPolicy(policies); |
1315 // Reload the page. | 1323 // Reload the page. |
1316 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); | 1324 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); |
1317 EXPECT_FALSE(IsJavascriptEnabled(contents)); | 1325 EXPECT_FALSE(IsJavascriptEnabled(contents)); |
1318 // Developer tools still work when javascript is disabled. | 1326 // Developer tools still work when javascript is disabled. |
1319 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS)); | 1327 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS)); |
1320 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS_CONSOLE)); | 1328 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS_CONSOLE)); |
1321 // Javascript is always enabled for the internal pages. | 1329 // Javascript is always enabled for the internal pages. |
1322 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL)); | 1330 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL)); |
1323 EXPECT_TRUE(IsJavascriptEnabled(contents)); | 1331 EXPECT_TRUE(IsJavascriptEnabled(contents)); |
1324 | 1332 |
1325 // The javascript content setting policy overrides the javascript policy. | 1333 // The javascript content setting policy overrides the javascript policy. |
1326 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); | 1334 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); |
1327 EXPECT_FALSE(IsJavascriptEnabled(contents)); | 1335 EXPECT_FALSE(IsJavascriptEnabled(contents)); |
1328 policies.Set(key::kDefaultJavaScriptSetting, POLICY_LEVEL_MANDATORY, | 1336 policies.Set(key::kDefaultJavaScriptSetting, POLICY_LEVEL_MANDATORY, |
1329 POLICY_SCOPE_USER, | 1337 POLICY_SCOPE_USER, |
1330 base::Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); | 1338 base::Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); |
1331 provider_.UpdateChromePolicy(policies); | 1339 UpdateProviderPolicy(policies); |
1332 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); | 1340 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); |
1333 EXPECT_TRUE(IsJavascriptEnabled(contents)); | 1341 EXPECT_TRUE(IsJavascriptEnabled(contents)); |
1334 } | 1342 } |
1335 | 1343 |
1336 IN_PROC_BROWSER_TEST_F(PolicyTest, SavingBrowserHistoryDisabled) { | 1344 IN_PROC_BROWSER_TEST_F(PolicyTest, SavingBrowserHistoryDisabled) { |
1337 // Verifies that browsing history is not saved. | 1345 // Verifies that browsing history is not saved. |
1338 PolicyMap policies; | 1346 PolicyMap policies; |
1339 policies.Set(key::kSavingBrowserHistoryDisabled, POLICY_LEVEL_MANDATORY, | 1347 policies.Set(key::kSavingBrowserHistoryDisabled, POLICY_LEVEL_MANDATORY, |
1340 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); | 1348 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); |
1341 provider_.UpdateChromePolicy(policies); | 1349 UpdateProviderPolicy(policies); |
1342 GURL url = ui_test_utils::GetTestUrl( | 1350 GURL url = ui_test_utils::GetTestUrl( |
1343 FilePath(FilePath::kCurrentDirectory), | 1351 FilePath(FilePath::kCurrentDirectory), |
1344 FilePath(FILE_PATH_LITERAL("empty.html"))); | 1352 FilePath(FILE_PATH_LITERAL("empty.html"))); |
1345 ui_test_utils::NavigateToURL(browser(), url); | 1353 ui_test_utils::NavigateToURL(browser(), url); |
1346 // Verify that the navigation wasn't saved in the history. | 1354 // Verify that the navigation wasn't saved in the history. |
1347 ui_test_utils::HistoryEnumerator enumerator1(browser()->profile()); | 1355 ui_test_utils::HistoryEnumerator enumerator1(browser()->profile()); |
1348 EXPECT_EQ(0u, enumerator1.urls().size()); | 1356 EXPECT_EQ(0u, enumerator1.urls().size()); |
1349 | 1357 |
1350 // Now flip the policy and try again. | 1358 // Now flip the policy and try again. |
1351 policies.Set(key::kSavingBrowserHistoryDisabled, POLICY_LEVEL_MANDATORY, | 1359 policies.Set(key::kSavingBrowserHistoryDisabled, POLICY_LEVEL_MANDATORY, |
1352 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false)); | 1360 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false)); |
1353 provider_.UpdateChromePolicy(policies); | 1361 UpdateProviderPolicy(policies); |
1354 ui_test_utils::NavigateToURL(browser(), url); | 1362 ui_test_utils::NavigateToURL(browser(), url); |
1355 // Verify that the navigation was saved in the history. | 1363 // Verify that the navigation was saved in the history. |
1356 ui_test_utils::HistoryEnumerator enumerator2(browser()->profile()); | 1364 ui_test_utils::HistoryEnumerator enumerator2(browser()->profile()); |
1357 ASSERT_EQ(1u, enumerator2.urls().size()); | 1365 ASSERT_EQ(1u, enumerator2.urls().size()); |
1358 EXPECT_EQ(url, enumerator2.urls()[0]); | 1366 EXPECT_EQ(url, enumerator2.urls()[0]); |
1359 } | 1367 } |
1360 | 1368 |
1361 IN_PROC_BROWSER_TEST_F(PolicyTest, TranslateEnabled) { | 1369 IN_PROC_BROWSER_TEST_F(PolicyTest, TranslateEnabled) { |
1362 // Verifies that translate can be forced enabled or disabled by policy. | 1370 // Verifies that translate can be forced enabled or disabled by policy. |
1363 | 1371 |
1364 // Get the InfoBarService, and verify that there are no infobars on startup. | 1372 // Get the InfoBarService, and verify that there are no infobars on startup. |
1365 content::WebContents* contents = chrome::GetActiveWebContents(browser()); | 1373 content::WebContents* contents = chrome::GetActiveWebContents(browser()); |
1366 ASSERT_TRUE(contents); | 1374 ASSERT_TRUE(contents); |
1367 InfoBarService* infobar_service = InfoBarService::FromWebContents(contents); | 1375 InfoBarService* infobar_service = InfoBarService::FromWebContents(contents); |
1368 ASSERT_TRUE(infobar_service); | 1376 ASSERT_TRUE(infobar_service); |
1369 EXPECT_EQ(0u, infobar_service->GetInfoBarCount()); | 1377 EXPECT_EQ(0u, infobar_service->GetInfoBarCount()); |
1370 | 1378 |
1371 // Force enable the translate feature. | 1379 // Force enable the translate feature. |
1372 PolicyMap policies; | 1380 PolicyMap policies; |
1373 policies.Set(key::kTranslateEnabled, POLICY_LEVEL_MANDATORY, | 1381 policies.Set(key::kTranslateEnabled, POLICY_LEVEL_MANDATORY, |
1374 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); | 1382 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); |
1375 provider_.UpdateChromePolicy(policies); | 1383 UpdateProviderPolicy(policies); |
1376 // Instead of waiting for NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, this test | 1384 // Instead of waiting for NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, this test |
1377 // waits for NOTIFICATION_TAB_LANGUAGE_DETERMINED because that's what the | 1385 // waits for NOTIFICATION_TAB_LANGUAGE_DETERMINED because that's what the |
1378 // TranslateManager observes. This allows checking that an infobar is NOT | 1386 // TranslateManager observes. This allows checking that an infobar is NOT |
1379 // shown below, without polling for infobars for some indeterminate amount | 1387 // shown below, without polling for infobars for some indeterminate amount |
1380 // of time. | 1388 // of time. |
1381 GURL url = ui_test_utils::GetTestUrl( | 1389 GURL url = ui_test_utils::GetTestUrl( |
1382 FilePath(), FilePath(FILE_PATH_LITERAL("french_page.html"))); | 1390 FilePath(), FilePath(FILE_PATH_LITERAL("french_page.html"))); |
1383 content::WindowedNotificationObserver language_observer1( | 1391 content::WindowedNotificationObserver language_observer1( |
1384 chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, | 1392 chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, |
1385 content::NotificationService::AllSources()); | 1393 content::NotificationService::AllSources()); |
1386 ui_test_utils::NavigateToURL(browser(), url); | 1394 ui_test_utils::NavigateToURL(browser(), url); |
1387 language_observer1.Wait(); | 1395 language_observer1.Wait(); |
1388 // Verify that the translate infobar showed up. | 1396 // Verify that the translate infobar showed up. |
1389 ASSERT_EQ(1u, infobar_service->GetInfoBarCount()); | 1397 ASSERT_EQ(1u, infobar_service->GetInfoBarCount()); |
1390 InfoBarDelegate* infobar_delegate = | 1398 InfoBarDelegate* infobar_delegate = |
1391 infobar_service->GetInfoBarDelegateAt(0); | 1399 infobar_service->GetInfoBarDelegateAt(0); |
1392 TranslateInfoBarDelegate* delegate = | 1400 TranslateInfoBarDelegate* delegate = |
1393 infobar_delegate->AsTranslateInfoBarDelegate(); | 1401 infobar_delegate->AsTranslateInfoBarDelegate(); |
1394 ASSERT_TRUE(delegate); | 1402 ASSERT_TRUE(delegate); |
1395 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, delegate->type()); | 1403 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, delegate->type()); |
1396 EXPECT_EQ("fr", delegate->original_language_code()); | 1404 EXPECT_EQ("fr", delegate->original_language_code()); |
1397 | 1405 |
1398 // Now force disable translate. | 1406 // Now force disable translate. |
1399 infobar_service->RemoveInfoBar(infobar_delegate); | 1407 infobar_service->RemoveInfoBar(infobar_delegate); |
1400 EXPECT_EQ(0u, infobar_service->GetInfoBarCount()); | 1408 EXPECT_EQ(0u, infobar_service->GetInfoBarCount()); |
1401 policies.Set(key::kTranslateEnabled, POLICY_LEVEL_MANDATORY, | 1409 policies.Set(key::kTranslateEnabled, POLICY_LEVEL_MANDATORY, |
1402 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false)); | 1410 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false)); |
1403 provider_.UpdateChromePolicy(policies); | 1411 UpdateProviderPolicy(policies); |
1404 // Navigating to the same URL now doesn't trigger an infobar. | 1412 // Navigating to the same URL now doesn't trigger an infobar. |
1405 content::WindowedNotificationObserver language_observer2( | 1413 content::WindowedNotificationObserver language_observer2( |
1406 chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, | 1414 chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, |
1407 content::NotificationService::AllSources()); | 1415 content::NotificationService::AllSources()); |
1408 ui_test_utils::NavigateToURL(browser(), url); | 1416 ui_test_utils::NavigateToURL(browser(), url); |
1409 language_observer2.Wait(); | 1417 language_observer2.Wait(); |
1410 EXPECT_EQ(0u, infobar_service->GetInfoBarCount()); | 1418 EXPECT_EQ(0u, infobar_service->GetInfoBarCount()); |
1411 } | 1419 } |
1412 | 1420 |
1413 IN_PROC_BROWSER_TEST_F(PolicyTest, URLBlacklist) { | 1421 IN_PROC_BROWSER_TEST_F(PolicyTest, URLBlacklist) { |
(...skipping 17 matching lines...) Expand all Loading... |
1431 // Verify that all the URLs can be opened without a blacklist. | 1439 // Verify that all the URLs can be opened without a blacklist. |
1432 for (size_t i = 0; i < arraysize(kURLS); ++i) | 1440 for (size_t i = 0; i < arraysize(kURLS); ++i) |
1433 CheckCanOpenURL(browser(), kURLS[i]); | 1441 CheckCanOpenURL(browser(), kURLS[i]); |
1434 | 1442 |
1435 // Set a blacklist. | 1443 // Set a blacklist. |
1436 base::ListValue blacklist; | 1444 base::ListValue blacklist; |
1437 blacklist.Append(base::Value::CreateStringValue("bbb.com")); | 1445 blacklist.Append(base::Value::CreateStringValue("bbb.com")); |
1438 PolicyMap policies; | 1446 PolicyMap policies; |
1439 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, | 1447 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, |
1440 POLICY_SCOPE_USER, blacklist.DeepCopy()); | 1448 POLICY_SCOPE_USER, blacklist.DeepCopy()); |
1441 provider_.UpdateChromePolicy(policies); | 1449 UpdateProviderPolicy(policies); |
1442 FlushBlacklistPolicy(); | 1450 FlushBlacklistPolicy(); |
1443 // All bbb.com URLs are blocked. | 1451 // All bbb.com URLs are blocked. |
1444 CheckCanOpenURL(browser(), kURLS[0]); | 1452 CheckCanOpenURL(browser(), kURLS[0]); |
1445 for (size_t i = 1; i < arraysize(kURLS); ++i) | 1453 for (size_t i = 1; i < arraysize(kURLS); ++i) |
1446 CheckURLIsBlocked(browser(), kURLS[i]); | 1454 CheckURLIsBlocked(browser(), kURLS[i]); |
1447 | 1455 |
1448 // Whitelist some sites of bbb.com. | 1456 // Whitelist some sites of bbb.com. |
1449 base::ListValue whitelist; | 1457 base::ListValue whitelist; |
1450 whitelist.Append(base::Value::CreateStringValue("sub.bbb.com")); | 1458 whitelist.Append(base::Value::CreateStringValue("sub.bbb.com")); |
1451 whitelist.Append(base::Value::CreateStringValue("bbb.com/policy")); | 1459 whitelist.Append(base::Value::CreateStringValue("bbb.com/policy")); |
1452 policies.Set(key::kURLWhitelist, POLICY_LEVEL_MANDATORY, | 1460 policies.Set(key::kURLWhitelist, POLICY_LEVEL_MANDATORY, |
1453 POLICY_SCOPE_USER, whitelist.DeepCopy()); | 1461 POLICY_SCOPE_USER, whitelist.DeepCopy()); |
1454 provider_.UpdateChromePolicy(policies); | 1462 UpdateProviderPolicy(policies); |
1455 FlushBlacklistPolicy(); | 1463 FlushBlacklistPolicy(); |
1456 CheckCanOpenURL(browser(), kURLS[0]); | 1464 CheckCanOpenURL(browser(), kURLS[0]); |
1457 CheckURLIsBlocked(browser(), kURLS[1]); | 1465 CheckURLIsBlocked(browser(), kURLS[1]); |
1458 CheckCanOpenURL(browser(), kURLS[2]); | 1466 CheckCanOpenURL(browser(), kURLS[2]); |
1459 CheckCanOpenURL(browser(), kURLS[3]); | 1467 CheckCanOpenURL(browser(), kURLS[3]); |
1460 | 1468 |
1461 BrowserThread::PostTaskAndReply( | 1469 BrowserThread::PostTaskAndReply( |
1462 BrowserThread::IO, FROM_HERE, | 1470 BrowserThread::IO, FROM_HERE, |
1463 base::Bind(UndoRedirectHostsToTestData, kURLS, arraysize(kURLS)), | 1471 base::Bind(UndoRedirectHostsToTestData, kURLS, arraysize(kURLS)), |
1464 MessageLoop::QuitClosure()); | 1472 MessageLoop::QuitClosure()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1502 bool prior_state = audio_handler->IsMuted(); | 1510 bool prior_state = audio_handler->IsMuted(); |
1503 // Make sure we are not muted and then toggle the policy and observe if the | 1511 // Make sure we are not muted and then toggle the policy and observe if the |
1504 // trigger was successful. | 1512 // trigger was successful. |
1505 EXPECT_CALL(*mock, OnMuteToggled()).Times(1); | 1513 EXPECT_CALL(*mock, OnMuteToggled()).Times(1); |
1506 audio_handler->SetMuted(false); | 1514 audio_handler->SetMuted(false); |
1507 EXPECT_FALSE(audio_handler->IsMuted()); | 1515 EXPECT_FALSE(audio_handler->IsMuted()); |
1508 EXPECT_CALL(*mock, OnMuteToggled()).Times(1); | 1516 EXPECT_CALL(*mock, OnMuteToggled()).Times(1); |
1509 PolicyMap policies; | 1517 PolicyMap policies; |
1510 policies.Set(key::kAudioOutputAllowed, POLICY_LEVEL_MANDATORY, | 1518 policies.Set(key::kAudioOutputAllowed, POLICY_LEVEL_MANDATORY, |
1511 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false)); | 1519 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false)); |
1512 provider_.UpdateChromePolicy(policies); | 1520 UpdateProviderPolicy(policies); |
1513 EXPECT_TRUE(audio_handler->IsMuted()); | 1521 EXPECT_TRUE(audio_handler->IsMuted()); |
1514 // This should not change the state now and should not trigger OnMuteToggled. | 1522 // This should not change the state now and should not trigger OnMuteToggled. |
1515 audio_handler->SetMuted(false); | 1523 audio_handler->SetMuted(false); |
1516 EXPECT_TRUE(audio_handler->IsMuted()); | 1524 EXPECT_TRUE(audio_handler->IsMuted()); |
1517 | 1525 |
1518 // Toggle back and observe if the trigger was successful. | 1526 // Toggle back and observe if the trigger was successful. |
1519 EXPECT_CALL(*mock, OnMuteToggled()).Times(1); | 1527 EXPECT_CALL(*mock, OnMuteToggled()).Times(1); |
1520 policies.Set(key::kAudioOutputAllowed, POLICY_LEVEL_MANDATORY, | 1528 policies.Set(key::kAudioOutputAllowed, POLICY_LEVEL_MANDATORY, |
1521 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); | 1529 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); |
1522 provider_.UpdateChromePolicy(policies); | 1530 UpdateProviderPolicy(policies); |
1523 EXPECT_FALSE(audio_handler->IsMuted()); | 1531 EXPECT_FALSE(audio_handler->IsMuted()); |
1524 EXPECT_CALL(*mock, OnMuteToggled()).Times(1); | 1532 EXPECT_CALL(*mock, OnMuteToggled()).Times(1); |
1525 audio_handler->SetMuted(true); | 1533 audio_handler->SetMuted(true); |
1526 EXPECT_TRUE(audio_handler->IsMuted()); | 1534 EXPECT_TRUE(audio_handler->IsMuted()); |
1527 // Revert the prior state. | 1535 // Revert the prior state. |
1528 EXPECT_CALL(*mock, OnMuteToggled()).Times(1); | 1536 EXPECT_CALL(*mock, OnMuteToggled()).Times(1); |
1529 audio_handler->SetMuted(prior_state); | 1537 audio_handler->SetMuted(prior_state); |
1530 audio_handler->RemoveVolumeObserver(mock.get()); | 1538 audio_handler->RemoveVolumeObserver(mock.get()); |
1531 } | 1539 } |
1532 #endif | 1540 #endif |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1743 EXPECT_EQ(kExpectedLabel, text.substr(0, kExpectedLabel.size())); | 1751 EXPECT_EQ(kExpectedLabel, text.substr(0, kExpectedLabel.size())); |
1744 // HomepageLocation has policy ID 1. | 1752 // HomepageLocation has policy ID 1. |
1745 EXPECT_NE(std::string::npos, text.find("<br>1 ---")); | 1753 EXPECT_NE(std::string::npos, text.find("<br>1 ---")); |
1746 // ShowHomeButton has policy ID 35. | 1754 // ShowHomeButton has policy ID 35. |
1747 EXPECT_NE(std::string::npos, text.find("<br>35 ---")); | 1755 EXPECT_NE(std::string::npos, text.find("<br>35 ---")); |
1748 // BookmarkBarEnabled has policy ID 82. | 1756 // BookmarkBarEnabled has policy ID 82. |
1749 EXPECT_NE(std::string::npos, text.find("<br>82 ---")); | 1757 EXPECT_NE(std::string::npos, text.find("<br>82 ---")); |
1750 } | 1758 } |
1751 | 1759 |
1752 } // namespace policy | 1760 } // namespace policy |
OLD | NEW |