browser/devtools/debugger/test/browser_dbg_bfcache.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/debugger/test/browser_dbg_bfcache.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,92 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Make sure that the debugger is updated with the correct sources when moving
     1.9 + * back and forward in the tab.
    1.10 + */
    1.11 +
    1.12 +const TAB_URL_1 = EXAMPLE_URL + "doc_script-switching-01.html";
    1.13 +const TAB_URL_2 = EXAMPLE_URL + "doc_recursion-stack.html";
    1.14 +
    1.15 +let gTab, gDebuggee, gPanel, gDebugger;
    1.16 +let gSources;
    1.17 +
    1.18 +function test() {
    1.19 +  initDebugger(TAB_URL_1).then(([aTab, aDebuggee, aPanel]) => {
    1.20 +    gTab = aTab;
    1.21 +    gDebuggee = aDebuggee;
    1.22 +    gPanel = aPanel;
    1.23 +    gDebugger = gPanel.panelWin;
    1.24 +    gSources = gDebugger.DebuggerView.Sources;
    1.25 +
    1.26 +    testFirstPage()
    1.27 +      .then(testLocationChange)
    1.28 +      .then(testBack)
    1.29 +      .then(testForward)
    1.30 +      .then(() => closeDebuggerAndFinish(gPanel))
    1.31 +      .then(null, aError => {
    1.32 +        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    1.33 +      });
    1.34 +  });
    1.35 +}
    1.36 +
    1.37 +function testFirstPage() {
    1.38 +  info("Testing first page.");
    1.39 +
    1.40 +  // Spin the event loop before causing the debuggee to pause, to allow
    1.41 +  // this function to return first.
    1.42 +  executeSoon(() => gDebuggee.firstCall());
    1.43 +
    1.44 +  return waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1).then(() => {
    1.45 +    validateFirstPage();
    1.46 +  });
    1.47 +}
    1.48 +
    1.49 +function testLocationChange() {
    1.50 +  info("Navigating to a different page.");
    1.51 +
    1.52 +  return navigateActiveTabTo(gPanel, TAB_URL_2, gDebugger.EVENTS.SOURCES_ADDED).then(() => {
    1.53 +    validateSecondPage();
    1.54 +  });
    1.55 +}
    1.56 +
    1.57 +function testBack() {
    1.58 +  info("Going back.");
    1.59 +
    1.60 +  return navigateActiveTabInHistory(gPanel, "back", gDebugger.EVENTS.SOURCES_ADDED).then(() => {
    1.61 +    validateFirstPage();
    1.62 +  });
    1.63 +}
    1.64 +
    1.65 +function testForward() {
    1.66 +  info("Going forward.");
    1.67 +
    1.68 +  return navigateActiveTabInHistory(gPanel, "forward", gDebugger.EVENTS.SOURCES_ADDED).then(() => {
    1.69 +    validateSecondPage();
    1.70 +  });
    1.71 +}
    1.72 +
    1.73 +function validateFirstPage() {
    1.74 +  is(gSources.itemCount, 2,
    1.75 +    "Found the expected number of sources.");
    1.76 +  ok(gSources.getItemForAttachment(e => e.label == "code_script-switching-01.js"),
    1.77 +    "Found the first source label.");
    1.78 +  ok(gSources.getItemForAttachment(e => e.label == "code_script-switching-02.js"),
    1.79 +    "Found the second source label.");
    1.80 +}
    1.81 +
    1.82 +function validateSecondPage() {
    1.83 +  is(gSources.itemCount, 1,
    1.84 +    "Found the expected number of sources.");
    1.85 +  ok(gSources.getItemForAttachment(e => e.label == "doc_recursion-stack.html"),
    1.86 +    "Found the single source label.");
    1.87 +}
    1.88 +
    1.89 +registerCleanupFunction(function() {
    1.90 +  gTab = null;
    1.91 +  gDebuggee = null;
    1.92 +  gPanel = null;
    1.93 +  gDebugger = null;
    1.94 +  gSources = null;
    1.95 +});

mercurial