New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 620435 link

Starred by 2 users

Issue metadata

Status: Fixed
Owner:
Closed: Nov 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

base::FeatureList tests modify global state

Project Member Reported by davidben@chromium.org, Jun 15 2016

Issue description

Tests that mess with base::FeatureList use base::FeatureList::SetInstance and base::FeatureList::ClearInstanceForTesting, but this modifies global state. It seems very easy to write a test that leaves temporary features enabled or clears the global FeatureList (causing things to crash).

Probably a better pattern would be some kind of ScopedFeatureListInstance that takes a std::unique_ptr<base::FeatureList> and undoes its change afterwards. (I tried writing such a thing but there's a bit of a nuisance with initialized_'s DCHECK.)
 

Comment 1 by jww@chromium.org, Jun 15 2016

I was actually just about to file a nearly identical bug to this because I ran into exactly this problem in https://codereview.chromium.org/2066703004/. I added a FeatureList and some unit tests that use it, but on iOS only, I was getting failures in unrelated unit tests.

It turns out that, at least in component_unittests, this global state is not reset between test runs, and my feature was still turned on for later, unrelated test runs, which was causing the tests to fail. As a temporary measure, I'm going to have to explicitly clear out the instance's FeatureList before the test starts, but this was unexpected, to say the least.

Comment 2 by jww@chromium.org, Jun 15 2016

Cc: jww@chromium.org
Annoyingly, just calling ClearInstanceForTesting doesn't seem to be right either. That leaves the instance as NULL and so later tests will crash on FeatureList::IsEnabled. :-/
Agree that we should fix this. I can take this when I'm back from vacation - which will be in a couple of weeks, or happy to let someone else drive this. Should be pretty straight forward, I think.
Components: Internals>Metrics

Comment 6 by jww@chromium.org, Jun 16 2016

Owner: asvitk...@chromium.org
Status: Assigned (was: Untriaged)
Thanks, asvitkine@! I'll assign to you for triage purposes then.

davidben@: Indeed, I learned that the hard way as well. My solution in https://codereview.chromium.org/2066703004/ is to ClearInstanceForTesting() and then immediately allocate a new FeatureList and pass it to SetInstance().
Status: Started (was: Assigned)
Project Member

Comment 8 by bugdroid1@chromium.org, Aug 9 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/9499b8d28ace546ebe511b777fa3529421ecc256

commit 9499b8d28ace546ebe511b777fa3529421ecc256
Author: asvitkine <asvitkine@chromium.org>
Date: Tue Aug 09 05:37:07 2016

Add a ScopedFeatureList class for testing and start using it.

This class improves upon the current situation by ensuring a test
doesn't end up modifying the global feature list permanently.

Migrates a number of tests to new the scoped class.

BUG= 620435 
TBR=jochen@chromium.org

