0

[commerce] Fix iOS notification tests

This patch fixes two tests that were missing the mock ShoppingService
set up. These tests previously depended on more bespoke utils and
field trial configs to accomplish the same thing. The tests are now
set up deterministially.

Bug: 378039633
Change-Id: I4ffb0d4da37b03b2bb7bd90bd06b3b24a3b30224
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6022063
Reviewed-by: David Maunder <davidjm@chromium.org>
Reviewed-by: Guillem Perez <guiperez@google.com>
Commit-Queue: Matthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1383282}
This commit is contained in:
Matt Jones
2024-11-14 22:36:41 +00:00
committed by Chromium LUCI CQ
parent f7fa516f0e
commit 990bb8853a
8 changed files with 95 additions and 4 deletions

@ -131,6 +131,7 @@ source_set("eg2_tests") {
sources = [ "notifications_egtest.mm" ]
deps = [
":constants",
":eg_test_support+eg2",
"//base",
"//base/test:test_support",
"//components/commerce/core:feature_list",
@ -143,3 +144,32 @@ source_set("eg2_tests") {
]
frameworks = [ "UIKit.framework" ]
}
source_set("eg_app_support+eg2") {
testonly = true
sources = [
"notifications_earl_grey_app_interface.h",
"notifications_earl_grey_app_interface.mm",
]
deps = [
"//base",
"//base/test:test_support",
"//components/commerce/core:shopping_service_test_support",
"//ios/chrome/browser/commerce/model:shopping_service",
"//ios/chrome/browser/shared/model/profile",
"//ios/chrome/test/app:test_support",
"//ios/web/public",
]
}
source_set("eg_test_support+eg2") {
testonly = true
sources = [
"notifications_earl_grey_app_interface.h",
"notifications_earl_grey_app_interface_stub.mm",
]
deps = [
"//base",
"//ios/testing/earl_grey:eg_test_support+eg2",
]
}

@ -0,0 +1,18 @@
// 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.
#ifndef IOS_CHROME_BROWSER_UI_SETTINGS_NOTIFICATIONS_NOTIFICATIONS_EARL_GREY_APP_INTERFACE_H_
#define IOS_CHROME_BROWSER_UI_SETTINGS_NOTIFICATIONS_NOTIFICATIONS_EARL_GREY_APP_INTERFACE_H_
#import <UIKit/UIKit.h>
// The app interface for notifications, facilitating test setup.
@interface NotificationsEarlGreyAppInterface : NSObject
// Replaces the shopping service with one where all features are enabled.
+ (void)setUpMockShoppingService;
@end
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_NOTIFICATIONS_NOTIFICATIONS_EARL_GREY_APP_INTERFACE_H_

@ -0,0 +1,28 @@
// 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.
#import "ios/chrome/browser/ui/settings/notifications/notifications_earl_grey_app_interface.h"
#import "components/commerce/core/mock_shopping_service.h"
#import "ios/chrome/browser/commerce/model/shopping_service_factory.h"
#import "ios/chrome/browser/shared/model/profile/profile_ios.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "testing/gmock/include/gmock/gmock.h"
@implementation NotificationsEarlGreyAppInterface : NSObject
+ (void)setUpMockShoppingService {
commerce::ShoppingServiceFactory::GetInstance()->SetTestingFactory(
chrome_test_util::GetOriginalProfile(),
base::BindRepeating([](web::BrowserState* state) {
std::unique_ptr<KeyedService> service = std::make_unique<
testing::NiceMock<commerce::MockShoppingService>>();
commerce::MockShoppingService* shopping_service =
static_cast<commerce::MockShoppingService*>(service.get());
shopping_service->SetIsShoppingListEligible(true);
return service;
}));
}
@end

@ -0,0 +1,9 @@
// 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.
#import "ios/chrome/browser/ui/settings/notifications/notifications_earl_grey_app_interface.h"
#import "ios/testing/earl_grey/earl_grey_test.h"
GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(NotificationsEarlGreyAppInterface)

@ -9,6 +9,7 @@
#import "components/variations/pref_names.h"
#import "ios/chrome/browser/ui/push_notification/scoped_notification_auth_swizzler.h"
#import "ios/chrome/browser/ui/settings/notifications/notifications_constants.h"
#import "ios/chrome/browser/ui/settings/notifications/notifications_earl_grey_app_interface.h"
#import "ios/chrome/grit/ios_branded_strings.h"
#import "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
@ -85,14 +86,15 @@ id<GREYMatcher> NotificationsSettingsMatcher() {
// Tests that the settings page is dismissed by swiping down from the top.
// TODO(crbug.com/326070899): remove this test when Tips Notifications is
// enabled by default.
// TODO(crbug.com/378039633): Reenable the test.
- (void)DISABLED_testPriceNotificationsSwipeDown {
- (void)testPriceNotificationsSwipeDown {
// Price tracking might only be enabled in certain countries, so it is
// overridden to ensure that it will be enabled.
[ChromeEarlGrey setStringValue:"us"
forLocalStatePref:variations::prefs::
kVariationsPermanentOverriddenCountry];
[NotificationsEarlGreyAppInterface setUpMockShoppingService];
// Opens price notifications setting.
[ChromeEarlGreyUI openSettingsMenu];
[ChromeEarlGreyUI tapSettingsMenuButton:SettingsMenuNotificationsButton()];

@ -81,6 +81,7 @@ source_set("eg2_tests") {
"//components/commerce/core:pref_names",
"//components/strings",
"//ios/chrome/app/strings",
"//ios/chrome/browser/ui/settings/notifications:eg_test_support+eg2",
"//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/testing/earl_grey:eg_test_support+eg2",
"//ui/base",

@ -3,6 +3,7 @@
// found in the LICENSE file.
#import "components/commerce/core/commerce_feature_list.h"
#import "ios/chrome/browser/ui/settings/notifications/notifications_earl_grey_app_interface.h"
#import "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
@ -36,8 +37,9 @@ using chrome_test_util::SettingsTrackingPriceTableView;
}
// Tests that the settings page is dismissed by swiping down from the top.
// TODO(crbug.com/378039633): Reenable the test.
- (void)DISABLED_testTrackingPriceSwipeDown_FromUpdatedSettingsView {
- (void)testTrackingPriceSwipeDown_FromUpdatedSettingsView {
[NotificationsEarlGreyAppInterface setUpMockShoppingService];
[self openTrackingPriceSettingsFromUpdatedSettingsView];
// Check that Tracking Price TableView is presented.

@ -199,6 +199,7 @@ source_set("eg_app_support+eg2") {
"//ios/chrome/browser/ui/settings/google_services/manage_accounts:constants",
"//ios/chrome/browser/ui/settings/language:eg_app_support+eg2",
"//ios/chrome/browser/ui/settings/notifications:constants",
"//ios/chrome/browser/ui/settings/notifications:eg_app_support+eg2",
"//ios/chrome/browser/ui/settings/notifications/tracking_price:constants",
"//ios/chrome/browser/ui/settings/password:eg_app_support+eg2",
"//ios/chrome/browser/ui/settings/password:password_constants",