summaryrefslogtreecommitdiffstats
path: root/devtools/client/framework/test/browser_toolbox_window_title_frame_select.js
blob: 42590ebf93f1d71fa38404e540989b1b7059fdf4 (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
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

/* import-globals-from shared-head.js */

"use strict";

/**
 * Check that the detached devtools window title is not updated when switching
 * the selected frame. Also check that frames command button has 'open'
 * attribute set when the list of frames is opened.
 */

var {Toolbox} = require("devtools/client/framework/toolbox");
const URL = URL_ROOT + "browser_toolbox_window_title_frame_select_page.html";
const IFRAME_URL = URL_ROOT + "browser_toolbox_window_title_changes_page.html";

add_task(function* () {
  Services.prefs.setBoolPref("devtools.command-button-frames.enabled", true);

  yield addTab(URL);
  let target = TargetFactory.forTab(gBrowser.selectedTab);
  let toolbox = yield gDevTools.showToolbox(target, null,
    Toolbox.HostType.BOTTOM);

  let onTitleChanged = waitForTitleChange(toolbox);
  yield toolbox.selectTool("inspector");
  yield onTitleChanged;

  yield toolbox.switchHost(Toolbox.HostType.WINDOW);
  // Wait for title change event *after* switch host, in order to listen
  // for the event on the WINDOW host window, which only exists after switchHost
  yield waitForTitleChange(toolbox);

  is(getTitle(), `Developer Tools - Page title - ${URL}`,
    "Devtools title correct after switching to detached window host");

  // Wait for tick to avoid unexpected 'popuphidden' event, which
  // blocks the frame popup menu opened below. See also bug 1276873
  yield waitForTick();

  // Open frame menu and wait till it's available on the screen.
  // Also check 'open' attribute on the command button.
  let btn = toolbox.doc.getElementById("command-button-frames");
  ok(!btn.getAttribute("open"), "The open attribute must not be present");
  let menu = toolbox.showFramesMenu({target: btn});
  yield once(menu, "open");

  is(btn.getAttribute("open"), "true", "The open attribute must be set");

  // Verify that the frame list menu is populated
  let frames = menu.items;
  is(frames.length, 2, "We have both frames in the list");

  let topFrameBtn = frames.filter(b => b.label == URL)[0];
  let iframeBtn = frames.filter(b => b.label == IFRAME_URL)[0];
  ok(topFrameBtn, "Got top level document in the list");
  ok(iframeBtn, "Got iframe document in the list");

  // Listen to will-navigate to check if the view is empty
  let willNavigate = toolbox.target.once("will-navigate");

  onTitleChanged = waitForTitleChange(toolbox);

  // Only select the iframe after we are able to select an element from the top
  // level document.
  let newRoot = toolbox.getPanel("inspector").once("new-root");
  info("Select the iframe");
  iframeBtn.click();

  yield willNavigate;
  yield newRoot;
  yield onTitleChanged;

  info("Navigation to the iframe is done, the inspector should be back up");
  is(getTitle(), `Developer Tools - Page title - ${URL}`,
    "Devtools title was not updated after changing inspected frame");

  info("Cleanup toolbox and test preferences.");
  yield toolbox.destroy();
  toolbox = null;
  gBrowser.removeCurrentTab();
  Services.prefs.clearUserPref("devtools.toolbox.host");
  Services.prefs.clearUserPref("devtools.toolbox.selectedTool");
  Services.prefs.clearUserPref("devtools.toolbox.sideEnabled");
  Services.prefs.clearUserPref("devtools.command-button-frames.enabled");
  finish();
});

function getTitle() {
  return Services.wm.getMostRecentWindow("devtools:toolbox").document.title;
}