summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/webextensions/test/browser/browser_bug577990.js
blob: 913b3b9548522c3f14efefb229201b03a20dccaf (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

// Tests that the visible delay in showing the "Language" category occurs
// very minimally

var gManagerWindow;
var gCategoryUtilities;
var gProvider;
var gInstall;
var gInstallProperties = [{
  name: "Locale Category Test",
  type: "locale"
}];

function test() {
  try {
    if (Components.classes["@mozilla.org/gfx/info;1"].getService(Components.interfaces.nsIGfxInfo).D2DEnabled) {
      requestLongerTimeout(2);
    }
  } catch (e) {}
  waitForExplicitFinish();

  gProvider = new MockProvider();

  open_manager("addons://list/extension", function(aWindow) {
    gManagerWindow = aWindow;
    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
    run_next_test();
  });
}

function end_test() {
  close_manager(gManagerWindow, finish);
}

function install_locale(aCallback) {
  gInstall = gProvider.createInstalls(gInstallProperties)[0];
  gInstall.addTestListener({
    onInstallEnded: function(aInstall) {
      gInstall.removeTestListener(this);
      executeSoon(aCallback);
    }
  });
  gInstall.install();
}

function check_hidden(aExpectedHidden) {
  var hidden = !gCategoryUtilities.isTypeVisible("locale");
  is(hidden, !!aExpectedHidden, "Should have correct hidden state");
}

function run_open_test(aTestSetup, aLoadHidden, aInitializedHidden, aSelected) {
  function loadCallback(aManagerWindow) {
    gManagerWindow = aManagerWindow;
    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
    check_hidden(aLoadHidden);
  }

  function run() {
    open_manager(null, function() {
      check_hidden(aInitializedHidden);
      var selected = (gCategoryUtilities.selectedCategory == "locale");
      is(selected, !!aSelected, "Should have correct selected state");

      run_next_test();
    }, loadCallback);
  }

  close_manager(gManagerWindow, function() {
    // Allow for asynchronous functions to run before the manager opens
    aTestSetup ? aTestSetup(run) : run();
  });
}


// Tests that the locale category is hidden when there are no locales installed
add_test(function() {
  run_open_test(null, true, true);
});

// Tests that installing a locale while the Add-on Manager is open shows the
// locale category
add_test(function() {
  check_hidden(true);
  install_locale(function() {
    check_hidden(false);
    run_next_test();
  });
});

// Tests that the locale category is shown with no delay when restarting
// Add-on Manager
add_test(function() {
  run_open_test(null, false, false);
});

// Tests that cancelling the locale install and restarting the Add-on Manager
// causes the locale category to be hidden with an acceptable delay
add_test(function() {
  gInstall.cancel();
  run_open_test(null, false, true)
});

// Tests that the locale category is hidden with no delay when restarting
// Add-on Manager
add_test(function() {
  run_open_test(null, true, true);
});

// Tests that installing a locale when the Add-on Manager is closed, and then
// opening the Add-on Manager causes the locale category to be shown with an
// acceptable delay
add_test(function() {
  run_open_test(install_locale, true, false);
});

// Tests that selection of the locale category persists
add_test(function() {
  gCategoryUtilities.openType("locale", function() {
    run_open_test(null, false, false, true);
  });
});

// Tests that cancelling the locale install and restarting the Add-on Manager
// causes the locale category to be hidden and not selected
add_test(function() {
  gInstall.cancel();
  run_open_test(null, false, true);
});