| 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 <string> |
| 6 |
| 5 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
| 6 #include "chrome/browser/policy/browser_policy_connector.h" | 8 #include "chrome/browser/policy/browser_policy_connector.h" |
| 7 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 9 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
| 8 #include "chrome/browser/policy/policy_map.h" | 10 #include "chrome/browser/policy/policy_map.h" |
| 9 #include "chrome/browser/prefs/pref_service.h" | 11 #include "chrome/browser/prefs/pref_service.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/ui/bookmarks/bookmark_bar.h" | 13 #include "chrome/browser/ui/bookmarks/bookmark_bar.h" |
| 12 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 14 #include "chrome/test/base/in_process_browser_test.h" | 16 #include "chrome/test/base/in_process_browser_test.h" |
| 15 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
| 18 #include "content/public/test/browser_test_utils.h" |
| 16 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
| 17 #include "policy/policy_constants.h" | 20 #include "policy/policy_constants.h" |
| 18 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 23 |
| 21 using testing::Return; | 24 using testing::Return; |
| 22 | 25 |
| 23 namespace policy { | 26 namespace policy { |
| 24 | 27 |
| 28 namespace { |
| 29 |
| 30 const char kURL[] = "http://example.com"; |
| 31 const char kCookieValue[] = "converted=true"; |
| 32 // Assigned to Philip J. Fry to fix eventually. |
| 33 const char kCookieOptions[] = ";expires=Wed Jan 01 3000 00:00:00 GMT"; |
| 34 |
| 35 } // namespace |
| 36 |
| 25 class PolicyTest : public InProcessBrowserTest { | 37 class PolicyTest : public InProcessBrowserTest { |
| 26 protected: | 38 protected: |
| 27 PolicyTest() {} | 39 PolicyTest() {} |
| 28 | 40 |
| 29 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 41 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 30 EXPECT_CALL(provider_, IsInitializationComplete()) | 42 EXPECT_CALL(provider_, IsInitializationComplete()) |
| 31 .WillRepeatedly(Return(true)); | 43 .WillRepeatedly(Return(true)); |
| 32 BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); | 44 BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); |
| 33 } | 45 } |
| 34 | 46 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 63 EXPECT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state()); | 75 EXPECT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state()); |
| 64 | 76 |
| 65 policies.Clear(); | 77 policies.Clear(); |
| 66 provider_.UpdateChromePolicy(policies); | 78 provider_.UpdateChromePolicy(policies); |
| 67 EXPECT_FALSE(prefs->IsManagedPreference(prefs::kShowBookmarkBar)); | 79 EXPECT_FALSE(prefs->IsManagedPreference(prefs::kShowBookmarkBar)); |
| 68 EXPECT_FALSE(prefs->GetBoolean(prefs::kShowBookmarkBar)); | 80 EXPECT_FALSE(prefs->GetBoolean(prefs::kShowBookmarkBar)); |
| 69 // The bookmark bar is shown detached in the NTP, when disabled by prefs only. | 81 // The bookmark bar is shown detached in the NTP, when disabled by prefs only. |
| 70 EXPECT_EQ(BookmarkBar::DETACHED, browser()->bookmark_bar_state()); | 82 EXPECT_EQ(BookmarkBar::DETACHED, browser()->bookmark_bar_state()); |
| 71 } | 83 } |
| 72 | 84 |
| 85 IN_PROC_BROWSER_TEST_F(PolicyTest, PRE_PRE_ClearSiteDataOnExit) { |
| 86 Profile* profile = browser()->profile(); |
| 87 GURL url(kURL); |
| 88 // No cookies at startup. |
| 89 EXPECT_TRUE(content::GetCookies(profile, url).empty()); |
| 90 // Set a cookie now. |
| 91 std::string value = std::string(kCookieValue) + std::string(kCookieOptions); |
| 92 EXPECT_TRUE(content::SetCookie(profile, url, value)); |
| 93 // Verify it was set. |
| 94 EXPECT_EQ(kCookieValue, GetCookies(profile, url)); |
| 95 } |
| 96 |
| 97 IN_PROC_BROWSER_TEST_F(PolicyTest, PRE_ClearSiteDataOnExit) { |
| 98 // Verify that the cookie persists across restarts. |
| 99 EXPECT_EQ(kCookieValue, GetCookies(browser()->profile(), GURL(kURL))); |
| 100 // Now set the policy and the cookie should be gone after another restart. |
| 101 PolicyMap policies; |
| 102 policies.Set(key::kClearSiteDataOnExit, POLICY_LEVEL_MANDATORY, |
| 103 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); |
| 104 provider_.UpdateChromePolicy(policies); |
| 105 } |
| 106 |
| 107 IN_PROC_BROWSER_TEST_F(PolicyTest, ClearSiteDataOnExit) { |
| 108 // Verify that the cookie is gone. |
| 109 EXPECT_TRUE(GetCookies(browser()->profile(), GURL(kURL)).empty()); |
| 110 } |
| 111 |
| 73 } // namespace policy | 112 } // namespace policy |
| OLD | NEW |