Skip to content

Commit 99fe420

Browse files
authored
Refactor FXIOS-11131 Native Error pages feature flag to be check status in a single place (#24293)
1 parent 3de5980 commit 99fe420

File tree

6 files changed

+77
-8
lines changed

6 files changed

+77
-8
lines changed

firefox-ios/Client.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,10 @@
279279
21ED80B32AF2E43A0065D4C7 /* TabDisplayDiffableDataSourceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21ED80B22AF2E43A0065D4C7 /* TabDisplayDiffableDataSourceTests.swift */; };
280280
21EEAA192D3852B300595119 /* BookmarksTelemetry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21EEAA182D3852B300595119 /* BookmarksTelemetry.swift */; };
281281
21EEAA1B2D3AE3B300595119 /* BookmarksTelemetryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21EEAA1A2D3AE3B300595119 /* BookmarksTelemetryTests.swift */; };
282+
21EEAA1D2D4005DE00595119 /* NativeErrorPageFeatureFlag.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21EEAA1C2D4005DE00595119 /* NativeErrorPageFeatureFlag.swift */; };
282283
21F2A2D22B0BC85200626AEC /* InactiveTabsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21F2A2D12B0BC85200626AEC /* InactiveTabsModel.swift */; };
283284
21F2A2D42B0D194A00626AEC /* TabsPanelStateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21F2A2D32B0D194A00626AEC /* TabsPanelStateTests.swift */; };
285+
21F96EE42D41830300A164A0 /* NativeErrorPageFeatureFlagTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21F96EE22D41830300A164A0 /* NativeErrorPageFeatureFlagTests.swift */; };
284286
21FA8FAE2AE856460013B815 /* TabsCoordinatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21FA8FAD2AE856460013B815 /* TabsCoordinatorTests.swift */; };
285287
21FA8FB02AE856590013B815 /* RemoteTabsCoordinatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21FA8FAF2AE856590013B815 /* RemoteTabsCoordinatorTests.swift */; };
286288
21FA8FB22AE856EB0013B815 /* MockTabTrayCoordinatorDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21FA8FB12AE856EB0013B815 /* MockTabTrayCoordinatorDelegate.swift */; };
@@ -2706,8 +2708,10 @@
27062708
21ED80B22AF2E43A0065D4C7 /* TabDisplayDiffableDataSourceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabDisplayDiffableDataSourceTests.swift; sourceTree = "<group>"; };
27072709
21EEAA182D3852B300595119 /* BookmarksTelemetry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarksTelemetry.swift; sourceTree = "<group>"; };
27082710
21EEAA1A2D3AE3B300595119 /* BookmarksTelemetryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarksTelemetryTests.swift; sourceTree = "<group>"; };
2711+
21EEAA1C2D4005DE00595119 /* NativeErrorPageFeatureFlag.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeErrorPageFeatureFlag.swift; sourceTree = "<group>"; };
27092712
21F2A2D12B0BC85200626AEC /* InactiveTabsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InactiveTabsModel.swift; sourceTree = "<group>"; };
27102713
21F2A2D32B0D194A00626AEC /* TabsPanelStateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabsPanelStateTests.swift; sourceTree = "<group>"; };
2714+
21F96EE22D41830300A164A0 /* NativeErrorPageFeatureFlagTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeErrorPageFeatureFlagTests.swift; sourceTree = "<group>"; };
27112715
21FA8FAD2AE856460013B815 /* TabsCoordinatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabsCoordinatorTests.swift; sourceTree = "<group>"; };
27122716
21FA8FAF2AE856590013B815 /* RemoteTabsCoordinatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteTabsCoordinatorTests.swift; sourceTree = "<group>"; };
27132717
21FA8FB12AE856EB0013B815 /* MockTabTrayCoordinatorDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockTabTrayCoordinatorDelegate.swift; sourceTree = "<group>"; };
@@ -11218,6 +11222,7 @@
1121811222
children = (
1121911223
630FE1322C7FB42500D9D6B2 /* NativeErrorPageViewControllerTests.swift */,
1122011224
635183FA2CF5555C00EDFCE2 /* NativeErrorPageStateTests.swift */,
11225+
21F96EE22D41830300A164A0 /* NativeErrorPageFeatureFlagTests.swift */,
1122111226
);
1122211227
path = NativeErrorPage;
1122311228
sourceTree = "<group>";
@@ -11231,6 +11236,7 @@
1123111236
631A369E2CC0A4FE0044DFEB /* NativeErrorPageMiddleware.swift */,
1123211237
631A36A22CC0B2470044DFEB /* NativeErrorPageHelper.swift */,
1123311238
63F7A9AB2C752BB0005846F5 /* NativeErrorPageViewController.swift */,
11239+
21EEAA1C2D4005DE00595119 /* NativeErrorPageFeatureFlag.swift */,
1123411240
);
1123511241
path = NativeErrorPage;
1123611242
sourceTree = "<group>";
@@ -16957,6 +16963,7 @@
1695716963
437A857827E43FE100E42764 /* FxAWebViewTelemetry.swift in Sources */,
1695816964
E13E9AB42AAB0FB5001A0E9D /* FakespotCoordinator.swift in Sources */,
1695916965
E1442FD1294782D9003680B0 /* UIModalPresentationStyle+Photon.swift in Sources */,
16966+
21EEAA1D2D4005DE00595119 /* NativeErrorPageFeatureFlag.swift in Sources */,
1696016967
E1ADE23E2B06559500FD17AA /* FakespotAction.swift in Sources */,
1696116968
5A32C2B62AD8517200A9B5A4 /* MetricKitWrapper.swift in Sources */,
1696216969
8A95FF642B1E969E00AC303D /* TelemetryContextualIdentifier.swift in Sources */,
@@ -17565,6 +17572,7 @@
1756517572
5A3A7DDA2889EC4D0065F81A /* ReadingListMock.swift in Sources */,
1756617573
8A33221F27DFE318008F809E /* TopSitesDataAdaptorTests.swift in Sources */,
1756717574
2165B2C02860BB41004C0786 /* AdjustTelemetryHelperTests.swift in Sources */,
17575+
21F96EE42D41830300A164A0 /* NativeErrorPageFeatureFlagTests.swift in Sources */,
1756817576
C869915428917803007ACC5C /* WallpaperTestDataProvider.swift in Sources */,
1756917577
0AC659292BF493CE005C614A /* MockFxAWebViewModel.swift in Sources */,
1757017578
8A5604F629DF09FA00035CA3 /* MockLaunchCoordinatorDelegate.swift in Sources */,

