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

"use strict";

const THEME_ID = "default-theme@mozilla.org";

function assertViewHas(win, selector, msg) {
  ok(win.document.querySelector(selector), msg);
}
function assertListView(win, type) {
  assertViewHas(win, `addon-list[type="${type}"]`, `On ${type} list`);
}

add_task(async function testClickingSidebarEntriesChangesView() {
  let win = await loadInitialView("extension");
  let doc = win.document;
  let themeCategory = doc.querySelector("#categories > [name=theme]");
  let extensionCategory = doc.querySelector("#categories > [name=extension]");

  assertListView(win, "extension");

  let loaded = waitForViewLoad(win);
  themeCategory.click();
  await loaded;

  assertListView(win, "theme");

  loaded = waitForViewLoad(win);
  getAddonCard(win, THEME_ID).click();
  await loaded;

  ok(!doc.querySelector("addon-list"), "No more addon-list");
  assertViewHas(
    win,
    `addon-card[addon-id="${THEME_ID}"][expanded]`,
    "Detail view now"
  );

  loaded = waitForViewLoad(win);
  EventUtils.synthesizeMouseAtCenter(themeCategory, {}, win);
  await loaded;

  assertListView(win, "theme");

  loaded = waitForViewLoad(win);
  EventUtils.synthesizeMouseAtCenter(extensionCategory, {}, win);
  await loaded;

  assertListView(win, "extension");

  await closeView(win);
});

add_task(async function testClickingSidebarPaddingNoChange() {
  let win = await loadInitialView("theme");
  let categoryUtils = new CategoryUtilities(win);
  let themeCategory = categoryUtils.get("theme");

  let loadDetailView = async () => {
    let loaded = waitForViewLoad(win);
    getAddonCard(win, THEME_ID).click();
    await loaded;

    is(
      win.gViewController.currentViewId,
      `addons://detail/${THEME_ID}`,
      "The detail view loaded"
    );
  };

  // Confirm that clicking the button directly works.
  await loadDetailView();
  let loaded = waitForViewLoad(win);
  EventUtils.synthesizeMouseAtCenter(themeCategory, {}, win);
  await loaded;
  is(
    win.gViewController.currentViewId,
    `addons://list/theme`,
    "The detail view loaded"
  );

  // Confirm that clicking on the padding beside it does nothing.
  await loadDetailView();
  EventUtils.synthesizeMouse(themeCategory, -5, -5, {}, win);
  ok(!win.gViewController.isLoading, "No view is loading");

  await closeView(win);
});

add_task(async function testKeyboardUsage() {
  let win = await loadInitialView("extension");
  let categories = win.document.getElementById("categories");
  let extensionCategory = categories.getButtonByName("extension");
  let themeCategory = categories.getButtonByName("theme");
  let pluginCategory = categories.getButtonByName("plugin");

  let waitForAnimationFrame = () =>
    new Promise(resolve => win.requestAnimationFrame(resolve));
  let sendKey = (key, e = {}) => {
    EventUtils.synthesizeKey(key, e, win);
    return waitForAnimationFrame();
  };
  let sendTabKey = e => sendKey("VK_TAB", e);
  let isFocusInCategories = () =>
    categories.contains(win.document.activeElement);

  ok(!isFocusInCategories(), "Focus is not in the category list");

  // Tab to the first focusable element.
  await sendTabKey();

  ok(isFocusInCategories(), "Focus is in the category list");
  is(
    win.document.activeElement,
    extensionCategory,
    "The extension button is focused"
  );

  // Tab out of the categories list.
  await sendTabKey();
  ok(!isFocusInCategories(), "Focus is out of the category list");

  // Tab back into the list.
  await sendTabKey({ shiftKey: true });
  is(win.document.activeElement, extensionCategory, "Back on Extensions");

  // We're on the extension list.
  assertListView(win, "extension");

  // Switch to theme list.
  let loaded = waitForViewLoad(win);
  await sendKey("VK_DOWN");
  is(win.document.activeElement, themeCategory, "Themes is focused");
  await loaded;

  assertListView(win, "theme");

  loaded = waitForViewLoad(win);
  await sendKey("VK_DOWN");
  is(win.document.activeElement, pluginCategory, "Plugins is focused");
  await loaded;

  assertListView(win, "plugin");

  await sendKey("VK_DOWN");
  is(win.document.activeElement, pluginCategory, "Plugins is still focused");
  ok(!win.gViewController.isLoading, "No view is loading");

  loaded = waitForViewLoad(win);
  await sendKey("VK_UP");
  await loaded;
  loaded = waitForViewLoad(win);
  await sendKey("VK_UP");
  await loaded;
  is(win.document.activeElement, extensionCategory, "Extensions is focused");
  assertListView(win, "extension");

  await closeView(win);
});