Bug 1881238 - Add logs to SettingsSubMenuHttpsOnlyModeRobot
[gecko.git] / mobile / android / fenix / app / src / androidTest / java / org / mozilla / fenix / ui / robots / SettingsSubMenuHttpsOnlyModeRobot.kt
blobd4a0c5c6427c17ee866213a88d5b3ec7fb615cc9
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/. */
5 package org.mozilla.fenix.ui.robots
7 import android.util.Log
8 import androidx.test.espresso.Espresso.onView
9 import androidx.test.espresso.action.ViewActions.click
10 import androidx.test.espresso.assertion.ViewAssertions.matches
11 import androidx.test.espresso.matcher.ViewMatchers.hasSibling
12 import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
13 import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
14 import androidx.test.espresso.matcher.ViewMatchers.withId
15 import androidx.test.espresso.matcher.ViewMatchers.withText
16 import org.hamcrest.CoreMatchers.allOf
17 import org.mozilla.fenix.R
18 import org.mozilla.fenix.helpers.Constants.TAG
19 import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
20 import org.mozilla.fenix.helpers.assertIsChecked
21 import org.mozilla.fenix.helpers.assertIsEnabled
22 import org.mozilla.fenix.helpers.click
23 import org.mozilla.fenix.helpers.isChecked
25 class SettingsSubMenuHttpsOnlyModeRobot {
27     fun verifyHttpsOnlyModeMenuHeader() {
28         Log.i(TAG, "verifyHttpsOnlyModeMenuHeader: Trying to verify that the \"HTTPS-Only Mode\" toolbar items are visible")
29         onView(
30             allOf(
31                 withText(getStringResource(R.string.preferences_https_only_title)),
32                 hasSibling(withContentDescription("Navigate up")),
33             ),
34         ).check(matches(isDisplayed()))
35         Log.i(TAG, "verifyHttpsOnlyModeMenuHeader: Verified that the \"HTTPS-Only Mode\" toolbar items are visible")
36     }
38     fun verifyHttpsOnlyModeSummary() {
39         Log.i(TAG, "verifyHttpsOnlyModeSummary: Trying to verify that the \"HTTPS-Only Mode\" title is visible")
40         onView(withId(R.id.https_only_title))
41             .check(matches(withText("HTTPS-Only Mode")))
42         Log.i(TAG, "verifyHttpsOnlyModeSummary: Verified that the \"HTTPS-Only Mode\" title is visible")
43         Log.i(TAG, "verifyHttpsOnlyModeSummary: Trying to verify that the \"HTTPS-Only Mode\" summary is visible")
44         onView(withId(R.id.https_only_summary))
45             .check(matches(withText("Automatically attempts to connect to sites using HTTPS encryption protocol for increased security. Learn more")))
46         Log.i(TAG, "verifyHttpsOnlyModeSummary: Verified that the \"HTTPS-Only Mode\" summary is visible")
47     }
49     fun verifyHttpsOnlyModeIsEnabled(shouldBeEnabled: Boolean) {
50         Log.i(TAG, "verifyHttpsOnlyModeIsEnabled: Trying to verify that the \"HTTPS-Only Mode\" toggle is checked: $shouldBeEnabled")
51         httpsModeOnlySwitch().check(
52             matches(
53                 if (shouldBeEnabled) {
54                     isChecked(true)
55                 } else {
56                     isChecked(false)
57                 },
58             ),
59         )
60         Log.i(TAG, "verifyHttpsOnlyModeIsEnabled: Verified that the \"HTTPS-Only Mode\" toggle is checked: $shouldBeEnabled")
61     }
63     fun clickHttpsOnlyModeSwitch() {
64         Log.i(TAG, "clickHttpsOnlyModeSwitch: Trying to click the \"HTTPS-Only Mode\" toggle")
65         httpsModeOnlySwitch().click()
66         Log.i(TAG, "clickHttpsOnlyModeSwitch: Clicked the \"HTTPS-Only Mode\" toggle")
67     }
69     fun verifyHttpsOnlyModeOptionsEnabled(shouldBeEnabled: Boolean) {
70         Log.i(TAG, "verifyHttpsOnlyModeOptionsEnabled: Trying to verify that the \"Enable in all tabs\" option is enabled: $shouldBeEnabled")
71         allTabsOption().assertIsEnabled(shouldBeEnabled)
72         Log.i(TAG, "verifyHttpsOnlyModeOptionsEnabled: Verified that the \"Enable in all tabs\" option is enabled: $shouldBeEnabled")
73         Log.i(TAG, "verifyHttpsOnlyModeOptionsEnabled: Trying to verify that the \"Enable only in private tabs\" option is enabled: $shouldBeEnabled")
74         onlyPrivateTabsOption().assertIsEnabled(shouldBeEnabled)
75         Log.i(TAG, "verifyHttpsOnlyModeOptionsEnabled: Verified that the \"Enable only in private tabs\" option is enabled: $shouldBeEnabled")
76     }
78     fun verifyHttpsOnlyOptionSelected(allTabsOptionSelected: Boolean, privateTabsOptionSelected: Boolean) {
79         if (allTabsOptionSelected) {
80             Log.i(TAG, "verifyHttpsOnlyOptionSelected: Trying to verify that the \"Enable in all tabs\" option is checked: $allTabsOptionSelected")
81             allTabsOption().assertIsChecked(true)
82             Log.i(TAG, "verifyHttpsOnlyOptionSelected: Verified that the \"Enable in all tabs\" option is checked: $allTabsOptionSelected")
83             Log.i(TAG, "verifyHttpsOnlyOptionSelected: Trying to verify that the \"Enable only in private tabs\" option is checked: $privateTabsOptionSelected")
84             onlyPrivateTabsOption().assertIsChecked(false)
85             Log.i(TAG, "verifyHttpsOnlyOptionSelected: Verified that the \"Enable only in private tabs\" option is checked: $privateTabsOptionSelected")
86         } else if (privateTabsOptionSelected) {
87             Log.i(TAG, "verifyHttpsOnlyOptionSelected: Trying to verify that the \"Enable in all tabs\" option is checked: $allTabsOptionSelected")
88             allTabsOption().assertIsChecked(false)
89             Log.i(TAG, "verifyHttpsOnlyOptionSelected: Verified that the \"Enable in all tabs\" option is checked: $allTabsOptionSelected")
90             Log.i(TAG, "verifyHttpsOnlyOptionSelected: Trying to verify that the \"Enable only in private tabs\" option is checked: $privateTabsOptionSelected")
91             onlyPrivateTabsOption().assertIsChecked(true)
92             Log.i(TAG, "verifyHttpsOnlyOptionSelected: Verified that the \"Enable only in private tabs\" option is checked: $privateTabsOptionSelected")
93         }
94     }
96     fun selectHttpsOnlyModeOption(allTabsOptionSelected: Boolean, privateTabsOptionSelected: Boolean) {
97         if (allTabsOptionSelected) {
98             Log.i(TAG, "selectHttpsOnlyModeOption: Trying to click the \"Enable in all tabs\" option")
99             allTabsOption().click()
100             Log.i(TAG, "selectHttpsOnlyModeOption: Clicked the \"Enable in all tabs\" option")
101             Log.i(TAG, "selectHttpsOnlyModeOption: Trying to verify that the \"Enable in all tabs\" option is checked: $allTabsOptionSelected")
102             allTabsOption().assertIsChecked(true)
103             Log.i(TAG, "selectHttpsOnlyModeOption: Verified that the \"Enable in all tabs\" option is checked: $allTabsOptionSelected")
104         } else if (privateTabsOptionSelected) {
105             Log.i(TAG, "selectHttpsOnlyModeOption: Trying to click the \"Enable only in private tabs\" option")
106             onlyPrivateTabsOption().click()
107             Log.i(TAG, "selectHttpsOnlyModeOption: Clicked the \"Enable only in private tabs\" option")
108             Log.i(TAG, "selectHttpsOnlyModeOption: Trying to verify that the \"Enable only in private tabs\" option is checked: $privateTabsOptionSelected")
109             onlyPrivateTabsOption().assertIsChecked(true)
110             Log.i(TAG, "selectHttpsOnlyModeOption: Verified that the \"Enable only in private tabs\" option is checked: $privateTabsOptionSelected")
111         }
112     }
114     class Transition {
115         fun goBack(interact: SettingsRobot.() -> Unit): SettingsRobot.Transition {
116             Log.i(TAG, "goBack: Trying to click the navigate up toolbar button")
117             goBackButton().perform(click())
118             Log.i(TAG, "goBack: Clicked the navigate up toolbar button")
120             SettingsRobot().interact()
121             return SettingsRobot.Transition()
122         }
123     }
126 private fun httpsModeOnlySwitch() = onView(withId(R.id.https_only_switch))
128 private fun allTabsOption() =
129     onView(
130         allOf(
131             withId(R.id.https_only_all_tabs),
132             withText("Enable in all tabs"),
133         ),
134     )
136 private fun onlyPrivateTabsOption() =
137     onView(
138         allOf(
139             withId(R.id.https_only_private_tabs),
140             withText("Enable only in private tabs"),
141         ),
142     )
144 private fun goBackButton() = onView(withContentDescription("Navigate up"))