firefox-ios/Client/Frontend/Browser/BrowserViewController/Views/BrowserViewController.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,11 @@ class BrowserViewController: UIViewController,
143143
}
144144

145145
var isNativeErrorPageEnabled: Bool {
146-
return featureFlags.isFeatureEnabled(.nativeErrorPage, checking: .buildOnly)
146+
return NativeErrorPageFeatureFlag().isNativeErrorPageEnabled
147147
}
148148

149-
/// Temporary flag for showing no internet connection native error page only.
150149
var isNICErrorPageEnabled: Bool {
151-
return featureFlags.isFeatureEnabled(.noInternetConnectionErrorPage, checking: .buildOnly)
150+
return NativeErrorPageFeatureFlag().isNICErrorPageEnabled
152151
}
153152

154153
var isJSAlertRefactorEnabled: Bool {

firefox-ios/Client/Frontend/InternalSchemeHandler/ErrorPageHelper.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,14 @@ private func cfErrorToName(_ err: CFNetworkErrors) -> String {
151151
class ErrorPageHandler: InternalSchemeResponse, FeatureFlaggable {
152152
static let path = InternalURL.Path.errorpage.rawValue
153153
// When nativeErrorPage feature flag is true, only create
154-
// html page with gray background similar to homepage or privatehomepage.
154+
// html page with gray background similar to homepage or private homepage.
155155
// TODO: responseForErrorWebPage() will be removed in future with rest of the old error page code.
156156
var isNativeErrorPageEnabled: Bool {
157-
return featureFlags.isFeatureEnabled(.nativeErrorPage, checking: .buildOnly)
157+
return NativeErrorPageFeatureFlag().isNativeErrorPageEnabled
158158
}
159159

160160
var isNICErrorPageEnabled: Bool {
161-
return featureFlags.isFeatureEnabled(.noInternetConnectionErrorPage, checking: .buildOnly)
161+
return NativeErrorPageFeatureFlag().isNICErrorPageEnabled
162162
}
163163

164164
func response(forRequest request: URLRequest) -> (URLResponse, Data)? {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/
4+
5+
import Foundation
6+
7+
struct NativeErrorPageFeatureFlag: FeatureFlaggable {
8+
var isNativeErrorPageEnabled: Bool {
9+
return featureFlags.isFeatureEnabled(.nativeErrorPage, checking: .buildOnly)
10+
}
11+
12+
/// Temporary flag for showing no internet connection native error page only.
13+
var isNICErrorPageEnabled: Bool {
14+
return featureFlags.isFeatureEnabled(.noInternetConnectionErrorPage, checking: .buildOnly)
15+
}
16+
}

firefox-ios/Client/Frontend/NativeErrorPage/NativeErrorPageViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ final class NativeErrorPageViewController: UIViewController,
1616
private let windowUUID: WindowUUID
1717

1818
// MARK: Themable Variables
19-
var themeManager: Common.ThemeManager
19+
var themeManager: ThemeManager
2020
var themeObserver: NSObjectProtocol?
21-
var notificationCenter: Common.NotificationProtocol
21+
var notificationCenter: NotificationProtocol
2222
var currentWindowUUID: UUID? {
2323
windowUUID
2424
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/
4+
5+
import Common
6+
import XCTest
7+
8+
@testable import Client
9+
10+
class NativeErrorPageFeatureFlagTests: XCTestCase {
11+
var subject: NativeErrorPageFeatureFlag!
12+
13+
override func setUp() {
14+
super.setUp()
15+
let profile = MockProfile()
16+
LegacyFeatureFlagsManager.shared.initializeDeveloperFeatures(with: profile)
17+
subject = NativeErrorPageFeatureFlag()
18+
}
19+
20+
override func tearDown() {
21+
super.tearDown()
22+
23+
subject = nil
24+
}
25+
26+
func testFeatureFlag_WhenNativeErrorPageEnabled_ThenFeatureIsEnabled() {
27+
setupNimbusNativeErrorPageTesting(isEnabled: true,
28+
noInternetConnectionErrorIsEnabled: true)
29+
XCTAssertTrue(subject.isNativeErrorPageEnabled)
30+
}
31+
32+
func testFeatureFlag_WhenNativeErrorPageDisabled_ThenFeatureIsDisabled() {
33+
setupNimbusNativeErrorPageTesting(isEnabled: false,
34+
noInternetConnectionErrorIsEnabled: false)
35+
XCTAssertFalse(subject.isNativeErrorPageEnabled)
36+
}
37+
38+
// Helper
39+
private func setupNimbusNativeErrorPageTesting(isEnabled: Bool,
40+
noInternetConnectionErrorIsEnabled: Bool) {
41+
FxNimbus.shared.features.nativeErrorPageFeature.with { _, _ in
42+
return NativeErrorPageFeature(enabled: isEnabled,
43+
noInternetConnectionError: noInternetConnectionErrorIsEnabled)
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)