-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
FxScreenGraph.swift
1257 lines (1066 loc) · 51.9 KB
/
FxScreenGraph.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import Foundation
import MappaMundi
import XCTest
let FirstRun = "OptionalFirstRun"
let TabTray = "TabTray"
let PrivateTabTray = "PrivateTabTray"
let NewTabScreen = "NewTabScreen"
let URLBarOpen = "URLBarOpen"
let URLBarLongPressMenu = "URLBarLongPressMenu"
let ReloadLongPressMenu = "ReloadLongPressMenu"
let PrivateURLBarOpen = "PrivateURLBarOpen"
let BrowserTab = "BrowserTab"
let PrivateBrowserTab = "PrivateBrowserTab"
let BrowserTabMenu = "BrowserTabMenu"
let PageOptionsMenu = "PageOptionsMenu"
let ToolsMenu = "ToolsMenu"
let FindInPage = "FindInPage"
let SettingsScreen = "SettingsScreen"
let SyncSettings = "SyncSettings"
let FxASigninScreen = "FxASigninScreen"
let FxCreateAccount = "FxCreateAccount"
let FxAccountManagementPage = "FxAccountManagementPage"
let Intro_FxASigninEmail = "Intro_FxASigninEmail"
let HomeSettings = "HomeSettings"
let SiriSettings = "SiriSettings"
let PasscodeSettings = "PasscodeSettings"
let PasscodeIntervalSettings = "PasscodeIntervalSettings"
let SearchSettings = "SearchSettings"
let NewTabSettings = "NewTabSettings"
let ClearPrivateDataSettings = "ClearPrivateDataSettings"
let WebsiteDataSettings = "WebsiteDataSettings"
let WebsiteSearchDataSettings = "WebsiteSearchDataSettings"
let LoginsSettings = "LoginsSettings"
let OpenWithSettings = "OpenWithSettings"
let ShowTourInSettings = "ShowTourInSettings"
let TrackingProtectionSettings = "TrackingProtectionSettings"
let Intro_FxASignin = "Intro_FxASignin"
let WebImageContextMenu = "WebImageContextMenu"
let WebLinkContextMenu = "WebLinkContextMenu"
let CloseTabMenu = "CloseTabMenu"
let AddCustomSearchSettings = "AddCustomSearchSettings"
let DisablePasscodeSettings = "DisablePasscodeSettings"
let ChangePasscodeSettings = "ChangePasscodeSettings"
let LockedLoginsSettings = "LockedLoginsSettings"
let TabTrayLongPressMenu = "TabTrayLongPressMenu"
let HistoryRecentlyClosed = "HistoryRecentlyClosed"
let TrackingProtectionContextMenuDetails = "TrackingProtectionContextMenuDetails"
let DisplaySettings = "DisplaySettings"
let TranslationSettings = "TranslationSettings"
let HomePanel_Library = "HomePanel_Library"
let TranslatePageMenu = "TranslatePageMenu"
let DontTranslatePageMenu = "DontTranslatePageMenu"
let MobileBookmarks = "MobileBookmarks"
let MobileBookmarksEdit = "MobileBookmarksEdit"
let MobileBookmarksAdd = "MobileBookmarksAdd"
let EnterNewBookmarkTitleAndUrl = "EnterNewBookmarkTitleAndUrl"
let RequestDesktopSite = "RequestDesktopSite"
let RequestMobileSite = "RequestMobileSite"
// These are in the exact order they appear in the settings
// screen. XCUIApplication loses them on small screens.
// This list should only be for settings screens that can be navigated to
// without changing userState. i.e. don't need conditional edges to be available
let allSettingsScreens = [
SearchSettings,
AddCustomSearchSettings,
NewTabSettings,
OpenWithSettings,
DisplaySettings,
TranslationSettings,
LoginsSettings,
PasscodeSettings,
ClearPrivateDataSettings,
TrackingProtectionSettings,
]
let HistoryPanelContextMenu = "HistoryPanelContextMenu"
let TopSitesPanelContextMenu = "TopSitesPanelContextMenu"
let BasicAuthDialog = "BasicAuthDialog"
let BookmarksPanelContextMenu = "BookmarksPanelContextMenu"
let SetPasscodeScreen = "SetPasscodeScreen"
let Intro_Welcome = "Intro.Welcome"
let Intro_Sync = "Intro.Sync"
let allIntroPages = [
Intro_Welcome,
Intro_Sync
]
let HomePanelsScreen = "HomePanels"
let PrivateHomePanelsScreen = "PrivateHomePanels"
let HomePanel_TopSites = "HomePanel.TopSites.0"
let LibraryPanel_Bookmarks = "LibraryPanel.Bookmarks.1"
let LibraryPanel_History = "LibraryPanel.History.2"
let LibraryPanel_ReadingList = "LibraryPanel.ReadingList.3"
let LibraryPanel_Downloads = "LibraryPanel.Downloads.4"
let LibraryPanel_SyncedTabs = "LibraryPanel.SyncedTabs.5"
let allHomePanels = [
LibraryPanel_Bookmarks,
LibraryPanel_History,
LibraryPanel_ReadingList,
LibraryPanel_Downloads,
LibraryPanel_SyncedTabs
]
class Action {
static let LoadURL = "LoadURL"
static let LoadURLByTyping = "LoadURLByTyping"
static let LoadURLByPasting = "LoadURLByPasting"
static let SetURL = "SetURL"
static let SetURLByTyping = "SetURLByTyping"
static let SetURLByPasting = "SetURLByPasting"
static let TrackingProtectionContextMenu = "TrackingProtectionContextMenu"
static let TrackingProtectionperSiteToggle = "TrackingProtectionperSiteToggle"
static let ReloadURL = "ReloadURL"
static let OpenNewTabFromTabTray = "OpenNewTabFromTabTray"
static let AcceptRemovingAllTabs = "AcceptRemovingAllTabs"
static let TogglePrivateMode = "TogglePrivateBrowing"
static let TogglePrivateModeFromTabBarHomePanel = "TogglePrivateModeFromTabBarHomePanel"
static let TogglePrivateModeFromTabBarBrowserTab = "TogglePrivateModeFromTabBarBrowserTab"
static let TogglePrivateModeFromTabBarNewTab = "TogglePrivateModeFromTabBarNewTab"
static let ToggleRequestDesktopSite = "ToggleRequestDesktopSite"
static let ToggleNightMode = "ToggleNightMode"
static let ToggleTrackingProtection = "ToggleTrackingProtection"
static let ToggleNoImageMode = "ToggleNoImageMode"
static let Bookmark = "Bookmark"
static let BookmarkThreeDots = "BookmarkThreeDots"
static let OpenPrivateTabLongPressTabsButton = "OpenPrivateTabLongPressTabsButton"
static let OpenNewTabLongPressTabsButton = "OpenNewTabLongPressTabsButton"
static let SetPasscode = "SetPasscode"
static let SetPasscodeTypeOnce = "SetPasscodeTypeOnce"
static let DisablePasscode = "DisablePasscode"
static let LoginPasscodeTypeIncorrectOne = "LoginPasscodeTypeIncorrectOne"
static let ChangePasscode = "ChangePasscode"
static let ChangePasscodeTypeOnce = "ChangePasscodeTypeOnce"
static let ConfirmPasscodeToChangePasscode = "ConfirmPasscodeToChangePasscode"
static let UnlockLoginsSettings = "UnlockLoginsSettings"
static let DisablePasscodeTypeIncorrectPasscode = "DisablePasscodeTypeIncorrectPasscode"
static let TogglePocketInNewTab = "TogglePocketInNewTab"
static let ToggleHistoryInNewTab = "ToggleHistoryInNewTab"
static let SelectNewTabAsBlankPage = "SelectNewTabAsBlankPage"
static let SelectNewTabAsFirefoxHomePage = "SelectNewTabAsFirefoxHomePage"
static let SelectNewTabAsCustomURL = "SelectNewTabAsCustomURL"
static let SelectHomeAsFirefoxHomePage = "SelectHomeAsFirefoxHomePage"
static let SelectHomeAsCustomURL = "SelectHomeAsCustomURL"
static let SelectTopSitesRows = "SelectTopSitesRows"
static let GoToHomePage = "GoToHomePage"
static let OpenSiriFromSettings = "OpenSiriFromSettings"
static let AcceptClearPrivateData = "AcceptClearPrivateData"
static let AcceptClearAllWebsiteData = "AcceptClearAllWebsiteData"
static let TapOnFilterWebsites = "TapOnFilterWebsites"
static let ShowMoreWebsiteDataEntries = "ShowMoreWebsiteDataEntries"
static let ClearRecentHistory = "ClearRecentHistory"
static let ToggleTrackingProtectionPerTabEnabled = "ToggleTrackingProtectionPerTabEnabled"
static let OpenSettingsFromTPMenu = "OpenSettingsFromTPMenu"
static let SwitchETP = "SwitchETP"
static let CloseTPContextMenu = "CloseTPContextMenu"
static let CloseTab = "CloseTab"
static let CloseTabFromTabTrayLongPressMenu = "CloseTabFromTabTrayLongPressMenu"
static let OpenEmailToSignIn = "OpenEmailToSignIn"
static let OpenEmailToQR = "OpenEmailToQR"
static let FxATypeEmail = "FxATypeEmail"
static let FxATypePassword = "FxATypePassword"
static let FxATapOnSignInButton = "FxATapOnSignInButton"
static let FxATapOnContinueButton = "FxATapOnContinueButton"
static let PinToTopSitesPAM = "PinToTopSitesPAM"
static let CopyAddressPAM = "CopyAddressPAM"
static let SelectAutomatically = "SelectAutomatically"
static let SelectManually = "SelectManually"
static let SystemThemeSwitch = "SystemThemeSwitch"
static let SelectTranslateThisPage = "SelectTranslateThisPage"
static let SelectDontTranslateThisPage = "SelectDontTranslateThisPage"
static let EnableTranslation = "EnableTranlation"
static let DisableTranslation = "DisableTranlation"
static let SelectGoogle = "SelectGoogle"
static let SelectBing = "SelectBing"
static let AddCustomSearchEngine = "AddCustomSearchEngine"
static let RemoveCustomSearchEngine = "RemoveCustomSearchEngine"
static let ExitMobileBookmarksFolder = "ExitMobileBookmarksFolder"
static let CloseBookmarkPanel = "CloseBookmarkPanel"
static let CloseReadingListPanel = "CloseReadingListPanel"
static let CloseHistoryListPanel = "CloseHistoryListPanel"
static let CloseDownloadsPanel = "CloseDownloadsPanel"
static let CloseSyncedTabsPanel = "CloseSyncedTabsPanel"
static let AddNewBookmark = "AddNewBookmark"
static let AddNewFolder = "AddNewFolder"
static let AddNewSeparator = "AddNewSeparator"
static let RemoveItemMobileBookmarks = "RemoveItemMobileBookmarks"
static let ConfirmRemoveItemMobileBookmarks = "ConfirmRemoveItemMobileBookmarks"
static let SaveCreatedBookmark = "SaveCreatedBookmark"
static let OpenWhatsNewPage = "OpenWhatsNewPage"
}
@objcMembers
class FxUserState: MMUserState {
required init() {
super.init()
initialScreenState = FirstRun
}
var isPrivate = false
var showIntro = false
var showWhatsNew = false
var waitForLoading = true
var url: String? = nil
var requestDesktopSite = false
var passcode: String? = nil
var newPasscode: String = "111111"
var wrongPasscode: String = "111112"
var noImageMode = false
var nightMode = false
var pocketInNewTab = false
var bookmarksInNewTab = true
var historyInNewTab = true
var fxaUsername: String? = nil
var fxaPassword: String? = nil
var numTabs: Int = 0
var numTopSitesRows: Int = 2
var trackingProtectionPerTabEnabled = true // TP can be shut off on a per-tab basis
var trackingProtectionSettingOnNormalMode = true
var trackingProtectionSettingOnPrivateMode = true
var localeIsExpectedDifferent = false
}
fileprivate let defaultURL = "https://www.mozilla.org/en-US/book/"
func createScreenGraph(for test: XCTestCase, with app: XCUIApplication) -> MMScreenGraph<FxUserState> {
let map = MMScreenGraph(for: test, with: FxUserState.self)
let navigationControllerBackAction = {
app.navigationBars.element(boundBy: 0).buttons.element(boundBy: 0).tap()
}
let cancelBackAction = {
if isTablet {
// There is no Cancel option in iPad.
app.otherElements["PopoverDismissRegion"].tap()
} else {
app.buttons["PhotonMenu.close"].tap()
}
}
let cancelTypePasscode = {
if isTablet {
if (app.buttons["Cancel"].exists){
app.buttons["Cancel"].tap()
} else {
app.navigationBars.element(boundBy: 0).buttons.element(boundBy: 0).tap()
}
} else {
app.navigationBars.element(boundBy: 0).buttons.element(boundBy: 0).tap()
}
}
let dismissContextMenuAction = {
app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.25)).tap()
}
map.addScreenState(FirstRun) { screenState in
screenState.noop(to: BrowserTab, if: "showIntro == false && showWhatsNew == true")
screenState.noop(to: NewTabScreen, if: "showIntro == false && showWhatsNew == false")
screenState.noop(to: allIntroPages[0], if: "showIntro == true")
}
// Add the intro screens.
var i = 0
let introLast = allIntroPages.count - 1
for intro in allIntroPages {
let prev = i == 0 ? nil : allIntroPages[i - 1]
let next = i == introLast ? nil : allIntroPages[i + 1]
map.addScreenState(intro) { screenState in
if let next = next {
screenState.tap(app.buttons["nextOnboardingButton"], to: next)
} else {
let startBrowsingButton = app.buttons["startBrowsingOnboardingButton"]
screenState.tap(startBrowsingButton, to: BrowserTab)
}
}
i += 1
}
let noopAction = {}
// Some internally useful screen states.
let WebPageLoading = "WebPageLoading"
map.addScreenState(NewTabScreen) { screenState in
screenState.noop(to: HomePanelsScreen)
if isTablet {
screenState.tap(app.buttons["TopTabsViewController.tabsButton"], to: TabTray)
} else {
screenState.gesture(to: TabTray) {
if (app.buttons["TabToolbar.tabsButton"].exists) {
app.buttons["TabToolbar.tabsButton"].tap()
} else {
app.buttons["URLBarView.tabsButton"].tap()
}
}
}
makeURLBarAvailable(screenState)
screenState.tap(app.buttons["TabToolbar.menuButton"], to: BrowserTabMenu)
if isTablet {
screenState.tap(app.buttons["Private Mode"], forAction: Action.TogglePrivateModeFromTabBarNewTab) { userState in
userState.isPrivate = !userState.isPrivate
}
}
}
map.addScreenState(URLBarLongPressMenu) { screenState in
let menu = app.tables["Context Menu"].firstMatch
screenState.gesture(forAction: Action.LoadURLByPasting, Action.LoadURL) { userState in
UIPasteboard.general.string = userState.url ?? defaultURL
menu.cells["menu-PasteAndGo"].firstMatch.tap()
}
screenState.gesture(forAction: Action.SetURLByPasting) { userState in
UIPasteboard.general.string = userState.url ?? defaultURL
menu.cells["menu-Paste"].firstMatch.tap()
}
screenState.backAction = {
if isTablet {
// There is no Cancel option in iPad.
app.otherElements["PopoverDismissRegion"].tap()
} else {
app.buttons["PhotonMenu.close"].tap()
}
}
screenState.dismissOnUse = true
}
map.addScreenState(TrackingProtectionContextMenuDetails) { screenState in
screenState.gesture(forAction: Action.TrackingProtectionperSiteToggle) { userState in
app.tables.cells["tp.add-to-whitelist"].tap()
userState.trackingProtectionPerTabEnabled = !userState.trackingProtectionPerTabEnabled
}
screenState.gesture(forAction: Action.OpenSettingsFromTPMenu) { userState in
app.cells["settings"].tap()
}
screenState.gesture(forAction: Action.CloseTPContextMenu) { userState in
if isTablet {
// There is no Cancel option in iPad.
app.otherElements["PopoverDismissRegion"].tap()
} else {
app.buttons["PhotonMenu.close"].tap()
}
}
screenState.backAction = {
if isTablet {
// There is no Cancel option in iPad.
app.otherElements["PopoverDismissRegion"].tap()
} else {
app.buttons["PhotonMenu.close"].tap()
}
}
}
// URLBarOpen is dismissOnUse, which ScreenGraph interprets as "now we've done this action, then go back to the one before it"
// but SetURL is an action than keeps us in URLBarOpen. So let's put it here.
map.addScreenAction(Action.SetURL, transitionTo: URLBarOpen)
map.addScreenState(URLBarOpen) { screenState in
// This is used for opening BrowserTab with default mozilla URL
// For custom URL, should use Navigator.openNewURL or Navigator.openURL.
screenState.gesture(forAction: Action.LoadURLByTyping) { userState in
let url = userState.url ?? defaultURL
// Workaround BB iOS13 be sure tap happens on url bar
app.textFields.firstMatch.tap()
app.textFields.firstMatch.tap()
app.textFields.firstMatch.typeText(url)
app.textFields.firstMatch.typeText("\r")
}
screenState.gesture(forAction: Action.SetURLByTyping, Action.SetURL) { userState in
let url = userState.url ?? defaultURL
// Workaround BB iOS13 be sure tap happens on url bar
sleep(1)
app.textFields.firstMatch.tap()
app.textFields.firstMatch.tap()
app.textFields.firstMatch.typeText("\(url)")
}
screenState.noop(to: HomePanelsScreen)
screenState.noop(to: HomePanel_TopSites)
screenState.backAction = {
app.buttons["urlBar-cancel"].tap()
}
screenState.dismissOnUse = true
}
// LoadURL points to WebPageLoading, which allows us to add additional
// onEntryWaitFor requirements, which we don't need when we're returning to BrowserTab without
// loading a webpage.
// We do end up at WebPageLoading however, so should lead quickly back to BrowserTab.
map.addScreenAction(Action.LoadURL, transitionTo: WebPageLoading)
map.addScreenState(WebPageLoading) { screenState in
screenState.dismissOnUse = true
// Would like to use app.otherElements.deviceStatusBars.networkLoadingIndicators.element
// but this means exposing some of SnapshotHelper to another target.
/*if !(app.progressIndicators.element(boundBy: 0).exists) {
screenState.onEnterWaitFor("exists != true", element: app.progressIndicators.element(boundBy: 0), if: "waitForLoading == true")
} else {
screenState.onEnterWaitFor(element: app.progressIndicators.element(boundBy: 0), if: "waitForLoading == false")
}*/
screenState.noop(to: BrowserTab, if: "waitForLoading == true")
screenState.noop(to: BasicAuthDialog, if: "waitForLoading == false")
}
map.addScreenState(BasicAuthDialog) { screenState in
screenState.onEnterWaitFor(element: app.alerts.element(boundBy: 0))
screenState.backAction = {
app.alerts.element(boundBy: 0).buttons.element(boundBy: 0).tap()
}
screenState.dismissOnUse = true
}
map.addScreenState(HomePanelsScreen) { screenState in
if isTablet {
screenState.tap(app.buttons["Private Mode"], forAction: Action.TogglePrivateModeFromTabBarHomePanel) { userState in
userState.isPrivate = !userState.isPrivate
}
}
// Workaround to bug Bug 1417522
if isTablet {
screenState.tap(app.buttons["TopTabsViewController.tabsButton"], to: TabTray)
} else {
screenState.gesture(to: TabTray) {
// iPhone sim tabs button is called differently when in portrait or landscape
if (XCUIDevice.shared.orientation == UIDeviceOrientation.landscapeLeft) {
app.buttons["URLBarView.tabsButton"].tap()
} else {
app.buttons["TabToolbar.tabsButton"].tap()
}
}
}
}
map.addScreenState(LibraryPanel_Bookmarks) { screenState in
let bookmarkCell = app.tables["Bookmarks List"].cells.element(boundBy: 0)
let bookmarksElement = app.navigationBars["Bookmarks"].staticTexts["Bookmarks"]
screenState.tap(app.cells.staticTexts["Mobile Bookmarks"], to: MobileBookmarks)
screenState.gesture(forAction: Action.CloseBookmarkPanel, transitionTo: HomePanelsScreen) { userState in
if isTablet {
app.buttons["TabToolbar.libraryButton"].tap()
} else {
bookmarksElement.press(forDuration: 2, thenDragTo: app.buttons["LibraryPanels.Bookmarks"])
}
}
screenState.press(app.tables["Bookmarks List"].cells.element(boundBy: 4), to: BookmarksPanelContextMenu)
}
map.addScreenState(MobileBookmarks) { screenState in
let bookmarksMenuNavigationBar = app.navigationBars["Mobile Bookmarks"]
let bookmarksButton = bookmarksMenuNavigationBar.buttons["Bookmarks"]
screenState.gesture(forAction: Action.ExitMobileBookmarksFolder, transitionTo: LibraryPanel_Bookmarks) { userState in
bookmarksButton.tap()
}
screenState.tap(app.buttons["Edit"], to: MobileBookmarksEdit)
}
map.addScreenState(MobileBookmarksEdit) { screenState in
screenState.tap(app.buttons["Add"], to: MobileBookmarksAdd)
screenState.gesture(forAction: Action.RemoveItemMobileBookmarks) { userState in
app.tables["Bookmarks List"].buttons.element(boundBy: 0).tap()
}
screenState.gesture(forAction: Action.ConfirmRemoveItemMobileBookmarks) { userState in
app.buttons["Delete"].tap()
}
}
map.addScreenState(MobileBookmarksAdd) { screenState in
screenState.gesture(forAction: Action.AddNewBookmark, transitionTo: EnterNewBookmarkTitleAndUrl) { userState in
app.tables.cells["action_bookmark"].tap()
}
screenState.gesture(forAction: Action.AddNewFolder) { userState in
app.tables.cells["bookmarkFolder"].tap()
}
screenState.gesture(forAction: Action.AddNewSeparator) { userState in
app.tables.cells["nav-menu"].tap()
}
}
map.addScreenState(EnterNewBookmarkTitleAndUrl) { screenState in
screenState.gesture(forAction: Action.SaveCreatedBookmark) { userState in
app.buttons["Save"].tap()
}
}
map.addScreenState(HomePanel_TopSites) { screenState in
let topSites = app.cells["TopSitesCell"]
screenState.press(topSites.cells.matching(identifier: "TopSite").element(boundBy: 0), to: TopSitesPanelContextMenu)
}
map.addScreenState(LibraryPanel_History) { screenState in
screenState.press(app.tables["History List"].cells.element(boundBy: 2), to: HistoryPanelContextMenu)
screenState.tap(app.cells["HistoryPanel.recentlyClosedCell"], to: HistoryRecentlyClosed)
screenState.gesture(forAction: Action.ClearRecentHistory) { userState in
app.tables["History List"].cells.matching(identifier: "HistoryPanel.clearHistory").element(boundBy: 0).tap()
}
let historyListElement = app.navigationBars["History"]
screenState.gesture(forAction: Action.CloseHistoryListPanel, transitionTo: HomePanelsScreen) { userState in
if isTablet {
app.buttons["TabToolbar.libraryButton"].tap()
} else {
historyListElement.press(forDuration: 2, thenDragTo: app.buttons["LibraryPanels.History"])
}
}
}
map.addScreenState(LibraryPanel_SyncedTabs) { screenState in
screenState.dismissOnUse = true
let syncedTabsElement = app.navigationBars["Synced Tabs"]
screenState.gesture(forAction: Action.CloseSyncedTabsPanel, transitionTo: HomePanelsScreen) { userState in
if isTablet {
app.buttons["TabToolbar.libraryButton"].tap()
} else {
syncedTabsElement.press(forDuration: 2, thenDragTo: app.buttons["LibraryPanels.SyncedTabs"])
}
}
}
map.addScreenState(LibraryPanel_ReadingList) { screenState in
screenState.dismissOnUse = true
let readingListElement = app.navigationBars["Reading list"]
screenState.gesture(forAction: Action.CloseReadingListPanel, transitionTo: HomePanelsScreen) { userState in
if isTablet {
app.buttons["TabToolbar.libraryButton"].tap()
} else {
readingListElement.press(forDuration: 2, thenDragTo: app.buttons["LibraryPanels.ReadingList"])
}
}
}
map.addScreenState(LibraryPanel_Downloads) { screenState in
screenState.dismissOnUse = true
let downloadsElement = app.navigationBars["Downloads"]
screenState.gesture(forAction: Action.CloseDownloadsPanel, transitionTo: HomePanelsScreen) { userState in
if isTablet {
app.buttons["TabToolbar.libraryButton"].tap()
} else {
downloadsElement.press(forDuration: 2, thenDragTo: app.buttons["LibraryPanels.Downloads"])
}
}
}
map.addScreenState(HistoryRecentlyClosed) { screenState in
screenState.dismissOnUse = true
screenState.tap(app.buttons["History"].firstMatch, to: LibraryPanel_History)
}
map.addScreenState(HistoryPanelContextMenu) { screenState in
screenState.dismissOnUse = true
}
map.addScreenState(BookmarksPanelContextMenu) { screenState in
screenState.dismissOnUse = true
}
map.addScreenState(TopSitesPanelContextMenu) { screenState in
screenState.dismissOnUse = true
screenState.backAction = dismissContextMenuAction
}
map.addScreenState(SettingsScreen) { screenState in
let table = app.tables.element(boundBy: 0)
screenState.tap(table.cells["Sync"], to: SyncSettings, if: "fxaUsername != nil")
screenState.tap(table.cells["SignInToSync"], to: Intro_FxASignin, if: "fxaUsername == nil")
screenState.tap(table.cells["Search"], to: SearchSettings)
screenState.tap(table.cells["NewTab"], to: NewTabSettings)
screenState.tap(table.cells["Home"], to: HomeSettings)
screenState.tap(table.cells["OpenWith.Setting"], to: OpenWithSettings)
screenState.tap(table.cells["DisplayThemeOption"], to: DisplaySettings)
screenState.tap(table.cells["TranslationOption"], to: TranslationSettings)
screenState.tap(table.cells["SiriSettings"], to: SiriSettings)
screenState.tap(table.cells["TouchIDPasscode"], to: PasscodeSettings)
screenState.tap(table.cells["Logins"], to: LoginsSettings, if: "passcode == nil")
screenState.tap(table.cells["Logins"], to: LockedLoginsSettings, if: "passcode != nil")
screenState.tap(table.cells["ClearPrivateData"], to: ClearPrivateDataSettings)
screenState.tap(table.cells["TrackingProtection"], to: TrackingProtectionSettings)
screenState.tap(table.cells["ShowTour"], to: ShowTourInSettings)
screenState.backAction = navigationControllerBackAction
}
map.addScreenState(DisplaySettings) { screenState in
screenState.gesture(forAction: Action.SelectAutomatically) { userState in
app.cells.staticTexts["Automatically"].tap()
}
screenState.gesture(forAction: Action.SelectManually) { userState in
app.cells.staticTexts["Manually"].tap()
}
screenState.gesture(forAction: Action.SystemThemeSwitch) { userState in
app.switches["SystemThemeSwitchValue"].tap()
}
screenState.backAction = navigationControllerBackAction
}
map.addScreenState(TranslationSettings) { screenState in
screenState.gesture(forAction: Action.DisableTranslation) { userState in
app.switches["TranslateSwitchValue"].tap()
}
screenState.gesture(forAction: Action.EnableTranslation) { userState in
app.switches["TranslateSwitchValue"].tap()
}
screenState.gesture(forAction: Action.SelectGoogle) { userstate in
app.tables.cells.element(boundBy:1).tap()
}
screenState.gesture(forAction: Action.SelectBing) { userstate in
app.tables.cells.element(boundBy:2).tap()
}
screenState.backAction = navigationControllerBackAction
}
map.addScreenState(SearchSettings) { screenState in
let table = app.tables.element(boundBy: 0)
screenState.tap(table.cells["customEngineViewButton"], to: AddCustomSearchSettings)
screenState.backAction = navigationControllerBackAction
screenState.gesture(forAction: Action.RemoveCustomSearchEngine) {userSTate in
// Screengraph will go back to main Settings screen. Manually tap on settings
app.tables["AppSettingsTableViewController.tableView"].staticTexts["Google"].tap()
app.navigationBars["Search"].buttons["Edit"].tap()
app.tables.buttons["Delete Mozilla Engine"].tap()
app.tables.buttons["Delete"].tap()
}
}
map.addScreenState(SiriSettings) { screenState in
screenState.gesture(forAction: Action.OpenSiriFromSettings) { userState in
// Tap on Open New Tab to open Siri
app.cells["SiriSettings"].staticTexts.element(boundBy: 0).tap()
}
screenState.backAction = navigationControllerBackAction
}
map.addScreenState(SyncSettings) { screenState in
screenState.backAction = navigationControllerBackAction
}
map.addScreenState(FxASigninScreen) { screenState in
screenState.backAction = navigationControllerBackAction
screenState.gesture(forAction: Action.FxATypeEmail) { userState in
if isTablet {
app.webViews.textFields.firstMatch.tap()
app.webViews.textFields.firstMatch.typeText(userState.fxaUsername!)
} else {
app.textFields["Email"].tap()
app.textFields["Email"].typeText(userState.fxaUsername!)
}
}
screenState.gesture(forAction: Action.FxATypePassword) { userState in
app.secureTextFields.element(boundBy: 0).tap()
app.secureTextFields.element(boundBy: 0).typeText(userState.fxaPassword!)
}
screenState.gesture(forAction: Action.FxATapOnContinueButton) { userState in
app.webViews.buttons["Continue"].tap()
}
screenState.gesture(forAction: Action.FxATapOnSignInButton) { userState in
app.webViews.buttons.element(boundBy: 0).tap()
}
screenState.tap(app.webViews.links["Create an account"].firstMatch, to: FxCreateAccount)
}
map.addScreenState(FxCreateAccount) { screenState in
screenState.backAction = navigationControllerBackAction
}
map.addScreenState(AddCustomSearchSettings) { screenState in
screenState.gesture(forAction: Action.AddCustomSearchEngine) { userState in
app.tables.textViews["customEngineTitle"].staticTexts["Search Engine"].tap()
app.typeText("Mozilla Engine")
app.tables.textViews["customEngineUrl"].tap()
UIPasteboard.general.string = "https://developer.mozilla.org/search?q=%s"
let tablesQuery = app.tables
let customengineurlTextView = tablesQuery.textViews["customEngineUrl"]
sleep(1)
customengineurlTextView.press(forDuration: 1.0)
app.staticTexts["Paste"].tap()
}
screenState.backAction = navigationControllerBackAction
}
map.addScreenState(WebsiteDataSettings) { screenState in
screenState.gesture(forAction: Action.AcceptClearAllWebsiteData) { userState in
app.tables.cells["ClearAllWebsiteData"].tap()
app.alerts.buttons["OK"].tap()
}
// The swipeDown() is a workaround for an intermitent issue that the search filed is not always in view.
screenState.gesture(forAction: Action.TapOnFilterWebsites) { userState in
app.searchFields["Filter Sites"].tap()
}
screenState.gesture(forAction: Action.ShowMoreWebsiteDataEntries) { userState in
app.tables.cells["ShowMoreWebsiteData"].tap()
}
screenState.backAction = navigationControllerBackAction
}
map.addScreenState(NewTabSettings) { screenState in
let table = app.tables.element(boundBy: 0)
screenState.gesture(forAction: Action.SelectNewTabAsBlankPage) { UserState in
table.cells["NewTabAsBlankPage"].tap()
}
screenState.gesture(forAction: Action.SelectNewTabAsFirefoxHomePage) { UserState in
table.cells["NewTabAsFirefoxHome"].tap()
}
screenState.gesture(forAction: Action.SelectNewTabAsCustomURL) { UserState in
table.cells["NewTabAsCustomURL"].tap()
}
screenState.backAction = navigationControllerBackAction
}
map.addScreenState(HomeSettings) { screenState in
screenState.gesture(forAction: Action.SelectHomeAsFirefoxHomePage) { UserState in
app.cells["HomeAsFirefoxHome"].tap()
}
screenState.gesture(forAction: Action.SelectHomeAsCustomURL) { UserState in
app.cells["HomeAsCustomURL"].tap()
}
screenState.gesture(forAction: Action.TogglePocketInNewTab) { userState in
userState.pocketInNewTab = !userState.pocketInNewTab
app.switches["ASPocketStoriesVisible"].tap()
}
screenState.gesture(forAction: Action.SelectTopSitesRows) { userState in
app.tables.cells["TopSitesRows"].tap()
select(rows: userState.numTopSitesRows)
app.navigationBars.element(boundBy: 0).buttons.element(boundBy: 0).tap()
}
screenState.backAction = navigationControllerBackAction
}
func select(rows: Int) {
app.staticTexts[String(rows)].firstMatch.tap()
}
map.addScreenState(PasscodeSettings) { screenState in
screenState.backAction = navigationControllerBackAction
let table = app.tables.element(boundBy: 0)
screenState.tap(table.cells["TurnOnPasscode"], to: SetPasscodeScreen, if: "passcode == nil")
screenState.tap(table.cells["TurnOffPasscode"], to: DisablePasscodeSettings, if: "passcode != nil")
screenState.tap(table.cells["PasscodeInterval"], to: PasscodeIntervalSettings, if: "passcode != nil")
screenState.tap(table.cells["ChangePasscode"], to: ChangePasscodeSettings, if: "passcode != nil")
}
func type(text: String) {
text.forEach { char in
app.keys[String(char)].tap()
}
}
map.addScreenState(SetPasscodeScreen) { screenState in
screenState.gesture(forAction: Action.SetPasscode, transitionTo: PasscodeSettings) { userState in
type(text: userState.newPasscode)
type(text: userState.newPasscode)
userState.passcode = userState.newPasscode
}
screenState.gesture(forAction: Action.SetPasscodeTypeOnce) { userState in
type(text: userState.newPasscode)
}
screenState.backAction = navigationControllerBackAction
}
map.addScreenState(DisablePasscodeSettings) { screenState in
screenState.gesture(forAction: Action.DisablePasscode, transitionTo: PasscodeSettings) { userState in
if let passcode = userState.passcode {
type(text: passcode)
}
}
screenState.gesture(forAction: Action.DisablePasscodeTypeIncorrectPasscode) { userState in
type(text: userState.wrongPasscode)
}
screenState.backAction = navigationControllerBackAction
}
map.addScreenState(PasscodeIntervalSettings) { screenState in
screenState.onEnter { userState in
if let passcode = userState.passcode {
type(text: passcode)
}
}
screenState.backAction = navigationControllerBackAction
}
map.addScreenState(ChangePasscodeSettings) { screenState in
screenState.gesture(forAction: Action.ChangePasscode, transitionTo: PasscodeSettings) { userState in
if let passcode = userState.passcode {
type(text: passcode)
type(text: userState.newPasscode)
type(text: userState.newPasscode)
userState.passcode = userState.newPasscode
}
}
screenState.gesture(forAction: Action.ConfirmPasscodeToChangePasscode) { userState in
if let passcode = userState.passcode {
type(text: passcode)
}
}
screenState.gesture(forAction: Action.ChangePasscodeTypeOnce) { userState in
type(text: userState.newPasscode)
}
screenState.backAction = navigationControllerBackAction
}
map.addScreenState(LoginsSettings) { screenState in
screenState.backAction = navigationControllerBackAction
}
map.addScreenState(LockedLoginsSettings) { screenState in
screenState.backAction = cancelTypePasscode
screenState.dismissOnUse = true
screenState.gesture(forAction: Action.LoginPasscodeTypeIncorrectOne) { userState in
type(text: userState.wrongPasscode)
}
// Gesture to get to the protected screen.
screenState.gesture(forAction: Action.UnlockLoginsSettings, transitionTo: LoginsSettings) { userState in
if let passcode = userState.passcode {
type(text: passcode)
}
}
}
map.addScreenState(ClearPrivateDataSettings) { screenState in
let table = app.tables.element(boundBy: 0)
screenState.tap(app.cells["WebsiteData"], to: WebsiteDataSettings)
screenState.gesture(forAction: Action.AcceptClearPrivateData) { userState in
app.tables.cells["ClearPrivateData"].tap()
app.alerts.buttons["OK"].tap()
}
screenState.backAction = navigationControllerBackAction
}
map.addScreenState(OpenWithSettings) { screenState in
screenState.backAction = navigationControllerBackAction
}
map.addScreenState(ShowTourInSettings) { screenState in
screenState.gesture(to: Intro_FxASignin) {
let turnOnSyncButton = app.buttons["signInOnboardingButton"]
turnOnSyncButton.tap()
}
}
map.addScreenState(TrackingProtectionSettings) { screenState in
screenState.backAction = navigationControllerBackAction
screenState.tap(app.switches["prefkey.trackingprotection.normalbrowsing"], forAction: Action.SwitchETP) { userState in
userState.trackingProtectionSettingOnNormalMode = !userState.trackingProtectionSettingOnNormalMode
}
}
map.addScreenState(Intro_FxASignin) { screenState in
screenState.tap(app.buttons["EmailSignIn.button"], forAction: Action.OpenEmailToSignIn, transitionTo: FxASigninScreen)
screenState.tap(app.buttons["QRCodeSignIn.button"], forAction: Action.OpenEmailToQR, transitionTo: Intro_FxASignin)
screenState.tap(app.navigationBars.buttons.element(boundBy: 0), to: SettingsScreen)
screenState.backAction = navigationControllerBackAction
}
map.addScreenState(TabTray) { screenState in
screenState.tap(app.buttons["TabTrayController.addTabButton"], forAction: Action.OpenNewTabFromTabTray, transitionTo: NewTabScreen)
screenState.tap(app.buttons["TabTrayController.maskButton"], forAction: Action.TogglePrivateMode) { userState in
userState.isPrivate = !userState.isPrivate
}
screenState.tap(app.buttons["TabTrayController.removeTabsButton"], to: CloseTabMenu)
screenState.onEnter { userState in
userState.numTabs = Int(app.collectionViews.cells.count)
}
}
// This menu is only available for iPhone, NOT for iPad, no menu when long tapping on tabs button
if !isTablet {
map.addScreenState(TabTrayLongPressMenu) { screenState in
screenState.dismissOnUse = true
screenState.tap(app.cells["quick_action_new_tab"], forAction: Action.OpenNewTabLongPressTabsButton, transitionTo: NewTabScreen)
screenState.tap(app.cells["tab_close"], forAction: Action.CloseTabFromTabTrayLongPressMenu, Action.CloseTab, transitionTo: HomePanelsScreen)
screenState.tap(app.cells["nav-tabcounter"], forAction: Action.OpenPrivateTabLongPressTabsButton, transitionTo: NewTabScreen) { userState in
userState.isPrivate = !userState.isPrivate
}
}
}
map.addScreenState(CloseTabMenu) { screenState in
screenState.tap(app.sheets.buttons["TabTrayController.deleteButton.closeAll"], forAction: Action.AcceptRemovingAllTabs, transitionTo: HomePanelsScreen)
screenState.backAction = cancelBackAction
}
func makeURLBarAvailable(_ screenState: MMScreenStateNode<FxUserState>) {
screenState.tap(app.textFields["url"], to: URLBarOpen)
screenState.gesture(to: URLBarLongPressMenu) {
sleep(1)
app.textFields["url"].press(forDuration: 1.0)
}
}
func makeToolBarAvailable(_ screenState: MMScreenStateNode<FxUserState>) {
screenState.tap(app.buttons["TabToolbar.menuButton"], to: BrowserTabMenu)
if isTablet {
screenState.tap(app.buttons["TopTabsViewController.tabsButton"], to: TabTray)
} else {
screenState.gesture(to: TabTray) {
if (app.buttons["TabToolbar.tabsButton"].exists) {
app.buttons["TabToolbar.tabsButton"].tap()
} else {
app.buttons["URLBarView.tabsButton"].tap()
}
}
}
}
map.addScreenState(BrowserTab) { screenState in
makeURLBarAvailable(screenState)
screenState.tap(app.buttons["TabLocationView.pageOptionsButton"], to: PageOptionsMenu)
screenState.tap(app.buttons["TabToolbar.menuButton"], to: BrowserTabMenu)
screenState.tap(app.buttons["TabLocationView.trackingProtectionButton"], to: TrackingProtectionContextMenuDetails)
makeToolBarAvailable(screenState)
let link = app.webViews.element(boundBy: 0).links.element(boundBy: 0)
let image = app.webViews.element(boundBy: 0).images.element(boundBy: 0)
screenState.press(link, to: WebLinkContextMenu)
screenState.press(image, to: WebImageContextMenu)
if !isTablet {
let reloadButton = app.buttons["TabToolbar.stopReloadButton"]
screenState.press(reloadButton, to: ReloadLongPressMenu)
screenState.tap(reloadButton, forAction: Action.ReloadURL, transitionTo: WebPageLoading) { _ in }
} else {
let reloadButton = app.buttons["Reload"]
screenState.press(reloadButton, to: ReloadLongPressMenu)