Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10188)

Unified Diff: chrome/browser/android/webapk/webapk_installer_unittest.cc

Issue 2441203002: Add field trial for the WebAPK server URL (Closed)
Patch Set: ABCD Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/android/webapk/webapk_installer.cc ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/webapk/webapk_installer_unittest.cc
diff --git a/chrome/browser/android/webapk/webapk_installer_unittest.cc b/chrome/browser/android/webapk/webapk_installer_unittest.cc
index d0842432891440e4630a0bfa68b7e38da5fca02c..f6a3e5d1c3c38a3773ec6b62ba385fd754cc2902 100644
--- a/chrome/browser/android/webapk/webapk_installer_unittest.cc
+++ b/chrome/browser/android/webapk/webapk_installer_unittest.cc
@@ -8,18 +8,23 @@
#include <memory>
#include <string>
+#include "base/android/field_trial_list.h"
#include "base/android/scoped_java_ref.h"
#include "base/bind.h"
#include "base/callback_forward.h"
-#include "base/command_line.h"
+#include "base/feature_list.h"
#include "base/files/file_path.h"
+#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
+#include "base/test/scoped_feature_list.h"
#include "base/threading/thread_task_runner_handle.h"
+#include "chrome/browser/android/chrome_feature_list.h"
#include "chrome/browser/android/shortcut_info.h"
#include "chrome/browser/android/webapk/webapk.pb.h"
#include "chrome/common/chrome_switches.h"
+#include "components/variations/variations_associated_data.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
@@ -35,6 +40,10 @@ namespace {
const base::FilePath::CharType kTestDataDir[] =
FILE_PATH_LITERAL("chrome/test/data");
+// Mock field trial name and field trial group to use for "WebApks" feature.
+const char kFieldTrialName[] = "MockFieldTrial";
+const char kFieldTrialGroup[] = "MockFieldTrialGroup";
+
// URL of mock WebAPK server.
const char* kServerUrl = "/webapkserver/";
@@ -184,7 +193,9 @@ class WebApkInstallerTest : public ::testing::Test {
WebApkInstallerTest()
: thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {}
- ~WebApkInstallerTest() override {}
+ ~WebApkInstallerTest() override {
+ variations::testing::ClearAllVariationParams();
+ }
void SetUp() override {
test_server_.AddDefaultHandlers(base::FilePath(kTestDataDir));
@@ -193,6 +204,16 @@ class WebApkInstallerTest : public ::testing::Test {
base::Unretained(this)));
ASSERT_TRUE(test_server_.Start());
+ field_trial_list_.reset(new base::FieldTrialList(nullptr));
+ base::FieldTrial* field_trial = base::FieldTrialList::CreateFieldTrial(
+ kFieldTrialName, kFieldTrialGroup);
+ std::unique_ptr<base::FeatureList> feature_list =
+ base::MakeUnique<base::FeatureList>();
+ feature_list->RegisterFieldTrialOverride(
+ chrome::android::kWebApks.name,
+ base::FeatureList::OVERRIDE_ENABLE_FEATURE, field_trial);
+ scoped_feature_list_.InitWithFeatureList(std::move(feature_list));
+
SetDefaults();
}
@@ -202,8 +223,11 @@ class WebApkInstallerTest : public ::testing::Test {
// Sets the URL to send the webapk::CreateWebApkRequest to. WebApkInstaller
// should fail if the URL is not |kServerUrl|.
void SetWebApkServerUrl(const GURL& server_url) {
- base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
- switches::kWebApkServerUrl, server_url.spec());
+ variations::testing::ClearAllVariationParams();
+ std::map<std::string, std::string> params;
+ params["ServerUrl"] = server_url.spec();
+ ASSERT_TRUE(variations::AssociateVariationParams(kFieldTrialName,
+ kFieldTrialGroup, params));
}
// Sets the function that should be used to build the response to the
@@ -241,6 +265,9 @@ class WebApkInstallerTest : public ::testing::Test {
content::TestBrowserThreadBundle thread_bundle_;
net::EmbeddedTestServer test_server_;
+ std::unique_ptr<base::FieldTrialList> field_trial_list_;
+ base::test::ScopedFeatureList scoped_feature_list_;
+
// Web Manifest's icon URL.
GURL icon_url_;
« no previous file with comments | « chrome/browser/android/webapk/webapk_installer.cc ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698