forked from chromium/chromium
-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add enterprise policy for :--foo deprecation
I am changing the syntax of the custom state pseudo class from :--foo to :state(foo). In order to do that, I am deprecating and eventually removing support for :--foo. We have already been emitting a console error when :--foo is used for several releases, but in order to actually disable it by default we need an enterprise policy in case anyone is relying on it. After having this enterprise policy available, I will disable the CSSCustomStateDeprecatedSyntax flag by default, and then after enough milestones, I will remove the code for it and retire/deprecate this enterprise policy. This deprecation for the old syntax: https://chromestatus.com/feature/5140610730426368 https://groups.google.com/a/chromium.org/g/blink-dev/c/JvpHoUfhJYE/m/uRtWiqoHAQAJ The new syntax which has already been enabled by default: https://chromestatus.com/feature/5586433790443520 https://groups.google.com/a/chromium.org/g/blink-dev/c/GDmNaxAuCY4/m/pwH7c4p6AAAJ Bug: 1514397 Change-Id: I41785603403087a0a7e2e0d4e38ad2be6b012dc1 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5538599 Reviewed-by: Chris Harrelson <chrishtr@chromium.org> Reviewed-by: Victor Gabriel Savu <vsavu@google.com> Reviewed-by: Igor <igorcov@chromium.org> Commit-Queue: Joey Arhar <jarhar@chromium.org> Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com> Cr-Commit-Position: refs/heads/main@{#1303748}
- Loading branch information
1 parent
03904bd
commit 1aad67a
Showing
15 changed files
with
254 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
chrome/browser/policy/test/css_custom_state_deprecated_syntax_policy_browsertest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright 2024 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "base/test/scoped_feature_list.h" | ||
#include "chrome/browser/policy/policy_test_utils.h" | ||
#include "components/policy/policy_constants.h" | ||
#include "content/public/test/browser_test.h" | ||
#include "content/public/test/browser_test_utils.h" | ||
#include "content/public/test/test_utils.h" | ||
#include "third_party/blink/public/common/features.h" | ||
|
||
namespace policy { | ||
|
||
enum class Policy { | ||
kDefault, | ||
kTrue, | ||
kFalse, | ||
}; | ||
|
||
class CSSCustomStateDeprecatedSyntaxEnabledPolicyBrowserTest | ||
: public PolicyTest, | ||
public ::testing::WithParamInterface<Policy> { | ||
public: | ||
static std::string DescribeParams( | ||
const ::testing::TestParamInfo<ParamType>& info) { | ||
switch (info.param) { | ||
case Policy::kDefault: | ||
return "Default"; | ||
case Policy::kTrue: | ||
return "True"; | ||
case Policy::kFalse: | ||
return "False"; | ||
} | ||
} | ||
|
||
protected: | ||
void SetUpCommandLine(base::CommandLine* command_line) override { | ||
feature_list_.InitAndDisableFeature( | ||
blink::features::kCSSCustomStateDeprecatedSyntax); | ||
} | ||
|
||
void SetUpInProcessBrowserTestFixture() override { | ||
PolicyTest::SetUpInProcessBrowserTestFixture(); | ||
|
||
if (GetParam() == Policy::kDefault) { | ||
return; | ||
} | ||
PolicyMap policies; | ||
SetPolicy(&policies, key::kCSSCustomStateDeprecatedSyntaxEnabled, | ||
base::Value(GetParam() == Policy::kTrue)); | ||
UpdateProviderPolicy(policies); | ||
} | ||
|
||
private: | ||
base::test::ScopedFeatureList feature_list_; | ||
}; | ||
|
||
IN_PROC_BROWSER_TEST_P(CSSCustomStateDeprecatedSyntaxEnabledPolicyBrowserTest, | ||
PolicyIsFollowed) { | ||
// Both false and the default (no parameter) should be disabled. | ||
const bool expected_enabled = GetParam() == Policy::kTrue; | ||
|
||
ASSERT_TRUE(embedded_test_server()->Start()); | ||
const GURL url(embedded_test_server()->GetURL( | ||
"/css_custom_state_deprecated_syntax.html")); | ||
ASSERT_TRUE(NavigateToUrl(url, this)); | ||
|
||
content::DOMMessageQueue message_queue( | ||
chrome_test_utils::GetActiveWebContents(this)); | ||
std::string enabled_color = "\"rgb(255, 0, 0)\""; | ||
std::string disabled_color = "\"rgb(0, 0, 255)\""; | ||
|
||
content::ExecuteScriptAsync( | ||
chrome_test_utils::GetActiveWebContents(this), | ||
"window.domAutomationController.send(window.deprecatedSyntaxColor)"); | ||
std::string deprecated_syntax_color; | ||
ASSERT_TRUE(message_queue.WaitForMessage(&deprecated_syntax_color)); | ||
std::string expected_color = | ||
expected_enabled ? enabled_color : disabled_color; | ||
EXPECT_EQ(deprecated_syntax_color, expected_color); | ||
|
||
// The new syntax should always be enabled and should not be affected by this | ||
// enterprise policy. | ||
content::ExecuteScriptAsync( | ||
chrome_test_utils::GetActiveWebContents(this), | ||
"window.domAutomationController.send(window.newSyntaxColor)"); | ||
std::string new_syntax_color; | ||
ASSERT_TRUE(message_queue.WaitForMessage(&new_syntax_color)); | ||
EXPECT_EQ(new_syntax_color, enabled_color); | ||
} | ||
|
||
INSTANTIATE_TEST_SUITE_P( | ||
/* no prefix */, | ||
CSSCustomStateDeprecatedSyntaxEnabledPolicyBrowserTest, | ||
::testing::Values(Policy::kDefault, Policy::kTrue, Policy::kFalse), | ||
&CSSCustomStateDeprecatedSyntaxEnabledPolicyBrowserTest::DescribeParams); | ||
|
||
} // namespace policy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!DOCTYPE html> | ||
|
||
<style> | ||
deprecated-syntax-element, new-syntax-element { | ||
color: blue; | ||
} | ||
deprecated-syntax-element:--foo { | ||
color: red; | ||
} | ||
new-syntax-element:state(foo) { | ||
color: red; | ||
} | ||
</style> | ||
|
||
<deprecated-syntax-element> | ||
<div>hello world</div> | ||
</deprecated-syntax-element> | ||
<new-syntax-element> | ||
<div>hello world</div> | ||
</new-syntax-element> | ||
|
||
<script> | ||
class DeprecatedSyntaxElement extends HTMLElement { | ||
constructor() { | ||
super(); | ||
this.internals = this.attachInternals(); | ||
this.internals.states.add('--foo'); | ||
} | ||
}; | ||
customElements.define('deprecated-syntax-element', DeprecatedSyntaxElement); | ||
|
||
class NewSyntaxElement extends HTMLElement { | ||
constructor() { | ||
super(); | ||
this.internals = this.attachInternals(); | ||
this.internals.states.add('foo'); | ||
} | ||
}; | ||
customElements.define('new-syntax-element', NewSyntaxElement); | ||
|
||
const deprecatedSyntaxElement = document.querySelector('deprecated-syntax-element'); | ||
const newSyntaxElement = document.querySelector('new-syntax-element'); | ||
window.deprecatedSyntaxColor = getComputedStyle(deprecatedSyntaxElement).color; | ||
window.newSyntaxColor = getComputedStyle(newSyntaxElement).color; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...ces/templates/policy_definitions/Miscellaneous/CSSCustomStateDeprecatedSyntaxEnabled.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
caption: Controls whether the deprecated <ph name="CUSTOM_STATE_DEPRECATED_SYNTAX">:--foo</ph> syntax for CSS custom state is enabled | ||
desc: |2- | ||
The <ph name="CUSTOM_STATE_DEPRECATED_SYNTAX">:--foo</ph> syntax for the CSS custom state feature is being changed to <ph name="CUSTOM_STATE_NEW_SYNTAX">:state(foo)</ph> in <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph> in order to comply with changes that have been made in <ph name="FIREFOX_PRODUCT_NAME">Firefox</ph> and <ph name="SAFARI_PRODUCT_NAME">Safari</ph>. This policy allows the old deprecated syntax to be enabled until M133. | ||
The deprecation may break some <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph>-only websites which use the deprecated <ph name="CUSTOM_STATE_DEPRECATED_SYNTAX">:--foo</ph> syntax. | ||
If this policy is enabled, then the old deprecated syntax will be enabled. | ||
If this policy is disabled, then the old deprecated syntax will be disabled. | ||
If this policy is not set, then the old deprecated syntax will be disabled. | ||
default: false | ||
example_value: true | ||
features: | ||
dynamic_refresh: false | ||
per_profile: true | ||
items: | ||
- caption: Old deprecated syntax will be enabled. | ||
value: true | ||
- caption: Old deprecated syntax will be disabled. | ||
value: false | ||
owners: | ||
- jarhar@chromium.org | ||
- masonf@chromium.org | ||
- dom-dev@google.com | ||
schema: | ||
type: boolean | ||
supported_on: | ||
- chrome.*:127- | ||
- chrome_os:127- | ||
- android:127- | ||
- webview_android:127- | ||
tags: [] | ||
type: main | ||
deprecated: false | ||
device_only: false |
43 changes: 43 additions & 0 deletions
43
components/policy/test/data/pref_mapping/CSSCustomStateDeprecatedSyntaxEnabled.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
[ | ||
{ | ||
"os": [ | ||
"win", | ||
"linux", | ||
"mac", | ||
"chromeos_ash", | ||
"chromeos_lacros", | ||
"android", | ||
"fuchsia" | ||
], | ||
"policy_pref_mapping_tests": [ | ||
{ | ||
"policies": { | ||
"CSSCustomStateDeprecatedSyntaxEnabled": true | ||
}, | ||
"prefs": { | ||
"policy.css_custom_state_deprecated_syntax_enabled": { | ||
"value": true | ||
} | ||
} | ||
}, | ||
{ | ||
"policies": { | ||
"CSSCustomStateDeprecatedSyntaxEnabled": false | ||
}, | ||
"prefs": { | ||
"policy.css_custom_state_deprecated_syntax_enabled": { | ||
"value": false | ||
} | ||
} | ||
}, | ||
{ | ||
"policies": {}, | ||
"prefs": { | ||
"policy.css_custom_state_deprecated_syntax_enabled": { | ||
"default_value": false | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters