summaryrefslogtreecommitdiffstats
path: root/dom/plugins/test/mochitest/browser_bug1196539.js
blob: 8b2210ccd08f8da800a158bb632f55e30a35f4b3 (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
var gTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");

function checkPaintCount(aCount) {
  ok(aCount != 0, "paint count can't be greater than zero, count was " + aCount);
  ok(aCount < kMaxPaints, "paint count should be within limits, count was " + aCount);
}

// maximum number of paints we allow before failing. The test plugin doesn't
// animate so this should really be just 1, but operating systems can
// occasionally fire a few of these so we give these tests a fudge factor.
// A bad regression would either be 0, or 100+.
const kMaxPaints = 10;

add_task(function* () {
  let result, tabSwitchedPromise;

  setTestPluginEnabledState(Ci.nsIPluginTag.STATE_ENABLED, "Test Plug-in");

  let testTab = gBrowser.selectedTab;
  let pluginTab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, gTestRoot + "plugin_test.html");
  let homeTab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:home");

  result = yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() {
    let doc = content.document;
    let plugin = doc.getElementById("testplugin");
    return !!plugin;
  });
  is(result, true, "plugin is loaded");

  result = yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() {
    let doc = content.document;
    let plugin = doc.getElementById("testplugin");
    return !XPCNativeWrapper.unwrap(plugin).nativeWidgetIsVisible();
  });
  is(result, true, "plugin is hidden");

  // reset plugin paint count
  yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() {
    let doc = content.document;
    let plugin = doc.getElementById("testplugin");
    XPCNativeWrapper.unwrap(plugin).resetPaintCount();
  });

  // select plugin tab
  tabSwitchedPromise = waitTabSwitched();
  gBrowser.selectedTab = pluginTab;
  yield tabSwitchedPromise;

  // wait a bit for spurious paints
  yield waitForMs(100);

  result = yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() {
    let doc = content.document;
    let plugin = doc.getElementById("testplugin");
    return XPCNativeWrapper.unwrap(plugin).nativeWidgetIsVisible();
  });
  is(result, true, "plugin is visible");

  // check for good paint count
  result = yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() {
    let doc = content.document;
    let plugin = doc.getElementById("testplugin");
    return XPCNativeWrapper.unwrap(plugin).getPaintCount();
  });
  checkPaintCount(result);

  // select home tab
  tabSwitchedPromise = waitTabSwitched();
  gBrowser.selectedTab = homeTab;
  yield tabSwitchedPromise;

  // reset paint count
  yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() {
    let doc = content.document;
    let plugin = doc.getElementById("testplugin");
    XPCNativeWrapper.unwrap(plugin).resetPaintCount();
  });

  // wait a bit for spurious paints
  yield waitForMs(100);

  // check for no paint count
  result = yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() {
    let doc = content.document;
    let plugin = doc.getElementById("testplugin");
    return XPCNativeWrapper.unwrap(plugin).getPaintCount();
  });
  is(result, 0, "no paints, this is correct.");

  result = yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() {
    let doc = content.document;
    let plugin = doc.getElementById("testplugin");
    return !XPCNativeWrapper.unwrap(plugin).nativeWidgetIsVisible();
  });
  is(result, true, "plugin is hidden");

  // reset paint count
  yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() {
    let doc = content.document;
    let plugin = doc.getElementById("testplugin");
    XPCNativeWrapper.unwrap(plugin).resetPaintCount();
  });

  // select plugin tab
  tabSwitchedPromise = waitTabSwitched();
  gBrowser.selectedTab = pluginTab;
  yield tabSwitchedPromise;

  // check paint count
  result = yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() {
    let doc = content.document;
    let plugin = doc.getElementById("testplugin");
    return XPCNativeWrapper.unwrap(plugin).getPaintCount();
  });
  checkPaintCount(result);

  gBrowser.removeTab(homeTab);
  gBrowser.removeTab(pluginTab);
});