summaryrefslogtreecommitdiff
path: root/browser/devtools/debugger/test/browser_dbg_listtabs-03.js
blob: 26ccc6837a92f0eac124a9d3a556e509ab9be757 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Make sure the listTabs request works as specified.
 */

const TAB1_URL = EXAMPLE_URL + "doc_empty-tab-01.html";

let gTab1, gTab1Actor, gTab2, gTab2Actor, gClient;

function listTabs() {
  let deferred = promise.defer();

  gClient.listTabs(aResponse => {
    deferred.resolve(aResponse.tabs);
  });

  return deferred.promise;
}

function request(params) {
  let deferred = promise.defer();
  gClient.request(params, deferred.resolve);
  return deferred.promise;
}

function test() {
  if (!DebuggerServer.initialized) {
    DebuggerServer.init();
    DebuggerServer.addBrowserActors();
  }

  let transport = DebuggerServer.connectPipe();
  gClient = new DebuggerClient(transport);
  gClient.connect(Task.async(function*(aType, aTraits) {
    is(aType, "browser",
      "Root actor should identify itself as a browser.");
    let tab = yield addTab(TAB1_URL);

    let tabs = yield listTabs();
    is(tabs.length, 2, "Should be two tabs");
    let tabGrip = tabs.filter(a => a.url ==TAB1_URL).pop();
    ok(tabGrip, "Should have an actor for the tab");

    let response = yield request({ to: tabGrip.actor, type: "attach" });
    is(response.type, "tabAttached", "Should have attached");

    tabs = yield listTabs();

    response = yield request({ to: tabGrip.actor, type: "detach" });
    is(response.type, "detached", "Should have detached");

    let newGrip = tabs.filter(a => a.url ==TAB1_URL).pop();
    is(newGrip.actor, tabGrip.actor, "Should have the same actor for the same tab");

    response = yield request({ to: tabGrip.actor, type: "attach" });
    is(response.type, "tabAttached", "Should have attached");
    response = yield request({ to: tabGrip.actor, type: "detach" });
    is(response.type, "detached", "Should have detached");

    yield removeTab(tab);
    yield closeConnection();
    finish();
  }));
}

function closeConnection() {
  let deferred = promise.defer();
  gClient.close(deferred.resolve);
  return deferred.promise;
}

registerCleanupFunction(function() {
  gTab1 = null;
  gTab1Actor = null;
  gTab2 = null;
  gTab2Actor = null;
  gClient = null;
});