summaryrefslogtreecommitdiffstats
path: root/devtools/client/webide/test/test_autoselect_project.html
blob: cd579355994f7eebe9d023fa34f5a6c82112e23e (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!DOCTYPE html>

<html>

  <head>
    <meta charset="utf8">
    <title></title>

    <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    <script type="application/javascript" src="chrome://mochikit/content/chrome-harness.js"></script>
    <script type="application/javascript;version=1.8" src="head.js"></script>
    <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
  </head>

  <body>

    <script type="application/javascript;version=1.8">
      window.onload = function() {
        SimpleTest.waitForExplicitFinish();

        Task.spawn(function* () {
          if (!DebuggerServer.initialized) {
            DebuggerServer.init();
            DebuggerServer.addBrowserActors();
          }

          let win = yield openWebIDE();
          let docRuntime = getRuntimeDocument(win);
          let docProject = getProjectDocument(win);

          let panelNode = docRuntime.querySelector("#runtime-panel");
          let items = panelNode.querySelectorAll(".runtime-panel-item-other");
          is(items.length, 2, "Found 2 runtime buttons");

          // Connect to local runtime
          let connectionsChanged = waitForConnectionChange("opened", 2);
          items[1].click();

          yield waitForUpdate(win, "runtime-targets");

          yield connectionsChanged;
          is(Object.keys(DebuggerServer._connections).length, 2, "Locally connected");

          ok(win.AppManager.isMainProcessDebuggable(), "Main process available");

          // Select main process
          yield win.Cmds.showProjectPanel();
          yield waitForUpdate(win, "runtime-targets");
          SimpleTest.executeSoon(() => {
            docProject.querySelectorAll("#project-panel-runtimeapps .panel-item")[0].click();
          });

          yield waitForUpdate(win, "project");

          let lastProject = Services.prefs.getCharPref("devtools.webide.lastSelectedProject");
          is(lastProject, "mainProcess:", "Last project is main process");

          connectionsChanged = waitForConnectionChange("closed", 2);

          yield nextTick();
          yield closeWebIDE(win);

          yield connectionsChanged;
          is(Object.keys(DebuggerServer._connections).length, 0, "Disconnected");

          connectionsChanged = waitForConnectionChange("opened", 2);

          // Re-open, should reselect main process after connection
          win = yield openWebIDE();

          docRuntime = getRuntimeDocument(win);

          panelNode = docRuntime.querySelector("#runtime-panel");
          items = panelNode.querySelectorAll(".runtime-panel-item-other");
          is(items.length, 2, "Found 2 runtime buttons");

          // Connect to local runtime
          items[1].click();

          yield waitForUpdate(win, "runtime-targets");

          yield connectionsChanged;
          is(Object.keys(DebuggerServer._connections).length, 2, "Locally connected");
          ok(win.AppManager.isMainProcessDebuggable(), "Main process available");
          is(win.AppManager.selectedProject.type, "mainProcess", "Main process reselected");

          // Wait for the toolbox to be fully loaded
          yield win.UI.toolboxPromise;

          // If we happen to pass a project object targeting the same context,
          // here, the main process, the `selectedProject` attribute shouldn't be updated
          // so that no `project` event would fire.
          let oldProject = win.AppManager.selectedProject;
          win.AppManager.selectedProject = {
            type: "mainProcess"
          };
          is(win.AppManager.selectedProject, oldProject, "AppManager.selectedProject shouldn't be updated if we selected the same project");

          yield win.Cmds.disconnectRuntime();

          yield closeWebIDE(win);

          DebuggerServer.destroy();

          SimpleTest.finish();
        });
      }
    </script>
  </body>
</html>