[ui] Fix integration tests.

- Fix broken summary tracks when utids are identical.
- Refresh after track's onCreate completes to ensure tracks appear.
- A few tweaks and comments re track lifecycle.
- Fix screenshot test for correctly rendered non finishing slices, which
  were previously rendered incorrectly (no gradient) until the window
  moves.

Change-Id: I9d395ea5d9ff63e1519177517f216004c011de6e
diff --git a/test/data/ui-screenshots/ui-android_trace_30s_load.png.sha256 b/test/data/ui-screenshots/ui-android_trace_30s_load.png.sha256
index 05dac05..6cee1b2 100644
--- a/test/data/ui-screenshots/ui-android_trace_30s_load.png.sha256
+++ b/test/data/ui-screenshots/ui-android_trace_30s_load.png.sha256
@@ -1 +1 @@
-b301d6515efaffb58f8e8227ae5bcf6b78ea592b92f9037c2abe1954c6102b8e
\ No newline at end of file
+ec0a00856b147b2e13d0fe18666a307eb085ac437d67f78787131d4ea4190581
\ No newline at end of file
diff --git a/ui/src/common/state.ts b/ui/src/common/state.ts
index 6ba8547..1a8c68e 100644
--- a/ui/src/common/state.ts
+++ b/ui/src/common/state.ts
@@ -122,7 +122,8 @@
 // 39. Ported cpu_slice, ftrace, and android_log tracks to plugin tracks. Track
 //     state entries now require a URI and old track implementations are no
 //     longer registered.
-export const STATE_VERSION = 39;
+// 40. Ported counter, process summary/sched, & cpu_freq to plugin tracks.
+export const STATE_VERSION = 40;
 
 export const SCROLLING_TRACK_GROUP = 'ScrollingTracks';
 
diff --git a/ui/src/controller/track_decider.ts b/ui/src/controller/track_decider.ts
index 4be0a24..b4a8228 100644
--- a/ui/src/controller/track_decider.ts
+++ b/ui/src/controller/track_decider.ts
@@ -1677,7 +1677,7 @@
         pUuid = this.getOrCreateUuid(utid, upid);
         const summaryTrackId = uuidv4();
         const type = hasSched ? 'schedule' : 'summary';
-        const uri = `perfetto.ProcessScheduling#${utid}.${type}`;
+        const uri = `perfetto.ProcessScheduling#${upid}.${utid}.${type}`;
 
         this.tracksToAdd.push({
           id: summaryTrackId,
diff --git a/ui/src/frontend/track_panel.ts b/ui/src/frontend/track_panel.ts
index 64cfd63..2586f31 100644
--- a/ui/src/frontend/track_panel.ts
+++ b/ui/src/frontend/track_panel.ts
@@ -365,14 +365,18 @@
   private state = TrackLifecycleState.Initializing;
 
   constructor(private track: TrackLike) {
-    track.onCreate().then(() => {
+    track.onCreate().finally(() => {
       if (this.state === TrackLifecycleState.DestroyPending) {
-        track.onDestroy();
+        track.onDestroy().finally(() => {
+          this.state = TrackLifecycleState.Destroyed;
+        });
         this.state = TrackLifecycleState.Destroying;
       } else {
         this.state = TrackLifecycleState.Initialized;
+        raf.scheduleFullRedraw();
       }
     });
+    // TODO(stevegolton): Handle failure case.
   }
 
   onFullRedraw(): void {
@@ -450,7 +454,7 @@
         break;
       case TrackLifecycleState.Initialized:
         this.state = TrackLifecycleState.Destroying;
-        this.track.onDestroy().then(() => {
+        this.track.onDestroy().finally(() => {
           this.state = TrackLifecycleState.Destroyed;
         });
         break;
diff --git a/ui/src/tracks/process_summary/index.ts b/ui/src/tracks/process_summary/index.ts
index 4e46456..154ead0 100644
--- a/ui/src/tracks/process_summary/index.ts
+++ b/ui/src/tracks/process_summary/index.ts
@@ -208,7 +208,7 @@
         pUuid = this.getOrCreateUuid(utid, upid);
         const pidForColor = pid || tid || upid || utid || 0;
         const type = hasSched ? 'schedule' : 'summary';
-        const uri = `perfetto.ProcessScheduling#${utid}.${type}`;
+        const uri = `perfetto.ProcessScheduling#${upid}.${utid}.${type}`;
 
         if (hasSched) {
           const config: ProcessSchedulingTrackConfig = {