summaryrefslogtreecommitdiffstats
path: root/toolkit/components/places/tests/browser/browser_onvisit_title_null_for_navigation.js
blob: a7c583975a0cf71dd31fc95a5afa203cae4a75ad (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
const TEST_PATH = getRootDirectory(gTestPath).replace(
  "chrome://mochitests/content",
  "http://example.com"
);

add_task(async function checkTitleNotificationForNavigation() {
  const EXPECTED_URL = Services.io.newURI(TEST_PATH + "empty_page.html");

  const promiseVisit = PlacesTestUtils.waitForNotification(
    "page-visited",
    events => events[0].url === EXPECTED_URL.spec
  );

  const promiseTitle = PlacesTestUtils.waitForNotification(
    "page-title-changed",
    events => events[0].url === EXPECTED_URL.spec
  );

  let tab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    EXPECTED_URL.spec
  );

  const visitEvents = await promiseVisit;
  Assert.equal(visitEvents.length, 1, "Right number of visits notified");
  Assert.equal(visitEvents[0].type, "page-visited");
  info("'page-visited': " + visitEvents[0].url);
  Assert.equal(visitEvents[0].lastKnownTitle, null, "Should not have a title");

  const titleEvents = await promiseTitle;
  Assert.equal(titleEvents.length, 1, "Right number of title changed notified");
  Assert.equal(titleEvents[0].type, "page-title-changed");
  info("'page-title-changed': " + titleEvents[0].url);
  Assert.equal(
    titleEvents[0].title,
    "I am an empty page",
    "Should have correct title in titlechanged notification"
  );

  BrowserTestUtils.removeTab(tab);
});