summaryrefslogtreecommitdiffstats
path: root/browser/components/migration/tests/chrome/test_migration_wizard.html
blob: 7f3f4ab9a97ba3cc1227d630203bf139732f86cc (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Basic tests for the Migration Wizard component</title>
    <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
    <script
      src="chrome://browser/content/migration/migration-wizard.mjs"
      type="module"
    ></script>
    <link
      rel="stylesheet"
      href="chrome://mochikit/content/tests/SimpleTest/test.css"
    />
    <script>
      "use strict";

      const { MigrationWizardConstants } = ChromeUtils.importESModule(
        "chrome://browser/content/migration/migration-wizard-constants.mjs"
      );

      const { BrowserTestUtils } = ChromeUtils.importESModule(
        "resource://testing-common/BrowserTestUtils.sys.mjs"
      );

      const MIGRATOR_PROFILE_INSTANCES = [
        {
          key: "some-browser-0",
          type: MigrationWizardConstants.MIGRATOR_TYPES.BROWSER,
          displayName: "Some Browser 0",
          resourceTypes: ["HISTORY", "FORMDATA", "PASSWORDS", "BOOKMARKS"],
          profile: { id: "person-2", name: "Person 2" },
        },
        {
          key: "some-browser-1",
          type: MigrationWizardConstants.MIGRATOR_TYPES.BROWSER,
          displayName: "Some Browser 1",
          resourceTypes: ["HISTORY", "BOOKMARKS"],
          profile: null,
        },
      ];

      let gWiz = null;
      let gShadowRoot = null;
      let gDeck = null;

      /**
       * Returns the .resource-progress-group div for a particular resource
       * type.
       *
       * @param {string} displayedResourceType
       *   One of the constants belonging to
       *   MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.
       * @returns {Element}
       */
      function getResourceGroup(displayedResourceType) {
        return gShadowRoot.querySelector(
          `.resource-progress-group[data-resource-type="${displayedResourceType}"]`
        );
      }

      add_setup(async function() {
        gWiz = document.getElementById("test-wizard");
        gShadowRoot = gWiz.openOrClosedShadowRoot;
        gDeck = gShadowRoot.querySelector("#wizard-deck");
      });

      /**
       * Tests that the MigrationWizard:RequestState event is fired when the
       * <migration-wizard> is added to the DOM if the auto-request-state attribute
       * is set, and then ensures that the starting page is correct.
       *
       * This also tests that the MigrationWizard:RequestState is not fired automatically
       * if the auto-request-state attribute is not set, but is then fired upon calling
       * requestState().
       *
       * This uses a dynamically created <migration-wizard> instead of the one already
       * in the content div to make sure that the init event is captured.
       */
      add_task(async function test_init_event() {
        const REQUEST_STATE_EVENT = "MigrationWizard:RequestState";

        let wiz = document.createElement("migration-wizard");
        wiz.toggleAttribute("auto-request-state", true);
        let panelList = document.createElement("panel-list");
        wiz.appendChild(panelList);
        let content = document.getElementById("content");
        let promise = new Promise(resolve => {
          content.addEventListener(REQUEST_STATE_EVENT, resolve, {
            once: true,
          });
        });
        content.appendChild(wiz);
        await promise;
        ok(true, `Saw ${REQUEST_STATE_EVENT} event.`);
        let shadowRoot = wiz.openOrClosedShadowRoot;
        let deck = shadowRoot.querySelector("#wizard-deck");
        is(
          deck.selectedViewName,
          "page-loading",
          "Should have the loading page selected"
        );
        wiz.remove();

        wiz.toggleAttribute("auto-request-state", false);
        let sawEvent = false;
        let handler = () => {
          sawEvent = true;
        };
        content.addEventListener(REQUEST_STATE_EVENT, handler);
        content.appendChild(wiz);
        ok(!sawEvent, `Should not have seen ${REQUEST_STATE_EVENT} event.`);
        content.removeEventListener(REQUEST_STATE_EVENT, handler);

        promise = new Promise(resolve => {
          content.addEventListener(REQUEST_STATE_EVENT, resolve, {
            once: true,
          });
        });
        wiz.requestState();
        await promise;
        ok(true, `Saw ${REQUEST_STATE_EVENT} event.`);
        wiz.remove();
      });

      /**
       * Tests that the wizard can show a list of browser and profiles.
       */
      add_task(async function test_selection() {
        gWiz.setState({
          page: MigrationWizardConstants.PAGES.SELECTION,
          migrators: MIGRATOR_PROFILE_INSTANCES,
          showImportAll: false,
        });

        let selector = gShadowRoot.querySelector("#browser-profile-selector");
        let preamble = gShadowRoot.querySelector(".resource-selection-preamble");
        ok(!isHidden(preamble), "preamble should shown.");

        let panelList = gWiz.querySelector("panel-list");
        is(panelList.childElementCount, 2, "Should have two child elements");

        let resourceTypeList = gShadowRoot.querySelector("#resource-type-list");
        let details = gShadowRoot.querySelector("details");
        ok(details.open, "Details should be open");

        // Test that the resource type checkboxes are shown or hidden depending on
        // which resourceTypes are included with the MigratorProfileInstance.
        for (let migratorInstance of MIGRATOR_PROFILE_INSTANCES) {
          selector.click();
          await new Promise(resolve => {
            gWiz
              .querySelector("panel-list")
              .addEventListener("shown", resolve, { once: true });
          });
          let panelItem = gWiz.querySelector(
            `panel-item[key="${migratorInstance.key}"]`
          );
          ok(panelItem, "Should find panel-item.");
          panelItem.click();

          is(
            selector.querySelector("#migrator-name").textContent,
            migratorInstance.displayName,
            "Selector should show display name"
          );
          let profileName = selector.querySelector("#profile-name");

          if (migratorInstance.profile) {
            ok(!isHidden(profileName), "Profile name element should be displayed.");
            is(
              profileName.textContent,
              migratorInstance.profile.name,
              "Selector should show profile name"
            );
          } else {
            ok(isHidden(profileName), "Profile name element should be hidden.");
            is(profileName.textContent, "");
          }

          for (let resourceType in MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES) {
            let node = resourceTypeList.querySelector(
              `label[data-resource-type="${resourceType}"]`
            );

            if (migratorInstance.resourceTypes.includes(resourceType)) {
              ok(!isHidden(node), `Selection for ${resourceType} should be shown.`);
              ok(
                node.control.checked,
                `Checkbox for ${resourceType} should be checked.`
              );
            } else {
              ok(isHidden(node), `Selection for ${resourceType} should be hidden.`);
              ok(
                !node.control.checked,
                `Checkbox for ${resourceType} should be unchecked.`
              );
            }
          }
        }

        let selectAll = gShadowRoot.querySelector("#select-all");
        let summary = gShadowRoot.querySelector("summary");
        ok(isHidden(selectAll), "Selection for select-all should be hidden.");
        ok(isHidden(summary), "Summary should be hidden.");
        ok(!isHidden(details), "Details should be shown.");
      });

      /**
       * Tests the migration wizard with no resources
       */
      add_task(async function test_no_resources() {
        gWiz.setState({
          page: MigrationWizardConstants.PAGES.SELECTION,
          migrators: [{
            key: "some-browser-0",
            type: MigrationWizardConstants.MIGRATOR_TYPES.BROWSER,
            displayName: "Some Browser 0 with no resources",
            resourceTypes: [],
            profile: { id: "person-1", name: "Person 1" },
          }],
          showImportAll: false,
        });

        let noResourcesFound = gShadowRoot.querySelector(".no-resources-found");
        let hideOnErrorEls = gShadowRoot.querySelectorAll(".hide-on-error");
        ok(
          !isHidden(noResourcesFound),
          "Error message of no reasources should be shown."
        );
        for (let hideOnErrorEl of hideOnErrorEls) {
          ok(isHidden(hideOnErrorEl), "Item should be hidden.");
        }
      });

      /**
       * Tests variant 2 of the migration wizard
       */
      add_task(async function test_selection_variant_2() {
        gWiz.setState({
          page: MigrationWizardConstants.PAGES.SELECTION,
          migrators: MIGRATOR_PROFILE_INSTANCES,
          showImportAll: true,
        });

        let preamble = gShadowRoot.querySelector(".resource-selection-preamble");
        ok(isHidden(preamble), "preamble should be hidden.");

        let selector = gShadowRoot.querySelector("#browser-profile-selector");
        selector.click();
        await new Promise(resolve => {
          let panelList = gWiz.querySelector("panel-list");
          if (panelList) {
            panelList.addEventListener("shown", resolve, { once: true });
          }
        });

        let panelItems = gWiz.querySelectorAll("panel-list > panel-item");
        is(panelItems.length, 2, "Should have two panel items");

        let details = gShadowRoot.querySelector("details");
        ok(!details.open, "Details should be closed");
        details.open = true;

        for (let i = 0; i < panelItems.length; i++) {
          let migratorInstance = MIGRATOR_PROFILE_INSTANCES[i];
          let panelItem = panelItems[i];
          panelItem.click();
          for (let resourceType in MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES) {
            let node = gShadowRoot.querySelector(
              `#resource-type-list label[data-resource-type="${resourceType}"]`
            );
            if (migratorInstance.resourceTypes.includes(resourceType)) {
              ok(!isHidden(node), `Selection for ${resourceType} should be shown.`);
              ok(
                node.control.checked,
                `Checkbox for ${resourceType} should be checked.`
              );
            } else {
              ok(isHidden(node), `Selection for ${resourceType} should be hidden.`);
              ok(
                !node.control.checked,
                `Checkbox for ${resourceType} should be unchecked.`
              );
            }
          }
        }

        let selectAll = gShadowRoot.querySelector("#select-all");
        let summary = gShadowRoot.querySelector("summary");
        ok(!isHidden(selectAll), "Selection for select-all should be shown.");
        ok(selectAll.control.checked, "Checkbox for select-all should be checked.");
        ok(!isHidden(summary), "Summary should be shown.");
        ok(!isHidden(details), "Details should be shown.");

        let selectAllCheckbox = gShadowRoot.querySelector(".select-all-checkbox");
        selectAllCheckbox.checked = true;
        selectAllCheckbox.dispatchEvent(new CustomEvent("change"));
        let resourceLabels = gShadowRoot.querySelectorAll("label[data-resource-type]");
        for (let resourceLabel of resourceLabels) {
          if (resourceLabel.hidden) {
            ok(
              !resourceLabel.control.checked,
              `Hidden checkbox for ${resourceLabel.dataset.resourceType} should be unchecked.`

            );
          } else {
            ok(
              resourceLabel.control.checked,
              `Visible checkbox for ${resourceLabel.dataset.resourceType} should be checked.`
            );
          }
        }

        let selectedDataHeader = gShadowRoot.querySelector(".selected-data-header");
        let selectedData = gShadowRoot.querySelector(".selected-data");

        let bookmarks = gShadowRoot.querySelector("#bookmarks");
        let history = gShadowRoot.querySelector("#history");

        let selectedDataUpdated = BrowserTestUtils.waitForEvent(
          gWiz,
          "MigrationWizard:ResourcesUpdated"
        );
        bookmarks.control.checked = true;
        history.control.checked = true;
        bookmarks.dispatchEvent(new CustomEvent("change"));

        ok(bookmarks.control.checked, "Bookmarks should be checked");
        ok(history.control.checked, "History should be checked");

        await selectedDataUpdated;

        is(
          selectedData.textContent,
          "Bookmarks and history",
          "Testing if selected-data reflects the selected resources."
        );

        is(
          selectedDataHeader.dataset.l10nId,
          "migration-all-available-data-label",
          "Testing if selected-data-header reflects the selected resources"
        );

        let importButton = gShadowRoot.querySelector("#import");

        ok(
          !importButton.disabled,
          "Testing if import button is enabled when at least one resource is selected."
        );

        let importButtonUpdated = BrowserTestUtils.waitForEvent(
          gWiz,
          "MigrationWizard:ResourcesUpdated"
        );

        selectAllCheckbox.checked = false;
        selectAllCheckbox.dispatchEvent(new CustomEvent("change", { bubbles: true }));
        await importButtonUpdated;

        ok(
          importButton.disabled,
          "Testing if import button is disabled when no resources are selected."
        );
      });

      /**
       * Tests variant 2 of the migration wizard when there's a single resource
       * item.
       */
      add_task(async function test_selection_variant_2_single_item() {
        let resourcesUpdated = BrowserTestUtils.waitForEvent(
          gWiz,
          "MigrationWizard:ResourcesUpdated"
        );
        gWiz.setState({
          page: MigrationWizardConstants.PAGES.SELECTION,
          migrators: [{
            key: "some-browser-0",
            type: MigrationWizardConstants.MIGRATOR_TYPES.BROWSER,
            displayName: "Some Browser 0 with a single resource",
            resourceTypes: ["HISTORY"],
            profile: { id: "person-1", name: "Person 1" },
          }, {
            key: "some-browser-1",
            type: MigrationWizardConstants.MIGRATOR_TYPES.BROWSER,
            displayName: "Some Browser 1 with a two resources",
            resourceTypes: ["HISTORY", "BOOKMARKS"],
            profile: { id: "person-2", name: "Person 2" },
          }],
          showImportAll: true,
        });
        await resourcesUpdated;

        let selectAll = gShadowRoot.querySelector("#select-all");
        let summary = gShadowRoot.querySelector("summary");
        let details = gShadowRoot.querySelector("details");
        ok(!details.open, "Details should be closed");
        details.open = true;

        ok(isHidden(selectAll), "Selection for select-all should be hidden.");
        ok(!isHidden(summary), "Summary should be shown.");
        ok(!isHidden(details), "Details should be shown.");

        resourcesUpdated = BrowserTestUtils.waitForEvent(
          gWiz,
          "MigrationWizard:ResourcesUpdated"
        );
        let browser1Item = gWiz.querySelector("panel-item[key='some-browser-1']");
        browser1Item.click();
        await resourcesUpdated;

        ok(!isHidden(selectAll), "Selection for select-all should be shown.");
        ok(!isHidden(summary), "Summary should be shown.");
        ok(!isHidden(details), "Details should be shown.");
      });

      /**
       * Tests that the Select All checkbox is checked if all non-hidden resource
       * types are checked, and unchecked otherwise.
       */
      add_task(async function test_selection_variant_2_select_all() {
        gWiz.setState({
          page: MigrationWizardConstants.PAGES.SELECTION,
          migrators: MIGRATOR_PROFILE_INSTANCES,
          showImportAll: true,
        });

        let details = gShadowRoot.querySelector("details");
        ok(!details.open, "Details should be closed");
        details.open = true;

        let selectAll = gShadowRoot.querySelector("#select-all");
        ok(selectAll.control.checked, "Select all should be checked by default");

        let bookmarksResourceLabel = gShadowRoot.querySelector(
          "label[data-resource-type='BOOKMARKS']"
        );
        ok(bookmarksResourceLabel.control.checked, "Bookmarks should be checked");

        bookmarksResourceLabel.control.click();
        ok(!bookmarksResourceLabel.control.checked, "Bookmarks should no longer be checked");
        ok(!selectAll.control.checked, "Select all should not longer be checked");

        bookmarksResourceLabel.control.click();
        ok(bookmarksResourceLabel.control.checked, "Bookmarks should be checked again");
        ok(selectAll.control.checked, "Select all should be checked");
      });

      /**
       * Tests that the wizard can show partial progress during migration.
       */
      add_task(async function test_partial_progress() {
        const BOOKMARKS_SUCCESS_STRING = "Some bookmarks success string";
        gWiz.setState({
          page: MigrationWizardConstants.PAGES.PROGRESS,
          key: "chrome",
          progress: {
            [MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.BOOKMARKS]: {
              inProgress: false,
              message: BOOKMARKS_SUCCESS_STRING,
            },
            // Don't include PASSWORDS to check that it's hidden.
            [MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.HISTORY]: {
              inProgress: true,
            },
            [MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.FORMDATA]: {
              inProgress: true,
            },
          },
        });
        is(
          gDeck.selectedViewName,
          "page-progress",
          "Should have the progress page selected"
        );

        // Bookmarks
        let bookmarksGroup = getResourceGroup(
          MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.BOOKMARKS
        );
        ok(!isHidden(bookmarksGroup), "Bookmarks group should be visible");
        let progressIcon = bookmarksGroup.querySelector(".progress-icon");
        ok(
          progressIcon.classList.contains("completed"),
          "Progress should be completed"
        );
        is(
          bookmarksGroup.querySelector(".success-text").textContent,
          BOOKMARKS_SUCCESS_STRING
        );

        // Passwords
        let passwordsGroup = getResourceGroup(
          MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.PASSWORDS
        );
        ok(isHidden(passwordsGroup), "Passwords group should be hidden");

        // History
        let historyGroup = getResourceGroup(
          MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.HISTORY
        );
        ok(!isHidden(historyGroup), "History group should be visible");
        progressIcon = historyGroup.querySelector(".progress-icon");
        ok(
          !progressIcon.classList.contains("completed"),
          "Progress should be still be underway"
        );
        is(historyGroup.querySelector(".success-text").textContent.trim(), "");

        // Form Data
        let formDataGroup = getResourceGroup(
          MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.FORMDATA
        );
        ok(!isHidden(formDataGroup), "Form data group should be visible");
        progressIcon = formDataGroup.querySelector(".progress-icon");
        ok(
          !progressIcon.classList.contains("completed"),
          "Progress should be still be underway"
        );
        is(formDataGroup.querySelector(".success-text").textContent.trim(), "");

        // With progress still being underway, the header should be using the
        // in progress string.
        let header = gShadowRoot.querySelector("#progress-header");
        is(
          header.getAttribute("data-l10n-id"),
          "migration-wizard-progress-header",
          "Should be showing in-progress header string"
        );

        let progressPage = gShadowRoot.querySelector("div[name='page-progress']");
        let doneButton = progressPage.querySelector(".done-button");
        ok(isHidden(doneButton), "Done button should be hidden");
        let cancelButton = progressPage.querySelector(".cancel-close");
        ok(!isHidden(cancelButton), "Cancel button should be visible");
        ok(cancelButton.disabled, "Cancel button should be disabled");
      });

      /**
       * Tests that the wizard can show completed migration progress.
       */
      add_task(async function test_completed_progress() {
        const BOOKMARKS_SUCCESS_STRING = "Some bookmarks success string";
        const PASSWORDS_SUCCESS_STRING = "Some passwords success string";
        const FORMDATA_SUCCESS_STRING = "Some formdata string";
        gWiz.setState({
          page: MigrationWizardConstants.PAGES.PROGRESS,
          key: "chrome",
          progress: {
            [MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.BOOKMARKS]: {
              inProgress: false,
              message: BOOKMARKS_SUCCESS_STRING,
            },
            [MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.PASSWORDS]: {
              inProgress: false,
              message: PASSWORDS_SUCCESS_STRING,
            },
            // Don't include HISTORY to check that it's hidden.
            [MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.FORMDATA]: {
              inProgress: false,
              message: FORMDATA_SUCCESS_STRING,
            },
          },
        });
        is(
          gDeck.selectedViewName,
          "page-progress",
          "Should have the progress page selected"
        );

        // Bookmarks
        let bookmarksGroup = getResourceGroup(
          MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.BOOKMARKS
        );
        ok(!isHidden(bookmarksGroup), "Bookmarks group should be visible");
        let progressIcon = bookmarksGroup.querySelector(".progress-icon");
        ok(
          progressIcon.classList.contains("completed"),
          "Progress should be completed"
        );
        is(
          bookmarksGroup.querySelector(".success-text").textContent,
          BOOKMARKS_SUCCESS_STRING
        );

        // Passwords
        let passwordsGroup = getResourceGroup(
          MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.PASSWORDS
        );
        ok(!isHidden(passwordsGroup), "Passwords group should be visible");
        progressIcon = passwordsGroup.querySelector(".progress-icon");
        ok(
          progressIcon.classList.contains("completed"),
          "Progress should be completed"
        );
        is(
          passwordsGroup.querySelector(".success-text").textContent,
          PASSWORDS_SUCCESS_STRING
        );

        // History
        let historyGroup = getResourceGroup(
          MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.HISTORY
        );
        ok(isHidden(historyGroup), "History group should be hidden");

        // Form Data
        let formDataGroup = getResourceGroup(
          MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.FORMDATA
        );
        ok(!isHidden(formDataGroup), "Form data group should be visible");
        progressIcon = formDataGroup.querySelector(".progress-icon");
        ok(
          progressIcon.classList.contains("completed"),
          "Progress should be completed"
        );
        is(
          formDataGroup.querySelector(".success-text").textContent,
          FORMDATA_SUCCESS_STRING
        );

        // With progress being complete, the header should be using the completed
        // migration string.
        let header = gShadowRoot.querySelector("#progress-header");
        is(
          header.getAttribute("data-l10n-id"),
          "migration-wizard-progress-done-header",
          "Should be showing completed migration header string"
        );

        let progressPage = gShadowRoot.querySelector("div[name='page-progress']");
        let doneButton = progressPage.querySelector(".done-button");
        ok(!isHidden(doneButton), "Done button should be visible and enabled");
        let cancelButton = progressPage.querySelector(".cancel-close");
        ok(isHidden(cancelButton), "Cancel button should be hidden");
      });

      /**
       * Tests that the wizard can show partial progress during file migration.
       */
      add_task(async function test_partial_file_progress() {
        const PASSWORDS_SUCCESS_STRING = "Some passwords success string";
        const TITLE = "Partial progress";

        gWiz.setState({
          page: MigrationWizardConstants.PAGES.FILE_IMPORT_PROGRESS,
          title: "Partial progress",
          progress: {
            [MigrationWizardConstants.DISPLAYED_FILE_RESOURCE_TYPES.PASSWORDS_FROM_FILE]: {
              inProgress: false,
              message: PASSWORDS_SUCCESS_STRING,
            },
            [MigrationWizardConstants.DISPLAYED_FILE_RESOURCE_TYPES.PASSWORDS_NEW]: {
              inProgress: true,
            },
          },
        });

        is(
          gDeck.selectedViewName,
          "page-file-import-progress",
          "Should have the file progress page selected"
        );

        let header = gShadowRoot.querySelector("#file-import-progress-header");
        is(header.textContent, TITLE, "Title is set correctly.");

        let passwordsFromFileGroup = getResourceGroup(
          MigrationWizardConstants.DISPLAYED_FILE_RESOURCE_TYPES.PASSWORDS_FROM_FILE
        );
        ok(!isHidden(passwordsFromFileGroup), "Passwords from file group should be visible");
        let progressIcon = passwordsFromFileGroup.querySelector(".progress-icon");
        ok(
          progressIcon.classList.contains("completed"),
          "Progress should be completed"
        );
        is(
          passwordsFromFileGroup.querySelector(".success-text").textContent,
          PASSWORDS_SUCCESS_STRING
        );

        let passwordsUpdatedGroup = getResourceGroup(
          MigrationWizardConstants.DISPLAYED_FILE_RESOURCE_TYPES.PASSWORDS_UPDATED
        );
        ok(isHidden(passwordsUpdatedGroup), "Passwords updated group should be hidden");

        let passwordsNewGroup = getResourceGroup(
          MigrationWizardConstants.DISPLAYED_FILE_RESOURCE_TYPES.PASSWORDS_NEW
        );
        ok(!isHidden(passwordsNewGroup), "Passwords new group should be visible");
        progressIcon = passwordsNewGroup.querySelector(".progress-icon");
        ok(
          !progressIcon.classList.contains("completed"),
          "Progress should be still be underway"
        );
        is(passwordsNewGroup.querySelector(".success-text").textContent.trim(), "");

        let progressPage = gShadowRoot.querySelector("div[name='page-file-import-progress']");
        let doneButton = progressPage.querySelector(".done-button");
        ok(isHidden(doneButton), "Done button should be hidden");
        let cancelButton = progressPage.querySelector(".cancel-close");
        ok(!isHidden(cancelButton), "Cancel button should be visible");
        ok(cancelButton.disabled, "Cancel button should be disabled");
      });

      /**
       * Tests that the wizard can show completed migration progress.
       */
      add_task(async function test_completed_file_progress() {
        const PASSWORDS_NEW_SUCCESS_STRING = "2 added";
        const PASSWORDS_UPDATED_SUCCESS_STRING = "5 updated";
        const TITLE = "Done doing file import";

        gWiz.setState({
          page: MigrationWizardConstants.PAGES.FILE_IMPORT_PROGRESS,
          title: TITLE,
          progress: {
            [MigrationWizardConstants.DISPLAYED_FILE_RESOURCE_TYPES.PASSWORDS_NEW]: {
              inProgress: false,
              message: PASSWORDS_NEW_SUCCESS_STRING,
            },
            [MigrationWizardConstants.DISPLAYED_FILE_RESOURCE_TYPES.PASSWORDS_UPDATED]: {
              inProgress: false,
              message: PASSWORDS_UPDATED_SUCCESS_STRING,
            },
          },
        });
        is(
          gDeck.selectedViewName,
          "page-file-import-progress",
          "Should have the file progress page selected"
        );

        let header = gShadowRoot.querySelector("#file-import-progress-header");
        is(header.textContent, TITLE, "Title is set correctly.");

        let passwordsNewGroup = getResourceGroup(
          MigrationWizardConstants.DISPLAYED_FILE_RESOURCE_TYPES.PASSWORDS_NEW
        );
        ok(!isHidden(passwordsNewGroup), "Passwords new group should be visible");
        let progressIcon = passwordsNewGroup.querySelector(".progress-icon");
        ok(
          progressIcon.classList.contains("completed"),
          "Progress should be completed"
        );
        is(
          passwordsNewGroup.querySelector(".success-text").textContent,
          PASSWORDS_NEW_SUCCESS_STRING
        );

        let passwordsUpdatedGroup = getResourceGroup(
          MigrationWizardConstants.DISPLAYED_FILE_RESOURCE_TYPES.PASSWORDS_UPDATED
        );
        ok(!isHidden(passwordsUpdatedGroup), "Passwords updated group should be visible");
        progressIcon = passwordsUpdatedGroup.querySelector(".progress-icon");
        ok(
          progressIcon.classList.contains("completed"),
          "Progress should be completed"
        );
        is(
          passwordsUpdatedGroup.querySelector(".success-text").textContent,
          PASSWORDS_UPDATED_SUCCESS_STRING
        );

        let passwordsFromFileGroup = getResourceGroup(
          MigrationWizardConstants.DISPLAYED_FILE_RESOURCE_TYPES.PASSWORDS_FROM_FILE
        );
        ok(isHidden(passwordsFromFileGroup), "Passwords from file group should be hidden");

        let progressPage = gShadowRoot.querySelector("div[name='page-file-import-progress']");
        let doneButton = progressPage.querySelector(".done-button");
        ok(!isHidden(doneButton), "Done button should be visible and enabled");
        let cancelButton = progressPage.querySelector(".cancel-close");
        ok(isHidden(cancelButton), "Cancel button should be hidden");
      });

      /**
       * Tests that the buttons that dismiss the wizard when embedded in
       * a dialog are only visible when in dialog mode, and dispatch a
       * MigrationWizard:Close event when clicked.
       */
      add_task(async function test_dialog_mode_close() {
        gWiz.toggleAttribute("dialog-mode", true);
        gWiz.setState({
          page: MigrationWizardConstants.PAGES.SELECTION,
          migrators: MIGRATOR_PROFILE_INSTANCES,
        });

        // For now, there's only a single .cancel-close button, so let's just test
        // that one. Let's make this test fail if there are multiple so that we can
        // then update this test to switch to the right pages to test those buttons
        // too.
        let buttons = gShadowRoot.querySelectorAll(".cancel-close:not([disabled])");
        ok(
          buttons.length,
          "This test expects at least one enabled .cancel-close button"
        );
        let button = buttons[0];
        ok(
          !isHidden(button),
          ".cancel-close button should be visible in dialog mode."
        );
        let closeEvent = BrowserTestUtils.waitForEvent(gWiz, "MigrationWizard:Close");
        synthesizeMouseAtCenter(button, {});
        await closeEvent;

        gWiz.toggleAttribute("dialog-mode", false);
        ok(
          isHidden(button),
          ".cancel-close button should be hidden when not in dialog mode."
        );
      });

      /**
       * Internet Explorer and Edge refer to bookmarks as "favorites",
       * and we change our labels to suit when either of those browsers are
       * selected as the migration source. This test tests that behavior in the
       * selection page.
       */
      add_task(async function test_ie_edge_favorites_selection() {
        gWiz.setState({
          page: MigrationWizardConstants.PAGES.SELECTION,
          migrators: MIGRATOR_PROFILE_INSTANCES,
          showImportAll: false,
        });

        let bookmarksCheckboxLabel = gShadowRoot.querySelector("#bookmarks");
        let span = bookmarksCheckboxLabel.querySelector("span[default-data-l10n-id]");
        ok(span, "The bookmarks selection span has a default-data-l10n-id attribute");
        is(
          span.getAttribute("data-l10n-id"),
          span.getAttribute("default-data-l10n-id"),
          "Should be showing the default string for bookmarks"
        );

        // Now test when in Variant 2, for the string in the <summary>.
        let selectedDataUpdated = BrowserTestUtils.waitForEvent(
          gWiz,
          "MigrationWizard:ResourcesUpdated"
        );

        gWiz.setState({
          page: MigrationWizardConstants.PAGES.SELECTION,
          migrators: MIGRATOR_PROFILE_INSTANCES,
          showImportAll: true,
        });

        await selectedDataUpdated;

        let summary = gShadowRoot.querySelector("summary");
        ok(
          summary.textContent.toLowerCase().includes("bookmarks"),
          "Summary should include the string 'bookmarks'"
        );

        for (let key of MigrationWizardConstants.USES_FAVORITES) {
          gWiz.setState({
            page: MigrationWizardConstants.PAGES.SELECTION,
            migrators: [{
              key,
              displayName: "Legacy Microsoft Browser",
              resourceTypes: ["BOOKMARKS"],
              profile: null,
            }],
            showImportAll: false,
          });

          is(
            span.getAttribute("data-l10n-id"),
            span.getAttribute("ie-edge-data-l10n-id"),
            "Should be showing the IE/Edge string for bookmarks"
          );

          // Now test when in Variant 2, for the string in the <summary>.
          selectedDataUpdated = BrowserTestUtils.waitForEvent(
            gWiz,
            "MigrationWizard:ResourcesUpdated"
          );

          gWiz.setState({
            page: MigrationWizardConstants.PAGES.SELECTION,
            migrators: [{
              key,
              displayName: "Legacy Microsoft Browser",
              resourceTypes: ["BOOKMARKS"],
              profile: null,
            }],
            showImportAll: true,
          });

          await selectedDataUpdated;

          ok(
            summary.textContent.toLowerCase().includes("favorites"),
            "Summary should include the string 'favorites'"
          );
        }
      });

      /**
       * Internet Explorer and Edge refer to bookmarks as "favorites",
       * and we change our labels to suit when either of those browsers are
       * selected as the migration source. This test tests that behavior in the
       * progress page
       */
      add_task(async function test_ie_edge_favorites_progress() {
        gWiz.setState({
          page: MigrationWizardConstants.PAGES.PROGRESS,
          key: "chrome",
          progress: {
            [MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.BOOKMARKS]: {
              inProgress: false,
              message: "A string from the parent",
            },
          },
        });

        let bookmarksGroup = getResourceGroup(
          MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.BOOKMARKS
        );
        let span = bookmarksGroup.querySelector("span[default-data-l10n-id]");
        ok(span, "Should have found a span with default-data-l10n-id");
        is(
          span.getAttribute("data-l10n-id"),
          span.getAttribute("default-data-l10n-id"),
          "Should be using the default string."
        );


        for (let key of MigrationWizardConstants.USES_FAVORITES) {
          gWiz.setState({
            page: MigrationWizardConstants.PAGES.PROGRESS,
            key,
            progress: {
              [MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.BOOKMARKS]: {
                inProgress: false,
                message: "A string from the parent",
              },
            },
          });

          is(
            span.getAttribute("data-l10n-id"),
            span.getAttribute("ie-edge-data-l10n-id"),
            "Should be showing the IE/Edge string for bookmarks"
          );
        }
      });

      /**
       * Tests that the button shown in either the browser migration success or
       * file migration success pages is a "continue" button rather than a
       * "done" button.
       */
      add_task(async function test_embedded_continue_button() {
        gWiz.toggleAttribute("dialog-mode", false);
        gWiz.setState({
          page: MigrationWizardConstants.PAGES.PROGRESS,
          key: "chrome",
          progress: {
            [MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.BOOKMARKS]: {
              inProgress: false,
              message: "A string from the parent",
            },
          },
        });

        let progressPage = gShadowRoot.querySelector("div[name='page-progress']");
        let cancelButton = progressPage.querySelector(".cancel-close");
        ok(isHidden(cancelButton), "Cancel button should be hidden");
        let doneButton = progressPage.querySelector(".done-button");
        ok(isHidden(doneButton), "Done button should be hidden when embedding");
        let continueButton = progressPage.querySelector(".continue-button");
        ok(!isHidden(continueButton), "Continue button should be displayed");

        let content = document.getElementById("content");

        let promise = new Promise(resolve => {
          content.addEventListener("MigrationWizard:Close", resolve, {
            once: true,
          });
        });
        continueButton.click();
        await promise;
        ok(
          true,
          "Clicking on the Continue button sent the MigrationWizard:Close event."
        );

        gWiz.setState({
          page: MigrationWizardConstants.PAGES.FILE_IMPORT_PROGRESS,
          title: "Done importing file data",
          progress: {
            [MigrationWizardConstants.DISPLAYED_FILE_RESOURCE_TYPES.PASSWORDS_NEW]: {
              inProgress: false,
              message: "Some message",
            },
            [MigrationWizardConstants.DISPLAYED_FILE_RESOURCE_TYPES.PASSWORDS_UPDATED]: {
              inProgress: false,
              message: "Some other",
            },
          },
        });

        progressPage = gShadowRoot.querySelector("div[name='page-file-import-progress']");
        cancelButton = progressPage.querySelector(".cancel-close");
        ok(isHidden(cancelButton), "Cancel button should be hidden");
        doneButton = progressPage.querySelector(".done-button");
        ok(isHidden(doneButton), "Done button should be hidden when embedding");
        continueButton = progressPage.querySelector(".continue-button");
        ok(!isHidden(continueButton), "Continue button should be displayed");

        promise = new Promise(resolve => {
          content.addEventListener("MigrationWizard:Close", resolve, {
            once: true,
          });
        });
        continueButton.click();
        await promise;
        ok(
          true,
          "Clicking on the Continue button sent the MigrationWizard:Close event."
        );

        gWiz.toggleAttribute("dialog-mode", true);
      });

      /**
       * Tests that if a progress update comes down which puts a resource from
       * being done to being back "inProgress", that the status message is
       * cleared.
       */
      add_task(async function test_clear_status_message_when_in_progress() {
        const STRING_TO_CLEAR = "This string should get cleared";
        gWiz.toggleAttribute("dialog-mode", false);
        gWiz.setState({
          page: MigrationWizardConstants.PAGES.PROGRESS,
          key: "chrome",
          progress: {
            [MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.BOOKMARKS]: {
              inProgress: false,
              message: STRING_TO_CLEAR,
            },
          },
        });

        let bookmarksGroup = getResourceGroup(
          MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.BOOKMARKS
        );
        ok(!isHidden(bookmarksGroup), "Bookmarks group should be visible");
        let progressIcon = bookmarksGroup.querySelector(".progress-icon");
        ok(
          progressIcon.classList.contains("completed"),
          "Progress should be completed"
        );
        is(
          bookmarksGroup.querySelector(".success-text").textContent,
          STRING_TO_CLEAR
        );

        gWiz.setState({
          page: MigrationWizardConstants.PAGES.PROGRESS,
          key: "chrome",
          progress: {
            [MigrationWizardConstants.DISPLAYED_RESOURCE_TYPES.BOOKMARKS]: {
              inProgress: true,
              message: "",
            },
          },
        });

        ok(!isHidden(bookmarksGroup), "Bookmarks group should be visible");
        ok(
          !progressIcon.classList.contains("completed"),
          "Progress should still be underway"
        );
        is(
          bookmarksGroup.querySelector(".success-text").textContent.trim(),
          ""
        );
      });

      /**
       * Tests that if a file progress update comes down which puts a resource
       * from being done to being back "inProgress", that the status message is
       * cleared.
       *
       * This is extremely similar to the above test, except that it's for progress
       * updates for file resources.
       */
      add_task(async function test_clear_status_message_when_in_file_progress() {
        const STRING_TO_CLEAR = "This string should get cleared";
        gWiz.toggleAttribute("dialog-mode", false);
        gWiz.setState({
          page: MigrationWizardConstants.PAGES.FILE_IMPORT_PROGRESS,
          key: "chrome",
          progress: {
            [MigrationWizardConstants.DISPLAYED_FILE_RESOURCE_TYPES.PASSWORDS_NEW]: {
              inProgress: false,
              message: STRING_TO_CLEAR,
            },
          },
        });

        let passwordsGroup = getResourceGroup(
          MigrationWizardConstants.DISPLAYED_FILE_RESOURCE_TYPES.PASSWORDS_NEW
        );
        ok(!isHidden(passwordsGroup), "Passwords group should be visible");
        let progressIcon = passwordsGroup.querySelector(".progress-icon");
        ok(
          progressIcon.classList.contains("completed"),
          "Progress should be completed"
        );
        is(
          passwordsGroup.querySelector(".success-text").textContent,
          STRING_TO_CLEAR
        );

        gWiz.setState({
          page: MigrationWizardConstants.PAGES.FILE_IMPORT_PROGRESS,
          key: "chrome",
          progress: {
            [MigrationWizardConstants.DISPLAYED_FILE_RESOURCE_TYPES.PASSWORDS_NEW]: {
              inProgress: true,
              message: "",
            },
          },
        });

        ok(!isHidden(passwordsGroup), "Passwords group should be visible");
        ok(
          !progressIcon.classList.contains("completed"),
          "Progress should still be underway"
        );
        is(
          passwordsGroup.querySelector(".success-text").textContent.trim(),
          ""
        );
      });
    </script>
  </head>
  <body>
    <p id="display"></p>
    <div id="content">
      <migration-wizard id="test-wizard" dialog-mode="">
        <panel-list></panel-list>
      </migration-wizard>
    </div>
    <pre id="test"></pre>
  </body>
</html>