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