Review-Url: https://codereview.chromium.org/2226063002
Cr-Commit-Position: refs/heads/master@{#410589}

[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/base/feature_list.cc
[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/base/feature_list.h
[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/base/test/BUILD.gn
[add] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/base/test/scoped_feature_list.cc
[add] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/base/test/scoped_feature_list.h
[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/chrome/browser/password_manager/chrome_password_manager_client_unittest.cc
[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/components/autofill/core/browser/autofill_assistant_unittest.cc
[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/components/autofill/core/browser/autofill_manager_unittest.cc
[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/components/autofill/core/browser/autofill_merge_unittest.cc
[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/components/autofill/core/browser/personal_data_manager_unittest.cc
[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/components/browser_sync/browser/profile_sync_service_unittest.cc
[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/components/flags_ui/BUILD.gn
[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/components/flags_ui/flags_state_unittest.cc
[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/components/network_time/network_time_tracker_unittest.cc
[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/components/offline_pages/offline_page_model_impl_unittest.cc
[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/components/password_manager/core/browser/password_form_manager_unittest.cc
[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/components/password_manager/core/browser/password_manager_test_utils.cc
[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/components/password_manager/core/browser/password_manager_test_utils.h
[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/components/password_manager/core/browser/password_manager_unittest.cc
[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/components/password_manager/sync/browser/sync_credentials_filter_unittest.cc
[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/components/ssl_config/BUILD.gn
[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/components/ssl_config/ssl_config_service_manager_pref_unittest.cc
[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/components/subresource_filter/core/browser/BUILD.gn
[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/components/subresource_filter/core/browser/subresource_filter_features_test_support.cc
[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/components/subresource_filter/core/browser/subresource_filter_features_test_support.h
[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/components/translate/core/browser/translate_prefs_unittest.cc
[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/components/translate/core/browser/translate_ui_delegate_unittest.cc
[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/components/variations/service/variations_service_unittest.cc
[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/components/variations/variations_associated_data_unittest.cc
[modify] https://crrev.com/9499b8d28ace546ebe511b777fa3529421ecc256/components/variations/variations_seed_processor_unittest.cc

Keeping this bug open as I plan to do another pass and convert some more tests to use the new scoped class.
Project Member

Comment 10 by bugdroid1@chromium.org, Nov 8 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/b1db826c74369f712111099190ae6bc6311ec9e7

commit b1db826c74369f712111099190ae6bc6311ec9e7
Author: asvitkine <asvitkine@chromium.org>
Date: Tue Nov 08 09:48:20 2016

Migrate more tests to ScopedFeatureList.

ScopedFeatureList ensures that the global FeatureList
instance is restored to the original state at the end
of the scope and results in less code.

BUG= 620435 
TBR=brettw@chromium.org

Review-Url: https://codereview.chromium.org/2484613002
Cr-Commit-Position: refs/heads/master@{#430560}

[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/base/feature_list.h
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/chrome/browser/android/offline_pages/offline_page_utils_unittest.cc
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/chrome/browser/browser_about_handler_unittest.cc
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/chrome/browser/chromeos/hats/hats_finch_helper_unittest.cc
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/chrome/browser/extensions/extension_service_sync_unittest.cc
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/chrome/browser/metrics/antivirus_metrics_provider_win_unittest.cc
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/chrome/browser/password_manager/password_manager_browsertest.cc
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/chrome/browser/safe_browsing/incident_reporting/incident_reporting_service_unittest.cc
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/chrome/browser/safe_browsing/permission_reporter_unittest.cc
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/chrome/browser/ssl/chrome_expect_ct_reporter_unittest.cc
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/chrome/browser/supervised_user/supervised_user_service_unittest.cc
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/chrome/browser/ui/startup/default_browser_infobar_delegate_unittest.cc
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/chrome/browser/ui/views/constrained_window_views_browsertest.cc
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/chrome/browser/ui/views/passwords/manage_passwords_bubble_view_interactive_uitest.cc
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/chrome/browser/ui/views/translate/translate_bubble_view_unittest.cc
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/chrome/browser/ui/webui/uber/uber_ui_browsertest.cc
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/components/sync/engine_impl/sync_manager_impl_unittest.cc
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/components/variations/field_trial_config/BUILD.gn
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/components/variations/field_trial_config/field_trial_util_unittest.cc
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/content/browser/loader/async_resource_handler_unittest.cc
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/content/browser/loader/async_revalidation_manager_browsertest.cc
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/content/browser/loader/reload_cache_control_browsertest.cc
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/content/browser/loader/resource_dispatcher_host_unittest.cc
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/content/browser/media/session/media_session_impl_visibility_browsertest.cc
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/content/browser/memory/memory_coordinator.cc
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/content/browser/memory/memory_coordinator.h
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/content/browser/memory/memory_coordinator_browsertest.cc
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/content/browser/memory/memory_coordinator_impl_unittest.cc
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/content/child/resource_dispatcher_unittest.cc
[modify] https://crrev.com/b1db826c74369f712111099190ae6bc6311ec9e7/media/blink/webmediaplayer_impl_unittest.cc

Status: Fixed (was: Started)

Sign in to add a comment