File: browser_bug415846.js

package info (click to toggle)
firefox-esr 52.8.1esr-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 1,983,244 kB
  • sloc: cpp: 4,810,275; ansic: 2,004,548; python: 451,282; java: 241,615; asm: 178,649; xml: 136,302; sh: 82,207; makefile: 22,575; perl: 15,783; objc: 4,389; yacc: 1,816; ada: 1,697; pascal: 1,519; lex: 1,257; cs: 879; exp: 499; php: 436; lisp: 258; awk: 152; sed: 51; ruby: 47; csh: 27
file content (86 lines) | stat: -rw-r--r-- 2,912 bytes parent folder | download | duplicates (4)
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
/* Check for the correct behaviour of the report web forgery/not a web forgery
menu items.

Mac makes this astonishingly painful to test since their help menu is special magic,
but we can at least test it on the other platforms.*/

const NORMAL_PAGE = "http://example.com";
const PHISH_PAGE = "http://www.itisatrap.org/firefox/its-a-trap.html";

/**
 * Opens a new tab and browses to some URL, tests for the existence
 * of the phishing menu items, and then runs a test function to check
 * the state of the menu once opened. This function will take care of
 * opening and closing the menu.
 *
 * @param url (string)
 *        The URL to browse the tab to.
 * @param testFn (function)
 *        The function to run once the menu has been opened. This
 *        function will be passed the "reportMenu" and "errorMenu"
 *        DOM nodes as arguments, in that order. This function
 *        should not yield anything.
 * @returns Promise
 */
function check_menu_at_page(url, testFn) {
  return BrowserTestUtils.withNewTab({
    gBrowser,
    url: "about:blank",
  }, function*(browser) {
    // We don't get load events when the DocShell redirects to error
    // pages, but we do get DOMContentLoaded, so we'll wait for that.
    let dclPromise = ContentTask.spawn(browser, null, function*() {
      yield ContentTaskUtils.waitForEvent(this, "DOMContentLoaded", false);
    });
    browser.loadURI(url);
    yield dclPromise;

    let menu = document.getElementById("menu_HelpPopup");
    ok(menu, "Help menu should exist");

    let reportMenu =
      document.getElementById("menu_HelpPopup_reportPhishingtoolmenu");
    ok(reportMenu, "Report phishing menu item should exist");

    let errorMenu =
      document.getElementById("menu_HelpPopup_reportPhishingErrortoolmenu");
    ok(errorMenu, "Report phishing error menu item should exist");

    let menuOpen = BrowserTestUtils.waitForEvent(menu, "popupshown");
    menu.openPopup(null, "", 0, 0, false, null);
    yield menuOpen;

    testFn(reportMenu, errorMenu);

    let menuClose = BrowserTestUtils.waitForEvent(menu, "popuphidden");
    menu.hidePopup();
    yield menuClose;
  });
}

/**
 * Tests that we show the "Report this page" menu item at a normal
 * page.
 */
add_task(function*() {
  yield check_menu_at_page(NORMAL_PAGE, (reportMenu, errorMenu) => {
    ok(!reportMenu.hidden,
       "Report phishing menu should be visible on normal sites");
    ok(errorMenu.hidden,
       "Report error menu item should be hidden on normal sites");
  });
});

/**
 * Tests that we show the "Report this page is okay" menu item at
 * a reported attack site.
 */
add_task(function*() {
  yield check_menu_at_page(PHISH_PAGE, (reportMenu, errorMenu) => {
    ok(reportMenu.hidden,
       "Report phishing menu should be hidden on phishing sites");
    ok(!errorMenu.hidden,
       "Report error menu item should be visible on phishing sites");
  });
});