-
Notifications
You must be signed in to change notification settings - Fork 895
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support brave-variations test seed testing process (#24604)
Add --variations-pr flag support.
- Loading branch information
Showing
16 changed files
with
230 additions
and
33 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
#include "brave/components/variations/command_line_utils.h" | ||
|
||
#include <string> | ||
|
||
#include "base/command_line.h" | ||
#include "base/strings/string_util.h" | ||
#include "brave/components/variations/buildflags.h" | ||
#include "brave/components/variations/switches.h" | ||
#include "components/variations/variations_switches.h" | ||
|
||
namespace variations { | ||
|
||
namespace { | ||
|
||
// A GitHub workflow in the brave/brave-variations repository generates the test | ||
// seed and uploads it to a URL with the following template, where $1 is the | ||
// pull request number. | ||
constexpr char kVariationsPrTestSeedUrlTemplate[] = | ||
"https://griffin.brave.com/pull/$1/seed"; | ||
|
||
} // namespace | ||
|
||
void AppendBraveCommandLineOptions(base::CommandLine& command_line) { | ||
std::string variations_server_url = BUILDFLAG(BRAVE_VARIATIONS_SERVER_URL); | ||
|
||
if (command_line.HasSwitch(switches::kVariationsPR)) { | ||
variations_server_url = base::ReplaceStringPlaceholders( | ||
kVariationsPrTestSeedUrlTemplate, | ||
{command_line.GetSwitchValueASCII(switches::kVariationsPR)}, nullptr); | ||
|
||
// Generated seed is not signed, so we need to disable signature check. | ||
command_line.AppendSwitch( | ||
variations::switches::kAcceptEmptySeedSignatureForTesting); | ||
|
||
// Disable fetch throttling to force the fetch at startup on mobile | ||
// platforms. | ||
command_line.AppendSwitch( | ||
variations::switches::kDisableVariationsSeedFetchThrottling); | ||
} | ||
|
||
if (!command_line.HasSwitch(variations::switches::kVariationsServerURL)) { | ||
command_line.AppendSwitchASCII(variations::switches::kVariationsServerURL, | ||
variations_server_url); | ||
} | ||
|
||
// Insecure fall-back for variations is set to the same (secure) URL. This | ||
// is done so that if VariationsService tries to fall back to insecure url | ||
// the check for kHttpScheme in VariationsService::MaybeRetryOverHTTP would | ||
// prevent it from doing so as we don't want to use an insecure fall-back. | ||
if (!command_line.HasSwitch( | ||
variations::switches::kVariationsInsecureServerURL)) { | ||
command_line.AppendSwitchASCII( | ||
variations::switches::kVariationsInsecureServerURL, | ||
variations_server_url); | ||
} | ||
} | ||
|
||
} // namespace variations |
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,21 @@ | ||
// Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
#ifndef BRAVE_COMPONENTS_VARIATIONS_COMMAND_LINE_UTILS_H_ | ||
#define BRAVE_COMPONENTS_VARIATIONS_COMMAND_LINE_UTILS_H_ | ||
|
||
namespace base { | ||
class CommandLine; | ||
} | ||
|
||
namespace variations { | ||
|
||
// Appends Brave-specific command line options to fetch variations seed from the | ||
// correct server. | ||
void AppendBraveCommandLineOptions(base::CommandLine& command_line); | ||
|
||
} // namespace variations | ||
|
||
#endif // BRAVE_COMPONENTS_VARIATIONS_COMMAND_LINE_UTILS_H_ |
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,70 @@ | ||
// Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
#include "brave/components/variations/command_line_utils.h" | ||
|
||
#include <string> | ||
|
||
#include "base/command_line.h" | ||
#include "brave/components/variations/buildflags.h" | ||
#include "brave/components/variations/switches.h" | ||
#include "components/variations/variations_switches.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
namespace variations { | ||
|
||
TEST(VariationsCommandLineUtils, DefaultVariationsServerUrl) { | ||
base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | ||
AppendBraveCommandLineOptions(command_line); | ||
|
||
EXPECT_EQ(command_line.GetSwitchValueASCII( | ||
variations::switches::kVariationsServerURL), | ||
BUILDFLAG(BRAVE_VARIATIONS_SERVER_URL)); | ||
EXPECT_EQ(command_line.GetSwitchValueASCII( | ||
variations::switches::kVariationsInsecureServerURL), | ||
BUILDFLAG(BRAVE_VARIATIONS_SERVER_URL)); | ||
EXPECT_FALSE(command_line.HasSwitch( | ||
variations::switches::kAcceptEmptySeedSignatureForTesting)); | ||
EXPECT_FALSE(command_line.HasSwitch( | ||
variations::switches::kDisableVariationsSeedFetchThrottling)); | ||
} | ||
|
||
TEST(VariationsCommandLineUtils, OverrideVariationsServerUrl) { | ||
base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | ||
const std::string override_variations_url = "https://variations.com"; | ||
const std::string override_insecure_variations_url = "http://insecure.com"; | ||
command_line.AppendSwitchASCII(variations::switches::kVariationsServerURL, | ||
override_variations_url); | ||
command_line.AppendSwitchASCII( | ||
variations::switches::kVariationsInsecureServerURL, | ||
override_insecure_variations_url); | ||
AppendBraveCommandLineOptions(command_line); | ||
|
||
EXPECT_EQ(override_variations_url, | ||
command_line.GetSwitchValueASCII( | ||
variations::switches::kVariationsServerURL)); | ||
EXPECT_EQ(override_insecure_variations_url, | ||
command_line.GetSwitchValueASCII( | ||
variations::switches::kVariationsInsecureServerURL)); | ||
} | ||
|
||
TEST(VariationsCommandLineUtils, SetVariationsPrParameter) { | ||
base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | ||
command_line.AppendSwitchASCII(variations::switches::kVariationsPR, "1234"); | ||
AppendBraveCommandLineOptions(command_line); | ||
|
||
EXPECT_EQ(command_line.GetSwitchValueASCII( | ||
variations::switches::kVariationsServerURL), | ||
"https://griffin.brave.com/pull/1234/seed"); | ||
EXPECT_EQ(command_line.GetSwitchValueASCII( | ||
variations::switches::kVariationsInsecureServerURL), | ||
"https://griffin.brave.com/pull/1234/seed"); | ||
EXPECT_TRUE(command_line.HasSwitch( | ||
variations::switches::kAcceptEmptySeedSignatureForTesting)); | ||
EXPECT_TRUE(command_line.HasSwitch( | ||
variations::switches::kDisableVariationsSeedFetchThrottling)); | ||
} | ||
|
||
} // namespace variations |
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,18 @@ | ||
// Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
#ifndef BRAVE_COMPONENTS_VARIATIONS_SWITCHES_H_ | ||
#define BRAVE_COMPONENTS_VARIATIONS_SWITCHES_H_ | ||
|
||
namespace variations::switches { | ||
|
||
// If this flag is set to a brave/brave-variations pull request number, the | ||
// browser will point "--variations-server-url" to a test seed URL from this | ||
// pull request. | ||
inline constexpr char kVariationsPR[] = "variations-pr"; | ||
|
||
} // namespace variations::switches | ||
|
||
#endif // BRAVE_COMPONENTS_VARIATIONS_SWITCHES_H_ |
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
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